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
qqmlglobal_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 QQMLGLOBAL_H
5#define QQMLGLOBAL_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/qmetaobject_p.h>
19#include <private/qqmlmetaobject_p.h>
20#include <private/qqmltype_p.h>
21#include <private/qtqmlglobal_p.h>
22
23#include <QtQml/qqml.h>
24#include <QtCore/qobject.h>
25
27
28inline bool qmlConvertBoolConfigOption(const char *v)
29{
30 return v != nullptr && qstrcmp(v, "0") != 0 && qstrcmp(v, "false") != 0;
31}
32
33template<typename T, T(*Convert)(const char *)>
34T qmlGetConfigOption(const char *var)
35{
37 return Convert(qgetenv(var));
38 return Convert(nullptr);
39}
40
41#define DEFINE_BOOL_CONFIG_OPTION(name, var) \
42 static bool name() \
43 { \
44 static const bool result = qmlGetConfigOption<bool, qmlConvertBoolConfigOption>(#var); \
45 return result; \
46 }
47
63#define qmlobject_connect(Sender, SenderType, Signal, Receiver, ReceiverType, Method) \
64do { \
65 SenderType *sender = (Sender); \
66 ReceiverType *receiver = (Receiver); \
67 const char *signal = (Signal); \
68 const char *method = (Method); \
69 static int signalIdx = -1; \
70 static int methodIdx = -1; \
71 if (signalIdx < 0) { \
72 Q_ASSERT((int(*signal) - '0') == QSIGNAL_CODE); \
73 signalIdx = SenderType::staticMetaObject.indexOfSignal(signal+1); \
74 } \
75 if (methodIdx < 0) { \
76 int code = (int(*method) - '0'); \
77 Q_ASSERT(code == QSLOT_CODE || code == QSIGNAL_CODE); \
78 if (code == QSLOT_CODE) \
79 methodIdx = ReceiverType::staticMetaObject.indexOfSlot(method+1); \
80 else \
81 methodIdx = ReceiverType::staticMetaObject.indexOfSignal(method+1); \
82 } \
83 Q_ASSERT(signalIdx != -1 && methodIdx != -1); \
84 QMetaObject::connect(sender, signalIdx, receiver, methodIdx, Qt::DirectConnection); \
85} while (0)
86
102#define qmlobject_disconnect(Sender, SenderType, Signal, Receiver, ReceiverType, Method) \
103do { \
104 SenderType *sender = (Sender); \
105 ReceiverType *receiver = (Receiver); \
106 const char *signal = (Signal); \
107 const char *method = (Method); \
108 static int signalIdx = -1; \
109 static int methodIdx = -1; \
110 if (signalIdx < 0) { \
111 Q_ASSERT((int(*signal) - '0') == QSIGNAL_CODE); \
112 signalIdx = SenderType::staticMetaObject.indexOfSignal(signal+1); \
113 } \
114 if (methodIdx < 0) { \
115 int code = (int(*method) - '0'); \
116 Q_ASSERT(code == QSLOT_CODE || code == QSIGNAL_CODE); \
117 if (code == QSLOT_CODE) \
118 methodIdx = ReceiverType::staticMetaObject.indexOfSlot(method+1); \
119 else \
120 methodIdx = ReceiverType::staticMetaObject.indexOfSignal(method+1); \
121 } \
122 Q_ASSERT(signalIdx != -1 && methodIdx != -1); \
123 QMetaObject::disconnect(sender, signalIdx, receiver, methodIdx); \
124} while (0)
125
126Q_QML_EXPORT bool qmlobject_can_cpp_cast(QObject *object, const QMetaObject *mo);
127Q_QML_EXPORT bool qmlobject_can_qml_cast(QObject *object, const QQmlType &type);
128
141template<class T>
143{
144 if (!object)
145 return nullptr;
146 if (qmlobject_can_cpp_cast(object, &(std::remove_pointer_t<T>::staticMetaObject)))
147 return static_cast<T>(object);
148 else
149 return nullptr;
150}
151
152class QQuickItem;
153template<>
155{
156 if (!object || !object->isQuickItemType())
157 return nullptr;
158 // QQuickItem is incomplete here -> can't use static_cast
159 // but we don't need any pointer adjustment, so reinterpret is safe
160 return reinterpret_cast<QQuickItem *>(object);
161}
162
163#define IS_SIGNAL_CONNECTED(Sender, SenderType, Name, Arguments) \
164do { \
165 QObject *sender = (Sender); \
166 void (SenderType::*signal)Arguments = &SenderType::Name; \
167 static QMetaMethod method = QMetaMethod::fromSignal(signal); \
168 static int signalIdx = QMetaObjectPrivate::signalIndex(method); \
169 return QObjectPrivate::get(sender)->isSignalConnected(signalIdx); \
170} while (0)
171
190bool QQml_isFileCaseCorrect(const QString &fileName, int length = -1);
191
198{
200 bool sce = d_ptr->sendChildEvents;
201 d_ptr->sendChildEvents = false;
202 object->setParent(parent);
203 d_ptr->sendChildEvents = sce;
204}
205
207{
208public:
209 static bool populateValueType(
210 QMetaType targetMetaType, void *target, const QV4::Value &source);
211 static bool populateValueType(
212 QMetaType targetMetaType, void *target, QMetaType sourceMetaType, void *source);
213
214 static Q_QML_EXPORT void *heapCreateValueType(
215 const QQmlType &targetType, const QV4::Value &source);
217 QMetaType targetMetaType, const QMetaObject *targetMetaObject,
218 int ctorIndex, void *ctorArg);
219
221 static QVariant createValueType(const QString &, QMetaType);
224};
225
226class Q_QML_EXPORT QQmlColorProvider
227{
228public:
229 virtual ~QQmlColorProvider();
230 virtual QVariant colorFromString(const QString &, bool *);
231 virtual unsigned rgbaFromString(const QString &, bool *);
232
233 virtual QVariant fromRgbF(double, double, double, double);
234 virtual QVariant fromHslF(double, double, double, double);
235 virtual QVariant fromHsvF(double, double, double, double);
236 virtual QVariant lighter(const QVariant &, qreal);
237 virtual QVariant darker(const QVariant &, qreal);
238 virtual QVariant alpha(const QVariant &, qreal);
239 virtual QVariant tint(const QVariant &, const QVariant &);
240};
241
244
245class QQmlApplication;
246class Q_QML_EXPORT QQmlGuiProvider
247{
248public:
249 virtual ~QQmlGuiProvider();
250 virtual QQmlApplication *application(QObject *parent);
251 virtual QObject *inputMethod();
252 virtual QObject *styleHints();
253 virtual QStringList fontFamilies();
254 virtual bool openUrlExternally(const QUrl &);
255 virtual QString pluginName() const;
256};
257
260
262
263class Q_QML_EXPORT QQmlApplication : public QObject
264{
265 //Application level logic, subclassed by Qt Quick if available via QQmlGuiProvider
268 Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
269 Q_PROPERTY(QString version READ version WRITE setVersion NOTIFY versionChanged)
270 Q_PROPERTY(QString organization READ organization WRITE setOrganization NOTIFY organizationChanged)
271 Q_PROPERTY(QString domain READ domain WRITE setDomain NOTIFY domainChanged)
274public:
275 QQmlApplication(QObject* parent=nullptr);
276
278
279 QString name() const;
280 QString version() const;
281 QString organization() const;
282 QString domain() const;
283
284public Q_SLOTS:
285 void setName(const QString &arg);
286 void setVersion(const QString &arg);
287 void setOrganization(const QString &arg);
288 void setDomain(const QString &arg);
289
291 void aboutToQuit();
292
293 void nameChanged();
294 void versionChanged();
295 void organizationChanged();
296 void domainChanged();
297
298protected:
299 QQmlApplication(QQmlApplicationPrivate &dd, QObject* parent=nullptr);
300
301private:
302 Q_DISABLE_COPY(QQmlApplication)
303 Q_DECLARE_PRIVATE(QQmlApplication)
304};
305
307{
308 Q_DECLARE_PUBLIC(QQmlApplication)
309public:
311 argsInit = false;
312 }
313
316};
317
327
329
330#endif // QQMLGLOBAL_H
The QJSValue class acts as a container for Qt/JavaScript data types.
Definition qjsvalue.h:31
\inmodule QtCore
Definition qmetatype.h:341
uint sendChildEvents
Definition qobject.h:80
static QObjectPrivate * get(QObject *o)
Definition qobject_p.h:150
\inmodule QtCore
Definition qobject.h:103
QScopedPointer< QObjectData > d_ptr
Definition qobject.h:373
static bool populateValueType(QMetaType targetMetaType, void *target, const QV4::Value &source)
static Q_QML_EXPORT void * heapCreateValueType(const QQmlType &targetType, const QV4::Value &source)
static QVariant constructValueType(QMetaType targetMetaType, const QMetaObject *targetMetaObject, int ctorIndex, void *ctorArg)
static QVariant createValueType(const QJSValue &, QMetaType)
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:63
QQuickItem * parent
\qmlproperty Item QtQuick::Item::parent This property holds the visual parent of the item.
Definition qquickitem.h:67
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\inmodule QtCore
Definition qurl.h:94
\inmodule QtCore
Definition qvariant.h:65
format setVersion(3, 2)
employee setName("Richard Schmit")
auto mo
[7]
QList< QVariant > arguments
Combined button and popup list for selecting options.
Q_CORE_EXPORT int qstrcmp(const char *str1, const char *str2)
#define Q_UNLIKELY(x)
GLsizei const GLfloat * v
[13]
GLenum GLuint GLenum GLsizei length
GLuint object
[3]
GLenum type
GLenum target
GLuint name
GLsizei GLsizei GLchar * source
GLenum GLenum GLsizei void GLsizei void * column
GLfloat GLfloat GLfloat alpha
Definition qopenglext.h:418
void QQml_setParent_noEvent(QObject *object, QObject *parent)
Makes the object a child of parent.
Q_QML_EXPORT QQmlGuiProvider * QQml_setGuiProvider(QQmlGuiProvider *)
bool QQml_isFileCaseCorrect(const QString &fileName, int length=-1)
Returns true if the case of fileName is equivalent to the file case of fileName on disk,...
Q_QML_EXPORT QQmlColorProvider * QQml_setColorProvider(QQmlColorProvider *)
Q_QML_EXPORT bool qmlobject_can_qml_cast(QObject *object, const QQmlType &type)
T qmlobject_cast(QObject *object)
This method is identical to qobject_cast<T>() except that it does not require lazy QMetaObjects to be...
Q_QML_EXPORT QQmlColorProvider * QQml_colorProvider()
Q_QML_EXPORT bool qmlobject_can_cpp_cast(QObject *object, const QMetaObject *mo)
T qmlGetConfigOption(const char *var)
Q_AUTOTEST_EXPORT QQmlGuiProvider * QQml_guiProvider()
QT_BEGIN_NAMESPACE bool qmlConvertBoolConfigOption(const char *v)
QQuickItem * qmlobject_cast< QQuickItem * >(QObject *object)
#define QML_ANONYMOUS
#define QML_ADDED_IN_VERSION(MAJOR, MINOR)
SSL_CTX int void * arg
#define Q_AUTOTEST_EXPORT
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
Q_CORE_EXPORT bool qEnvironmentVariableIsEmpty(const char *varName) noexcept
#define Q_PROPERTY(...)
#define Q_OBJECT
#define Q_SLOTS
#define Q_SIGNALS
unsigned short quint16
Definition qtypes.h:48
double qreal
Definition qtypes.h:187
QJSValueList args
\inmodule QtCore
QQmlSourceLocation(const QString &sourceFile, quint16 line, quint16 column)