1 /****************************************************************************
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
6 ** This file is part of the QtQml module of the Qt Toolkit.
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 Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
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 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
40 ****************************************************************************/
45 #include <private/qtqmlglobal_p.h>
46 #include <QtCore/QObject>
47 #include <private/qqmlpropertycache_p.h>
48 #include <private/qmetaobject_p.h>
49 #include <private/qv8engine_p.h>
56 #define DEFINE_BOOL_CONFIG_OPTION(name, var) \
59 static enum { Yes, No, Unknown } status = Unknown; \
60 if (status == Unknown) { \
61 QByteArray v = qgetenv(#var); \
62 bool value = !v.isEmpty() && v != "0" && v != "false"; \
63 if (value) status = Yes; \
66 return status == Yes; \
70 Connect \a Signal of \a Sender to \a Method of \a Receiver. \a Signal must be
71 of type \a SenderType and \a Receiver of type \a ReceiverType.
73 Unlike QObject::connect(), this method caches the lookup of the signal and method
74 indexes. It also does not require lazy QMetaObjects to be built so should be
75 preferred in all QML code that might interact with QML built objects.
78 QQuickTextControl *control;
79 QQuickTextEdit *textEdit;
80 qmlobject_connect(control, QQuickTextControl, SIGNAL(updateRequest(QRectF)),
81 textEdit, QQuickTextEdit, SLOT(updateDocument()));
84 #define qmlobject_connect(Sender, SenderType, Signal, Receiver, ReceiverType, Method) \
86 SenderType *sender = (Sender); \
87 ReceiverType *receiver = (Receiver); \
88 const char *signal = (Signal); \
89 const char *method = (Method); \
90 static int signalIdx = -1; \
91 static int methodIdx = -1; \
92 if (signalIdx < 0) { \
93 Q_ASSERT(((int)(*signal) - '0') == QSIGNAL_CODE); \
94 signalIdx = SenderType::staticMetaObject.indexOfSignal(signal+1); \
96 if (methodIdx < 0) { \
97 int code = ((int)(*method) - '0'); \
98 Q_ASSERT(code == QSLOT_CODE || code == QSIGNAL_CODE); \
99 if (code == QSLOT_CODE) \
100 methodIdx = ReceiverType::staticMetaObject.indexOfSlot(method+1); \
102 methodIdx = ReceiverType::staticMetaObject.indexOfSignal(method+1); \
104 Q_ASSERT(signalIdx != -1 && methodIdx != -1); \
105 QMetaObject::connect(sender, signalIdx, receiver, methodIdx, Qt::DirectConnection); \
109 Disconnect \a Signal of \a Sender from \a Method of \a Receiver. \a Signal must be
110 of type \a SenderType and \a Receiver of type \a ReceiverType.
112 Unlike QObject::disconnect(), this method caches the lookup of the signal and method
113 indexes. It also does not require lazy QMetaObjects to be built so should be
114 preferred in all QML code that might interact with QML built objects.
117 QQuickTextControl *control;
118 QQuickTextEdit *textEdit;
119 qmlobject_disconnect(control, QQuickTextControl, SIGNAL(updateRequest(QRectF)),
120 textEdit, QQuickTextEdit, SLOT(updateDocument()));
123 #define qmlobject_disconnect(Sender, SenderType, Signal, Receiver, ReceiverType, Method) \
125 SenderType *sender = (Sender); \
126 ReceiverType *receiver = (Receiver); \
127 const char *signal = (Signal); \
128 const char *method = (Method); \
129 static int signalIdx = -1; \
130 static int methodIdx = -1; \
131 if (signalIdx < 0) { \
132 Q_ASSERT(((int)(*signal) - '0') == QSIGNAL_CODE); \
133 signalIdx = SenderType::staticMetaObject.indexOfSignal(signal+1); \
135 if (methodIdx < 0) { \
136 int code = ((int)(*method) - '0'); \
137 Q_ASSERT(code == QSLOT_CODE || code == QSIGNAL_CODE); \
138 if (code == QSLOT_CODE) \
139 methodIdx = ReceiverType::staticMetaObject.indexOfSlot(method+1); \
141 methodIdx = ReceiverType::staticMetaObject.indexOfSignal(method+1); \
143 Q_ASSERT(signalIdx != -1 && methodIdx != -1); \
144 QMetaObject::disconnect(sender, signalIdx, receiver, methodIdx); \
148 This method is identical to qobject_cast<T>() except that it does not require lazy
149 QMetaObjects to be built, so should be preferred in all QML code that might interact
150 with QML built objects.
154 if (QQuickTextEdit *textEdit = qmlobject_cast<QQuickTextEdit *>(object)) {
155 // ...Do something...
160 T qmlobject_cast(QObject *object)
162 if (object && QQmlMetaObject::canConvert(object, &reinterpret_cast<T>(object)->staticMetaObject))
163 return static_cast<T>(object);
168 inline quint16 qmlSourceCoordinate(int n)
170 return (n > 0 && n <= static_cast<int>(USHRT_MAX)) ? static_cast<quint16>(n) : 0;
173 inline int qmlSourceCoordinate(quint16 n)
175 return (n == 0) ? -1 : static_cast<int>(n);
178 #define IS_SIGNAL_CONNECTED(Sender, SenderType, Name, Arguments) \
180 QObject *sender = (Sender); \
181 void (SenderType::*signal)Arguments = &SenderType::Name; \
182 static QMetaMethod method = QMetaMethod::fromSignal(signal); \
183 static int signalIdx = QMetaObjectPrivate::signalIndex(method); \
184 return QObjectPrivate::get(sender)->isSignalConnected(signalIdx); \
187 struct QQmlGraphics_DerivedObject : public QObject
189 void setParent_noEvent(QObject *parent) {
190 bool sce = d_ptr->sendChildEvents;
191 d_ptr->sendChildEvents = false;
193 d_ptr->sendChildEvents = sce;
198 Returns true if the case of \a fileName is equivalent to the file case of
199 \a fileName on disk, and false otherwise.
201 This is used to ensure that the behavior of QML on a case-insensitive file
202 system is the same as on a case-sensitive file system. This function
203 performs a "best effort" attempt to determine the real case of the file.
204 It may have false positives (say the case is correct when it isn't), but it
205 should never have a false negative (say the case is incorrect when it is
208 bool QQml_isFileCaseCorrect(const QString &fileName);
211 Makes the \a object a child of \a parent. Note that when using this method,
212 neither \a parent nor the object's previous parent (if it had one) will
213 receive ChildRemoved or ChildAdded events.
215 inline void QQml_setParent_noEvent(QObject *object, QObject *parent)
217 static_cast<QQmlGraphics_DerivedObject *>(object)->setParent_noEvent(parent);
223 class Q_QML_PRIVATE_EXPORT QQmlValueTypeProvider
226 QQmlValueTypeProvider();
227 virtual ~QQmlValueTypeProvider();
229 QQmlValueType *createValueType(int);
231 bool initValueType(int, void *, size_t);
232 bool destroyValueType(int, void *, size_t);
233 bool copyValueType(int, const void *, void *, size_t);
235 QVariant createValueType(int, int, const void *[]);
236 bool createValueFromString(int, const QString &, void *, size_t);
237 bool createStringFromValue(int, const void *, QString *);
239 QVariant createVariantFromString(const QString &);
240 QVariant createVariantFromString(int, const QString &, bool *);
241 QVariant createVariantFromJsObject(int, QQmlV8Handle, QV8Engine *, bool*);
243 bool equalValueType(int, const void *, const void *, size_t);
244 bool storeValueType(int, const void *, void *, size_t);
245 bool readValueType(int, const void *, size_t, int, void *);
246 bool writeValueType(int, const void *, void *, size_t);
249 virtual bool create(int, QQmlValueType *&);
251 virtual bool init(int, void *, size_t);
252 virtual bool destroy(int, void *, size_t);
253 virtual bool copy(int, const void *, void *, size_t);
255 virtual bool create(int, int, const void *[], QVariant *);
256 virtual bool createFromString(int, const QString &, void *, size_t);
257 virtual bool createStringFrom(int, const void *, QString *);
259 virtual bool variantFromString(const QString &, QVariant *);
260 virtual bool variantFromString(int, const QString &, QVariant *);
261 virtual bool variantFromJsObject(int, QQmlV8Handle, QV8Engine *, QVariant *);
263 virtual bool equal(int, const void *, const void *, size_t);
264 virtual bool store(int, const void *, void *, size_t);
265 virtual bool read(int, const void *, size_t, int, void *);
266 virtual bool write(int, const void *, void *, size_t);
268 friend Q_QML_PRIVATE_EXPORT void QQml_addValueTypeProvider(QQmlValueTypeProvider *);
270 QQmlValueTypeProvider *next;
273 Q_QML_PRIVATE_EXPORT void QQml_addValueTypeProvider(QQmlValueTypeProvider *);
274 Q_AUTOTEST_EXPORT QQmlValueTypeProvider *QQml_valueTypeProvider();
277 class Q_QML_PRIVATE_EXPORT QQmlColorProvider
280 virtual ~QQmlColorProvider();
281 virtual QVariant colorFromString(const QString &, bool *);
282 virtual unsigned rgbaFromString(const QString &, bool *);
284 virtual QVariant fromRgbF(double, double, double, double);
285 virtual QVariant fromHslF(double, double, double, double);
286 virtual QVariant lighter(const QVariant &, qreal);
287 virtual QVariant darker(const QVariant &, qreal);
288 virtual QVariant tint(const QVariant &, const QVariant &);
291 Q_QML_PRIVATE_EXPORT QQmlColorProvider *QQml_setColorProvider(QQmlColorProvider *);
292 Q_QML_PRIVATE_EXPORT QQmlColorProvider *QQml_colorProvider();
295 class Q_QML_PRIVATE_EXPORT QQmlGuiProvider
298 virtual ~QQmlGuiProvider();
299 virtual QObject *application(QObject *parent);
300 virtual QObject *inputMethod();
301 virtual QStringList fontFamilies();
302 virtual bool openUrlExternally(QUrl &);
305 Q_QML_PRIVATE_EXPORT QQmlGuiProvider *QQml_setGuiProvider(QQmlGuiProvider *);
306 Q_AUTOTEST_EXPORT QQmlGuiProvider *QQml_guiProvider();
312 #endif // QQMLGLOBAL_H