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 | |
25 | QT_REQUIRE_CONFIG(qml_locale); |
26 | |
27 | QT_BEGIN_NAMESPACE |
28 | |
29 | |
30 | class QQmlDateExtension |
31 | { |
32 | public: |
33 | static void registerExtension(QV4::ExecutionEngine *engine); |
34 | |
35 | private: |
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 | |
46 | class QQmlNumberExtension |
47 | { |
48 | public: |
49 | static void registerExtension(QV4::ExecutionEngine *engine); |
50 | |
51 | private: |
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 | |
58 | namespace QQmlLocale |
59 | { |
60 | Q_NAMESPACE_EXPORT(Q_QML_PRIVATE_EXPORT) |
61 | QML_NAMED_ELEMENT(Locale) |
62 | QML_ADDED_IN_VERSION(2, 2) |
63 | QML_NAMESPACE_EXTENDED(QLocale) |
64 | |
65 | // Qt defines Sunday as 7, but JS Date assigns Sunday 0 |
66 | enum DayOfWeek { |
67 | Sunday = 0, |
68 | Monday = Qt::Monday, |
69 | Tuesday = Qt::Tuesday, |
70 | Wednesday = Qt::Wednesday, |
71 | Thursday = Qt::Thursday, |
72 | Friday = Qt::Friday, |
73 | Saturday = Qt::Saturday |
74 | }; |
75 | Q_ENUM_NS(DayOfWeek) |
76 | |
77 | Q_QML_PRIVATE_EXPORT QV4::ReturnedValue locale(QV4::ExecutionEngine *engine, const QString &localeName); |
78 | Q_QML_PRIVATE_EXPORT QV4::ReturnedValue wrap(QV4::ExecutionEngine *engine, const QLocale &locale); |
79 | Q_QML_PRIVATE_EXPORT void registerStringLocaleCompare(QV4::ExecutionEngine *engine); |
80 | Q_QML_PRIVATE_EXPORT QV4::ReturnedValue method_localeCompare(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc); |
81 | }; |
82 | |
83 | namespace QV4 { |
84 | |
85 | namespace Heap { |
86 | |
87 | struct QQmlLocaleData : Object { |
88 | inline void init() { locale = new QLocale; } |
89 | void destroy() { |
90 | delete locale; |
91 | Object::destroy(); |
92 | } |
93 | QLocale *locale; |
94 | }; |
95 | |
96 | } |
97 | |
98 | struct QQmlLocaleData : public QV4::Object |
99 | { |
100 | V4_OBJECT2(QQmlLocaleData, Object) |
101 | V4_NEEDS_DESTROY |
102 | |
103 | static QLocale *getThisLocale(QV4::Scope &scope, const QV4::Value *thisObject) { |
104 | const QV4::Object *o = thisObject->as<Object>(); |
105 | const QQmlLocaleData *data = o ? o->as<QQmlLocaleData>() : nullptr; |
106 | if (!data) { |
107 | scope.engine->throwTypeError(); |
108 | return nullptr; |
109 | } |
110 | return data->d()->locale; |
111 | } |
112 | |
113 | static QV4::ReturnedValue method_currencySymbol(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc); |
114 | static QV4::ReturnedValue method_dateTimeFormat(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc); |
115 | static QV4::ReturnedValue method_timeFormat(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc); |
116 | static QV4::ReturnedValue method_dateFormat(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc); |
117 | static QV4::ReturnedValue method_monthName(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc); |
118 | static QV4::ReturnedValue method_standaloneMonthName(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc); |
119 | static QV4::ReturnedValue method_dayName(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc); |
120 | static QV4::ReturnedValue method_standaloneDayName(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc); |
121 | static QV4::ReturnedValue method_toString(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc); |
122 | |
123 | static QV4::ReturnedValue method_get_firstDayOfWeek(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc); |
124 | static QV4::ReturnedValue method_get_measurementSystem(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc); |
125 | static QV4::ReturnedValue method_get_textDirection(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc); |
126 | static QV4::ReturnedValue method_get_weekDays(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc); |
127 | static QV4::ReturnedValue method_get_uiLanguages(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc); |
128 | |
129 | static QV4::ReturnedValue method_get_name(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc); |
130 | static QV4::ReturnedValue method_get_nativeLanguageName(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc); |
131 | #if QT_DEPRECATED_SINCE(6, 6) |
132 | static QV4::ReturnedValue method_get_nativeCountryName(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc); |
133 | #endif |
134 | static QV4::ReturnedValue method_get_nativeTerritoryName(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc); |
135 | static QV4::ReturnedValue method_get_decimalPoint(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc); |
136 | static QV4::ReturnedValue method_get_groupSeparator(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc); |
137 | static QV4::ReturnedValue method_get_percent(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc); |
138 | static QV4::ReturnedValue method_get_zeroDigit(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc); |
139 | static QV4::ReturnedValue method_get_negativeSign(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc); |
140 | static QV4::ReturnedValue method_get_positiveSign(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc); |
141 | static QV4::ReturnedValue method_get_exponential(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc); |
142 | static QV4::ReturnedValue method_get_amText(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc); |
143 | static QV4::ReturnedValue method_get_pmText(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc); |
144 | |
145 | static QV4::ReturnedValue method_get_numberOptions(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc); |
146 | static QV4::ReturnedValue method_set_numberOptions(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc); |
147 | |
148 | static QV4::ReturnedValue method_get_formattedDataSize(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc); |
149 | }; |
150 | |
151 | } |
152 | |
153 | QT_END_NAMESPACE |
154 | |
155 | #endif |
156 | |