author | eckhart.koppen@nokia.com |
Wed, 31 Mar 2010 11:06:36 +0300 | |
changeset 7 | f7bc934e204c |
parent 0 | 1918ee327afb |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
7
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtCore module of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
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 |
||
77 |
QT_BEGIN_NAMESPACE |
|
78 |
||
79 |
class QDateTimePrivate |
|
80 |
{ |
|
81 |
public: |
|
82 |
enum Spec { LocalUnknown = -1, LocalStandard = 0, LocalDST = 1, UTC = 2, OffsetFromUTC = 3}; |
|
83 |
||
84 |
QDateTimePrivate() : spec(LocalUnknown), utcOffset(0) {} |
|
85 |
QDateTimePrivate(const QDateTimePrivate &other) |
|
86 |
: date(other.date), time(other.time), spec(other.spec), utcOffset(other.utcOffset) |
|
87 |
{} |
|
88 |
||
89 |
QAtomicInt ref; |
|
90 |
QDate date; |
|
91 |
QTime time; |
|
92 |
Spec spec; |
|
93 |
/*! |
|
94 |
\internal |
|
95 |
\since 4.4 |
|
96 |
||
97 |
The offset in seconds. Applies only when timeSpec() is OffsetFromUTC. |
|
98 |
*/ |
|
99 |
int utcOffset; |
|
100 |
||
101 |
Spec getLocal(QDate &outDate, QTime &outTime) const; |
|
102 |
void getUTC(QDate &outDate, QTime &outTime) const; |
|
103 |
static QDateTime addMSecs(const QDateTime &dt, qint64 msecs); |
|
104 |
static void addMSecs(QDate &utcDate, QTime &utcTime, qint64 msecs); |
|
105 |
}; |
|
106 |
||
107 |
#ifndef QT_BOOTSTRAPPED |
|
108 |
||
109 |
class Q_CORE_EXPORT QDateTimeParser |
|
110 |
{ |
|
111 |
public: |
|
112 |
enum Context { |
|
113 |
FromString, |
|
114 |
DateTimeEdit |
|
115 |
}; |
|
116 |
QDateTimeParser(QVariant::Type t, Context ctx) |
|
117 |
: currentSectionIndex(-1), display(0), cachedDay(-1), parserType(t), |
|
118 |
fixday(false), spec(Qt::LocalTime), context(ctx) |
|
119 |
{ |
|
120 |
defaultLocale = QLocale::system(); |
|
121 |
first.type = FirstSection; |
|
122 |
first.pos = -1; |
|
123 |
first.count = -1; |
|
124 |
last.type = FirstSection; |
|
125 |
last.pos = -1; |
|
126 |
last.count = -1; |
|
127 |
none.type = NoSection; |
|
128 |
none.pos = -1; |
|
129 |
none.count = -1; |
|
130 |
} |
|
131 |
virtual ~QDateTimeParser() {} |
|
132 |
enum { |
|
133 |
Neither = -1, |
|
134 |
AM = 0, |
|
135 |
PM = 1, |
|
136 |
PossibleAM = 2, |
|
137 |
PossiblePM = 3, |
|
138 |
PossibleBoth = 4 |
|
139 |
}; |
|
140 |
||
141 |
enum Section { |
|
142 |
NoSection = 0x00000, |
|
143 |
AmPmSection = 0x00001, |
|
144 |
MSecSection = 0x00002, |
|
145 |
SecondSection = 0x00004, |
|
146 |
MinuteSection = 0x00008, |
|
147 |
Hour12Section = 0x00010, |
|
148 |
Hour24Section = 0x00020, |
|
149 |
TimeSectionMask = (AmPmSection|MSecSection|SecondSection|MinuteSection|Hour12Section|Hour24Section), |
|
150 |
Internal = 0x10000, |
|
151 |
DaySection = 0x00100, |
|
152 |
MonthSection = 0x00200, |
|
153 |
YearSection = 0x00400, |
|
154 |
YearSection2Digits = 0x00800, |
|
155 |
DayOfWeekSection = 0x01000, |
|
156 |
DateSectionMask = (DaySection|MonthSection|YearSection|YearSection2Digits|DayOfWeekSection), |
|
157 |
FirstSection = 0x02000|Internal, |
|
158 |
LastSection = 0x04000|Internal, |
|
159 |
CalendarPopupSection = 0x08000|Internal, |
|
160 |
||
161 |
NoSectionIndex = -1, |
|
162 |
FirstSectionIndex = -2, |
|
163 |
LastSectionIndex = -3, |
|
164 |
CalendarPopupIndex = -4 |
|
165 |
}; // duplicated from qdatetimeedit.h |
|
166 |
Q_DECLARE_FLAGS(Sections, Section) |
|
167 |
||
168 |
struct SectionNode { |
|
169 |
Section type; |
|
170 |
mutable int pos; |
|
171 |
int count; |
|
172 |
}; |
|
173 |
||
174 |
enum State { // duplicated from QValidator |
|
175 |
Invalid, |
|
176 |
Intermediate, |
|
177 |
Acceptable |
|
178 |
}; |
|
179 |
||
180 |
struct StateNode { |
|
181 |
StateNode() : state(Invalid), conflicts(false) {} |
|
182 |
QString input; |
|
183 |
State state; |
|
184 |
bool conflicts; |
|
185 |
QDateTime value; |
|
186 |
}; |
|
187 |
||
188 |
enum AmPm { |
|
189 |
AmText, |
|
190 |
PmText |
|
191 |
}; |
|
192 |
||
193 |
enum Case { |
|
194 |
UpperCase, |
|
195 |
LowerCase |
|
196 |
}; |
|
197 |
||
198 |
#ifndef QT_NO_DATESTRING |
|
199 |
StateNode parse(QString &input, int &cursorPosition, const QDateTime ¤tValue, bool fixup) const; |
|
200 |
#endif |
|
201 |
int sectionMaxSize(int index) const; |
|
202 |
int sectionSize(int index) const; |
|
203 |
int sectionMaxSize(Section s, int count) const; |
|
204 |
int sectionPos(int index) const; |
|
205 |
int sectionPos(const SectionNode &sn) const; |
|
206 |
||
207 |
const SectionNode §ionNode(int index) const; |
|
208 |
Section sectionType(int index) const; |
|
209 |
QString sectionText(int sectionIndex) const; |
|
210 |
QString sectionText(const QString &text, int sectionIndex, int index) const; |
|
211 |
int getDigit(const QDateTime &dt, int index) const; |
|
212 |
bool setDigit(QDateTime &t, int index, int newval) const; |
|
213 |
int parseSection(const QDateTime ¤tValue, int sectionIndex, QString &txt, int &cursorPosition, |
|
214 |
int index, QDateTimeParser::State &state, int *used = 0) const; |
|
215 |
int absoluteMax(int index, const QDateTime &value = QDateTime()) const; |
|
216 |
int absoluteMin(int index) const; |
|
217 |
bool parseFormat(const QString &format); |
|
218 |
#ifndef QT_NO_DATESTRING |
|
219 |
bool fromString(const QString &text, QDate *date, QTime *time) const; |
|
220 |
#endif |
|
221 |
||
222 |
#ifndef QT_NO_TEXTDATE |
|
223 |
int findMonth(const QString &str1, int monthstart, int sectionIndex, |
|
224 |
QString *monthName = 0, int *used = 0) const; |
|
225 |
int findDay(const QString &str1, int intDaystart, int sectionIndex, |
|
226 |
QString *dayName = 0, int *used = 0) const; |
|
227 |
#endif |
|
228 |
int findAmPm(QString &str1, int index, int *used = 0) const; |
|
229 |
int maxChange(int s) const; |
|
230 |
bool potentialValue(const QString &str, int min, int max, int index, |
|
231 |
const QDateTime ¤tValue, int insert) const; |
|
232 |
bool skipToNextSection(int section, const QDateTime ¤t, const QString §ionText) const; |
|
233 |
QString sectionName(int s) const; |
|
234 |
QString stateName(int s) const; |
|
235 |
||
236 |
QString sectionFormat(int index) const; |
|
237 |
QString sectionFormat(Section s, int count) const; |
|
238 |
||
239 |
enum FieldInfoFlag { |
|
240 |
Numeric = 0x01, |
|
241 |
FixedWidth = 0x02, |
|
242 |
AllowPartial = 0x04, |
|
243 |
Fraction = 0x08 |
|
244 |
}; |
|
245 |
Q_DECLARE_FLAGS(FieldInfo, FieldInfoFlag) |
|
246 |
||
247 |
FieldInfo fieldInfo(int index) const; |
|
248 |
||
249 |
virtual QDateTime getMinimum() const; |
|
250 |
virtual QDateTime getMaximum() const; |
|
251 |
virtual int cursorPosition() const { return -1; } |
|
252 |
virtual QString displayText() const { return text; } |
|
253 |
virtual QString getAmPmText(AmPm ap, Case cs) const; |
|
254 |
virtual QLocale locale() const { return defaultLocale; } |
|
255 |
||
256 |
mutable int currentSectionIndex; |
|
257 |
Sections display; |
|
258 |
mutable int cachedDay; |
|
259 |
mutable QString text; |
|
260 |
QVector<SectionNode> sectionNodes; |
|
261 |
SectionNode first, last, none, popup; |
|
262 |
QStringList separators; |
|
263 |
QString displayFormat; |
|
264 |
QLocale defaultLocale; |
|
265 |
QVariant::Type parserType; |
|
266 |
||
267 |
bool fixday; |
|
268 |
||
269 |
Qt::TimeSpec spec; // spec if used by QDateTimeEdit |
|
270 |
Context context; |
|
271 |
}; |
|
272 |
||
273 |
Q_CORE_EXPORT bool operator==(const QDateTimeParser::SectionNode &s1, const QDateTimeParser::SectionNode &s2); |
|
274 |
||
275 |
Q_DECLARE_OPERATORS_FOR_FLAGS(QDateTimeParser::Sections) |
|
276 |
Q_DECLARE_OPERATORS_FOR_FLAGS(QDateTimeParser::FieldInfo) |
|
277 |
||
278 |
||
279 |
#endif // QT_BOOTSTRAPPED |
|
280 |
||
281 |
QT_END_NAMESPACE |
|
282 |
||
283 |
#endif // QDATETIME_P_H |