X-Git-Url: https://vaikene.ee/gitweb/pswgen11.html?a=blobdiff_plain;f=src%2Fapps%2FScosTime%2Fgui.h;h=1d7483bcfc5dd1b9de639bf487ce74699636aeb2;hb=4c0329c5c2690bde28212c89029015a5da4c7e34;hp=90f33c2f90edf3e269acf84c022e355ce79d0d30;hpb=2bf3bf2e6edd9cb9e56cf21bfec76b2a0f983ada;p=evaf diff --git a/src/apps/ScosTime/gui.h b/src/apps/ScosTime/gui.h index 90f33c2..1d7483b 100644 --- a/src/apps/ScosTime/gui.h +++ b/src/apps/ScosTime/gui.h @@ -3,7 +3,7 @@ * @brief GUI for the ScosTime application * @author Enar Vaikene * - * Copyright (c) 2012 Enar Vaikene + * Copyright (c) 2012-2019 Enar Vaikene * * This file is part of the eVaf C++ cross-platform application development framework. * @@ -20,6 +20,8 @@ #ifndef __SCOSTIME_GUI_H # define __SCOSTIME_GUI_H +#include "version.h" + #include #include @@ -43,15 +45,30 @@ class DateTime { public: + /// Type of the date/time entry + enum Type + { + Invalid, + ASD, + ISO, + CUC + }; + + /** + * Creates an invalid date/time value with the default epoch + */ + DateTime(); + /** - * Creates an invalid date/time value + * Dtor */ - DateTime() {} + ~DateTime(); /** - * Creates a date/time value from the string. + * Sets the date/time value from a string. * @param s Input string * @param epoch Epoch + * @return Type of the input string * * The input string can be: * @li Date/time in ISO format yyyy-MM-ddThh:mm[:ss[.zzz]] @@ -60,37 +77,93 @@ public: * * If the string is invalid, creates an invalid date/time value. */ - DateTime(String const & s, String const & epoch); + Type setDateTime(QString const & s, QDateTime const & epoch); + + /** + * Sets the date/time value from a string using the previously set epoch. + * @param s Input string + * @return Type of the input string + * + * The input string can be: + * @li Date/time in ISO format yyyy-MM-ddThh:mm[:ss[.zzz]] + * @li Date/time in ASD format yyyy.ddd.hh.mm[.ss[.zzz]] + * @li CUC hex string cccccccc[ffff] + * + * If the input string is invalid or no epoch is set, creates an invalid + * date/time value. + */ + Type setDateTime(QString const & s); + + /** + * Sets the epoch + * @param epoch Epoch + */ + void setEpoch(QDateTime const & epoch); + + /** + * Returns the current epoch + */ + QDateTime const & epoch() const { return mEpoch; } /** * Returns true if the date/time value is valid. */ bool isValid() const { return mDateTime.isValid(); } + /** + * Returns the type of the date/time string from which the date/time + * value was created. + */ + Type type() const { return mType; } + + /** + * Returns the current date/time value + */ + QDateTime const & dateTime() const { return mDateTime; } + /** * Returns the date/time value a string in the ISO format yyyy-MM-ddThh:mm:ss.zzz */ - QString asIsoString() const; + QString asISOstring() const; /** * Returns the date/time value as a string in the ASD format yyyy.ddd.hh.mm.ss.zzz */ - QString asAsdString() const; + QString asASDstring() const; /** * Returns the date/time value as a CUC hex string in the format ccccccccffff */ - QString asCucHexString() const; + QString asCUChexString() const; -private: +private: // methods - /// Date/time value - QDateTime mDateTime; + Type getDateTimeType(QString const & s) const; + + QDateTime strToDateTime(QString const & s, Type t) const; + + +private: // members + + /// Type of the input string + Type mType; /// Epoch QDateTime mEpoch; + /// Date/time value + QDateTime mDateTime; + + /// Regular expression for ISO date/time strings + QRegExp * mRxIso; + + /// Regular expression for ASD date/time strings + QRegExp * mRxAsd; + + /// Regular expression for CUC date/time strings + QRegExp * mRxCUC; + }; } // namespace eVaf::ScosTime::Internal @@ -104,13 +177,7 @@ class Module : public Plugins::iPlugin { Q_OBJECT Q_INTERFACES(eVaf::Plugins::iPlugin) - - enum DateTimeType - { - InvalidDateTime, - AsdDateTime, - IsoDateTime - }; + Q_PLUGIN_METADATA(IID VER_MODULE_NAME_STR) enum ValidEntry { @@ -145,28 +212,17 @@ private slots: private: // Methods - DateTimeType getDateTimeType(QString const & s) const; - - QDateTime strToDateTime(QString const & s, DateTimeType type) const; - - QString dateTimeToAsdStr(QDateTime const & tm) const; - - void setDateTimeFromCucHex(QString const & s); - - void setCucHexFromDateTime(QString const & s, DateTimeType type); - private: // Members /// Flag indicating that the module is ready bool mReady; - /// Last valid entry (field modified by the user) - ValidEntry mLastValidEntry; + /// Current date/time value + Internal::DateTime mDateTime; - /// Regular expressions - QRegExp * rxIsoDateTime; - QRegExp * rxAsdDateTime; + /// Last date/time format type used in the date/time entry field + Internal::DateTime::Type mLastDateTimeType; /// Widgets on the screen QComboBox * wEpoch;