1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: http://www.qt-project.org/
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #ifndef QDECLARATIVELIST_H
43 #define QDECLARATIVELIST_H
45 #include <QtCore/qglobal.h>
46 #include <QtCore/qlist.h>
47 #include <QtCore/qvariant.h>
57 #ifndef QDECLARATIVELISTPROPERTY
58 #define QDECLARATIVELISTPROPERTY
60 class QDeclarativeListProperty {
62 typedef void (*AppendFunction)(QDeclarativeListProperty<T> *, T*);
63 typedef int (*CountFunction)(QDeclarativeListProperty<T> *);
64 typedef T *(*AtFunction)(QDeclarativeListProperty<T> *, int);
65 typedef void (*ClearFunction)(QDeclarativeListProperty<T> *);
67 QDeclarativeListProperty()
68 : object(0), data(0), append(0), count(0), at(0), clear(0), dummy1(0), dummy2(0) {}
69 QDeclarativeListProperty(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 QDeclarativeListProperty(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 QDeclarativeListProperty &o) const {
77 return object == o.object &&
88 AppendFunction append;
99 static void qlist_append(QDeclarativeListProperty *p, T *v) {
100 reinterpret_cast<QList<T *> *>(p->data)->append(v);
102 static int qlist_count(QDeclarativeListProperty *p) {
103 return reinterpret_cast<QList<T *> *>(p->data)->count();
105 static T *qlist_at(QDeclarativeListProperty *p, int idx) {
106 return reinterpret_cast<QList<T *> *>(p->data)->at(idx);
108 static void qlist_clear(QDeclarativeListProperty *p) {
109 return reinterpret_cast<QList<T *> *>(p->data)->clear();
114 class QDeclarativeEngine;
115 class QDeclarativeListReferencePrivate;
116 class Q_DECLARATIVE_EXPORT QDeclarativeListReference
119 QDeclarativeListReference();
120 QDeclarativeListReference(QObject *, const char *property, QDeclarativeEngine * = 0);
121 QDeclarativeListReference(const QDeclarativeListReference &);
122 QDeclarativeListReference &operator=(const QDeclarativeListReference &);
123 ~QDeclarativeListReference();
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 QDeclarativeListReferencePrivate;
142 QDeclarativeListReferencePrivate* d;
147 Q_DECLARE_METATYPE(QDeclarativeListReference)
151 #endif // QDECLARATIVELIST_H