]> vaikene.ee Git - evaf/blob - src/apps/ScosTime/gui.h
1ce7972344dfb574bacde9050f66c03385adb0f8
[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 /// Type of the date/time entry
47 enum Type
48 {
49 Invalid,
50 ASD,
51 ISO,
52 CUC
53 };
54
55 /**
56 * Creates an invalid date/time value with the default epoch
57 */
58 DateTime();
59
60 /**
61 * Dtor
62 */
63 ~DateTime();
64
65 /**
66 * Sets the date/time value from a string.
67 * @param s Input string
68 * @param epoch Epoch
69 * @return Type of the input string
70 *
71 * The input string can be:
72 * @li Date/time in ISO format yyyy-MM-ddThh:mm[:ss[.zzz]]
73 * @li Date/time in ASD format yyyy.ddd.hh.mm[.ss[.zzz]]
74 * @li CUC hex string cccccccc[ffff]
75 *
76 * If the string is invalid, creates an invalid date/time value.
77 */
78 Type setDateTime(QString const & s, QDateTime const & epoch);
79
80 /**
81 * Sets the date/time value from a string using the previously set epoch.
82 * @param s Input string
83 * @return Type of the input string
84 *
85 * The input string can be:
86 * @li Date/time in ISO format yyyy-MM-ddThh:mm[:ss[.zzz]]
87 * @li Date/time in ASD format yyyy.ddd.hh.mm[.ss[.zzz]]
88 * @li CUC hex string cccccccc[ffff]
89 *
90 * If the input string is invalid or no epoch is set, creates an invalid
91 * date/time value.
92 */
93 Type setDateTime(QString const & s);
94
95 /**
96 * Sets the epoch
97 * @param epoch Epoch
98 */
99 void setEpoch(QDateTime const & epoch);
100
101 /**
102 * Returns the current epoch
103 */
104 QDateTime const & epoch() const { return mEpoch; }
105
106 /**
107 * Returns true if the date/time value is valid.
108 */
109 bool isValid() const { return mDateTime.isValid(); }
110
111 /**
112 * Returns the type of the date/time string from which the date/time
113 * value was created.
114 */
115 Type type() const { return mType; }
116
117 /**
118 * Returns the current date/time value
119 */
120 QDateTime const & dateTime() const { return mDateTime; }
121
122 /**
123 * Returns the date/time value a string in the ISO format yyyy-MM-ddThh:mm:ss.zzz
124 */
125 QString asISOstring() const;
126
127 /**
128 * Returns the date/time value as a string in the ASD format yyyy.ddd.hh.mm.ss.zzz
129 */
130 QString asASDstring() const;
131
132 /**
133 * Returns the date/time value as a CUC hex string in the format ccccccccffff
134 */
135 QString asCUChexString() const;
136
137
138 private: // methods
139
140 Type getDateTimeType(QString const & s) const;
141
142 QDateTime strToDateTime(QString const & s, Type t) const;
143
144
145 private: // members
146
147 /// Type of the input string
148 Type mType;
149
150 /// Epoch
151 QDateTime mEpoch;
152
153 /// Date/time value
154 QDateTime mDateTime;
155
156 /// Regular expression for ISO date/time strings
157 QRegExp * mRxIso;
158
159 /// Regular expression for ASD date/time strings
160 QRegExp * mRxAsd;
161
162 /// Regular expression for CUC date/time strings
163 QRegExp * mRxCUC;
164
165 };
166
167 } // namespace eVaf::ScosTime::Internal
168
169 /**
170 * Graphical User Interface for the ScosTime application.
171 *
172 * This module adds a GUI window to the ScosTime application using the SdiWindow module.
173 */
174 class Module : public Plugins::iPlugin
175 {
176 Q_OBJECT
177 Q_INTERFACES(eVaf::Plugins::iPlugin)
178
179 enum ValidEntry
180 {
181 NoValidEntry,
182 DateTimeEntry,
183 CUCEntry
184 };
185
186 public:
187
188 Module();
189
190 virtual ~Module();
191
192 virtual bool init(const QString & args);
193
194 virtual void done();
195
196 virtual bool isReady() const { return mReady; }
197
198
199 private slots:
200
201 void epochChanged(QString const & s);
202
203 void dateTimeClicked();
204
205 void dateTimeEdited(QString const & s);
206
207 void cucHexEdited(QString const & s);
208
209
210 private: // Methods
211
212
213 private: // Members
214
215 /// Flag indicating that the module is ready
216 bool mReady;
217
218 /// Current date/time value
219 Internal::DateTime mDateTime;
220
221 /// Last date/time format type used in the date/time entry field
222 Internal::DateTime::Type mLastDateTimeType;
223
224 /// Widgets on the screen
225 QComboBox * wEpoch;
226 QLineEdit * wDateTime;
227 QPushButton * wConvertDateTime;
228 QLineEdit * wCucHex;
229
230 };
231
232 } // namespace eVaf::ScosTime
233 } // namespace eVaf
234
235 #endif // gui.h