Qt 4.8
qdatetime_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtCore module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QDATETIME_P_H
43 #define QDATETIME_P_H
44 
45 //
46 // W A R N I N G
47 // -------------
48 //
49 // This file is not part of the Qt API. It exists purely as an
50 // implementation detail. This header file may change from version to
51 // version without notice, or even be removed.
52 //
53 // We mean it.
54 //
55 
56 #include "qplatformdefs.h"
57 #include "QtCore/qatomic.h"
58 #include "QtCore/qdatetime.h"
59 #include "QtCore/qstringlist.h"
60 #include "QtCore/qlocale.h"
61 #ifndef QT_BOOTSTRAPPED
62 # include "QtCore/qvariant.h"
63 #endif
64 #include "QtCore/qvector.h"
65 
66 
67 #define QDATETIMEEDIT_TIME_MIN QTime(0, 0, 0, 0)
68 #define QDATETIMEEDIT_TIME_MAX QTime(23, 59, 59, 999)
69 #define QDATETIMEEDIT_DATE_MIN QDate(100, 1, 1)
70 #define QDATETIMEEDIT_COMPAT_DATE_MIN QDate(1752, 9, 14)
71 #define QDATETIMEEDIT_DATE_MAX QDate(7999, 12, 31)
72 #define QDATETIMEEDIT_DATETIME_MIN QDateTime(QDATETIMEEDIT_DATE_MIN, QDATETIMEEDIT_TIME_MIN)
73 #define QDATETIMEEDIT_COMPAT_DATETIME_MIN QDateTime(QDATETIMEEDIT_COMPAT_DATE_MIN, QDATETIMEEDIT_TIME_MIN)
74 #define QDATETIMEEDIT_DATETIME_MAX QDateTime(QDATETIMEEDIT_DATE_MAX, QDATETIMEEDIT_TIME_MAX)
75 #define QDATETIMEEDIT_DATE_INITIAL QDate(2000, 1, 1)
76 
78 
80 {
81 public:
82  enum Spec { LocalUnknown = -1, LocalStandard = 0, LocalDST = 1, UTC = 2, OffsetFromUTC = 3};
83 
86  : date(other.date), time(other.time), spec(other.spec), utcOffset(other.utcOffset)
87  {}
88 
103 
104  Spec getLocal(QDate &outDate, QTime &outTime) const;
105  void getUTC(QDate &outDate, QTime &outTime) const;
106  static QDateTime addMSecs(const QDateTime &dt, qint64 msecs);
107  static void addMSecs(QDate &utcDate, QTime &utcTime, qint64 msecs);
108 };
109 
110 #ifndef QT_BOOTSTRAPPED
111 
113 {
114 public:
115  enum Context {
117  DateTimeEdit
118  };
120  : currentSectionIndex(-1), display(0), cachedDay(-1), parserType(t),
121  fixday(false), spec(Qt::LocalTime), context(ctx)
122  {
123  defaultLocale = QLocale::system();
124  first.type = FirstSection;
125  first.pos = -1;
126  first.count = -1;
127  last.type = FirstSection;
128  last.pos = -1;
129  last.count = -1;
130  none.type = NoSection;
131  none.pos = -1;
132  none.count = -1;
133  }
134  virtual ~QDateTimeParser() {}
135  enum {
136  Neither = -1,
137  AM = 0,
138  PM = 1,
139  PossibleAM = 2,
140  PossiblePM = 3,
141  PossibleBoth = 4
142  };
143 
144  enum Section {
145  NoSection = 0x00000,
146  AmPmSection = 0x00001,
147  MSecSection = 0x00002,
148  SecondSection = 0x00004,
149  MinuteSection = 0x00008,
150  Hour12Section = 0x00010,
151  Hour24Section = 0x00020,
152  TimeSectionMask = (AmPmSection|MSecSection|SecondSection|MinuteSection|Hour12Section|Hour24Section),
153  Internal = 0x10000,
154  DaySection = 0x00100,
155  MonthSection = 0x00200,
156  YearSection = 0x00400,
157  YearSection2Digits = 0x00800,
158  DayOfWeekSection = 0x01000,
159  DateSectionMask = (DaySection|MonthSection|YearSection|YearSection2Digits|DayOfWeekSection),
160  FirstSection = 0x02000|Internal,
161  LastSection = 0x04000|Internal,
162  CalendarPopupSection = 0x08000|Internal,
163 
164  NoSectionIndex = -1,
165  FirstSectionIndex = -2,
166  LastSectionIndex = -3,
167  CalendarPopupIndex = -4
168  }; // duplicated from qdatetimeedit.h
169  Q_DECLARE_FLAGS(Sections, Section)
170 
171  struct SectionNode {
173  mutable int pos;
174  int count;
175  };
176 
177  enum State { // duplicated from QValidator
180  Acceptable
181  };
182 
183  struct StateNode {
184  StateNode() : state(Invalid), conflicts(false) {}
187  bool conflicts;
189  };
190 
191  enum AmPm {
193  PmText
194  };
195 
196  enum Case {
198  LowerCase
199  };
200 
201 #ifndef QT_NO_DATESTRING
202  StateNode parse(QString &input, int &cursorPosition, const QDateTime &currentValue, bool fixup) const;
203 #endif
204  int sectionMaxSize(int index) const;
205  int sectionSize(int index) const;
206  int sectionMaxSize(Section s, int count) const;
207  int sectionPos(int index) const;
208  int sectionPos(const SectionNode &sn) const;
209 
210  const SectionNode &sectionNode(int index) const;
211  Section sectionType(int index) const;
212  QString sectionText(int sectionIndex) const;
213  QString sectionText(const QString &text, int sectionIndex, int index) const;
214  int getDigit(const QDateTime &dt, int index) const;
215  bool setDigit(QDateTime &t, int index, int newval) const;
216  int parseSection(const QDateTime &currentValue, int sectionIndex, QString &txt, int &cursorPosition,
217  int index, QDateTimeParser::State &state, int *used = 0) const;
218  int absoluteMax(int index, const QDateTime &value = QDateTime()) const;
219  int absoluteMin(int index) const;
220  bool parseFormat(const QString &format);
221 #ifndef QT_NO_DATESTRING
222  bool fromString(const QString &text, QDate *date, QTime *time) const;
223 #endif
224 
225 #ifndef QT_NO_TEXTDATE
226  int findMonth(const QString &str1, int monthstart, int sectionIndex,
227  QString *monthName = 0, int *used = 0) const;
228  int findDay(const QString &str1, int intDaystart, int sectionIndex,
229  QString *dayName = 0, int *used = 0) const;
230 #endif
231  int findAmPm(QString &str1, int index, int *used = 0) const;
232  int maxChange(int s) const;
233  bool potentialValue(const QString &str, int min, int max, int index,
234  const QDateTime &currentValue, int insert) const;
235  bool skipToNextSection(int section, const QDateTime &current, const QString &sectionText) const;
236  QString sectionName(int s) const;
237  QString stateName(int s) const;
238 
239  QString sectionFormat(int index) const;
240  QString sectionFormat(Section s, int count) const;
241 
243  Numeric = 0x01,
244  FixedWidth = 0x02,
245  AllowPartial = 0x04,
246  Fraction = 0x08
247  };
248  Q_DECLARE_FLAGS(FieldInfo, FieldInfoFlag)
249 
250  FieldInfo fieldInfo(int index) const;
251 
252  virtual QDateTime getMinimum() const;
253  virtual QDateTime getMaximum() const;
254  virtual int cursorPosition() const { return -1; }
255  virtual QString displayText() const { return text; }
256  virtual QString getAmPmText(AmPm ap, Case cs) const;
257  virtual QLocale locale() const { return defaultLocale; }
258 
259  mutable int currentSectionIndex;
260  Sections display;
261  mutable int cachedDay;
262  mutable QString text;
264  SectionNode first, last, none, popup;
269 
270  bool fixday;
271 
272  Qt::TimeSpec spec; // spec if used by QDateTimeEdit
274 };
275 
277 
278 Q_DECLARE_OPERATORS_FOR_FLAGS(QDateTimeParser::Sections)
279 Q_DECLARE_OPERATORS_FOR_FLAGS(QDateTimeParser::FieldInfo)
280 
281 #ifdef Q_OS_SYMBIAN
282 QDateTime qt_symbian_TTime_To_QDateTime(const TTime& time);
283 TTime qt_symbian_QDateTime_To_TTime(const QDateTime& datetime);
284 time_t qt_symbian_TTime_To_time_t(const TTime& time);
285 TTime qt_symbian_time_t_To_TTime(time_t time);
286 #endif //Q_OS_SYMBIAN
287 
288 #endif // QT_BOOTSTRAPPED
289 
291 
292 #endif // QDATETIME_P_H
virtual QString displayText() const
Definition: qdatetime_p.h:255
Q_CORE_EXPORT bool operator==(const QDateTimeParser::SectionNode &s1, const QDateTimeParser::SectionNode &s2)
Definition: qdatetime.cpp:6137
SectionNode popup
Definition: qdatetime_p.h:264
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
virtual QLocale locale() const
Definition: qdatetime_p.h:257
#define Q_DECLARE_FLAGS(Flags, Enum)
The Q_DECLARE_FLAGS() macro expands to.
Definition: qglobal.h:2348
The QAtomicInt class provides platform-independent atomic operations on integers. ...
Definition: qatomic.h:55
QVector< SectionNode > sectionNodes
Definition: qdatetime_p.h:263
The QDate class provides date functions.
Definition: qdatetime.h:55
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
static QLocale system()
Returns a QLocale object initialized to the system locale.
Definition: qlocale.cpp:1917
QAtomicInt ref
Definition: qdatetime_p.h:89
TimeSpec
Definition: qnamespace.h:1404
The QTime class provides clock time functions.
Definition: qdatetime.h:148
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QVariant::Type parserType
Definition: qdatetime_p.h:268
Q_GUI_EXPORT EGLDisplay display()
Definition: qegl.cpp:589
#define Q_DECLARE_OPERATORS_FOR_FLAGS(Flags)
The Q_DECLARE_OPERATORS_FOR_FLAGS() macro declares global operator|() functions for Flags...
Definition: qglobal.h:2355
unsigned long time_t
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
Type
This enum type defines the types of variable that a QVariant can contain.
Definition: qvariant.h:95
void getUTC(QDate &outDate, QTime &outTime) const
Definition: qdatetime.cpp:4422
__int64 qint64
Definition: qglobal.h:942
The State element defines configurations of objects and properties.
QStringList separators
Definition: qdatetime_p.h:265
virtual int cursorPosition() const
Definition: qdatetime_p.h:254
Qt::TimeSpec spec
Definition: qdatetime_p.h:272
static QDateTime addMSecs(const QDateTime &dt, qint64 msecs)
Definition: qdatetime.cpp:2814
QDateTimeParser(QVariant::Type t, Context ctx)
Definition: qdatetime_p.h:119
The QDateTime class provides date and time functions.
Definition: qdatetime.h:216
int utcOffset
The offset in seconds.
Definition: qdatetime_p.h:102
#define Q_CORE_EXPORT
Definition: qglobal.h:1449
Sections display
Definition: qdatetime_p.h:260
virtual ~QDateTimeParser()
Definition: qdatetime_p.h:134
#define ctx
Definition: qgl.cpp:6094
Spec getLocal(QDate &outDate, QTime &outTime) const
Definition: qdatetime.cpp:4413
Definition: qnamespace.h:54
quint16 index
QLocale defaultLocale
Definition: qdatetime_p.h:267
QDateTimePrivate(const QDateTimePrivate &other)
Definition: qdatetime_p.h:85
QString displayFormat
Definition: qdatetime_p.h:266
#define text
Definition: qobjectdefs.h:80