X-Git-Url: https://vaikene.ee/gitweb/gitweb.cgi?p=evaf;a=blobdiff_plain;f=src%2Fapps%2FScosTime%2Fgui.h;fp=src%2Fapps%2FScosTime%2Fgui.h;h=42516e5ec736af20be2a74a0a9fe776a55c3143d;hp=581760bc1daaab003b29e944dbd2c4593067d894;hb=0c61450fcffcb36a6e23ca5b083c26543d956084;hpb=a81a943bee20df3c7eb34bafb3e3fe878facfe4e diff --git a/src/apps/ScosTime/gui.h b/src/apps/ScosTime/gui.h index 581760b..42516e5 100644 --- a/src/apps/ScosTime/gui.h +++ b/src/apps/ScosTime/gui.h @@ -30,10 +30,144 @@ class QLineEdit; class QComboBox; +class QRegExp; +class QPushButton; namespace eVaf { namespace ScosTime { +namespace Internal { + +/** + * SCOS date/time class + */ +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(); + + /** + * Dtor + */ + ~DateTime(); + + /** + * 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]] + * @li Date/time in ASD format yyyy.ddd.hh.mm[.ss[.zzz]] + * @li CUC hex string cccccccc[ffff] + * + * If the string is invalid, creates an invalid date/time value. + */ + 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; + + /** + * Returns the date/time value as a string in the ASD format yyyy.ddd.hh.mm.ss.zzz + */ + QString asASDstring() const; + + /** + * Returns the date/time value as a CUC hex string in the format ccccccccffff + */ + QString asCUChexString() const; + + +private: // methods + + 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 + /** * Graphical User Interface for the ScosTime application. * @@ -45,6 +179,13 @@ class Module : public Plugins::iPlugin Q_INTERFACES(eVaf::Plugins::iPlugin) Q_PLUGIN_METADATA(IID VER_MODULE_NAME_STR) + enum ValidEntry + { + NoValidEntry, + DateTimeEntry, + CUCEntry + }; + public: Module(); @@ -60,24 +201,34 @@ public: private slots: + void epochChanged(QString const & s); + void dateTimeClicked(); - void hexClicked(); + void dateTimeEdited(QString const & s); + + void cucHexEdited(QString const & s); private: // Methods - QDateTime strToDateTime(QString const & s) const; private: // Members /// Flag indicating that the module is ready bool mReady; + /// Current date/time value + Internal::DateTime mDateTime; + + /// Last date/time format type used in the date/time entry field + Internal::DateTime::Type mLastDateTimeType; + /// Widgets on the screen QComboBox * wEpoch; QLineEdit * wDateTime; - QLineEdit * wHex; + QPushButton * wConvertDateTime; + QLineEdit * wCucHex; };