1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtQml module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
45 #include <QtQml/qtqmlglobal.h>
46 #include <QtCore/qlist.h>
47 #include <QtCore/qvariant.h>
57 #ifndef QQMLLISTPROPERTY
58 #define QQMLLISTPROPERTY
60 class QQmlListProperty {
62 typedef void (*AppendFunction)(QQmlListProperty<T> *, T*);
63 typedef int (*CountFunction)(QQmlListProperty<T> *);
64 typedef T *(*AtFunction)(QQmlListProperty<T> *, int);
65 typedef void (*ClearFunction)(QQmlListProperty<T> *);
68 : object(0), data(0), append(0), count(0), at(0), clear(0), dummy1(0), dummy2(0) {}
69 QQmlListProperty(QObject *o, QList<T *> &list)
70 : object(o), data(&list), append(qlist_append), count(qlist_count), at(qlist_at),
71 clear(qlist_clear), dummy1(0), dummy2(0) {}
72 QQmlListProperty(QObject *o, void *d, AppendFunction a, CountFunction c = 0, AtFunction t = 0,
74 : object(o), data(d), append(a), count(c), at(t), clear(r), dummy1(0), dummy2(0) {}
76 bool operator==(const QQmlListProperty &o) const {
77 return object == o.object &&
88 AppendFunction append;
99 static void qlist_append(QQmlListProperty *p, T *v) {
100 reinterpret_cast<QList<T *> *>(p->data)->append(v);
102 static int qlist_count(QQmlListProperty *p) {
103 return reinterpret_cast<QList<T *> *>(p->data)->count();
105 static T *qlist_at(QQmlListProperty *p, int idx) {
106 return reinterpret_cast<QList<T *> *>(p->data)->at(idx);
108 static void qlist_clear(QQmlListProperty *p) {
109 return reinterpret_cast<QList<T *> *>(p->data)->clear();
115 class QQmlListReferencePrivate;
116 class Q_QML_EXPORT QQmlListReference
120 QQmlListReference(QObject *, const char *property, QQmlEngine * = 0);
121 QQmlListReference(const QQmlListReference &);
122 QQmlListReference &operator=(const QQmlListReference &);
123 ~QQmlListReference();
125 bool isValid() const;
127 QObject *object() const;
128 const QMetaObject *listElementType() const;
130 bool canAppend() const;
132 bool canClear() const;
133 bool canCount() const;
135 bool append(QObject *) const;
136 QObject *at(int) const;
141 friend class QQmlListReferencePrivate;
142 QQmlListReferencePrivate* d;
147 Q_DECLARE_METATYPE(QQmlListReference)