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
qqmlbuiltinfunctions_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 QQMLBUILTINFUNCTIONS_P_H
5#define QQMLBUILTINFUNCTIONS_P_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 <private/qjsengine_p.h>
19#include <private/qqmlglobal_p.h>
20#include <private/qqmlplatform_p.h>
21#include <private/qv4functionobject_p.h>
22
23#include <QtCore/qnamespace.h>
24#include <QtCore/qdatetime.h>
25#include <QtCore/qsize.h>
26#include <QtCore/qrect.h>
27#include <QtCore/qpoint.h>
28
29#include <QtQml/qqmlcomponent.h>
30#include <QtQml/qqmlengine.h>
31
33
36
37class Q_QML_EXPORT QtObject : public QObject
38{
39 Q_OBJECT
40 Q_PROPERTY(QQmlApplication *application READ application CONSTANT)
41 Q_PROPERTY(QQmlPlatform *platform READ platform CONSTANT)
42 Q_PROPERTY(QObject *inputMethod READ inputMethod CONSTANT)
43 Q_PROPERTY(QObject *styleHints READ styleHints CONSTANT)
44
45#if QT_CONFIG(translation)
46 Q_PROPERTY(QString uiLanguage READ uiLanguage WRITE setUiLanguage BINDABLE uiLanguageBindable)
47#endif
48
49 QML_NAMED_ELEMENT(Qt)
50 QML_SINGLETON
51 QML_EXTENDED_NAMESPACE(Qt)
52
53 Q_CLASSINFO("QML.StrictArguments", "true")
54
55public:
56 enum LoadingMode { Asynchronous = 0, Synchronous = 1 };
57 Q_ENUM(LoadingMode);
58
59 static QtObject *create(QQmlEngine *, QJSEngine *jsEngine);
60
61 Q_INVOKABLE QJSValue include(const QString &url, const QJSValue &callback = QJSValue()) const;
62 Q_INVOKABLE bool isQtObject(const QJSValue &value) const;
63
64 Q_INVOKABLE QVariant color(const QString &name) const;
65 Q_INVOKABLE QVariant rgba(double r, double g, double b, double a = 1) const;
66 Q_INVOKABLE QVariant hsla(double h, double s, double l, double a = 1) const;
67 Q_INVOKABLE QVariant hsva(double h, double s, double v, double a = 1) const;
68 Q_INVOKABLE bool colorEqual(const QVariant &lhs, const QVariant &rhs) const;
69
70 Q_INVOKABLE QRectF rect(double x, double y, double width, double height) const;
71 Q_INVOKABLE QPointF point(double x, double y) const;
72 Q_INVOKABLE QSizeF size(double width, double height) const;
73 Q_INVOKABLE QVariant vector2d(double x, double y) const;
74 Q_INVOKABLE QVariant vector3d(double x, double y, double z) const;
75 Q_INVOKABLE QVariant vector4d(double x, double y, double z, double w) const;
76 Q_INVOKABLE QVariant quaternion(double scalar, double x, double y, double z) const;
77
78 Q_INVOKABLE QVariant matrix4x4() const;
79 Q_INVOKABLE QVariant matrix4x4(double m11, double m12, double m13, double m14,
80 double m21, double m22, double m23, double m24,
81 double m31, double m32, double m33, double m34,
82 double m41, double m42, double m43, double m44) const;
83 Q_INVOKABLE QVariant matrix4x4(const QJSValue &value) const;
84
85 Q_INVOKABLE QVariant lighter(const QJSValue &color, double factor = 1.5) const;
86 Q_INVOKABLE QVariant darker(const QJSValue &color, double factor = 2.0) const;
87 Q_INVOKABLE QVariant alpha(const QJSValue &baseColor, double value) const;
88 Q_INVOKABLE QVariant tint(const QJSValue &baseColor, const QJSValue &tintColor) const;
89
90 Q_INVOKABLE QString formatDate(QDate date, const QString &format) const;
91 Q_INVOKABLE QString formatDate(const QDateTime &dateTime, const QString &format) const;
92 Q_INVOKABLE QString formatDate(const QString &string, const QString &format) const;
93 Q_INVOKABLE QString formatDate(QDate date, Qt::DateFormat format) const;
94 Q_INVOKABLE QString formatDate(const QDateTime &dateTime, Qt::DateFormat format) const;
95 Q_INVOKABLE QString formatDate(const QString &string, Qt::DateFormat format) const;
96
97 Q_INVOKABLE QString formatTime(QTime time, const QString &format) const;
98 Q_INVOKABLE QString formatTime(const QDateTime &dateTime, const QString &format) const;
99 Q_INVOKABLE QString formatTime(const QString &time, const QString &format) const;
100 Q_INVOKABLE QString formatTime(QTime time, Qt::DateFormat format) const;
101 Q_INVOKABLE QString formatTime(const QDateTime &dateTime, Qt::DateFormat format) const;
102 Q_INVOKABLE QString formatTime(const QString &time, Qt::DateFormat format) const;
103
104 Q_INVOKABLE QString formatDateTime(const QDateTime &date, const QString &format) const;
105 Q_INVOKABLE QString formatDateTime(const QString &string, const QString &format) const;
106 Q_INVOKABLE QString formatDateTime(const QDateTime &date, Qt::DateFormat format) const;
107 Q_INVOKABLE QString formatDateTime(const QString &string, Qt::DateFormat format) const;
108
109#if QT_CONFIG(qml_locale)
110 Q_INVOKABLE QString formatDate(QDate date, const QLocale &locale = QLocale(),
111 QLocale::FormatType formatType = QLocale::ShortFormat) const;
112 Q_INVOKABLE QString formatDate(const QDateTime &dateTime, const QLocale &locale = QLocale(),
113 QLocale::FormatType formatType = QLocale::ShortFormat) const;
114 Q_INVOKABLE QString formatDate(const QString &string, const QLocale &locale = QLocale(),
115 QLocale::FormatType formatType = QLocale::ShortFormat) const;
116 Q_INVOKABLE QString formatTime(QTime time, const QLocale &locale = QLocale(),
117 QLocale::FormatType formatType = QLocale::ShortFormat) const;
118 Q_INVOKABLE QString formatTime(const QDateTime &dateTime, const QLocale &locale = QLocale(),
119 QLocale::FormatType formatType = QLocale::ShortFormat) const;
120 Q_INVOKABLE QString formatTime(const QString &time, const QLocale &locale = QLocale(),
121 QLocale::FormatType formatType = QLocale::ShortFormat) const;
122 Q_INVOKABLE QString formatDateTime(const QDateTime &date, const QLocale &locale = QLocale(),
123 QLocale::FormatType formatType = QLocale::ShortFormat) const;
124 Q_INVOKABLE QString formatDateTime(const QString &string, const QLocale &locale = QLocale(),
125 QLocale::FormatType formatType = QLocale::ShortFormat) const;
126 Q_INVOKABLE QLocale locale() const;
127 Q_INVOKABLE QLocale locale(const QString &name) const;
128#endif
129
130 Q_INVOKABLE QUrl url(const QUrl &url) const;
131 Q_INVOKABLE QUrl resolvedUrl(const QUrl &url) const;
132 Q_INVOKABLE QUrl resolvedUrl(const QUrl &url, QObject *context) const;
133 Q_INVOKABLE bool openUrlExternally(const QUrl &url) const;
134
135 Q_INVOKABLE QVariant font(const QJSValue &fontSpecifier) const;
136 Q_INVOKABLE QStringList fontFamilies() const;
137
138 Q_INVOKABLE QString md5(const QString &data) const;
139 Q_INVOKABLE QString btoa(const QString &data) const;
140 Q_INVOKABLE QString atob(const QString &data) const;
141
142 Q_INVOKABLE void quit() const;
143 Q_INVOKABLE void exit(int retCode) const;
144
145 Q_INVOKABLE QObject *createQmlObject(const QString &qml, QObject *parent,
146 const QUrl &url = QUrl(QStringLiteral("inline"))) const;
147 Q_INVOKABLE QQmlComponent *createComponent(const QUrl &url, QObject *parent) const;
148 Q_INVOKABLE QQmlComponent *createComponent(
149 const QUrl &url, QQmlComponent::CompilationMode mode = QQmlComponent::PreferSynchronous,
150 QObject *parent = nullptr) const;
151
152 Q_INVOKABLE QQmlComponent *createComponent(const QString &moduleUri,
153 const QString &typeName, QObject *parent) const;
154 Q_INVOKABLE QQmlComponent *createComponent(const QString &moduleUri, const QString &typeName,
155 QQmlComponent::CompilationMode mode = QQmlComponent::PreferSynchronous,
156 QObject *parent = nullptr) const;
157
158 Q_INVOKABLE QJSValue binding(const QJSValue &function) const;
159 Q_INVOKABLE void callLater(QQmlV4FunctionPtr args);
160
161#if QT_CONFIG(translation)
162 QString uiLanguage() const;
163 void setUiLanguage(const QString &uiLanguage);
164 QBindable<QString> uiLanguageBindable();
165#endif
166
167 // Not const because created on first use, and parented to this.
168 QQmlPlatform *platform();
169 QQmlApplication *application();
170
171 QObject *inputMethod() const;
172 QObject *styleHints() const;
173
174private:
175 friend struct QV4::ExecutionEngine;
176
177 QtObject(QV4::ExecutionEngine *engine);
178
179 QQmlEngine *qmlEngine() const { return m_engine->qmlEngine(); }
180 QJSEngine *jsEngine() const { return m_engine->jsEngine(); }
181 QV4::ExecutionEngine *v4Engine() const { return m_engine; }
182
183 struct Contexts {
184 QQmlRefPointer<QQmlContextData> context;
185 QQmlRefPointer<QQmlContextData> effectiveContext;
186 };
187 Contexts getContexts() const;
188
189 QQmlPlatform *m_platform = nullptr;
190 QQmlApplication *m_application = nullptr;
191
192 QV4::ExecutionEngine *m_engine = nullptr;
193};
194
195namespace QV4 {
196
197namespace Heap {
198
200 void init();
201};
202
203#define QQmlBindingFunctionMembers(class, Member)
204 Member(class, Pointer, JavaScriptFunctionObject *, bindingFunction)
206 DECLARE_MARKOBJECTS(QQmlBindingFunction)
207 void init(const QV4::JavaScriptFunctionObject *bindingFunction);
208};
209
210}
211
213{
214 V4_OBJECT2(ConsoleObject, Object)
215
216 static ReturnedValue method_error(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc);
217 static ReturnedValue method_log(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc);
218 static ReturnedValue method_info(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc);
219 static ReturnedValue method_profile(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc);
220 static ReturnedValue method_profileEnd(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc);
221 static ReturnedValue method_time(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc);
222 static ReturnedValue method_timeEnd(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc);
223 static ReturnedValue method_count(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc);
224 static ReturnedValue method_trace(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc);
225 static ReturnedValue method_warn(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc);
226 static ReturnedValue method_assert(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc);
227 static ReturnedValue method_exception(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc);
228
229};
230
231struct Q_QML_EXPORT GlobalExtensions {
233
234#if QT_CONFIG(translation)
236 static ReturnedValue method_qsTranslate(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc);
238 static ReturnedValue method_qsTr(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc);
239 static ReturnedValue method_qsTrNoOp(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc);
240 static ReturnedValue method_qsTrId(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc);
241 static ReturnedValue method_qsTrIdNoOp(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc);
242#endif
243 static ReturnedValue method_gc(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc);
244
245 // on String:prototype
246 static ReturnedValue method_string_arg(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc);
247
248};
249
251{
252 V4_OBJECT2(QQmlBindingFunction, JavaScriptFunctionObject)
253
255 const FunctionObject *f, const Value *thisObject, const Value *argv, int argc);
256
257 Heap::JavaScriptFunctionObject *bindingFunction() const { return d()->bindingFunction; }
258 QQmlSourceLocation currentLocation() const; // from caller stack trace
259};
260
261inline bool FunctionObject::isBinding() const
262{
263 return d()->vtable() == QQmlBindingFunction::staticVTable();
264}
265
266}
267
268QT_END_NAMESPACE
269
270#endif // QQMLBUILTINFUNCTIONS_P_H
Combined button and popup list for selecting options.
DECLARE_HEAP_OBJECT(QmlContext, ExecutionContext)
Definition qjsvalue.h:23
Q_LOGGING_CATEGORY(lcEventDispatcher, "qt.eventdispatcher")
QT_BEGIN_NAMESPACE Q_DECLARE_LOGGING_CATEGORY(lcEventDispatcher)
DEFINE_OBJECT_VTABLE(QQmlBindingFunction)
static QTime dateTimeToTime(const QDateTime &dateTime)
static QString serializeArray(Object *array, ExecutionEngine *v4, QSet< QV4::Heap::Object * > &alreadySeen)
void addParameters(QJSEngine *e, QJSValue &result, int i, T parameter, Others... others)
static QVariant constructFromJSValue(QJSEngine *e, QMetaType type, T... parameters)
void addParameters< double >(QJSEngine *, QJSValue &result, int i, double parameter)
static std::optional< QDate > dateFromString(const QString &string, QV4::ExecutionEngine *engine)
\qmlmethod string Qt::formatDate(datetime date, variant format, variant localeFormatOption)
DEFINE_OBJECT_VTABLE(ConsoleObject)
static ReturnedValue writeToConsole(const FunctionObject *b, const Value *argv, int argc, ConsoleLogTypes logType, bool printStack=false)
void addParameters(QJSEngine *e, QJSValue &result, int i, T parameter)
static QString jsStack(QV4::ExecutionEngine *engine)
static std::optional< QTime > timeFromString(const QString &string, QV4::ExecutionEngine *engine)
\qmlmethod string Qt::formatTime(datetime time, variant format, variant localeFormatOption)
static std::optional< QDateTime > dateTimeFromString(const QString &string, QV4::ExecutionEngine *engine)
\qmlmethod string Qt::formatDateTime(datetime dateTime, variant format, variant localeFormatOption)
static Q_DECL_COLD_FUNCTION void throw_invalid_compilation_mode(QV4::ExecutionEngine *engine, QQmlComponent::CompilationMode mode)
static QVariant colorVariantFromJSValue(const QJSValue &color, bool *ok)
Q_DECLARE_LOGGING_CATEGORY(lcJs)
static ReturnedValue method_profile(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_warn(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_log(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_count(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_info(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_timeEnd(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_exception(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_assert(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_time(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_profileEnd(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_trace(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc)
QQmlSourceLocation currentLocation() const
Heap::JavaScriptFunctionObject * bindingFunction() const