Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
34class Q_QML_EXPORT QtObject : public QObject
35{
37 Q_PROPERTY(QQmlApplication *application READ application CONSTANT)
39 Q_PROPERTY(QObject *inputMethod READ inputMethod CONSTANT)
40 Q_PROPERTY(QObject *styleHints READ styleHints CONSTANT)
41
42#if QT_CONFIG(translation)
43 Q_PROPERTY(QString uiLanguage READ uiLanguage WRITE setUiLanguage BINDABLE uiLanguageBindable)
44#endif
45
50
51 Q_CLASSINFO("QML.StrictArguments", "true")
52
53public:
54 enum LoadingMode { Asynchronous = 0, Synchronous = 1 };
56
57 static QtObject *create(QQmlEngine *, QJSEngine *jsEngine);
58
59 Q_INVOKABLE QJSValue include(const QString &url, const QJSValue &callback = QJSValue()) const;
60 Q_INVOKABLE bool isQtObject(const QJSValue &value) const;
61
63 Q_INVOKABLE QVariant rgba(double r, double g, double b, double a = 1) const;
64 Q_INVOKABLE QVariant hsla(double h, double s, double l, double a = 1) const;
65 Q_INVOKABLE QVariant hsva(double h, double s, double v, double a = 1) const;
66 Q_INVOKABLE bool colorEqual(const QVariant &lhs, const QVariant &rhs) const;
67
68 Q_INVOKABLE QRectF rect(double x, double y, double width, double height) const;
69 Q_INVOKABLE QPointF point(double x, double y) const;
70 Q_INVOKABLE QSizeF size(double width, double height) const;
71 Q_INVOKABLE QVariant vector2d(double x, double y) const;
72 Q_INVOKABLE QVariant vector3d(double x, double y, double z) const;
73 Q_INVOKABLE QVariant vector4d(double x, double y, double z, double w) const;
74 Q_INVOKABLE QVariant quaternion(double scalar, double x, double y, double z) const;
75
76 Q_INVOKABLE QVariant matrix4x4() const;
77 Q_INVOKABLE QVariant matrix4x4(double m11, double m12, double m13, double m14,
78 double m21, double m22, double m23, double m24,
79 double m31, double m32, double m33, double m34,
80 double m41, double m42, double m43, double m44) const;
81 Q_INVOKABLE QVariant matrix4x4(const QJSValue &value) const;
82
83 Q_INVOKABLE QVariant lighter(const QJSValue &color, double factor = 1.5) const;
84 Q_INVOKABLE QVariant darker(const QJSValue &color, double factor = 2.0) const;
85 Q_INVOKABLE QVariant alpha(const QJSValue &baseColor, double value) const;
86 Q_INVOKABLE QVariant tint(const QJSValue &baseColor, const QJSValue &tintColor) const;
87
88 Q_INVOKABLE QString formatDate(QDate date, const QString &format) const;
89 Q_INVOKABLE QString formatDate(const QDateTime &dateTime, const QString &format) const;
90 Q_INVOKABLE QString formatDate(const QString &string, const QString &format) const;
93 Q_INVOKABLE QString formatDate(const QString &string, Qt::DateFormat format) const;
94
95 Q_INVOKABLE QString formatTime(QTime time, const QString &format) const;
96 Q_INVOKABLE QString formatTime(const QDateTime &dateTime, const QString &format) const;
97 Q_INVOKABLE QString formatTime(const QString &time, const QString &format) const;
100 Q_INVOKABLE QString formatTime(const QString &time, Qt::DateFormat format) const;
101
102 Q_INVOKABLE QString formatDateTime(const QDateTime &date, const QString &format) const;
103 Q_INVOKABLE QString formatDateTime(const QString &string, const QString &format) const;
104 Q_INVOKABLE QString formatDateTime(const QDateTime &date, Qt::DateFormat format) const;
105 Q_INVOKABLE QString formatDateTime(const QString &string, Qt::DateFormat format) const;
106
107#if QT_CONFIG(qml_locale)
108 Q_INVOKABLE QString formatDate(QDate date, const QLocale &locale = QLocale(),
109 QLocale::FormatType formatType = QLocale::ShortFormat) const;
110 Q_INVOKABLE QString formatDate(const QDateTime &dateTime, const QLocale &locale = QLocale(),
111 QLocale::FormatType formatType = QLocale::ShortFormat) const;
112 Q_INVOKABLE QString formatDate(const QString &string, const QLocale &locale = QLocale(),
113 QLocale::FormatType formatType = QLocale::ShortFormat) const;
114 Q_INVOKABLE QString formatTime(QTime time, const QLocale &locale = QLocale(),
115 QLocale::FormatType formatType = QLocale::ShortFormat) const;
116 Q_INVOKABLE QString formatTime(const QDateTime &dateTime, const QLocale &locale = QLocale(),
117 QLocale::FormatType formatType = QLocale::ShortFormat) const;
118 Q_INVOKABLE QString formatTime(const QString &time, const QLocale &locale = QLocale(),
119 QLocale::FormatType formatType = QLocale::ShortFormat) const;
120 Q_INVOKABLE QString formatDateTime(const QDateTime &date, const QLocale &locale = QLocale(),
121 QLocale::FormatType formatType = QLocale::ShortFormat) const;
122 Q_INVOKABLE QString formatDateTime(const QString &string, const QLocale &locale = QLocale(),
123 QLocale::FormatType formatType = QLocale::ShortFormat) const;
124 Q_INVOKABLE QLocale locale() const;
125 Q_INVOKABLE QLocale locale(const QString &name) const;
126#endif
127
128 Q_INVOKABLE QUrl url(const QUrl &url) const;
129 Q_INVOKABLE QUrl resolvedUrl(const QUrl &url) const;
131 Q_INVOKABLE bool openUrlExternally(const QUrl &url) const;
132
133 Q_INVOKABLE QVariant font(const QJSValue &fontSpecifier) const;
134 Q_INVOKABLE QStringList fontFamilies() const;
135
136 Q_INVOKABLE QString md5(const QString &data) const;
137 Q_INVOKABLE QString btoa(const QString &data) const;
138 Q_INVOKABLE QString atob(const QString &data) const;
139
140 Q_INVOKABLE void quit() const;
141 Q_INVOKABLE void exit(int retCode) const;
142
143 Q_INVOKABLE QObject *createQmlObject(const QString &qml, QObject *parent,
144 const QUrl &url = QUrl(QStringLiteral("inline"))) const;
145 Q_INVOKABLE QQmlComponent *createComponent(const QUrl &url, QObject *parent) const;
146 Q_INVOKABLE QQmlComponent *createComponent(
148 QObject *parent = nullptr) const;
149
150 Q_INVOKABLE QQmlComponent *createComponent(const QString &moduleUri,
151 const QString &typeName, QObject *parent) const;
152 Q_INVOKABLE QQmlComponent *createComponent(const QString &moduleUri, const QString &typeName,
154 QObject *parent = nullptr) const;
155
156 Q_INVOKABLE QJSValue binding(const QJSValue &function) const;
157 Q_INVOKABLE void callLater(QQmlV4FunctionPtr args);
158
159#if QT_CONFIG(translation)
160 QString uiLanguage() const;
161 void setUiLanguage(const QString &uiLanguage);
162 QBindable<QString> uiLanguageBindable();
163#endif
164
165 // Not const because created on first use, and parented to this.
168
169 QObject *inputMethod() const;
170 QObject *styleHints() const;
171
172private:
173 friend struct QV4::ExecutionEngine;
174
176
177 QQmlEngine *qmlEngine() const { return m_engine->qmlEngine(); }
178 QJSEngine *jsEngine() const { return m_engine->jsEngine(); }
179 QV4::ExecutionEngine *v4Engine() const { return m_engine; }
180
181 struct Contexts {
182 QQmlRefPointer<QQmlContextData> context;
183 QQmlRefPointer<QQmlContextData> effectiveContext;
184 };
185 Contexts getContexts() const;
186
187 QQmlPlatform *m_platform = nullptr;
188 QQmlApplication *m_application = nullptr;
189
190 QV4::ExecutionEngine *m_engine = nullptr;
191};
192
193namespace QV4 {
194
195namespace Heap {
196
198 void init();
199};
200
201#define QQmlBindingFunctionMembers(class, Member) \
202 Member(class, Pointer, JavaScriptFunctionObject *, bindingFunction)
207
208}
209
211{
213
214 static ReturnedValue method_error(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc);
215 static ReturnedValue method_log(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc);
216 static ReturnedValue method_info(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc);
217 static ReturnedValue method_profile(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc);
218 static ReturnedValue method_profileEnd(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc);
219 static ReturnedValue method_time(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc);
220 static ReturnedValue method_timeEnd(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc);
221 static ReturnedValue method_count(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc);
222 static ReturnedValue method_trace(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc);
223 static ReturnedValue method_warn(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc);
224 static ReturnedValue method_assert(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc);
225 static ReturnedValue method_exception(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc);
226
227};
228
229struct Q_QML_EXPORT GlobalExtensions {
230 static void init(Object *globalObject, QJSEngine::Extensions extensions);
231
232#if QT_CONFIG(translation)
233 static QString currentTranslationContext(ExecutionEngine *engine);
234 static ReturnedValue method_qsTranslate(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc);
235 static ReturnedValue method_qsTranslateNoOp(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc);
236 static ReturnedValue method_qsTr(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc);
237 static ReturnedValue method_qsTrNoOp(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc);
238 static ReturnedValue method_qsTrId(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc);
239 static ReturnedValue method_qsTrIdNoOp(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc);
240#endif
241 static ReturnedValue method_gc(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc);
242
243 // on String:prototype
244 static ReturnedValue method_string_arg(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc);
245
246};
247
249{
251
253 const FunctionObject *f, const Value *thisObject, const Value *argv, int argc);
254
255 Heap::JavaScriptFunctionObject *bindingFunction() const { return d()->bindingFunction; }
256 QQmlSourceLocation currentLocation() const; // from caller stack trace
257};
258
259inline bool FunctionObject::isBinding() const
260{
261 return d()->vtable() == QQmlBindingFunction::staticVTable();
262}
263
264}
265
267
268#endif // QQMLBUILTINFUNCTIONS_P_H
\inmodule QtCore\reentrant
Definition qdatetime.h:283
\inmodule QtCore \reentrant
Definition qdatetime.h:29
The QJSEngine class provides an environment for evaluating JavaScript code.
Definition qjsengine.h:26
The QJSValue class acts as a container for Qt/JavaScript data types.
Definition qjsvalue.h:31
@ ShortFormat
Definition qlocale.h:875
\inmodule QtCore
Definition qobject.h:103
\inmodule QtCore\reentrant
Definition qpoint.h:217
The QQmlComponent class encapsulates a QML component definition.
CompilationMode
Specifies whether the QQmlComponent should load the component immediately, or asynchonously.
The QQmlEngine class provides an environment for instantiating QML components.
Definition qqmlengine.h:57
QQmlEngine * qmlEngine(const QObject *object)
Returns the QQmlEngine associated with object, if any.
Definition qqml.cpp:80
\inmodule QtCore\reentrant
Definition qrect.h:484
\inmodule QtCore
Definition qsize.h:208
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\inmodule QtCore \reentrant
Definition qdatetime.h:215
\inmodule QtCore
Definition qurl.h:94
\inmodule QtCore
Definition qvariant.h:65
QQmlApplication * application()
Q_ENUM(LoadingMode)
QQmlPlatform * platform()
QDate date
[1]
rect
[4]
Combined button and popup list for selecting options.
quint64 ReturnedValue
Definition qcompare.h:63
DateFormat
static void * context
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
static QV4::ExecutionEngine * v4Engine(QV4::Value *d)
const char * typeName
GLboolean GLboolean GLboolean b
GLsizei const GLfloat * v
[13]
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat z
GLint GLint GLint GLint GLint x
[0]
GLenum mode
GLfloat GLfloat GLfloat w
[0]
GLint GLsizei GLsizei height
GLboolean GLboolean GLboolean GLboolean a
[7]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLboolean r
[2]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLfloat GLfloat f
GLint GLsizei width
GLuint color
[2]
GLboolean GLboolean g
GLuint name
GLint GLsizei GLsizei GLenum format
GLint y
GLfloat GLfloat GLfloat GLfloat h
GLdouble s
[6]
Definition qopenglext.h:235
GLfloat GLfloat GLfloat alpha
Definition qopenglext.h:418
QQmlEngine * qmlEngine(const QObject *obj)
Definition qqml.cpp:80
#define QML_NAMED_ELEMENT(NAME)
#define QML_SINGLETON
#define QML_EXTENDED_NAMESPACE(EXTENDED_NAMESPACE)
#define QML_ADDED_IN_VERSION(MAJOR, MINOR)
static QUrl resolvedUrl(const QUrl &url, const QQmlRefPointer< QQmlContextData > &context)
#define QStringLiteral(str)
static QT_BEGIN_NAMESPACE void init(QTextBoundaryFinder::BoundaryType type, QStringView str, QCharAttributes *attributes)
#define Q_PROPERTY(...)
#define Q_OBJECT
#define Q_CLASSINFO(name, value)
#define Q_INVOKABLE
#define DECLARE_HEAP_OBJECT(name, base)
#define DECLARE_MARKOBJECTS(class)
#define V4_OBJECT2(DataClass, superClass)
QT_BEGIN_NAMESPACE Platform platform()
QUrl url("example.com")
[constructor-url-reference]
QDateTime dateTime
[12]
view create()
engine globalObject().setProperty("myObject"
QJSValueList args
QJSEngine engine
[0]
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_error(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
static constexpr VTable::Call virtualCall