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 QQMLGLOBAL_H |
41 | #define QQMLGLOBAL_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 <private/qtqmlglobal_p.h> |
55 | #include <QtCore/QObject> |
56 | #include <private/qqmlmetaobject_p.h> |
57 | #include <private/qmetaobject_p.h> |
58 | |
59 | QT_BEGIN_NAMESPACE |
60 | |
61 | |
62 | #define DEFINE_BOOL_CONFIG_OPTION(name, var) \ |
63 | static bool name() \ |
64 | { \ |
65 | static enum { Yes, No, Unknown } status = Unknown; \ |
66 | if (status == Unknown) { \ |
67 | status = No; \ |
68 | if (Q_UNLIKELY(!qEnvironmentVariableIsEmpty(#var))) { \ |
69 | const QByteArray v = qgetenv(#var); \ |
70 | if (v != "0" && v != "false") \ |
71 | status = Yes; \ |
72 | } \ |
73 | } \ |
74 | return status == Yes; \ |
75 | } |
76 | |
77 | /*! |
78 | Connect \a Signal of \a Sender to \a Method of \a Receiver. \a Signal must be |
79 | of type \a SenderType and \a Receiver of type \a ReceiverType. |
80 | |
81 | Unlike QObject::connect(), this method caches the lookup of the signal and method |
82 | indexes. It also does not require lazy QMetaObjects to be built so should be |
83 | preferred in all QML code that might interact with QML built objects. |
84 | |
85 | \code |
86 | QQuickTextControl *control; |
87 | QQuickTextEdit *textEdit; |
88 | qmlobject_connect(control, QQuickTextControl, SIGNAL(updateRequest(QRectF)), |
89 | textEdit, QQuickTextEdit, SLOT(updateDocument())); |
90 | \endcode |
91 | */ |
92 | #define qmlobject_connect(Sender, SenderType, Signal, Receiver, ReceiverType, Method) \ |
93 | do { \ |
94 | SenderType *sender = (Sender); \ |
95 | ReceiverType *receiver = (Receiver); \ |
96 | const char *signal = (Signal); \ |
97 | const char *method = (Method); \ |
98 | static int signalIdx = -1; \ |
99 | static int methodIdx = -1; \ |
100 | if (signalIdx < 0) { \ |
101 | Q_ASSERT((int(*signal) - '0') == QSIGNAL_CODE); \ |
102 | signalIdx = SenderType::staticMetaObject.indexOfSignal(signal+1); \ |
103 | } \ |
104 | if (methodIdx < 0) { \ |
105 | int code = (int(*method) - '0'); \ |
106 | Q_ASSERT(code == QSLOT_CODE || code == QSIGNAL_CODE); \ |
107 | if (code == QSLOT_CODE) \ |
108 | methodIdx = ReceiverType::staticMetaObject.indexOfSlot(method+1); \ |
109 | else \ |
110 | methodIdx = ReceiverType::staticMetaObject.indexOfSignal(method+1); \ |
111 | } \ |
112 | Q_ASSERT(signalIdx != -1 && methodIdx != -1); \ |
113 | QMetaObject::connect(sender, signalIdx, receiver, methodIdx, Qt::DirectConnection); \ |
114 | } while (0) |
115 | |
116 | /*! |
117 | Disconnect \a Signal of \a Sender from \a Method of \a Receiver. \a Signal must be |
118 | of type \a SenderType and \a Receiver of type \a ReceiverType. |
119 | |
120 | Unlike QObject::disconnect(), this method caches the lookup of the signal and method |
121 | indexes. It also does not require lazy QMetaObjects to be built so should be |
122 | preferred in all QML code that might interact with QML built objects. |
123 | |
124 | \code |
125 | QQuickTextControl *control; |
126 | QQuickTextEdit *textEdit; |
127 | qmlobject_disconnect(control, QQuickTextControl, SIGNAL(updateRequest(QRectF)), |
128 | textEdit, QQuickTextEdit, SLOT(updateDocument())); |
129 | \endcode |
130 | */ |
131 | #define qmlobject_disconnect(Sender, SenderType, Signal, Receiver, ReceiverType, Method) \ |
132 | do { \ |
133 | SenderType *sender = (Sender); \ |
134 | ReceiverType *receiver = (Receiver); \ |
135 | const char *signal = (Signal); \ |
136 | const char *method = (Method); \ |
137 | static int signalIdx = -1; \ |
138 | static int methodIdx = -1; \ |
139 | if (signalIdx < 0) { \ |
140 | Q_ASSERT((int(*signal) - '0') == QSIGNAL_CODE); \ |
141 | signalIdx = SenderType::staticMetaObject.indexOfSignal(signal+1); \ |
142 | } \ |
143 | if (methodIdx < 0) { \ |
144 | int code = (int(*method) - '0'); \ |
145 | Q_ASSERT(code == QSLOT_CODE || code == QSIGNAL_CODE); \ |
146 | if (code == QSLOT_CODE) \ |
147 | methodIdx = ReceiverType::staticMetaObject.indexOfSlot(method+1); \ |
148 | else \ |
149 | methodIdx = ReceiverType::staticMetaObject.indexOfSignal(method+1); \ |
150 | } \ |
151 | Q_ASSERT(signalIdx != -1 && methodIdx != -1); \ |
152 | QMetaObject::disconnect(sender, signalIdx, receiver, methodIdx); \ |
153 | } while (0) |
154 | |
155 | /*! |
156 | This method is identical to qobject_cast<T>() except that it does not require lazy |
157 | QMetaObjects to be built, so should be preferred in all QML code that might interact |
158 | with QML built objects. |
159 | |
160 | \code |
161 | QObject *object; |
162 | if (QQuickTextEdit *textEdit = qmlobject_cast<QQuickTextEdit *>(object)) { |
163 | // ...Do something... |
164 | } |
165 | \endcode |
166 | */ |
167 | template<class T> |
168 | T qmlobject_cast(QObject *object) |
169 | { |
170 | if (object && QQmlMetaObject::canConvert(from: object, to: &reinterpret_cast<T>(object)->staticMetaObject)) |
171 | return static_cast<T>(object); |
172 | else |
173 | return 0; |
174 | } |
175 | |
176 | #define IS_SIGNAL_CONNECTED(Sender, SenderType, Name, Arguments) \ |
177 | do { \ |
178 | QObject *sender = (Sender); \ |
179 | void (SenderType::*signal)Arguments = &SenderType::Name; \ |
180 | static QMetaMethod method = QMetaMethod::fromSignal(signal); \ |
181 | static int signalIdx = QMetaObjectPrivate::signalIndex(method); \ |
182 | return QObjectPrivate::get(sender)->isSignalConnected(signalIdx); \ |
183 | } while (0) |
184 | |
185 | /*! |
186 | Returns true if the case of \a fileName is equivalent to the file case of |
187 | \a fileName on disk, and false otherwise. |
188 | |
189 | This is used to ensure that the behavior of QML on a case-insensitive file |
190 | system is the same as on a case-sensitive file system. This function |
191 | performs a "best effort" attempt to determine the real case of the file. |
192 | It may have false positives (say the case is correct when it isn't), but it |
193 | should never have a false negative (say the case is incorrect when it is |
194 | correct). |
195 | |
196 | Length specifies specifies the number of characters to be checked from |
197 | behind. That is, if a file name results from a relative path specification |
198 | like "foo/bar.qml" and is made absolute, the original length (11) should |
199 | be passed indicating that only the last part of the relative path should |
200 | be checked. |
201 | |
202 | */ |
203 | bool QQml_isFileCaseCorrect(const QString &fileName, int length = -1); |
204 | |
205 | /*! |
206 | Makes the \a object a child of \a parent. Note that when using this method, |
207 | neither \a parent nor the object's previous parent (if it had one) will |
208 | receive ChildRemoved or ChildAdded events. |
209 | */ |
210 | inline void QQml_setParent_noEvent(QObject *object, QObject *parent) |
211 | { |
212 | QObjectPrivate *d_ptr = QObjectPrivate::get(o: object); |
213 | bool sce = d_ptr->sendChildEvents; |
214 | d_ptr->sendChildEvents = false; |
215 | object->setParent(parent); |
216 | d_ptr->sendChildEvents = sce; |
217 | } |
218 | |
219 | class Q_QML_PRIVATE_EXPORT QQmlValueTypeProvider |
220 | { |
221 | public: |
222 | QQmlValueTypeProvider(); |
223 | virtual ~QQmlValueTypeProvider(); |
224 | |
225 | const QMetaObject *metaObjectForMetaType(int); |
226 | |
227 | bool initValueType(int, QVariant&); |
228 | |
229 | QVariant createValueType(int, int, const void *[]); |
230 | bool createValueFromString(int, const QString &, void *, size_t); |
231 | bool createStringFromValue(int, const void *, QString *); |
232 | |
233 | QVariant createVariantFromString(const QString &); |
234 | QVariant createVariantFromString(int, const QString &, bool *); |
235 | QVariant createVariantFromJsObject(int, const QV4::Value &, QV4::ExecutionEngine *, bool *); |
236 | |
237 | bool equalValueType(int, const void *, const QVariant&); |
238 | bool storeValueType(int, const void *, void *, size_t); |
239 | bool readValueType(const QVariant&, void *, int); |
240 | bool writeValueType(int, const void *, QVariant&); |
241 | |
242 | private: |
243 | virtual const QMetaObject *getMetaObjectForMetaType(int); |
244 | virtual bool init(int, QVariant&); |
245 | |
246 | virtual bool create(int, int, const void *[], QVariant *); |
247 | virtual bool createFromString(int, const QString &, void *, size_t); |
248 | virtual bool createStringFrom(int, const void *, QString *); |
249 | |
250 | virtual bool variantFromString(const QString &, QVariant *); |
251 | virtual bool variantFromString(int, const QString &, QVariant *); |
252 | virtual bool variantFromJsObject(int, const QV4::Value &, QV4::ExecutionEngine *, QVariant *); |
253 | |
254 | virtual bool equal(int, const void *, const QVariant&); |
255 | virtual bool store(int, const void *, void *, size_t); |
256 | virtual bool read(const QVariant&, void *, int); |
257 | virtual bool write(int, const void *, QVariant&); |
258 | |
259 | friend Q_QML_PRIVATE_EXPORT void QQml_addValueTypeProvider(QQmlValueTypeProvider *); |
260 | friend Q_QML_PRIVATE_EXPORT void QQml_removeValueTypeProvider(QQmlValueTypeProvider *); |
261 | |
262 | QQmlValueTypeProvider *next; |
263 | }; |
264 | |
265 | Q_QML_PRIVATE_EXPORT void QQml_addValueTypeProvider(QQmlValueTypeProvider *); |
266 | Q_AUTOTEST_EXPORT QQmlValueTypeProvider *QQml_valueTypeProvider(); |
267 | |
268 | |
269 | class Q_QML_PRIVATE_EXPORT QQmlColorProvider |
270 | { |
271 | public: |
272 | virtual ~QQmlColorProvider(); |
273 | virtual QVariant colorFromString(const QString &, bool *); |
274 | virtual unsigned rgbaFromString(const QString &, bool *); |
275 | |
276 | virtual QVariant fromRgbF(double, double, double, double); |
277 | virtual QVariant fromHslF(double, double, double, double); |
278 | virtual QVariant fromHsvF(double, double, double, double); |
279 | virtual QVariant lighter(const QVariant &, qreal); |
280 | virtual QVariant darker(const QVariant &, qreal); |
281 | virtual QVariant tint(const QVariant &, const QVariant &); |
282 | }; |
283 | |
284 | Q_QML_PRIVATE_EXPORT QQmlColorProvider *QQml_setColorProvider(QQmlColorProvider *); |
285 | Q_QML_PRIVATE_EXPORT QQmlColorProvider *QQml_colorProvider(); |
286 | |
287 | |
288 | class Q_QML_PRIVATE_EXPORT QQmlGuiProvider |
289 | { |
290 | public: |
291 | virtual ~QQmlGuiProvider(); |
292 | virtual QObject *application(QObject *parent); |
293 | virtual QObject *inputMethod(); |
294 | virtual QObject *styleHints(); |
295 | virtual QStringList fontFamilies(); |
296 | virtual bool openUrlExternally(QUrl &); |
297 | virtual QString pluginName() const; |
298 | }; |
299 | |
300 | Q_QML_PRIVATE_EXPORT QQmlGuiProvider *QQml_setGuiProvider(QQmlGuiProvider *); |
301 | Q_AUTOTEST_EXPORT QQmlGuiProvider *QQml_guiProvider(); |
302 | |
303 | class QQmlApplicationPrivate; |
304 | |
305 | class Q_QML_PRIVATE_EXPORT QQmlApplication : public QObject |
306 | { |
307 | //Application level logic, subclassed by Qt Quick if available via QQmlGuiProvider |
308 | Q_OBJECT |
309 | Q_PROPERTY(QStringList arguments READ args CONSTANT) |
310 | Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) |
311 | Q_PROPERTY(QString version READ version WRITE setVersion NOTIFY versionChanged) |
312 | Q_PROPERTY(QString organization READ organization WRITE setOrganization NOTIFY organizationChanged) |
313 | Q_PROPERTY(QString domain READ domain WRITE setDomain NOTIFY domainChanged) |
314 | public: |
315 | QQmlApplication(QObject* parent=nullptr); |
316 | |
317 | QStringList args(); |
318 | |
319 | QString name() const; |
320 | QString version() const; |
321 | QString organization() const; |
322 | QString domain() const; |
323 | |
324 | public Q_SLOTS: |
325 | void setName(const QString &arg); |
326 | void setVersion(const QString &arg); |
327 | void setOrganization(const QString &arg); |
328 | void setDomain(const QString &arg); |
329 | |
330 | Q_SIGNALS: |
331 | void aboutToQuit(); |
332 | |
333 | void nameChanged(); |
334 | void versionChanged(); |
335 | void organizationChanged(); |
336 | void domainChanged(); |
337 | |
338 | protected: |
339 | QQmlApplication(QQmlApplicationPrivate &dd, QObject* parent=nullptr); |
340 | |
341 | private: |
342 | Q_DISABLE_COPY(QQmlApplication) |
343 | Q_DECLARE_PRIVATE(QQmlApplication) |
344 | }; |
345 | |
346 | class QQmlApplicationPrivate : public QObjectPrivate |
347 | { |
348 | Q_DECLARE_PUBLIC(QQmlApplication) |
349 | public: |
350 | QQmlApplicationPrivate() { |
351 | argsInit = false; |
352 | } |
353 | |
354 | bool argsInit; |
355 | QStringList args; |
356 | }; |
357 | |
358 | struct QQmlSourceLocation |
359 | { |
360 | QQmlSourceLocation() {} |
361 | QQmlSourceLocation(const QString &sourceFile, quint16 line, quint16 column) |
362 | : sourceFile(sourceFile), line(line), column(column) {} |
363 | QString sourceFile; |
364 | quint16 line = 0; |
365 | quint16 column = 0; |
366 | }; |
367 | |
368 | QT_END_NAMESPACE |
369 | |
370 | #endif // QQMLGLOBAL_H |
371 | |