| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** All rights reserved.
|
|---|
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com)
|
|---|
| 6 | **
|
|---|
| 7 | ** This file is part of the QtDeclarative module of the Qt Toolkit.
|
|---|
| 8 | **
|
|---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 10 | ** Commercial Usage
|
|---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 14 | ** a written agreement between you and Nokia.
|
|---|
| 15 | **
|
|---|
| 16 | ** GNU Lesser General Public License Usage
|
|---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 18 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 20 | ** packaging of this file. Please review the following information to
|
|---|
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 23 | **
|
|---|
| 24 | ** In addition, as a special exception, Nokia gives you certain additional
|
|---|
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
|---|
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|---|
| 27 | **
|
|---|
| 28 | ** GNU General Public License Usage
|
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 32 | ** packaging of this file. Please review the following information to
|
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 35 | **
|
|---|
| 36 | ** If you have questions regarding the use of this file, please contact
|
|---|
| 37 | ** Nokia at qt-info@nokia.com.
|
|---|
| 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 |
|
|---|
| 59 | QT_BEGIN_HEADER
|
|---|
| 60 |
|
|---|
| 61 | QT_BEGIN_NAMESPACE
|
|---|
| 62 |
|
|---|
| 63 | QT_MODULE(Declarative)
|
|---|
| 64 |
|
|---|
| 65 | typedef QObject *(*QDeclarativeAttachedPropertiesFunc)(QObject *);
|
|---|
| 66 |
|
|---|
| 67 | template <typename TYPE>
|
|---|
| 68 | class QDeclarativeTypeInfo
|
|---|
| 69 | {
|
|---|
| 70 | public:
|
|---|
| 71 | enum {
|
|---|
| 72 | hasAttachedProperties = 0
|
|---|
| 73 | };
|
|---|
| 74 | };
|
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 | class QDeclarativeCustomParser;
|
|---|
| 78 | namespace QDeclarativePrivate
|
|---|
| 79 | {
|
|---|
| 80 | void Q_DECLARATIVE_EXPORT qdeclarativeelement_destructor(QObject *);
|
|---|
| 81 | template<typename T>
|
|---|
| 82 | class QDeclarativeElement : public T
|
|---|
| 83 | {
|
|---|
| 84 | public:
|
|---|
| 85 | virtual ~QDeclarativeElement() {
|
|---|
| 86 | QDeclarativePrivate::qdeclarativeelement_destructor(this);
|
|---|
| 87 | }
|
|---|
| 88 | };
|
|---|
| 89 |
|
|---|
| 90 | template<typename T>
|
|---|
| 91 | void createInto(void *memory) { new (memory) QDeclarativeElement<T>; }
|
|---|
| 92 |
|
|---|
| 93 | template<typename T>
|
|---|
| 94 | QObject *createParent(QObject *p) { return new T(p); }
|
|---|
| 95 |
|
|---|
| 96 | template<class From, class To, int N>
|
|---|
| 97 | struct StaticCastSelectorClass
|
|---|
| 98 | {
|
|---|
| 99 | static inline int cast() { return -1; }
|
|---|
| 100 | };
|
|---|
| 101 |
|
|---|
| 102 | template<class From, class To>
|
|---|
| 103 | struct StaticCastSelectorClass<From, To, sizeof(int)>
|
|---|
| 104 | {
|
|---|
| 105 | static inline int cast() { return int(reinterpret_cast<quintptr>(static_cast<To *>(reinterpret_cast<From *>(0x10000000)))) - 0x10000000; }
|
|---|
| 106 | };
|
|---|
| 107 |
|
|---|
| 108 | template<class From, class To>
|
|---|
| 109 | struct StaticCastSelector
|
|---|
| 110 | {
|
|---|
| 111 | typedef int yes_type;
|
|---|
| 112 | typedef char no_type;
|
|---|
| 113 |
|
|---|
| 114 | static yes_type check(To *);
|
|---|
| 115 | static no_type check(...);
|
|---|
| 116 |
|
|---|
| 117 | static inline int cast()
|
|---|
| 118 | {
|
|---|
| 119 | return StaticCastSelectorClass<From, To, sizeof(check(reinterpret_cast<From *>(0)))>::cast();
|
|---|
| 120 | }
|
|---|
| 121 | };
|
|---|
| 122 |
|
|---|
| 123 | template <typename T>
|
|---|
| 124 | struct has_attachedPropertiesMember
|
|---|
| 125 | {
|
|---|
| 126 | static bool const value = QDeclarativeTypeInfo<T>::hasAttachedProperties;
|
|---|
| 127 | };
|
|---|
| 128 |
|
|---|
| 129 | template <typename T, bool hasMember>
|
|---|
| 130 | class has_attachedPropertiesMethod
|
|---|
| 131 | {
|
|---|
| 132 | public:
|
|---|
| 133 | typedef int yes_type;
|
|---|
| 134 | typedef char no_type;
|
|---|
| 135 |
|
|---|
| 136 | template<typename ReturnType>
|
|---|
| 137 | static yes_type check(ReturnType *(*)(QObject *));
|
|---|
| 138 | static no_type check(...);
|
|---|
| 139 |
|
|---|
| 140 | static bool const value = sizeof(check(&T::qmlAttachedProperties)) == sizeof(yes_type);
|
|---|
| 141 | };
|
|---|
| 142 |
|
|---|
| 143 | template <typename T>
|
|---|
| 144 | class has_attachedPropertiesMethod<T, false>
|
|---|
| 145 | {
|
|---|
| 146 | public:
|
|---|
| 147 | static bool const value = false;
|
|---|
| 148 | };
|
|---|
| 149 |
|
|---|
| 150 | template<typename T, int N>
|
|---|
| 151 | class AttachedPropertySelector
|
|---|
| 152 | {
|
|---|
| 153 | public:
|
|---|
| 154 | static inline QDeclarativeAttachedPropertiesFunc func() { return 0; }
|
|---|
| 155 | static inline const QMetaObject *metaObject() { return 0; }
|
|---|
| 156 | };
|
|---|
| 157 | template<typename T>
|
|---|
| 158 | class AttachedPropertySelector<T, 1>
|
|---|
| 159 | {
|
|---|
| 160 | static inline QObject *attachedProperties(QObject *obj) {
|
|---|
| 161 | return T::qmlAttachedProperties(obj);
|
|---|
| 162 | }
|
|---|
| 163 | template<typename ReturnType>
|
|---|
| 164 | static inline const QMetaObject *attachedPropertiesMetaObject(ReturnType *(*)(QObject *)) {
|
|---|
| 165 | return &ReturnType::staticMetaObject;
|
|---|
| 166 | }
|
|---|
| 167 | public:
|
|---|
| 168 | static inline QDeclarativeAttachedPropertiesFunc func() {
|
|---|
| 169 | return &attachedProperties;
|
|---|
| 170 | }
|
|---|
| 171 | static inline const QMetaObject *metaObject() {
|
|---|
| 172 | return attachedPropertiesMetaObject(&T::qmlAttachedProperties);
|
|---|
| 173 | }
|
|---|
| 174 | };
|
|---|
| 175 |
|
|---|
| 176 | template<typename T>
|
|---|
| 177 | inline QDeclarativeAttachedPropertiesFunc attachedPropertiesFunc()
|
|---|
| 178 | {
|
|---|
| 179 | return AttachedPropertySelector<T, has_attachedPropertiesMethod<T, has_attachedPropertiesMember<T>::value>::value>::func();
|
|---|
| 180 | }
|
|---|
| 181 |
|
|---|
| 182 | template<typename T>
|
|---|
| 183 | inline const QMetaObject *attachedPropertiesMetaObject()
|
|---|
| 184 | {
|
|---|
| 185 | return AttachedPropertySelector<T, has_attachedPropertiesMethod<T, has_attachedPropertiesMember<T>::value>::value>::metaObject();
|
|---|
| 186 | }
|
|---|
| 187 |
|
|---|
| 188 | enum AutoParentResult { Parented, IncompatibleObject, IncompatibleParent };
|
|---|
| 189 | typedef AutoParentResult (*AutoParentFunction)(QObject *object, QObject *parent);
|
|---|
| 190 |
|
|---|
| 191 | struct RegisterType {
|
|---|
| 192 | int version;
|
|---|
| 193 |
|
|---|
| 194 | int typeId;
|
|---|
| 195 | int listId;
|
|---|
| 196 | int objectSize;
|
|---|
| 197 | void (*create)(void *);
|
|---|
| 198 | QString noCreationReason;
|
|---|
| 199 |
|
|---|
| 200 | const char *uri;
|
|---|
| 201 | int versionMajor;
|
|---|
| 202 | int versionMinor;
|
|---|
| 203 | const char *elementName;
|
|---|
| 204 | const QMetaObject *metaObject;
|
|---|
| 205 |
|
|---|
| 206 | QDeclarativeAttachedPropertiesFunc attachedPropertiesFunction;
|
|---|
| 207 | const QMetaObject *attachedPropertiesMetaObject;
|
|---|
| 208 |
|
|---|
| 209 | int parserStatusCast;
|
|---|
| 210 | int valueSourceCast;
|
|---|
| 211 | int valueInterceptorCast;
|
|---|
| 212 |
|
|---|
| 213 | QObject *(*extensionObjectCreate)(QObject *);
|
|---|
| 214 | const QMetaObject *extensionMetaObject;
|
|---|
| 215 |
|
|---|
| 216 | QDeclarativeCustomParser *customParser;
|
|---|
| 217 | };
|
|---|
| 218 |
|
|---|
| 219 | struct RegisterInterface {
|
|---|
| 220 | int version;
|
|---|
| 221 |
|
|---|
| 222 | int typeId;
|
|---|
| 223 | int listId;
|
|---|
| 224 |
|
|---|
| 225 | const char *iid;
|
|---|
| 226 | };
|
|---|
| 227 |
|
|---|
| 228 | struct RegisterAutoParent {
|
|---|
| 229 | int version;
|
|---|
| 230 |
|
|---|
| 231 | AutoParentFunction function;
|
|---|
| 232 | };
|
|---|
| 233 |
|
|---|
| 234 | enum RegistrationType {
|
|---|
| 235 | TypeRegistration = 0,
|
|---|
| 236 | InterfaceRegistration = 1,
|
|---|
| 237 | AutoParentRegistration = 2
|
|---|
| 238 | };
|
|---|
| 239 |
|
|---|
| 240 | int Q_DECLARATIVE_EXPORT qmlregister(RegistrationType, void *);
|
|---|
| 241 | }
|
|---|
| 242 |
|
|---|
| 243 | QT_END_NAMESPACE
|
|---|
| 244 |
|
|---|
| 245 | QT_END_HEADER
|
|---|
| 246 |
|
|---|
| 247 | #endif // QDECLARATIVEPRIVATE_H
|
|---|