Qt 4.8
qdeclarativeprivate.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 QDECLARATIVEPRIVATE_H
43 #define QDECLARATIVEPRIVATE_H
44 
45 //
46 // W A R N I N G
47 // -------------
48 //
49 // This file is not part of the Qt API. It exists purely as an
50 // implementation detail. This header file may change from version to
51 // version without notice, or even be removed.
52 //
53 // We mean it.
54 //
55 
56 #include <QtCore/qglobal.h>
57 #include <QtCore/qvariant.h>
58 #include <QtCore/qurl.h>
59 #include <QtDeclarative/QDeclarativeListProperty>
60 #include <QtDeclarative/QDeclarativeParserStatus>
61 #include <QtDeclarative/QDeclarativePropertyValueSource>
62 #include <QtDeclarative/QDeclarativePropertyValueInterceptor>
63 
65 
67 
68 QT_MODULE(Declarative)
69 
71 
72 template <typename TYPE>
74 {
75 public:
76  enum {
77  hasAttachedProperties = 0
78  };
79 };
80 
81 
84 {
86  template<typename T>
87  class QDeclarativeElement : public T
88  {
89  public:
90  virtual ~QDeclarativeElement() {
92  }
93  };
94 
95  template<typename T>
96  void createInto(void *memory) { new (memory) QDeclarativeElement<T>; }
97 
98  template<typename T>
99  QObject *createParent(QObject *p) { return new T(p); }
100 
101  template<class From, class To, int N>
103  {
104  static inline int cast() { return -1; }
105  };
106 
107  template<class From, class To>
108  struct StaticCastSelectorClass<From, To, sizeof(int)>
109  {
110  static inline int cast() { return int(reinterpret_cast<quintptr>(static_cast<To *>(reinterpret_cast<From *>(0x10000000)))) - 0x10000000; }
111  };
112 
113  template<class From, class To>
115  {
116  typedef int yes_type;
117  typedef char no_type;
118 
119  static yes_type check(To *);
120  static no_type check(...);
121 
122  static inline int cast()
123  {
125  }
126  };
127 
128  template <typename T>
130  {
132  };
133 
134  template <typename T, bool hasMember>
136  {
137  public:
138  typedef int yes_type;
139  typedef char no_type;
140 
141  template<typename ReturnType>
142  static yes_type check(ReturnType *(*)(QObject *));
143  static no_type check(...);
144 
145  static bool const value = sizeof(check(&T::qmlAttachedProperties)) == sizeof(yes_type);
146  };
147 
148  template <typename T>
150  {
151  public:
152  static bool const value = false;
153  };
154 
155  template<typename T, int N>
157  {
158  public:
159  static inline QDeclarativeAttachedPropertiesFunc func() { return 0; }
160  static inline const QMetaObject *metaObject() { return 0; }
161  };
162  template<typename T>
164  {
165  static inline QObject *attachedProperties(QObject *obj) {
166  return T::qmlAttachedProperties(obj);
167  }
168  template<typename ReturnType>
169  static inline const QMetaObject *attachedPropertiesMetaObject(ReturnType *(*)(QObject *)) {
170  return &ReturnType::staticMetaObject;
171  }
172  public:
174  return &attachedProperties;
175  }
176  static inline const QMetaObject *metaObject() {
177  return attachedPropertiesMetaObject(&T::qmlAttachedProperties);
178  }
179  };
180 
181  template<typename T>
183  {
185  }
186 
187  template<typename T>
189  {
191  }
192 
194  typedef AutoParentResult (*AutoParentFunction)(QObject *object, QObject *parent);
195 
196  struct RegisterType {
197  int version;
198 
199  int typeId;
200  int listId;
202  void (*create)(void *);
204 
205  const char *uri;
208  const char *elementName;
210 
213 
217 
218  QObject *(*extensionObjectCreate)(QObject *);
220 
222  int revision;
223  // If this is extended ensure "version" is bumped!!!
224  };
225 
227  int version;
228 
229  int typeId;
230  int listId;
231 
232  const char *iid;
233  };
234 
236  int version;
237 
239  };
240 
242  const QUrl &url;
243  const char *uri;
244  const char *typeName;
247  };
248 
254  };
255 
257 
258 
274  inline int qmlRegisterType(const QUrl &url, const char *uri, int versionMajor, int versionMinor, const char *qmlName)
275  {
277  url,
278  uri,
279  qmlName,
280  versionMajor,
281  versionMinor
282  };
283 
285  }
293  template<typename T, int metaObjectRevision>
294  int qmlRegisterUncreatableType(const char *uri, int versionMajor, int versionMinor, const char *qmlName, const QString& reason)
295  {
296  QByteArray name(T::staticMetaObject.className());
297 
298  QByteArray pointerName(name + '*');
299  QByteArray listName("QDeclarativeListProperty<" + name + ">");
300 
302  1,
303 
304  qRegisterMetaType<T *>(pointerName.constData()),
306  0, 0,
307  reason,
308 
309  uri, versionMajor, versionMinor, qmlName, &T::staticMetaObject,
310 
311  QDeclarativePrivate::attachedPropertiesFunc<T>(),
312  QDeclarativePrivate::attachedPropertiesMetaObject<T>(),
313 
317 
318  0, 0,
319 
320  0,
321  metaObjectRevision
322  };
323 
325  }
326 
327 
328 }
329 
331 
333 
334 #endif // QDECLARATIVEPRIVATE_H
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
QDeclarativeCustomParser * customParser
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
void createInto(void *memory)
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)
AutoParentResult(* AutoParentFunction)(QObject *object, QObject *parent)
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
The QString class provides a Unicode character string.
Definition: qstring.h:83
QDeclarativeAttachedPropertiesFunc attachedPropertiesFunc()
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
const char * className
Definition: qwizard.cpp:137
QObject * createParent(QObject *p)
static const QMetaObject * attachedPropertiesMetaObject(ReturnType *(*)(QObject *))
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
const char * name
static QDeclarativeAttachedPropertiesFunc func()
int qRegisterMetaType(const char *typeName)
Definition: qmetatype.h:185
int Q_DECLARATIVE_EXPORT qmlregister(RegistrationType, void *)
The QDeclarativeCustomParser class allows you to add new arbitrary types to QML.
static QDeclarativeAttachedPropertiesFunc func()
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
void Q_DECLARATIVE_EXPORT qdeclarativeelement_destructor(QObject *)
const QMetaObject * attachedPropertiesMetaObject
QDeclarativeAttachedPropertiesFunc attachedPropertiesFunction
#define class
#define QT_END_HEADER
Definition: qglobal.h:137
int qmlRegisterUncreatableType(const char *uri, int versionMajor, int versionMinor, const char *qmlName, const QString &reason)
The QDeclarativeListProperty class allows applications to expose list-like properties to QML...
const QMetaObject * attachedPropertiesMetaObject()
int qmlRegisterType(const QUrl &url, const char *uri, int versionMajor, int versionMinor, const char *qmlName)