Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
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
4#ifndef QQMLLOCALE_H
5#define QQMLLOCALE_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <qqml.h>
19
20#include <QtCore/qlocale.h>
21#include <QtCore/qobject.h>
22#include <private/qtqmlglobal_p.h>
23#include <private/qv4object_p.h>
24
26
27QT_BEGIN_NAMESPACE
28
29
30class QQmlDateExtension
31{
32public:
33 static void registerExtension(QV4::ExecutionEngine *engine);
34
35private:
36 static QV4::ReturnedValue method_toLocaleString(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc);
37 static QV4::ReturnedValue method_toLocaleTimeString(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc);
38 static QV4::ReturnedValue method_toLocaleDateString(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc);
39 static QV4::ReturnedValue method_fromLocaleString(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc);
40 static QV4::ReturnedValue method_fromLocaleTimeString(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc);
41 static QV4::ReturnedValue method_fromLocaleDateString(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc);
42 static QV4::ReturnedValue method_timeZoneUpdated(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc);
43};
44
45
47{
48public:
49 static void registerExtension(QV4::ExecutionEngine *engine);
50
51private:
52 static QV4::ReturnedValue method_toLocaleString(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc);
53 static QV4::ReturnedValue method_fromLocaleString(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc);
54 static QV4::ReturnedValue method_toLocaleCurrencyString(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc);
55};
56
57// This needs to be a struct so that we can derive from QLocale and inherit its enums. Then we can
58// use it as extension in QQmlLocaleEnums and expose all the enums in one go, without duplicating
59// any in different qmltypes files.
60struct Q_QML_EXPORT QQmlLocale : public QLocale
61{
62 Q_GADGET
63 QML_ANONYMOUS
64public:
65
66 // Qt defines Sunday as 7, but JS Date assigns Sunday 0
67 enum DayOfWeek {
68 Sunday = 0,
69 Monday = Qt::Monday,
70 Tuesday = Qt::Tuesday,
71 Wednesday = Qt::Wednesday,
72 Thursday = Qt::Thursday,
73 Friday = Qt::Friday,
74 Saturday = Qt::Saturday
75 };
76 Q_ENUM(DayOfWeek)
77
78 static QV4::ReturnedValue locale(QV4::ExecutionEngine *engine, const QString &localeName);
79 static void registerStringLocaleCompare(QV4::ExecutionEngine *engine);
80 static QV4::ReturnedValue method_localeCompare(
81 const QV4::FunctionObject *, const QV4::Value *thisObject,
82 const QV4::Value *argv, int argc);
83};
84
86{
87 Q_GADGET
88 QML_ANONYMOUS
91};
92
94{
95 QLocale locale;
96
97 Q_PROPERTY(QQmlLocale::DayOfWeek firstDayOfWeek READ firstDayOfWeek CONSTANT)
102
105#if QT_DEPRECATED_SINCE(6, 6)
107#endif
118
120
126
127public:
129
135
140
145
150
152 {
153 // +1 added to idx because JS is 0-based, whereas QLocale months begin at 1.
154 return locale.monthName(index + 1, format);
155 }
156
159 {
160 // +1 added to idx because JS is 0-based, whereas QLocale months begin at 1.
162 }
163
165 {
166 // 0 -> 7 as Qt::Sunday is 7, but Sunday is 0 in JS Date
167 return locale.dayName(index == 0 ? 7 : index, format);
168 }
169
172 {
173 // 0 -> 7 as Qt::Sunday is 7, but Sunday is 0 in JS Date
174 return locale.standaloneDayName(index == 0 ? 7 : index, format);
175 }
176
178 Q_INVOKABLE QString formattedDataSize(
179 double bytes, int precision = 2,
181 {
184 }
185
187
188 // As a special (undocumented) case, when called with no arguments,
189 // just forward to QDebug. This makes it consistent with other types
190 // in JS that can be converted to a string via toString().
192
193 Q_INVOKABLE QString toString(int i) const { return locale.toString(i); }
195 {
197 }
198 Q_INVOKABLE QString toString(double f, const QString &format, int precision = 6) const
199 {
200 // Lacking a char type, we have to use QString here
201 return format.length() < 1
202 ? QString()
204 }
206 {
208 }
214
219
221 QLocale::MeasurementSystem measurementSystem() const { return locale.measurementSystem(); }
222 Qt::LayoutDirection textDirection() const { return locale.textDirection(); }
224 QStringList uiLanguages() const { return locale.uiLanguages(); }
225
226 QString name() const { return locale.name(); }
227 QString nativeLanguageName() const { return locale.nativeLanguageName(); }
228#if QT_DEPRECATED_SINCE(6, 6)
230 {
232 }
233#endif
234 QString nativeTerritoryName() const { return locale.nativeTerritoryName(); }
235 QString decimalPoint() const { return locale.decimalPoint(); }
236 QString groupSeparator() const { return locale.groupSeparator(); }
237 QString percent() const { return locale.percent(); }
238 QString zeroDigit() const { return locale.zeroDigit(); }
239 QString negativeSign() const { return locale.negativeSign(); }
240 QString positiveSign() const { return locale.positiveSign(); }
241 QString exponential() const { return locale.exponential(); }
242 QString amText() const { return locale.amText(); }
243 QString pmText() const { return locale.pmText(); }
244
245 QLocale::NumberOptions numberOptions() const { return locale.numberOptions(); }
246 void setNumberOptions(const QLocale::NumberOptions &numberOptions)
247 {
248 locale.setNumberOptions(numberOptions);
249 }
250};
251
252QT_END_NAMESPACE
253
254#endif
QString nativeLanguageName() const
void setNumberOptions(const QLocale::NumberOptions &numberOptions)
QString decimalPoint() const
QString amText() const
QList< QQmlLocale::DayOfWeek > weekDays() const
QString name() const
QLocale::NumberOptions numberOptions() const
QString nativeTerritoryName() const
QString negativeSign() const
QStringList uiLanguages() const
Qt::LayoutDirection textDirection() const
QLocale::MeasurementSystem measurementSystem() const
QString zeroDigit() const
QString percent() const
QString exponential() const
QString pmText() const
QString positiveSign() const
QString groupSeparator() const
static void registerExtension(QV4::ExecutionEngine *engine)
#define GET_LOCALE_DATA_RESOURCE(OBJECT)
static bool isLocaleObject(const QV4::Value &val)
#define THROW_ERROR(string)
static QQmlLocale::DayOfWeek qtDayToQmlDay(Qt::DayOfWeek day)
QT_REQUIRE_CONFIG(thread)