1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtQml module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
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 <= 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();
228 QQmlValueType *createValueType(int);
230 bool initValueType(int, void *, size_t);
231 bool destroyValueType(int, void *, size_t);
232 bool copyValueType(int, const void *, void *, size_t);
234 QVariant createValueType(int, int, const void *[]);
235 bool createValueFromString(int, const QString &, void *, size_t);
236 bool createStringFromValue(int, const void *, QString *);
238 QVariant createVariantFromString(const QString &);
239 QVariant createVariantFromString(int, const QString &, bool *);
240 QVariant createVariantFromJsObject(int, QQmlV8Handle, QV8Engine *, bool*);
242 bool equalValueType(int, const void *, const void *, size_t);
243 bool storeValueType(int, const void *, void *, size_t);
244 bool readValueType(int, const void *, size_t, int, void *);
245 bool writeValueType(int, const void *, void *, size_t);
248 virtual bool create(int, QQmlValueType *&);
250 virtual bool init(int, void *, size_t);
251 virtual bool destroy(int, void *, size_t);
252 virtual bool copy(int, const void *, void *, size_t);
254 virtual bool create(int, int, const void *[], QVariant *);
255 virtual bool createFromString(int, const QString &, void *, size_t);
256 virtual bool createStringFrom(int, const void *, QString *);
258 virtual bool variantFromString(const QString &, QVariant *);
259 virtual bool variantFromString(int, const QString &, QVariant *);
260 virtual bool variantFromJsObject(int, QQmlV8Handle, QV8Engine *, QVariant *);
262 virtual bool equal(int, const void *, const void *, size_t);
263 virtual bool store(int, const void *, void *, size_t);
264 virtual bool read(int, const void *, size_t, int, void *);
265 virtual bool write(int, const void *, void *, size_t);
267 friend Q_QML_PRIVATE_EXPORT void QQml_addValueTypeProvider(QQmlValueTypeProvider *);
269 QQmlValueTypeProvider *next;
272 Q_QML_PRIVATE_EXPORT void QQml_addValueTypeProvider(QQmlValueTypeProvider *);
273 Q_AUTOTEST_EXPORT QQmlValueTypeProvider *QQml_valueTypeProvider();
276 class Q_QML_PRIVATE_EXPORT QQmlColorProvider
279 virtual QVariant colorFromString(const QString &, bool *);
280 virtual unsigned rgbaFromString(const QString &, bool *);
282 virtual QVariant fromRgbF(double, double, double, double);
283 virtual QVariant fromHslF(double, double, double, double);
284 virtual QVariant lighter(const QVariant &, qreal);
285 virtual QVariant darker(const QVariant &, qreal);
286 virtual QVariant tint(const QVariant &, const QVariant &);
289 Q_QML_PRIVATE_EXPORT QQmlColorProvider *QQml_setColorProvider(QQmlColorProvider *);
290 Q_QML_PRIVATE_EXPORT QQmlColorProvider *QQml_colorProvider();
293 class Q_QML_PRIVATE_EXPORT QQmlGuiProvider
296 virtual QObject *application(QObject *parent);
297 virtual QObject *inputMethod();
298 virtual QStringList fontFamilies();
299 virtual bool openUrlExternally(QUrl &);
302 Q_QML_PRIVATE_EXPORT QQmlGuiProvider *QQml_setGuiProvider(QQmlGuiProvider *);
303 Q_AUTOTEST_EXPORT QQmlGuiProvider *QQml_guiProvider();
309 #endif // QQMLGLOBAL_H