| 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 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 |  | 
|---|
| 54 | QT_BEGIN_HEADER | 
|---|
| 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 */ | 
|---|
| 70 | QML_HAS_ATTACHED_PROPERTIES = 0x01 | 
|---|
| 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 |  | 
|---|
| 85 | QT_BEGIN_NAMESPACE | 
|---|
| 86 |  | 
|---|
| 87 | QT_MODULE(Declarative) | 
|---|
| 88 |  | 
|---|
| 89 | template<typename T> | 
|---|
| 90 | int qmlRegisterType() | 
|---|
| 91 | { | 
|---|
| 92 | QByteArray name(T::staticMetaObject.className()); | 
|---|
| 93 |  | 
|---|
| 94 | QByteArray pointerName(name + '*'); | 
|---|
| 95 | QByteArray listName("QDeclarativeListProperty<" + name + ">"); | 
|---|
| 96 |  | 
|---|
| 97 | QDeclarativePrivate::RegisterType type = { | 
|---|
| 98 | 0, | 
|---|
| 99 |  | 
|---|
| 100 | qRegisterMetaType<T *>(pointerName.constData()), | 
|---|
| 101 | qRegisterMetaType<QDeclarativeListProperty<T> >(listName.constData()), | 
|---|
| 102 | 0, 0, | 
|---|
| 103 | QString(), | 
|---|
| 104 |  | 
|---|
| 105 | 0, 0, 0, 0, &T::staticMetaObject, | 
|---|
| 106 |  | 
|---|
| 107 | QDeclarativePrivate::attachedPropertiesFunc<T>(), | 
|---|
| 108 | QDeclarativePrivate::attachedPropertiesMetaObject<T>(), | 
|---|
| 109 |  | 
|---|
| 110 | QDeclarativePrivate::StaticCastSelector<T,QDeclarativeParserStatus>::cast(), | 
|---|
| 111 | QDeclarativePrivate::StaticCastSelector<T,QDeclarativePropertyValueSource>::cast(), | 
|---|
| 112 | QDeclarativePrivate::StaticCastSelector<T,QDeclarativePropertyValueInterceptor>::cast(), | 
|---|
| 113 |  | 
|---|
| 114 | 0, 0, | 
|---|
| 115 |  | 
|---|
| 116 | 0 | 
|---|
| 117 | }; | 
|---|
| 118 |  | 
|---|
| 119 | return QDeclarativePrivate::qmlregister(QDeclarativePrivate::TypeRegistration, &type); | 
|---|
| 120 | } | 
|---|
| 121 |  | 
|---|
| 122 | int Q_AUTOTEST_EXPORT qmlRegisterTypeNotAvailable(const char *uri, int versionMajor, int versionMinor, const char *qmlName, const QString& message); | 
|---|
| 123 |  | 
|---|
| 124 | template<typename T> | 
|---|
| 125 | int qmlRegisterUncreatableType(const char *uri, int versionMajor, int versionMinor, const char *qmlName, const QString& reason) | 
|---|
| 126 | { | 
|---|
| 127 | QByteArray name(T::staticMetaObject.className()); | 
|---|
| 128 |  | 
|---|
| 129 | QByteArray pointerName(name + '*'); | 
|---|
| 130 | QByteArray listName("QDeclarativeListProperty<" + name + ">"); | 
|---|
| 131 |  | 
|---|
| 132 | QDeclarativePrivate::RegisterType type = { | 
|---|
| 133 | 0, | 
|---|
| 134 |  | 
|---|
| 135 | qRegisterMetaType<T *>(pointerName.constData()), | 
|---|
| 136 | qRegisterMetaType<QDeclarativeListProperty<T> >(listName.constData()), | 
|---|
| 137 | 0, 0, | 
|---|
| 138 | reason, | 
|---|
| 139 |  | 
|---|
| 140 | uri, versionMajor, versionMinor, qmlName, &T::staticMetaObject, | 
|---|
| 141 |  | 
|---|
| 142 | QDeclarativePrivate::attachedPropertiesFunc<T>(), | 
|---|
| 143 | QDeclarativePrivate::attachedPropertiesMetaObject<T>(), | 
|---|
| 144 |  | 
|---|
| 145 | QDeclarativePrivate::StaticCastSelector<T,QDeclarativeParserStatus>::cast(), | 
|---|
| 146 | QDeclarativePrivate::StaticCastSelector<T,QDeclarativePropertyValueSource>::cast(), | 
|---|
| 147 | QDeclarativePrivate::StaticCastSelector<T,QDeclarativePropertyValueInterceptor>::cast(), | 
|---|
| 148 |  | 
|---|
| 149 | 0, 0, | 
|---|
| 150 |  | 
|---|
| 151 | 0 | 
|---|
| 152 | }; | 
|---|
| 153 |  | 
|---|
| 154 | return QDeclarativePrivate::qmlregister(QDeclarativePrivate::TypeRegistration, &type); | 
|---|
| 155 | } | 
|---|
| 156 |  | 
|---|
| 157 | template<typename T> | 
|---|
| 158 | int qmlRegisterType(const char *uri, int versionMajor, int versionMinor, const char *qmlName) | 
|---|
| 159 | { | 
|---|
| 160 | QByteArray name(T::staticMetaObject.className()); | 
|---|
| 161 |  | 
|---|
| 162 | QByteArray pointerName(name + '*'); | 
|---|
| 163 | QByteArray listName("QDeclarativeListProperty<" + name + ">"); | 
|---|
| 164 |  | 
|---|
| 165 | QDeclarativePrivate::RegisterType type = { | 
|---|
| 166 | 0, | 
|---|
| 167 |  | 
|---|
| 168 | qRegisterMetaType<T *>(pointerName.constData()), | 
|---|
| 169 | qRegisterMetaType<QDeclarativeListProperty<T> >(listName.constData()), | 
|---|
| 170 | sizeof(T), QDeclarativePrivate::createInto<T>, | 
|---|
| 171 | QString(), | 
|---|
| 172 |  | 
|---|
| 173 | uri, versionMajor, versionMinor, qmlName, &T::staticMetaObject, | 
|---|
| 174 |  | 
|---|
| 175 | QDeclarativePrivate::attachedPropertiesFunc<T>(), | 
|---|
| 176 | QDeclarativePrivate::attachedPropertiesMetaObject<T>(), | 
|---|
| 177 |  | 
|---|
| 178 | QDeclarativePrivate::StaticCastSelector<T,QDeclarativeParserStatus>::cast(), | 
|---|
| 179 | QDeclarativePrivate::StaticCastSelector<T,QDeclarativePropertyValueSource>::cast(), | 
|---|
| 180 | QDeclarativePrivate::StaticCastSelector<T,QDeclarativePropertyValueInterceptor>::cast(), | 
|---|
| 181 |  | 
|---|
| 182 | 0, 0, | 
|---|
| 183 |  | 
|---|
| 184 | 0 | 
|---|
| 185 | }; | 
|---|
| 186 |  | 
|---|
| 187 | return QDeclarativePrivate::qmlregister(QDeclarativePrivate::TypeRegistration, &type); | 
|---|
| 188 | } | 
|---|
| 189 |  | 
|---|
| 190 | template<typename T, typename E> | 
|---|
| 191 | int qmlRegisterExtendedType() | 
|---|
| 192 | { | 
|---|
| 193 | QByteArray name(T::staticMetaObject.className()); | 
|---|
| 194 |  | 
|---|
| 195 | QByteArray pointerName(name + '*'); | 
|---|
| 196 | QByteArray listName("QDeclarativeListProperty<" + name + ">"); | 
|---|
| 197 |  | 
|---|
| 198 | QDeclarativePrivate::RegisterType type = { | 
|---|
| 199 | 0, | 
|---|
| 200 |  | 
|---|
| 201 | qRegisterMetaType<T *>(pointerName.constData()), | 
|---|
| 202 | qRegisterMetaType<QDeclarativeListProperty<T> >(listName.constData()), | 
|---|
| 203 | 0, 0, | 
|---|
| 204 | QString(), | 
|---|
| 205 |  | 
|---|
| 206 | 0, 0, 0, 0, &T::staticMetaObject, | 
|---|
| 207 |  | 
|---|
| 208 | QDeclarativePrivate::attachedPropertiesFunc<T>(), | 
|---|
| 209 | QDeclarativePrivate::attachedPropertiesMetaObject<T>(), | 
|---|
| 210 |  | 
|---|
| 211 | QDeclarativePrivate::StaticCastSelector<T,QDeclarativeParserStatus>::cast(), | 
|---|
| 212 | QDeclarativePrivate::StaticCastSelector<T,QDeclarativePropertyValueSource>::cast(), | 
|---|
| 213 | QDeclarativePrivate::StaticCastSelector<T,QDeclarativePropertyValueInterceptor>::cast(), | 
|---|
| 214 |  | 
|---|
| 215 | QDeclarativePrivate::createParent<E>, &E::staticMetaObject, | 
|---|
| 216 |  | 
|---|
| 217 | 0 | 
|---|
| 218 | }; | 
|---|
| 219 |  | 
|---|
| 220 | return QDeclarativePrivate::qmlregister(QDeclarativePrivate::TypeRegistration, &type); | 
|---|
| 221 | } | 
|---|
| 222 |  | 
|---|
| 223 | template<typename T, typename E> | 
|---|
| 224 | int qmlRegisterExtendedType(const char *uri, int versionMajor, int versionMinor, | 
|---|
| 225 | const char *qmlName) | 
|---|
| 226 | { | 
|---|
| 227 | QByteArray name(T::staticMetaObject.className()); | 
|---|
| 228 |  | 
|---|
| 229 | QByteArray pointerName(name + '*'); | 
|---|
| 230 | QByteArray listName("QDeclarativeListProperty<" + name + ">"); | 
|---|
| 231 |  | 
|---|
| 232 | QDeclarativeAttachedPropertiesFunc attached = QDeclarativePrivate::attachedPropertiesFunc<E>(); | 
|---|
| 233 | const QMetaObject * attachedMetaObject = QDeclarativePrivate::attachedPropertiesMetaObject<E>(); | 
|---|
| 234 | if (!attached) { | 
|---|
| 235 | attached = QDeclarativePrivate::attachedPropertiesFunc<T>(); | 
|---|
| 236 | attachedMetaObject = QDeclarativePrivate::attachedPropertiesMetaObject<T>(); | 
|---|
| 237 | } | 
|---|
| 238 |  | 
|---|
| 239 | QDeclarativePrivate::RegisterType type = { | 
|---|
| 240 | 0, | 
|---|
| 241 |  | 
|---|
| 242 | qRegisterMetaType<T *>(pointerName.constData()), | 
|---|
| 243 | qRegisterMetaType<QDeclarativeListProperty<T> >(listName.constData()), | 
|---|
| 244 | sizeof(T), QDeclarativePrivate::createInto<T>, | 
|---|
| 245 | QString(), | 
|---|
| 246 |  | 
|---|
| 247 | uri, versionMajor, versionMinor, qmlName, &T::staticMetaObject, | 
|---|
| 248 |  | 
|---|
| 249 | attached, | 
|---|
| 250 | attachedMetaObject, | 
|---|
| 251 |  | 
|---|
| 252 | QDeclarativePrivate::StaticCastSelector<T,QDeclarativeParserStatus>::cast(), | 
|---|
| 253 | QDeclarativePrivate::StaticCastSelector<T,QDeclarativePropertyValueSource>::cast(), | 
|---|
| 254 | QDeclarativePrivate::StaticCastSelector<T,QDeclarativePropertyValueInterceptor>::cast(), | 
|---|
| 255 |  | 
|---|
| 256 | QDeclarativePrivate::createParent<E>, &E::staticMetaObject, | 
|---|
| 257 |  | 
|---|
| 258 | 0 | 
|---|
| 259 | }; | 
|---|
| 260 |  | 
|---|
| 261 | return QDeclarativePrivate::qmlregister(QDeclarativePrivate::TypeRegistration, &type); | 
|---|
| 262 | } | 
|---|
| 263 |  | 
|---|
| 264 | template<typename T> | 
|---|
| 265 | int qmlRegisterInterface(const char *typeName) | 
|---|
| 266 | { | 
|---|
| 267 | QByteArray name(typeName); | 
|---|
| 268 |  | 
|---|
| 269 | QByteArray pointerName(name + '*'); | 
|---|
| 270 | QByteArray listName("QDeclarativeListProperty<" + name + ">"); | 
|---|
| 271 |  | 
|---|
| 272 | QDeclarativePrivate::RegisterInterface qmlInterface = { | 
|---|
| 273 | 0, | 
|---|
| 274 |  | 
|---|
| 275 | qRegisterMetaType<T *>(pointerName.constData()), | 
|---|
| 276 | qRegisterMetaType<QDeclarativeListProperty<T> >(listName.constData()), | 
|---|
| 277 |  | 
|---|
| 278 | qobject_interface_iid<T *>() | 
|---|
| 279 | }; | 
|---|
| 280 |  | 
|---|
| 281 | return QDeclarativePrivate::qmlregister(QDeclarativePrivate::InterfaceRegistration, &qmlInterface); | 
|---|
| 282 | } | 
|---|
| 283 |  | 
|---|
| 284 | template<typename T> | 
|---|
| 285 | int qmlRegisterCustomType(const char *uri, int versionMajor, int versionMinor, | 
|---|
| 286 | const char *qmlName, QDeclarativeCustomParser *parser) | 
|---|
| 287 | { | 
|---|
| 288 | QByteArray name(T::staticMetaObject.className()); | 
|---|
| 289 |  | 
|---|
| 290 | QByteArray pointerName(name + '*'); | 
|---|
| 291 | QByteArray listName("QDeclarativeListProperty<" + name + ">"); | 
|---|
| 292 |  | 
|---|
| 293 | QDeclarativePrivate::RegisterType type = { | 
|---|
| 294 | 0, | 
|---|
| 295 |  | 
|---|
| 296 | qRegisterMetaType<T *>(pointerName.constData()), | 
|---|
| 297 | qRegisterMetaType<QDeclarativeListProperty<T> >(listName.constData()), | 
|---|
| 298 | sizeof(T), QDeclarativePrivate::createInto<T>, | 
|---|
| 299 | QString(), | 
|---|
| 300 |  | 
|---|
| 301 | uri, versionMajor, versionMinor, qmlName, &T::staticMetaObject, | 
|---|
| 302 |  | 
|---|
| 303 | QDeclarativePrivate::attachedPropertiesFunc<T>(), | 
|---|
| 304 | QDeclarativePrivate::attachedPropertiesMetaObject<T>(), | 
|---|
| 305 |  | 
|---|
| 306 | QDeclarativePrivate::StaticCastSelector<T,QDeclarativeParserStatus>::cast(), | 
|---|
| 307 | QDeclarativePrivate::StaticCastSelector<T,QDeclarativePropertyValueSource>::cast(), | 
|---|
| 308 | QDeclarativePrivate::StaticCastSelector<T,QDeclarativePropertyValueInterceptor>::cast(), | 
|---|
| 309 |  | 
|---|
| 310 | 0, 0, | 
|---|
| 311 |  | 
|---|
| 312 | parser | 
|---|
| 313 | }; | 
|---|
| 314 |  | 
|---|
| 315 | return QDeclarativePrivate::qmlregister(QDeclarativePrivate::TypeRegistration, &type); | 
|---|
| 316 | } | 
|---|
| 317 |  | 
|---|
| 318 | class QDeclarativeContext; | 
|---|
| 319 | class QDeclarativeEngine; | 
|---|
| 320 | Q_DECLARATIVE_EXPORT void qmlExecuteDeferred(QObject *); | 
|---|
| 321 | Q_DECLARATIVE_EXPORT QDeclarativeContext *qmlContext(const QObject *); | 
|---|
| 322 | Q_DECLARATIVE_EXPORT QDeclarativeEngine *qmlEngine(const QObject *); | 
|---|
| 323 | Q_DECLARATIVE_EXPORT QObject *qmlAttachedPropertiesObjectById(int, const QObject *, bool create = true); | 
|---|
| 324 | Q_DECLARATIVE_EXPORT QObject *qmlAttachedPropertiesObject(int *, const QObject *, const QMetaObject *, bool create); | 
|---|
| 325 |  | 
|---|
| 326 | template<typename T> | 
|---|
| 327 | QObject *qmlAttachedPropertiesObject(const QObject *obj, bool create = true) | 
|---|
| 328 | { | 
|---|
| 329 | static int idx = -1; | 
|---|
| 330 | return qmlAttachedPropertiesObject(&idx, obj, &T::staticMetaObject, create); | 
|---|
| 331 | } | 
|---|
| 332 |  | 
|---|
| 333 | QT_END_NAMESPACE | 
|---|
| 334 |  | 
|---|
| 335 | QML_DECLARE_TYPE(QObject) | 
|---|
| 336 | Q_DECLARE_METATYPE(QVariant) | 
|---|
| 337 |  | 
|---|
| 338 | QT_END_HEADER | 
|---|
| 339 |  | 
|---|
| 340 | #endif // QDECLARATIVE_H | 
|---|