Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qqmllocale_p.h
Go to the documentation of this file.
1
// Copyright (C) 2016 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
// Qt-Security score:significant
4
5
#
ifndef
QQMLLOCALE_H
6
#
define
QQMLLOCALE_H
7
8
//
9
// W A R N I N G
10
// -------------
11
//
12
// This file is not part of the Qt API. It exists purely as an
13
// implementation detail. This header file may change from version to
14
// version without notice, or even be removed.
15
//
16
// We mean it.
17
//
18
19
#
include
<
qqml
.
h
>
20
21
#
include
<
QtCore
/
qlocale
.
h
>
22
#
include
<
QtCore
/
qobject
.
h
>
23
#
include
<
private
/
qtqmlglobal_p
.
h
>
24
#
include
<
private
/
qv4object_p
.
h
>
25
26
QT_REQUIRE_CONFIG
(
qml_locale
);
27
28
QT_BEGIN_NAMESPACE
29
30
31
class
QQmlDateExtension
32
{
33
public
:
34
static
void
registerExtension(QV4::ExecutionEngine *engine);
35
36
private
:
37
static
QV4::ReturnedValue method_toLocaleString(
const
QV4::FunctionObject *,
const
QV4::Value *thisObject,
const
QV4::Value *argv,
int
argc);
38
static
QV4::ReturnedValue method_toLocaleTimeString(
const
QV4::FunctionObject *,
const
QV4::Value *thisObject,
const
QV4::Value *argv,
int
argc);
39
static
QV4::ReturnedValue method_toLocaleDateString(
const
QV4::FunctionObject *,
const
QV4::Value *thisObject,
const
QV4::Value *argv,
int
argc);
40
static
QV4::ReturnedValue method_fromLocaleString(
const
QV4::FunctionObject *,
const
QV4::Value *thisObject,
const
QV4::Value *argv,
int
argc);
41
static
QV4::ReturnedValue method_fromLocaleTimeString(
const
QV4::FunctionObject *,
const
QV4::Value *thisObject,
const
QV4::Value *argv,
int
argc);
42
static
QV4::ReturnedValue method_fromLocaleDateString(
const
QV4::FunctionObject *,
const
QV4::Value *thisObject,
const
QV4::Value *argv,
int
argc);
43
static
QV4::ReturnedValue method_timeZoneUpdated(
const
QV4::FunctionObject *,
const
QV4::Value *thisObject,
const
QV4::Value *argv,
int
argc);
44
};
45
46
47
class
QQmlNumberExtension
48
{
49
public
:
50
static
void
registerExtension
(QV4::ExecutionEngine *engine);
51
52
private
:
53
static
QV4::ReturnedValue method_toLocaleString(
const
QV4::FunctionObject *,
const
QV4::Value *thisObject,
const
QV4::Value *argv,
int
argc);
54
static
QV4::ReturnedValue method_fromLocaleString(
const
QV4::FunctionObject *,
const
QV4::Value *thisObject,
const
QV4::Value *argv,
int
argc);
55
static
QV4::ReturnedValue method_toLocaleCurrencyString(
const
QV4::FunctionObject *,
const
QV4::Value *thisObject,
const
QV4::Value *argv,
int
argc);
56
};
57
58
// This needs to be a struct so that we can derive from QLocale and inherit its enums. Then we can
59
// use it as extension in QQmlLocaleEnums and expose all the enums in one go, without duplicating
60
// any in different qmltypes files.
61
struct
Q_QML_EXPORT
QQmlLocale
:
public
QLocale
62
{
63
Q_GADGET
64
QML_ANONYMOUS
65
public
:
66
67
// Qt defines Sunday as 7, but JS Date assigns Sunday 0
68
enum
DayOfWeek {
69
Sunday = 0,
70
Monday = Qt::Monday,
71
Tuesday = Qt::Tuesday,
72
Wednesday = Qt::Wednesday,
73
Thursday = Qt::Thursday,
74
Friday = Qt::Friday,
75
Saturday = Qt::Saturday
76
};
77
Q_ENUM(DayOfWeek)
78
79
static
QV4::ReturnedValue locale(QV4::ExecutionEngine *engine,
const
QString &localeName);
80
static
void
registerStringLocaleCompare(QV4::ExecutionEngine *engine);
81
static
QV4::ReturnedValue method_localeCompare(
82
const
QV4::FunctionObject *,
const
QV4::Value *thisObject,
83
const
QV4::Value *argv,
int
argc);
84
};
85
86
struct
DayOfWeekList
87
{
88
Q_GADGET
89
QML_ANONYMOUS
90
QML_FOREIGN
(
QList
<
QQmlLocale
::
DayOfWeek
>)
91
QML_SEQUENTIAL_CONTAINER
(
QQmlLocale
::
DayOfWeek
)
92
};
93
94
class
QQmlLocaleValueType
95
{
96
QLocale locale;
97
98
Q_PROPERTY(QQmlLocale::DayOfWeek firstDayOfWeek READ firstDayOfWeek CONSTANT)
99
Q_PROPERTY
(
QLocale
::
MeasurementSystem
measurementSystem
READ
measurementSystem
CONSTANT
)
100
Q_PROPERTY
(
Qt
::
LayoutDirection
textDirection
READ
textDirection
CONSTANT
)
101
Q_PROPERTY
(
QList
<
QQmlLocale
::
DayOfWeek
>
weekDays
READ
weekDays
CONSTANT
)
102
Q_PROPERTY
(
QStringList
uiLanguages
READ
uiLanguages
CONSTANT
)
103
104
Q_PROPERTY
(
QString
name
READ
name
CONSTANT
)
105
Q_PROPERTY
(
QString
nativeLanguageName
READ
nativeLanguageName
CONSTANT
)
106
#
if
QT_DEPRECATED_SINCE
(
6
,
6
)
107
Q_PROPERTY
(
QString
nativeCountryName
READ
nativeCountryName
CONSTANT
)
108
#
endif
109
Q_PROPERTY
(
QString
nativeTerritoryName
READ
nativeTerritoryName
CONSTANT
)
110
Q_PROPERTY
(
QString
decimalPoint
READ
decimalPoint
CONSTANT
)
111
Q_PROPERTY
(
QString
groupSeparator
READ
groupSeparator
CONSTANT
)
112
Q_PROPERTY
(
QString
percent
READ
percent
CONSTANT
)
113
Q_PROPERTY
(
QString
zeroDigit
READ
zeroDigit
CONSTANT
)
114
Q_PROPERTY
(
QString
negativeSign
READ
negativeSign
CONSTANT
)
115
Q_PROPERTY
(
QString
positiveSign
READ
positiveSign
CONSTANT
)
116
Q_PROPERTY
(
QString
exponential
READ
exponential
CONSTANT
)
117
Q_PROPERTY
(
QString
amText
READ
amText
CONSTANT
)
118
Q_PROPERTY
(
QString
pmText
READ
pmText
CONSTANT
)
119
120
Q_PROPERTY
(
QLocale
::
NumberOptions
numberOptions
READ
numberOptions
WRITE
setNumberOptions
)
121
122
Q_GADGET_EXPORT
(
Q_QML_EXPORT
)
123
QML_ANONYMOUS
124
QML_FOREIGN
(
QLocale
)
125
QML_EXTENDED
(
QQmlLocaleValueType
)
126
QML_CONSTRUCTIBLE_VALUE
127
128
public
:
129
Q_INVOKABLE
QQmlLocaleValueType
(
const
QString
&
name
) :
locale
(
name
) {}
130
131
Q_INVOKABLE
QString
currencySymbol
(
132
QLocale
::
CurrencySymbolFormat
format
=
QLocale
::
CurrencySymbol
)
const
133
{
134
return
locale
.
currencySymbol
(
format
);
135
}
136
137
Q_INVOKABLE
QString
dateTimeFormat
(
QLocale
::
FormatType
format
=
QLocale
::
LongFormat
)
const
138
{
139
return
locale
.
dateTimeFormat
(
format
);
140
}
141
142
Q_INVOKABLE
QString
timeFormat
(
QLocale
::
FormatType
format
=
QLocale
::
LongFormat
)
const
143
{
144
return
locale
.
timeFormat
(
format
);
145
}
146
147
Q_INVOKABLE
QString
dateFormat
(
QLocale
::
FormatType
format
=
QLocale
::
LongFormat
)
const
148
{
149
return
locale
.
dateFormat
(
format
);
150
}
151
152
Q_INVOKABLE
QString
monthName
(
int
index
,
QLocale
::
FormatType
format
=
QLocale
::
LongFormat
)
const
153
{
154
// +1 added to idx because JS is 0-based, whereas QLocale months begin at 1.
155
return
locale
.
monthName
(
index
+ 1,
format
);
156
}
157
158
Q_INVOKABLE
QString
standaloneMonthName
(
159
int
index
,
QLocale
::
FormatType
format
=
QLocale
::
LongFormat
)
const
160
{
161
// +1 added to idx because JS is 0-based, whereas QLocale months begin at 1.
162
return
locale
.
standaloneMonthName
(
index
+ 1,
format
);
163
}
164
165
Q_INVOKABLE
QString
dayName
(
int
index
,
QLocale
::
FormatType
format
=
QLocale
::
LongFormat
)
const
166
{
167
// 0 -> 7 as Qt::Sunday is 7, but Sunday is 0 in JS Date
168
return
locale
.
dayName
(
index
== 0 ? 7 :
index
,
format
);
169
}
170
171
Q_INVOKABLE
QString
standaloneDayName
(
172
int
index
,
QLocale
::
FormatType
format
=
QLocale
::
LongFormat
)
const
173
{
174
// 0 -> 7 as Qt::Sunday is 7, but Sunday is 0 in JS Date
175
return
locale
.
standaloneDayName
(
index
== 0 ? 7 :
index
,
format
);
176
}
177
178
Q_INVOKABLE
void
formattedDataSize
(
QQmlV4FunctionPtr
args
)
const
;
179
Q_INVOKABLE QString
formattedDataSize
(
180
double
bytes
,
int
precision
= 2,
181
QLocale
::
DataSizeFormats
format
=
QLocale
::
DataSizeIecFormat
)
const
182
{
183
return
locale
.
formattedDataSize
(
184
qint64
(
QV4
::
Value
::
toInteger
(
bytes
)),
precision
,
format
);
185
}
186
187
Q_INVOKABLE
void
toString
(
QQmlV4FunctionPtr
args
)
const
;
188
189
// As a special (undocumented) case, when called with no arguments,
190
// just forward to QDebug. This makes it consistent with other types
191
// in JS that can be converted to a string via toString().
192
Q_INVOKABLE
QString
toString
()
const
{
return
QDebug
::
toString
(
locale
); }
193
194
Q_INVOKABLE
QString
toString
(
int
i
)
const
{
return
locale
.
toString
(
i
); }
195
Q_INVOKABLE
QString
toString
(
double
f
)
const
196
{
197
return
QJSNumberCoercion
::
isInteger
(
f
) ?
toString
(
int
(
f
)) :
locale
.
toString
(
f
);
198
}
199
Q_INVOKABLE
QString
toString
(
double
f
,
const
QString
&
format
,
int
precision
= 6)
const
200
{
201
// Lacking a char type, we have to use QString here
202
return
format
.
length
() < 1
203
?
QString
()
204
:
locale
.
toString
(
f
,
format
.
at
(0).
toLatin1
(),
precision
);
205
}
206
Q_INVOKABLE
QString
toString
(
const
QDateTime
&
dateTime
,
const
QString
&
format
)
const
207
{
208
return
locale
.
toString
(
dateTime
,
format
);
209
}
210
Q_INVOKABLE
QString
toString
(
211
const
QDateTime
&
dateTime
,
QLocale
::
FormatType
format
=
QLocale
::
LongFormat
)
const
212
{
213
return
locale
.
toString
(
dateTime
,
format
);
214
}
215
216
Q_INVOKABLE
QString
createSeparatedList
(
const
QStringList
&
list
)
const
217
{
218
return
locale
.
createSeparatedList
(
list
);
219
}
220
221
QQmlLocale
::
DayOfWeek
firstDayOfWeek
()
const
;
222
QLocale
::
MeasurementSystem
measurementSystem
()
const
{
return
locale.measurementSystem(); }
223
Qt
::
LayoutDirection
textDirection
()
const
{
return
locale.textDirection(); }
224
QList
<
QQmlLocale
::
DayOfWeek
>
weekDays
()
const
;
225
QStringList
uiLanguages
()
const
{
return
locale.uiLanguages(); }
226
227
QString
name
()
const
{
return
locale.name(); }
228
QString
nativeLanguageName
()
const
{
return
locale.nativeLanguageName(); }
229
#
if
QT_DEPRECATED_SINCE
(
6
,
6
)
230
QString
nativeCountryName
()
const
231
{
232
QT_IGNORE_DEPRECATIONS
(
return
locale
.
nativeCountryName
();)
233
}
234
#
endif
235
QString
nativeTerritoryName
()
const
{
return
locale.nativeTerritoryName(); }
236
QString
decimalPoint
()
const
{
return
locale.decimalPoint(); }
237
QString
groupSeparator
()
const
{
return
locale.groupSeparator(); }
238
QString
percent
()
const
{
return
locale.percent(); }
239
QString
zeroDigit
()
const
{
return
locale.zeroDigit(); }
240
QString
negativeSign
()
const
{
return
locale.negativeSign(); }
241
QString
positiveSign
()
const
{
return
locale.positiveSign(); }
242
QString
exponential
()
const
{
return
locale.exponential(); }
243
QString
amText
()
const
{
return
locale.amText(); }
244
QString
pmText
()
const
{
return
locale.pmText(); }
245
246
QLocale
::
NumberOptions
numberOptions
()
const
{
return
locale.numberOptions(); }
247
void
setNumberOptions
(
const
QLocale::NumberOptions &numberOptions)
248
{
249
locale.setNumberOptions(numberOptions);
250
}
251
};
252
253
QT_END_NAMESPACE
254
255
#
endif
QQmlLocaleValueType
Definition
qqmllocale_p.h:95
QQmlLocaleValueType::nativeLanguageName
QString nativeLanguageName() const
Definition
qqmllocale_p.h:228
QQmlLocaleValueType::setNumberOptions
void setNumberOptions(const QLocale::NumberOptions &numberOptions)
Definition
qqmllocale_p.h:247
QQmlLocaleValueType::decimalPoint
QString decimalPoint() const
Definition
qqmllocale_p.h:236
QQmlLocaleValueType::amText
QString amText() const
Definition
qqmllocale_p.h:243
QQmlLocaleValueType::weekDays
QList< QQmlLocale::DayOfWeek > weekDays() const
Definition
qqmllocale.cpp:513
QQmlLocaleValueType::name
QString name() const
Definition
qqmllocale_p.h:227
QQmlLocaleValueType::numberOptions
QLocale::NumberOptions numberOptions() const
Definition
qqmllocale_p.h:246
QQmlLocaleValueType::nativeTerritoryName
QString nativeTerritoryName() const
Definition
qqmllocale_p.h:235
QQmlLocaleValueType::negativeSign
QString negativeSign() const
Definition
qqmllocale_p.h:240
QQmlLocaleValueType::uiLanguages
QStringList uiLanguages() const
Definition
qqmllocale_p.h:225
QQmlLocaleValueType::textDirection
Qt::LayoutDirection textDirection() const
Definition
qqmllocale_p.h:223
QQmlLocaleValueType::measurementSystem
QLocale::MeasurementSystem measurementSystem() const
Definition
qqmllocale_p.h:222
QQmlLocaleValueType::zeroDigit
QString zeroDigit() const
Definition
qqmllocale_p.h:239
QQmlLocaleValueType::percent
QString percent() const
Definition
qqmllocale_p.h:238
QQmlLocaleValueType::exponential
QString exponential() const
Definition
qqmllocale_p.h:242
QQmlLocaleValueType::pmText
QString pmText() const
Definition
qqmllocale_p.h:244
QQmlLocaleValueType::positiveSign
QString positiveSign() const
Definition
qqmllocale_p.h:241
QQmlLocaleValueType::groupSeparator
QString groupSeparator() const
Definition
qqmllocale_p.h:237
QQmlNumberExtension
Definition
qqmllocale_p.h:48
QQmlNumberExtension::registerExtension
static void registerExtension(QV4::ExecutionEngine *engine)
Definition
qqmllocale.cpp:329
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
QT_REQUIRE_CONFIG
QT_REQUIRE_CONFIG(liburing)
GET_LOCALE_DATA_RESOURCE
#define GET_LOCALE_DATA_RESOURCE(OBJECT)
Definition
qqmllocale.cpp:28
isLocaleObject
static bool isLocaleObject(const QV4::Value &val)
Definition
qqmllocale.cpp:36
THROW_ERROR
#define THROW_ERROR(string)
Definition
qqmllocale.cpp:22
qtDayToQmlDay
static QQmlLocale::DayOfWeek qtDayToQmlDay(Qt::DayOfWeek day)
Definition
qqmllocale.cpp:503
DayOfWeekList
Definition
qqmllocale_p.h:87
QQmlLocale
Definition
qqmllocale_p.h:62
qtdeclarative
src
qml
qml
qqmllocale_p.h
Generated on
for Qt by
1.18.0