]> vaikene.ee Git - evaf/blob - src/apps/ScosTime/gui.h
90f33c2f90edf3e269acf84c022e355ce79d0d30
[evaf] / src / apps / ScosTime / gui.h
1 /**
2 * @file ScosTime/gui.h
3 * @brief GUI for the ScosTime application
4 * @author Enar Vaikene
5 *
6 * Copyright (c) 2012 Enar Vaikene
7 *
8 * This file is part of the eVaf C++ cross-platform application development framework.
9 *
10 * This file can be used under the terms of the GNU General Public License
11 * version 3.0 as published by the Free Software Foundation and appearing in
12 * the file LICENSE included in the packaging of this file. Please review the
13 * the following information to ensure the GNU General Public License version
14 * 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
15 *
16 * Alternatively, this file may be used in accordance with the Commercial License
17 * Agreement provided with the Software.
18 */
19
20 #ifndef __SCOSTIME_GUI_H
21 # define __SCOSTIME_GUI_H
22
23 #include <Plugins/iPlugin>
24
25 #include <QObject>
26 #include <QString>
27 #include <QDateTime>
28
29 class QLineEdit;
30 class QComboBox;
31 class QRegExp;
32 class QPushButton;
33
34 namespace eVaf {
35 namespace ScosTime {
36
37 namespace Internal {
38
39 /**
40 * SCOS date/time class
41 */
42 class DateTime
43 {
44 public:
45
46 /**
47 * Creates an invalid date/time value
48 */
49 DateTime() {}
50
51 /**
52 * Creates a date/time value from the string.
53 * @param s Input string
54 * @param epoch Epoch
55 *
56 * The input string can be:
57 * @li Date/time in ISO format yyyy-MM-ddThh:mm[:ss[.zzz]]
58 * @li Date/time in ASD format yyyy.ddd.hh.mm[.ss[.zzz]]
59 * @li CUC hex string cccccccc[ffff]
60 *
61 * If the string is invalid, creates an invalid date/time value.
62 */
63 DateTime(String const & s, String const & epoch);
64
65 /**
66 * Returns true if the date/time value is valid.
67 */
68 bool isValid() const { return mDateTime.isValid(); }
69
70 /**
71 * Returns the date/time value a string in the ISO format yyyy-MM-ddThh:mm:ss.zzz
72 */
73 QString asIsoString() const;
74
75 /**
76 * Returns the date/time value as a string in the ASD format yyyy.ddd.hh.mm.ss.zzz
77 */
78 QString asAsdString() const;
79
80 /**
81 * Returns the date/time value as a CUC hex string in the format ccccccccffff
82 */
83 QString asCucHexString() const;
84
85
86 private:
87
88 /// Date/time value
89 QDateTime mDateTime;
90
91 /// Epoch
92 QDateTime mEpoch;
93
94 };
95
96 } // namespace eVaf::ScosTime::Internal
97
98 /**
99 * Graphical User Interface for the ScosTime application.
100 *
101 * This module adds a GUI window to the ScosTime application using the SdiWindow module.
102 */
103 class Module : public Plugins::iPlugin
104 {
105 Q_OBJECT
106 Q_INTERFACES(eVaf::Plugins::iPlugin)
107
108 enum DateTimeType
109 {
110 InvalidDateTime,
111 AsdDateTime,
112 IsoDateTime
113 };
114
115 enum ValidEntry
116 {
117 NoValidEntry,
118 DateTimeEntry,
119 CUCEntry
120 };
121
122 public:
123
124 Module();
125
126 virtual ~Module();
127
128 virtual bool init(const QString & args);
129
130 virtual void done();
131
132 virtual bool isReady() const { return mReady; }
133
134
135 private slots:
136
137 void epochChanged(QString const & s);
138
139 void dateTimeClicked();
140
141 void dateTimeEdited(QString const & s);
142
143 void cucHexEdited(QString const & s);
144
145
146 private: // Methods
147
148 DateTimeType getDateTimeType(QString const & s) const;
149
150 QDateTime strToDateTime(QString const & s, DateTimeType type) const;
151
152 QString dateTimeToAsdStr(QDateTime const & tm) const;
153
154 void setDateTimeFromCucHex(QString const & s);
155
156 void setCucHexFromDateTime(QString const & s, DateTimeType type);
157
158
159 private: // Members
160
161 /// Flag indicating that the module is ready
162 bool mReady;
163
164 /// Last valid entry (field modified by the user)
165 ValidEntry mLastValidEntry;
166
167 /// Regular expressions
168 QRegExp * rxIsoDateTime;
169 QRegExp * rxAsdDateTime;
170
171 /// Widgets on the screen
172 QComboBox * wEpoch;
173 QLineEdit * wDateTime;
174 QPushButton * wConvertDateTime;
175 QLineEdit * wCucHex;
176
177 };
178
179 } // namespace eVaf::ScosTime
180 } // namespace eVaf
181
182 #endif // gui.h