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