Qt 4.8
qdeclarative.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtDeclarative 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 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.
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 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.
24 **
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.
28 **
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.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QDECLARATIVE_H
43 #define QDECLARATIVE_H
44 
45 #include <QtDeclarative/qdeclarativeprivate.h>
46 #include <QtDeclarative/qdeclarativeparserstatus.h>
47 #include <QtDeclarative/qdeclarativepropertyvaluesource.h>
48 #include <QtDeclarative/qdeclarativepropertyvalueinterceptor.h>
49 #include <QtDeclarative/qdeclarativelist.h>
50 
51 #include <QtCore/qbytearray.h>
52 #include <QtCore/qmetaobject.h>
53 
55 
56 #define QML_DECLARE_TYPE(TYPE) \
57  Q_DECLARE_METATYPE(TYPE *) \
58  Q_DECLARE_METATYPE(QDeclarativeListProperty<TYPE>)
59 
60 #define QML_DECLARE_TYPE_HASMETATYPE(TYPE) \
61  Q_DECLARE_METATYPE(QDeclarativeListProperty<TYPE>)
62 
63 #define QML_DECLARE_INTERFACE(INTERFACE) \
64  QML_DECLARE_TYPE(INTERFACE)
65 
66 #define QML_DECLARE_INTERFACE_HASMETATYPE(INTERFACE) \
67  QML_DECLARE_TYPE_HASMETATYPE(INTERFACE)
68 
69 enum { /* TYPEINFO flags */
71 };
72 
73 #define QML_DECLARE_TYPEINFO(TYPE, FLAGS) \
74 QT_BEGIN_NAMESPACE \
75 template <> \
76 class QDeclarativeTypeInfo<TYPE > \
77 { \
78 public: \
79  enum { \
80  hasAttachedProperties = (((FLAGS) & QML_HAS_ATTACHED_PROPERTIES) == QML_HAS_ATTACHED_PROPERTIES) \
81  }; \
82 }; \
83 QT_END_NAMESPACE
84 
86 
87 QT_MODULE(Declarative)
88 
89 template<typename T>
91 {
92  QByteArray name(T::staticMetaObject.className());
93 
94  QByteArray pointerName(name + '*');
95  QByteArray listName("QDeclarativeListProperty<" + name + ">");
96 
98  0,
99 
100  qRegisterMetaType<T *>(pointerName.constData()),
102  0, 0,
103  QString(),
104 
105  0, 0, 0, 0, &T::staticMetaObject,
106 
107  QDeclarativePrivate::attachedPropertiesFunc<T>(),
108  QDeclarativePrivate::attachedPropertiesMetaObject<T>(),
109 
113 
114  0, 0,
115 
116  0,
117  0
118  };
119 
121 }
122 
123 int Q_AUTOTEST_EXPORT qmlRegisterTypeNotAvailable(const char *uri, int versionMajor, int versionMinor, const char *qmlName, const QString& message);
124 
125 template<typename T>
126 int qmlRegisterUncreatableType(const char *uri, int versionMajor, int versionMinor, const char *qmlName, const QString& reason)
127 {
128  QByteArray name(T::staticMetaObject.className());
129 
130  QByteArray pointerName(name + '*');
131  QByteArray listName("QDeclarativeListProperty<" + name + ">");
132 
134  0,
135 
136  qRegisterMetaType<T *>(pointerName.constData()),
138  0, 0,
139  reason,
140 
141  uri, versionMajor, versionMinor, qmlName, &T::staticMetaObject,
142 
143  QDeclarativePrivate::attachedPropertiesFunc<T>(),
144  QDeclarativePrivate::attachedPropertiesMetaObject<T>(),
145 
149 
150  0, 0,
151 
152  0,
153  0
154  };
155 
157 }
158 
159 template<typename T>
160 int qmlRegisterType(const char *uri, int versionMajor, int versionMinor, const char *qmlName)
161 {
162  QByteArray name(T::staticMetaObject.className());
163 
164  QByteArray pointerName(name + '*');
165  QByteArray listName("QDeclarativeListProperty<" + name + ">");
166 
168  0,
169 
170  qRegisterMetaType<T *>(pointerName.constData()),
172  sizeof(T), QDeclarativePrivate::createInto<T>,
173  QString(),
174 
175  uri, versionMajor, versionMinor, qmlName, &T::staticMetaObject,
176 
177  QDeclarativePrivate::attachedPropertiesFunc<T>(),
178  QDeclarativePrivate::attachedPropertiesMetaObject<T>(),
179 
183 
184  0, 0,
185 
186  0,
187  0
188  };
189 
191 }
192 
193 template<typename T, int metaObjectRevision>
194 int qmlRegisterType(const char *uri, int versionMajor, int versionMinor, const char *qmlName)
195 {
196  QByteArray name(T::staticMetaObject.className());
197 
198  QByteArray pointerName(name + '*');
199  QByteArray listName("QDeclarativeListProperty<" + name + ">");
200 
202  1,
203 
204  qRegisterMetaType<T *>(pointerName.constData()),
206  sizeof(T), QDeclarativePrivate::createInto<T>,
207  QString(),
208 
209  uri, versionMajor, versionMinor, qmlName, &T::staticMetaObject,
210 
211  QDeclarativePrivate::attachedPropertiesFunc<T>(),
212  QDeclarativePrivate::attachedPropertiesMetaObject<T>(),
213 
217 
218  0, 0,
219 
220  0,
221  metaObjectRevision
222  };
223 
225 }
226 
227 template<typename T, int metaObjectRevision>
228 int qmlRegisterRevision(const char *uri, int versionMajor, int versionMinor)
229 {
230  QByteArray name(T::staticMetaObject.className());
231 
232  QByteArray pointerName(name + '*');
233  QByteArray listName("QDeclarativeListProperty<" + name + ">");
234 
236  1,
237 
238  qRegisterMetaType<T *>(pointerName.constData()),
240  sizeof(T), QDeclarativePrivate::createInto<T>,
241  QString(),
242 
243  uri, versionMajor, versionMinor, 0, &T::staticMetaObject,
244 
245  QDeclarativePrivate::attachedPropertiesFunc<T>(),
246  QDeclarativePrivate::attachedPropertiesMetaObject<T>(),
247 
251 
252  0, 0,
253 
254  0,
255  metaObjectRevision
256  };
257 
259 }
260 
261 
262 template<typename T, typename E>
264 {
265  QByteArray name(T::staticMetaObject.className());
266 
267  QByteArray pointerName(name + '*');
268  QByteArray listName("QDeclarativeListProperty<" + name + ">");
269 
271  0,
272 
273  qRegisterMetaType<T *>(pointerName.constData()),
275  0, 0,
276  QString(),
277 
278  0, 0, 0, 0, &T::staticMetaObject,
279 
280  QDeclarativePrivate::attachedPropertiesFunc<T>(),
281  QDeclarativePrivate::attachedPropertiesMetaObject<T>(),
282 
286 
287  QDeclarativePrivate::createParent<E>, &E::staticMetaObject,
288 
289  0,
290  0
291  };
292 
294 }
295 
296 template<typename T, typename E>
297 int qmlRegisterExtendedType(const char *uri, int versionMajor, int versionMinor,
298  const char *qmlName)
299 {
300  QByteArray name(T::staticMetaObject.className());
301 
302  QByteArray pointerName(name + '*');
303  QByteArray listName("QDeclarativeListProperty<" + name + ">");
304 
305  QDeclarativeAttachedPropertiesFunc attached = QDeclarativePrivate::attachedPropertiesFunc<E>();
306  const QMetaObject * attachedMetaObject = QDeclarativePrivate::attachedPropertiesMetaObject<E>();
307  if (!attached) {
308  attached = QDeclarativePrivate::attachedPropertiesFunc<T>();
309  attachedMetaObject = QDeclarativePrivate::attachedPropertiesMetaObject<T>();
310  }
311 
313  0,
314 
315  qRegisterMetaType<T *>(pointerName.constData()),
317  sizeof(T), QDeclarativePrivate::createInto<T>,
318  QString(),
319 
320  uri, versionMajor, versionMinor, qmlName, &T::staticMetaObject,
321 
322  attached,
323  attachedMetaObject,
324 
328 
329  QDeclarativePrivate::createParent<E>, &E::staticMetaObject,
330 
331  0,
332  0
333  };
334 
336 }
337 
338 template<typename T>
340 {
341  QByteArray name(typeName);
342 
343  QByteArray pointerName(name + '*');
344  QByteArray listName("QDeclarativeListProperty<" + name + ">");
345 
347  0,
348 
349  qRegisterMetaType<T *>(pointerName.constData()),
351 
352  qobject_interface_iid<T *>()
353  };
354 
356 }
357 
358 template<typename T>
359 int qmlRegisterCustomType(const char *uri, int versionMajor, int versionMinor,
360  const char *qmlName, QDeclarativeCustomParser *parser)
361 {
362  QByteArray name(T::staticMetaObject.className());
363 
364  QByteArray pointerName(name + '*');
365  QByteArray listName("QDeclarativeListProperty<" + name + ">");
366 
368  0,
369 
370  qRegisterMetaType<T *>(pointerName.constData()),
372  sizeof(T), QDeclarativePrivate::createInto<T>,
373  QString(),
374 
375  uri, versionMajor, versionMinor, qmlName, &T::staticMetaObject,
376 
377  QDeclarativePrivate::attachedPropertiesFunc<T>(),
378  QDeclarativePrivate::attachedPropertiesMetaObject<T>(),
379 
383 
384  0, 0,
385 
386  parser,
387  0
388  };
389 
391 }
392 
393 class QDeclarativeContext;
394 class QDeclarativeEngine;
400 
401 template<typename T>
403 {
404  static int idx = -1;
405  return qmlAttachedPropertiesObject(&idx, obj, &T::staticMetaObject, create);
406 }
407 
409 
412 
414 
415 #endif // QDECLARATIVE_H
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
QObject *(* QDeclarativeAttachedPropertiesFunc)(QObject *)
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
int type
Definition: qmetatype.cpp:239
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
#define QT_MODULE(x)
Definition: qglobal.h:2783
#define QML_DECLARE_TYPE(TYPE)
Definition: qdeclarative.h:56
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
int qmlRegisterCustomType(const char *uri, int versionMajor, int versionMinor, const char *qmlName, QDeclarativeCustomParser *parser)
Definition: qdeclarative.h:359
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
static Expression::Ptr create(Expression *const expr, const YYLTYPE &sourceLocator, const ParserContext *const parseInfo)
int Q_AUTOTEST_EXPORT qmlRegisterTypeNotAvailable(const char *uri, int versionMajor, int versionMinor, const char *qmlName, const QString &message)
Q_DECLARATIVE_EXPORT QObject * qmlAttachedPropertiesObject(int *, const QObject *, const QMetaObject *, bool create)
int qRegisterMetaType()
Call this function to register the type T.
Definition: qmetatype.h:234
int qmlRegisterType(const char *url, const char *uri, int versionMajor, int versionMinor, const char *qmlName)
The QString class provides a Unicode character string.
Definition: qstring.h:83
int qmlRegisterRevision(const char *uri, int versionMajor, int versionMinor)
Definition: qdeclarative.h:228
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
Q_DECLARATIVE_EXPORT QDeclarativeContext * qmlContext(const QObject *)
const char * className
Definition: qwizard.cpp:137
Q_DECLARATIVE_EXPORT QObject * qmlAttachedPropertiesObjectById(int, const QObject *, bool create=true)
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
const char * typeName
Definition: qmetatype.cpp:239
const char * name
Q_DECLARATIVE_EXPORT void qmlExecuteDeferred(QObject *)
int qmlRegisterUncreatableType(const char *url, const char *uri, int versionMajor, int versionMinor, const char *qmlName)
int Q_DECLARATIVE_EXPORT qmlregister(RegistrationType, void *)
The QDeclarativeCustomParser class allows you to add new arbitrary types to QML.
#define Q_DECLARE_METATYPE(TYPE)
This macro makes the type Type known to QMetaType as long as it provides a public default constructor...
Definition: qmetatype.h:265
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
#define Q_DECLARATIVE_EXPORT
Definition: qglobal.h:1454
Q_DECLARATIVE_EXPORT QDeclarativeEngine * qmlEngine(const QObject *)
The QDeclarativeEngine class provides an environment for instantiating QML components.
#define Q_AUTOTEST_EXPORT
Definition: qglobal.h:1510
The QDeclarativeContext class defines a context within a QML engine.
int qmlRegisterExtendedType()
Definition: qdeclarative.h:263
int qmlRegisterInterface(const char *typeName)
Definition: qdeclarative.h:339
#define QT_END_HEADER
Definition: qglobal.h:137
The QDeclarativeListProperty class allows applications to expose list-like properties to QML...