1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtQml module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QQMLLOCALE_H
41#define QQMLLOCALE_H
42
43//
44// W A R N I N G
45// -------------
46//
47// This file is not part of the Qt API. It exists purely as an
48// implementation detail. This header file may change from version to
49// version without notice, or even be removed.
50//
51// We mean it.
52//
53
54#include <qqml.h>
55
56#include <QtCore/qlocale.h>
57#include <QtCore/qobject.h>
58#include <private/qqmlglobal_p.h>
59#include <private/qv4object_p.h>
60
61QT_REQUIRE_CONFIG(qml_locale);
62
63QT_BEGIN_NAMESPACE
64
65
66class QQmlDateExtension
67{
68public:
69 static void registerExtension(QV4::ExecutionEngine *engine);
70
71private:
72 static QV4::ReturnedValue method_toLocaleString(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc);
73 static QV4::ReturnedValue method_toLocaleTimeString(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc);
74 static QV4::ReturnedValue method_toLocaleDateString(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc);
75 static QV4::ReturnedValue method_fromLocaleString(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc);
76 static QV4::ReturnedValue method_fromLocaleTimeString(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc);
77 static QV4::ReturnedValue method_fromLocaleDateString(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc);
78 static QV4::ReturnedValue method_timeZoneUpdated(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc);
79};
80
81
82class QQmlNumberExtension
83{
84public:
85 static void registerExtension(QV4::ExecutionEngine *engine);
86
87private:
88 static QV4::ReturnedValue method_toLocaleString(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc);
89 static QV4::ReturnedValue method_fromLocaleString(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc);
90 static QV4::ReturnedValue method_toLocaleCurrencyString(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc);
91};
92
93
94class Q_QML_PRIVATE_EXPORT QQmlLocale
95{
96 Q_GADGET
97 QML_NAMED_ELEMENT(Locale)
98 QML_UNCREATABLE("Locale cannot be instantiated. Use Qt.locale().")
99 QML_ADDED_IN_MINOR_VERSION(2)
100
101public:
102 ~QQmlLocale();
103
104 enum MeasurementSystem {
105 MetricSystem = QLocale::MetricSystem,
106 ImperialSystem = QLocale::ImperialSystem,
107 ImperialUSSystem = QLocale::ImperialUSSystem,
108 ImperialUKSystem = QLocale::ImperialUKSystem
109 };
110 Q_ENUM(MeasurementSystem)
111 enum FormatType {
112 LongFormat = QLocale::LongFormat,
113 ShortFormat = QLocale::ShortFormat,
114 NarrowFormat = QLocale::NarrowFormat
115 };
116 Q_ENUM(FormatType)
117 enum CurrencySymbolFormat {
118 CurrencyIsoCode = QLocale::CurrencyIsoCode,
119 CurrencySymbol = QLocale::CurrencySymbol,
120 CurrencyDisplayName = QLocale::CurrencyDisplayName
121 };
122 Q_ENUM(CurrencySymbolFormat)
123 // Qt defines Sunday as 7, but JS Date assigns Sunday 0
124 enum DayOfWeek {
125 Sunday = 0,
126 Monday = Qt::Monday,
127 Tuesday = Qt::Tuesday,
128 Wednesday = Qt::Wednesday,
129 Thursday = Qt::Thursday,
130 Friday = Qt::Friday,
131 Saturday = Qt::Saturday
132 };
133 Q_ENUM(DayOfWeek)
134 enum NumberOptions {
135 DefaultNumberOptions = QLocale::DefaultNumberOptions,
136 OmitGroupSeparator = QLocale::OmitGroupSeparator,
137 RejectGroupSeparator = QLocale::RejectGroupSeparator,
138 OmitLeadingZeroInExponent = QLocale::OmitLeadingZeroInExponent,
139 RejectLeadingZeroInExponent = QLocale::RejectLeadingZeroInExponent,
140 IncludeTrailingZeroesAfterDot = QLocale::IncludeTrailingZeroesAfterDot,
141 RejectTrailingZeroesAfterDot = QLocale::RejectTrailingZeroesAfterDot
142 };
143 Q_ENUM(NumberOptions)
144
145 static QV4::ReturnedValue locale(QV4::ExecutionEngine *engine, const QString &localeName);
146 static QV4::ReturnedValue wrap(QV4::ExecutionEngine *engine, const QLocale &locale);
147
148 static void registerStringLocaleCompare(QV4::ExecutionEngine *engine);
149
150private:
151 QQmlLocale();
152
153 static QV4::ReturnedValue method_localeCompare(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc);
154};
155
156namespace QV4 {
157
158namespace Heap {
159
160struct QQmlLocaleData : Object {
161 inline void init() { locale = new QLocale; }
162 void destroy() {
163 delete locale;
164 Object::destroy();
165 }
166 QLocale *locale;
167};
168
169}
170
171struct QQmlLocaleData : public QV4::Object
172{
173 V4_OBJECT2(QQmlLocaleData, Object)
174 V4_NEEDS_DESTROY
175
176 static QLocale *getThisLocale(QV4::Scope &scope, const QV4::Value *thisObject) {
177 const QV4::Object *o = thisObject->as<Object>();
178 const QQmlLocaleData *data = o ? o->as<QQmlLocaleData>() : nullptr;
179 if (!data) {
180 scope.engine->throwTypeError();
181 return nullptr;
182 }
183 return data->d()->locale;
184 }
185
186 static QV4::ReturnedValue method_currencySymbol(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc);
187 static QV4::ReturnedValue method_dateTimeFormat(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc);
188 static QV4::ReturnedValue method_timeFormat(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc);
189 static QV4::ReturnedValue method_dateFormat(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc);
190 static QV4::ReturnedValue method_monthName(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc);
191 static QV4::ReturnedValue method_standaloneMonthName(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc);
192 static QV4::ReturnedValue method_dayName(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc);
193 static QV4::ReturnedValue method_standaloneDayName(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc);
194
195 static QV4::ReturnedValue method_get_firstDayOfWeek(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc);
196 static QV4::ReturnedValue method_get_measurementSystem(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc);
197 static QV4::ReturnedValue method_get_textDirection(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc);
198 static QV4::ReturnedValue method_get_weekDays(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc);
199 static QV4::ReturnedValue method_get_uiLanguages(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc);
200
201 static QV4::ReturnedValue method_get_name(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc);
202 static QV4::ReturnedValue method_get_nativeLanguageName(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc);
203 static QV4::ReturnedValue method_get_nativeCountryName(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc);
204 static QV4::ReturnedValue method_get_decimalPoint(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc);
205 static QV4::ReturnedValue method_get_groupSeparator(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc);
206 static QV4::ReturnedValue method_get_percent(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc);
207 static QV4::ReturnedValue method_get_zeroDigit(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc);
208 static QV4::ReturnedValue method_get_negativeSign(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc);
209 static QV4::ReturnedValue method_get_positiveSign(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc);
210 static QV4::ReturnedValue method_get_exponential(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc);
211 static QV4::ReturnedValue method_get_amText(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc);
212 static QV4::ReturnedValue method_get_pmText(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc);
213
214 static QV4::ReturnedValue method_get_numberOptions(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc);
215 static QV4::ReturnedValue method_set_numberOptions(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc);
216};
217
218}
219
220QT_END_NAMESPACE
221
222#endif
223

source code of qtdeclarative/src/qml/qml/qqmllocale_p.h