1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
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 QDECLARATIVEVISUALDATAMODEL_H
43 #define QDECLARATIVEVISUALDATAMODEL_H
45 #include <QtDeclarative/qdeclarative.h>
47 #include <QtCore/qobject.h>
48 #include <QtCore/qabstractitemmodel.h>
52 Q_DECLARE_METATYPE(QModelIndex)
56 QT_MODULE(Declarative)
58 class QDeclarativeComponent;
59 class QDeclarativeItem;
60 class QDeclarative1Package;
61 class QDeclarative1VisualDataModelPrivate;
63 class Q_AUTOTEST_EXPORT QDeclarative1VisualModel : public QObject
67 Q_PROPERTY(int count READ count NOTIFY countChanged)
70 virtual ~QDeclarative1VisualModel() {}
72 enum ReleaseFlag { Referenced = 0x01, Destroyed = 0x02 };
73 Q_DECLARE_FLAGS(ReleaseFlags, ReleaseFlag)
75 virtual int count() const = 0;
76 virtual bool isValid() const = 0;
77 virtual QDeclarativeItem *item(int index, bool complete=true) = 0;
78 virtual ReleaseFlags release(QDeclarativeItem *item) = 0;
79 virtual bool completePending() const = 0;
80 virtual void completeItem() = 0;
81 virtual QString stringValue(int, const QString &) = 0;
82 virtual void setWatchedRoles(QList<QByteArray> roles) = 0;
84 virtual int indexOf(QDeclarativeItem *item, QObject *objectContext) const = 0;
88 void itemsInserted(int index, int count);
89 void itemsRemoved(int index, int count);
90 void itemsMoved(int from, int to, int count);
91 void itemsChanged(int index, int count);
93 void createdItem(int index, QDeclarativeItem *item);
94 void destroyingItem(QDeclarativeItem *item);
97 QDeclarative1VisualModel(QObjectPrivate &dd, QObject *parent = 0)
98 : QObject(dd, parent) {}
101 Q_DISABLE_COPY(QDeclarative1VisualModel)
104 class QDeclarative1VisualItemModelAttached;
105 class QDeclarative1VisualItemModelPrivate;
106 class Q_AUTOTEST_EXPORT QDeclarative1VisualItemModel : public QDeclarative1VisualModel
109 Q_DECLARE_PRIVATE(QDeclarative1VisualItemModel)
111 Q_PROPERTY(QDeclarativeListProperty<QDeclarativeItem> children READ children NOTIFY childrenChanged DESIGNABLE false)
112 Q_CLASSINFO("DefaultProperty", "children")
115 QDeclarative1VisualItemModel(QObject *parent=0);
116 virtual ~QDeclarative1VisualItemModel() {}
118 virtual int count() const;
119 virtual bool isValid() const;
120 virtual QDeclarativeItem *item(int index, bool complete=true);
121 virtual ReleaseFlags release(QDeclarativeItem *item);
122 virtual bool completePending() const;
123 virtual void completeItem();
124 virtual QString stringValue(int index, const QString &role);
125 virtual void setWatchedRoles(QList<QByteArray>) {}
127 virtual int indexOf(QDeclarativeItem *item, QObject *objectContext) const;
129 QDeclarativeListProperty<QDeclarativeItem> children();
131 static QDeclarative1VisualItemModelAttached *qmlAttachedProperties(QObject *obj);
134 void childrenChanged();
137 Q_DISABLE_COPY(QDeclarative1VisualItemModel)
141 class Q_AUTOTEST_EXPORT QDeclarative1VisualDataModel : public QDeclarative1VisualModel
144 Q_DECLARE_PRIVATE(QDeclarative1VisualDataModel)
146 Q_PROPERTY(QVariant model READ model WRITE setModel)
147 Q_PROPERTY(QDeclarativeComponent *delegate READ delegate WRITE setDelegate)
148 Q_PROPERTY(QString part READ part WRITE setPart)
149 Q_PROPERTY(QObject *parts READ parts CONSTANT)
150 Q_PROPERTY(QVariant rootIndex READ rootIndex WRITE setRootIndex NOTIFY rootIndexChanged)
151 Q_CLASSINFO("DefaultProperty", "delegate")
153 QDeclarative1VisualDataModel();
154 QDeclarative1VisualDataModel(QDeclarativeContext *, QObject *parent=0);
155 virtual ~QDeclarative1VisualDataModel();
157 QVariant model() const;
158 void setModel(const QVariant &);
160 QDeclarativeComponent *delegate() const;
161 void setDelegate(QDeclarativeComponent *);
163 QVariant rootIndex() const;
164 void setRootIndex(const QVariant &root);
166 Q_INVOKABLE QVariant modelIndex(int idx) const;
167 Q_INVOKABLE QVariant parentModelIndex() const;
169 QString part() const;
170 void setPart(const QString &);
173 bool isValid() const { return delegate() != 0; }
174 QDeclarativeItem *item(int index, bool complete=true);
175 QDeclarativeItem *item(int index, const QByteArray &, bool complete=true);
176 ReleaseFlags release(QDeclarativeItem *item);
177 bool completePending() const;
179 virtual QString stringValue(int index, const QString &role);
180 virtual void setWatchedRoles(QList<QByteArray> roles);
182 int indexOf(QDeclarativeItem *item, QObject *objectContext) const;
187 void createdPackage(int index, QDeclarative1Package *package);
188 void destroyingPackage(QDeclarative1Package *package);
189 void rootIndexChanged();
192 void _q_itemsChanged(int, int, const QList<int> &);
193 void _q_itemsInserted(int index, int count);
194 void _q_itemsRemoved(int index, int count);
195 void _q_itemsMoved(int from, int to, int count);
196 void _q_rowsInserted(const QModelIndex &,int,int);
197 void _q_rowsRemoved(const QModelIndex &,int,int);
198 void _q_rowsMoved(const QModelIndex &, int, int, const QModelIndex &, int);
199 void _q_dataChanged(const QModelIndex&,const QModelIndex&);
200 void _q_layoutChanged();
201 void _q_modelReset();
202 void _q_createdPackage(int index, QDeclarative1Package *package);
203 void _q_destroyingPackage(QDeclarative1Package *package);
206 Q_DISABLE_COPY(QDeclarative1VisualDataModel)
209 class QDeclarative1VisualItemModelAttached : public QObject
214 QDeclarative1VisualItemModelAttached(QObject *parent)
215 : QObject(parent), m_index(0) {}
216 ~QDeclarative1VisualItemModelAttached() {
217 attachedProperties.remove(parent());
220 Q_PROPERTY(int index READ index NOTIFY indexChanged)
221 int index() const { return m_index; }
222 void setIndex(int idx) {
223 if (m_index != idx) {
229 static QDeclarative1VisualItemModelAttached *properties(QObject *obj) {
230 QDeclarative1VisualItemModelAttached *rv = attachedProperties.value(obj);
232 rv = new QDeclarative1VisualItemModelAttached(obj);
233 attachedProperties.insert(obj, rv);
244 static QHash<QObject*, QDeclarative1VisualItemModelAttached*> attachedProperties;
250 QML_DECLARE_TYPE(QDeclarative1VisualModel)
251 QML_DECLARE_TYPE(QDeclarative1VisualItemModel)
252 QML_DECLARE_TYPEINFO(QDeclarative1VisualItemModel, QML_HAS_ATTACHED_PROPERTIES)
253 QML_DECLARE_TYPE(QDeclarative1VisualDataModel)
257 #endif // QDECLARATIVEVISUALDATAMODEL_H