summaryrefslogtreecommitdiffstats
path: root/src/declarative/qml/qmlmetatype.h
blob: 42c278cc665989b061644d10626dea3f2b5e1770 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** Contact: Qt Software Information (qt-info@nokia.com)
**
** This file is part of the QtDeclarative module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the either Technology Preview License Agreement or the
** Beta Release License Agreement.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain
** additional rights. These rights are described in the Nokia Qt LGPL
** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
** package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at qt-sales@nokia.com.
** $QT_END_LICENSE$
**
****************************************************************************/

#ifndef QMLMETATYPE_H
#define QMLMETATYPE_H

#include <QtCore/qglobal.h>
#include <QtCore/qvariant.h>
#include <QtCore/qbitarray.h>
#include <QtDeclarative/qmlprivate.h>
#include <QtDeclarative/qmlparserstatus.h>
#include <QtDeclarative/qmlpropertyvaluesource.h>
#include <QtDeclarative/qmlpropertyvalueinterceptor.h>

QT_BEGIN_HEADER

QT_BEGIN_NAMESPACE

QT_MODULE(Declarative)

class QmlType;
class QmlCustomParser;
class Q_DECLARATIVE_EXPORT QmlMetaType
{
public:
    static int registerType(const QmlPrivate::MetaTypeIds &, QmlPrivate::Func, const char *, int vmaj, int vmin_from, int vmin_to, const char *qmlName, const QMetaObject *, QmlAttachedPropertiesFunc, const QMetaObject *, int pStatus, int object, int valueSource, int valueInterceptor, QmlPrivate::CreateFunc extFunc, const QMetaObject *extmo, QmlCustomParser *);
    static int registerInterface(const QmlPrivate::MetaTypeIds &, QmlPrivate::Func, const char *);

    static bool copy(int type, void *data, const void *copy = 0);

    static QList<QByteArray> qmlTypeNames();
    static QList<QmlType*> qmlTypes();

    static QmlType *qmlType(const QByteArray &, int, int);
    static QmlType *qmlType(const QMetaObject *);

    static QMetaProperty defaultProperty(const QMetaObject *);
    static QMetaProperty defaultProperty(QObject *);
    static QMetaMethod defaultMethod(const QMetaObject *);
    static QMetaMethod defaultMethod(QObject *);
    static QMetaProperty property(QObject *, const QByteArray &);
    static QMetaProperty property(QObject *, const char *);
    static QObject *toQObject(const QVariant &);
    static int qmlParserStatusCast(int);
    static int qmlPropertyValueSourceCast(int);
    static int qmlPropertyValueInterceptorCast(int);
    static int listType(int);
    static bool clear(const QVariant &);
    static bool append(const QVariant &, const QVariant &);
    static QVariant fromObject(QObject *, int type);
    static const QMetaObject *rawMetaObjectForType(int);
    static const QMetaObject *metaObjectForType(int);
    static int attachedPropertiesFuncId(const QMetaObject *);
    static QmlAttachedPropertiesFunc attachedPropertiesFuncById(int);

    enum TypeCategory { Unknown, Object, List, QmlList };
    static TypeCategory typeCategory(int);
        
    static bool isInterface(int);
    static const char *interfaceIId(int);
    static bool isObject(int);
    static bool isObject(const QMetaObject *);
    static bool isList(int);
    static bool isList(const QVariant &);
    static bool isQmlList(int);
    static int qmlListType(int);
    static int listCount(const QVariant &);
    static QVariant listAt(const QVariant &, int);

    typedef QVariant (*StringConverter)(const QString &);
    static void registerCustomStringConverter(int, StringConverter);
    static StringConverter customStringConverter(int);
};

class QmlTypePrivate;
class Q_DECLARATIVE_EXPORT QmlType
{
public:
    QByteArray typeName() const;
    QByteArray qmlTypeName() const;

    int majorVersion() const;
    int minMinorVersion() const;
    int maxMinorVersion() const;
    bool availableInVersion(int vmajor, int vminor) const;

    QByteArray hash() const;

    QObject *create() const;

    QmlCustomParser *customParser() const;

    bool isInterface() const;
    int typeId() const;
    int qListTypeId() const;
    int qmlListTypeId() const;

    void listClear(const QVariant &);
    void listAppend(const QVariant &, const QVariant &);
    QVariant listAt(const QVariant &, int);
    int listCount(const QVariant &);

    const QMetaObject *metaObject() const;
    const QMetaObject *baseMetaObject() const;

    QmlAttachedPropertiesFunc attachedPropertiesFunction() const;
    const QMetaObject *attachedPropertiesType() const;

    int parserStatusCast() const;
    QVariant fromObject(QObject *) const;
    const char *interfaceIId() const;
    int propertyValueSourceCast() const;
    int propertyValueInterceptorCast() const;

    int index() const;
private:
    friend class QmlMetaType;
    friend class QmlTypePrivate;
    friend class QmlMetaTypeData;
    QmlType(int, int, int, QmlPrivate::Func, const char *, int);
    QmlType(int, int, int, QmlPrivate::Func, const char *, int, int, int, const QMetaObject *, QmlAttachedPropertiesFunc, const QMetaObject *, int, int, int, QmlPrivate::CreateFunc, const QMetaObject *, int, QmlCustomParser *);
    ~QmlType();

    QmlTypePrivate *d;
};

template<typename T>
int qmlRegisterType(const char *typeName)
{
    QByteArray name(typeName);
    QmlPrivate::MetaTypeIds ids = {
        qRegisterMetaType<T *>(QByteArray(name + "*").constData()),
        qRegisterMetaType<T *>(QByteArray("QList<" + name + "*>*").constData()),
        qRegisterMetaType<T *>(QByteArray("QmlList<" + name + "*>*").constData())
    };

    return QmlMetaType::registerType(ids, QmlPrivate::list_nocreate_op<T>, 0, 0, 0, 0, 0,
            &T::staticMetaObject,
            QmlPrivate::attachedPropertiesFunc<T>(),
            QmlPrivate::attachedPropertiesMetaObject<T>(),
            QmlPrivate::StaticCastSelector<T,QmlParserStatus>::cast(), 
            QmlPrivate::StaticCastSelector<T,QObject>::cast(),
            QmlPrivate::StaticCastSelector<T,QmlPropertyValueSource>::cast(),
            QmlPrivate::StaticCastSelector<T,QmlPropertyValueInterceptor>::cast(),
            0, 0, 0);
}

template<typename T>
int qmlRegisterType(const char *uri, int version_maj, int version_min_from, int version_min_to, const char *qmlName, const char *typeName)
{
    QByteArray name(typeName);
    QmlPrivate::MetaTypeIds ids = {
        qRegisterMetaType<T *>(QByteArray(name + "*").constData()),
        qRegisterMetaType<T *>(QByteArray("QList<" + name + "*>*").constData()),
        qRegisterMetaType<T *>(QByteArray("QmlList<" + name + "*>*").constData())
    };

    return QmlMetaType::registerType(ids, QmlPrivate::list_op<T>,
            uri, version_maj, version_min_from, version_min_to, qmlName, 
            &T::staticMetaObject,
            QmlPrivate::attachedPropertiesFunc<T>(),
            QmlPrivate::attachedPropertiesMetaObject<T>(),
            QmlPrivate::StaticCastSelector<T,QmlParserStatus>::cast(), 
            QmlPrivate::StaticCastSelector<T,QObject>::cast(), 
            QmlPrivate::StaticCastSelector<T,QmlPropertyValueSource>::cast(),
            QmlPrivate::StaticCastSelector<T,QmlPropertyValueInterceptor>::cast(),
            0, 0, 0);
}

template<typename T, typename E>
int qmlRegisterExtendedType(const char *typeName)
{
    QByteArray name(typeName);
    QmlPrivate::MetaTypeIds ids = {
        qRegisterMetaType<T *>(QByteArray(name + "*").constData()),
        qRegisterMetaType<T *>(QByteArray("QList<" + name + "*>*").constData()),
        qRegisterMetaType<T *>(QByteArray("QmlList<" + name + "*>*").constData())
    };

    QmlAttachedPropertiesFunc attached = 
        QmlPrivate::attachedPropertiesFunc<E>();
    const QMetaObject * attachedMo = 
        QmlPrivate::attachedPropertiesMetaObject<E>();
    if (!attached) {
        attached = QmlPrivate::attachedPropertiesFunc<T>();
        attachedMo = QmlPrivate::attachedPropertiesMetaObject<T>();
    }

    return QmlMetaType::registerType(ids, QmlPrivate::list_nocreate_op<T>, 0, 0, 0, 0, 0,
            &T::staticMetaObject, attached, attachedMo,
            QmlPrivate::StaticCastSelector<T,QmlParserStatus>::cast(), 
            QmlPrivate::StaticCastSelector<T,QObject>::cast(),
            QmlPrivate::StaticCastSelector<T,QmlPropertyValueSource>::cast(),
            QmlPrivate::StaticCastSelector<T,QmlPropertyValueInterceptor>::cast(),
            &QmlPrivate::CreateParent<E>::create, &E::staticMetaObject, 0);
}

template<typename T, typename E>
int qmlRegisterExtendedType(const char *uri, int version_maj, int version_min_from, int version_min_to, const char *qmlName, const char *typeName)
{
    QByteArray name(typeName);
    QmlPrivate::MetaTypeIds ids = {
        qRegisterMetaType<T *>(QByteArray(name + "*").constData()),
        qRegisterMetaType<T *>(QByteArray("QList<" + name + "*>*").constData()),
        qRegisterMetaType<T *>(QByteArray("QmlList<" + name + "*>*").constData())
    };

    QmlAttachedPropertiesFunc attached = 
        QmlPrivate::attachedPropertiesFunc<E>();
    const QMetaObject * attachedMo = 
        QmlPrivate::attachedPropertiesMetaObject<E>(); 
    if (!attached) {
        attached = QmlPrivate::attachedPropertiesFunc<T>();
        attachedMo = QmlPrivate::attachedPropertiesMetaObject<T>();
    }

    return QmlMetaType::registerType(ids, QmlPrivate::list_op<T>, 
            uri, version_maj, version_min_from, version_min_to, qmlName, 
            &T::staticMetaObject,
            attached, attachedMo,
            QmlPrivate::StaticCastSelector<T,QmlParserStatus>::cast(), 
            QmlPrivate::StaticCastSelector<T,QObject>::cast(),
            QmlPrivate::StaticCastSelector<T,QmlPropertyValueSource>::cast(),
            QmlPrivate::StaticCastSelector<T,QmlPropertyValueInterceptor>::cast(),
            &QmlPrivate::CreateParent<E>::create, 
            &E::staticMetaObject, 0);
}

template<typename T>
int qmlRegisterInterface(const char *typeName)
{
    QByteArray name(typeName);
    QmlPrivate::MetaTypeIds ids = {
        qRegisterMetaType<T *>(QByteArray(name + "*").constData()),
        qRegisterMetaType<T *>(QByteArray("QList<" + name + "*>*").constData()),
        qRegisterMetaType<T *>(QByteArray("QmlList<" + name + "*>*").constData())
    };

    return QmlMetaType::registerInterface(ids, 
            QmlPrivate::list_interface_op<T>, 
            qobject_interface_iid<T *>());
}

template<typename T>
int qmlRegisterCustomType(const char *uri, int version_maj, int version_min_from, int version_min_to, const char *qmlName, const char *typeName, QmlCustomParser *parser)
{
    QByteArray name(typeName);
    QmlPrivate::MetaTypeIds ids = {
        qRegisterMetaType<T *>(QByteArray(name + "*").constData()),
        qRegisterMetaType<T *>(QByteArray("QList<" + name + "*>*").constData()),
        qRegisterMetaType<T *>(QByteArray("QmlList<" + name + "*>*").constData())
    };

    return QmlMetaType::registerType(ids, QmlPrivate::list_op<T>,
            uri, version_maj, version_min_from, version_min_to, qmlName, 
            &T::staticMetaObject,
            QmlPrivate::attachedPropertiesFunc<T>(),
            QmlPrivate::attachedPropertiesMetaObject<T>(),
            QmlPrivate::StaticCastSelector<T,QmlParserStatus>::cast(), 
            QmlPrivate::StaticCastSelector<T,QObject>::cast(),
            QmlPrivate::StaticCastSelector<T,QmlPropertyValueSource>::cast(),
            QmlPrivate::StaticCastSelector<T,QmlPropertyValueInterceptor>::cast(),
            0, 0, parser);
}

QT_END_NAMESPACE

QT_END_HEADER

#endif // QMLMETATYPE_H