Engauge Digitizer  2
FormatDateTime.h
1 /******************************************************************************************************
2  * (C) 2014 markummitchell@github.com. This file is part of Engauge Digitizer, which is released *
3  * under GNU General Public License version 2 (GPLv2) or (at your option) any later version. See file *
4  * LICENSE or go to gnu.org/licenses for details. Distribution requires prior written permission. *
5  ******************************************************************************************************/
6 
7 #ifndef FORMAT_DATE_TIME_H
8 #define FORMAT_DATE_TIME_H
9 
10 #include "CoordUnitsDate.h"
11 #include "CoordUnitsTime.h"
12 #include <QDateTime>
13 #include <QHash>
14 #include <QString>
15 #include <QStringList>
16 #include <QValidator>
17 
18 typedef QHash<CoordUnitsDate, QString> FormatDate;
19 typedef QHash<CoordUnitsTime, QString> FormatTime;
20 
21 typedef QHash<CoordUnitsDate, QStringList> FormatsDate;
22 typedef QHash<CoordUnitsTime, QStringList> FormatsTime;
23 
26  public:
29 
31  QString formatOutput (CoordUnitsDate coordUnitsDate,
32  CoordUnitsTime coordUnitsTime,
33  double value) const;
34 
37  QValidator::State parseInput (CoordUnitsDate coordUnitsDate,
38  CoordUnitsTime coordUnitsTime,
39  const QString &stringUntrimmed,
40  double &value) const;
41 
42  private:
43 
44  bool ambiguityBetweenDateAndTime (CoordUnitsDate coordUnitsDate,
45  CoordUnitsTime coordUnitsTime,
46  const QString &string) const;
47  void dateTimeLookup (const FormatsDate &formatsDate,
48  const FormatsTime &formatsTime,
49  CoordUnitsDate coordUnitsDate,
50  CoordUnitsTime coordUnitsTime,
51  const QString &string,
52  bool useQDateTimeElseQRegExp,
53  double &value, // Set only if useQDateTimeElseQRegExp=success=true
54  bool &success) const;
55  void loadFormatsFormat();
56  void loadFormatsParseAcceptable();
57  void loadFormatsParseIncomplete();
58 
59  // For formatting output
60  FormatDate m_formatsDateFormat;
61  FormatTime m_formatsTimeFormat;
62 
63  // For parsing input, using built in Qt date/time parsing according to QDateTime
64  FormatsDate m_formatsDateParseAcceptable;
65  FormatsTime m_formatsTimeParseAcceptable;
66 
67  // For parsing input, after input has been found to not be Acceptable. Regular expressions are used since Qt date/time
68  // parsing of Intermediate strings does not work. Example, 'J' and 'Ja' would be rejected although they are typed
69  // in the process of entering 'Jan' for the month
70  FormatsDate m_formatsDateParseIncomplete;
71  FormatsTime m_formatsTimeParseIncomplete;
72 };
73 
74 #endif // FORMAT_DATE_TIME_H
FormatDateTime()
Single constructor.
QValidator::State parseInput(CoordUnitsDate coordUnitsDate, CoordUnitsTime coordUnitsTime, const QString &stringUntrimmed, double &value) const
Parse the input string into a time value.
Input parsing and output formatting for date/time values.
QString formatOutput(CoordUnitsDate coordUnitsDate, CoordUnitsTime coordUnitsTime, double value) const
Format the date/time value according to date/time format settings.