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// 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
27
28QT_BEGIN_NAMESPACE
29
30
31class QQmlDateExtension
32{
33public:
34 static void registerExtension(QV4::ExecutionEngine *engine);
35
36private:
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
48{
49public:
50 static void registerExtension(QV4::ExecutionEngine *engine);
51
52private:
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.
61struct Q_QML_EXPORT QQmlLocale : public QLocale
62{
63 Q_GADGET
64 QML_ANONYMOUS
65public:
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
87{
88 Q_GADGET
89 QML_ANONYMOUS
92};
93
95{
96 QLocale locale;
97
98 Q_PROPERTY(QQmlLocale::DayOfWeek firstDayOfWeek READ firstDayOfWeek CONSTANT)
103
106#if QT_DEPRECATED_SINCE(6, 6)
108#endif
119
121
127
128public:
130
136
141
146
151
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
160 {
161 // +1 added to idx because JS is 0-based, whereas QLocale months begin at 1.
163 }
164
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
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
179 Q_INVOKABLE QString formattedDataSize(
180 double bytes, int precision = 2,
182 {
185 }
186
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().
193
194 Q_INVOKABLE QString toString(int i) const { return locale.toString(i); }
196 {
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()
205 }
207 {
209 }
215
220
222 QLocale::MeasurementSystem measurementSystem() const { return locale.measurementSystem(); }
223 Qt::LayoutDirection textDirection() const { return locale.textDirection(); }
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)
231 {
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
253QT_END_NAMESPACE
254
255#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)
Combined button and popup list for selecting options.
QT_REQUIRE_CONFIG(liburing)
#define GET_LOCALE_DATA_RESOURCE(OBJECT)
static bool isLocaleObject(const QV4::Value &val)
#define THROW_ERROR(string)
static QQmlLocale::DayOfWeek qtDayToQmlDay(Qt::DayOfWeek day)