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 #define IS_SIGNAL_CONNECTED(Sender, SenderType, Name, Arguments) \
170 QObject *sender = (Sender); \
171 void (SenderType::*signal)Arguments = &SenderType::Name; \
172 static QMetaMethod method = QMetaMethod::fromSignal(signal); \
173 static int signalIdx = QMetaObjectPrivate::signalIndex(method); \
174 return QObjectPrivate::get(sender)->isSignalConnected(signalIdx); \
177 struct QQmlGraphics_DerivedObject : public QObject
179 void setParent_noEvent(QObject *parent) {
180 bool sce = d_ptr->sendChildEvents;
181 d_ptr->sendChildEvents = false;
183 d_ptr->sendChildEvents = sce;
188 Returns true if the case of \a fileName is equivalent to the file case of
189 \a fileName on disk, and false otherwise.
191 This is used to ensure that the behavior of QML on a case-insensitive file
192 system is the same as on a case-sensitive file system. This function
193 performs a "best effort" attempt to determine the real case of the file.
194 It may have false positives (say the case is correct when it isn't), but it
195 should never have a false negative (say the case is incorrect when it is
198 bool QQml_isFileCaseCorrect(const QString &fileName);
201 Makes the \a object a child of \a parent. Note that when using this method,
202 neither \a parent nor the object's previous parent (if it had one) will
203 receive ChildRemoved or ChildAdded events.
205 inline void QQml_setParent_noEvent(QObject *object, QObject *parent)
207 static_cast<QQmlGraphics_DerivedObject *>(object)->setParent_noEvent(parent);
213 class Q_QML_PRIVATE_EXPORT QQmlValueTypeProvider
216 QQmlValueTypeProvider();
218 QQmlValueType *createValueType(int);
220 bool initValueType(int, void *, size_t);
221 bool destroyValueType(int, void *, size_t);
222 bool copyValueType(int, const void *, void *, size_t);
224 QVariant createValueType(int, int, const void *[]);
225 bool createValueFromString(int, const QString &, void *, size_t);
226 bool createStringFromValue(int, const void *, QString *);
228 QVariant createVariantFromString(const QString &);
229 QVariant createVariantFromString(int, const QString &, bool *);
230 QVariant createVariantFromJsObject(int, QQmlV8Handle, QV8Engine *, bool*);
232 bool equalValueType(int, const void *, const void *, size_t);
233 bool storeValueType(int, const void *, void *, size_t);
234 bool readValueType(int, const void *, size_t, int, void *);
235 bool writeValueType(int, const void *, void *, size_t);
238 virtual bool create(int, QQmlValueType *&);
240 virtual bool init(int, void *, size_t);
241 virtual bool destroy(int, void *, size_t);
242 virtual bool copy(int, const void *, void *, size_t);
244 virtual bool create(int, int, const void *[], QVariant *);
245 virtual bool createFromString(int, const QString &, void *, size_t);
246 virtual bool createStringFrom(int, const void *, QString *);
248 virtual bool variantFromString(const QString &, QVariant *);
249 virtual bool variantFromString(int, const QString &, QVariant *);
250 virtual bool variantFromJsObject(int, QQmlV8Handle, QV8Engine *, QVariant *);
252 virtual bool equal(int, const void *, const void *, size_t);
253 virtual bool store(int, const void *, void *, size_t);
254 virtual bool read(int, const void *, size_t, int, void *);
255 virtual bool write(int, const void *, void *, size_t);
257 friend Q_QML_PRIVATE_EXPORT void QQml_addValueTypeProvider(QQmlValueTypeProvider *);
259 QQmlValueTypeProvider *next;
262 Q_QML_PRIVATE_EXPORT void QQml_addValueTypeProvider(QQmlValueTypeProvider *);
263 Q_AUTOTEST_EXPORT QQmlValueTypeProvider *QQml_valueTypeProvider();
266 class Q_QML_PRIVATE_EXPORT QQmlColorProvider
269 virtual QVariant colorFromString(const QString &, bool *);
270 virtual unsigned rgbaFromString(const QString &, bool *);
272 virtual QVariant fromRgbF(double, double, double, double);
273 virtual QVariant fromHslF(double, double, double, double);
274 virtual QVariant lighter(const QVariant &, qreal);
275 virtual QVariant darker(const QVariant &, qreal);
276 virtual QVariant tint(const QVariant &, const QVariant &);
279 Q_QML_PRIVATE_EXPORT QQmlColorProvider *QQml_setColorProvider(QQmlColorProvider *);
280 Q_QML_PRIVATE_EXPORT QQmlColorProvider *QQml_colorProvider();
283 class Q_QML_PRIVATE_EXPORT QQmlGuiProvider
286 virtual QObject *application(QObject *parent);
287 virtual QObject *inputMethod();
288 virtual QStringList fontFamilies();
289 virtual bool openUrlExternally(QUrl &);
292 Q_QML_PRIVATE_EXPORT QQmlGuiProvider *QQml_setGuiProvider(QQmlGuiProvider *);
293 Q_AUTOTEST_EXPORT QQmlGuiProvider *QQml_guiProvider();
299 #endif // QQMLGLOBAL_H