1 /****************************************************************************
3 ** Copyright (C) 2012 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)
57 class QDeclarativeComponent;
58 class QDeclarativeItem;
59 class QDeclarative1Package;
60 class QDeclarative1VisualDataModelPrivate;
62 class Q_AUTOTEST_EXPORT QDeclarative1VisualModel : public QObject
66 Q_PROPERTY(int count READ count NOTIFY countChanged)
69 virtual ~QDeclarative1VisualModel() {}
71 enum ReleaseFlag { Referenced = 0x01, Destroyed = 0x02 };
72 Q_DECLARE_FLAGS(ReleaseFlags, ReleaseFlag)
74 virtual int count() const = 0;
75 virtual bool isValid() const = 0;
76 virtual QDeclarativeItem *item(int index, bool complete=true) = 0;
77 virtual ReleaseFlags release(QDeclarativeItem *item) = 0;
78 virtual bool completePending() const = 0;
79 virtual void completeItem() = 0;
80 virtual QString stringValue(int, const QString &) = 0;
81 virtual void setWatchedRoles(QList<QByteArray> roles) = 0;
83 virtual int indexOf(QDeclarativeItem *item, QObject *objectContext) const = 0;
87 void itemsInserted(int index, int count);
88 void itemsRemoved(int index, int count);
89 void itemsMoved(int from, int to, int count);
90 void itemsChanged(int index, int count);
92 void createdItem(int index, QDeclarativeItem *item);
93 void destroyingItem(QDeclarativeItem *item);
96 QDeclarative1VisualModel(QObjectPrivate &dd, QObject *parent = 0)
97 : QObject(dd, parent) {}
100 Q_DISABLE_COPY(QDeclarative1VisualModel)
103 class QDeclarative1VisualItemModelAttached;
104 class QDeclarative1VisualItemModelPrivate;
105 class Q_AUTOTEST_EXPORT QDeclarative1VisualItemModel : public QDeclarative1VisualModel
108 Q_DECLARE_PRIVATE(QDeclarative1VisualItemModel)
110 Q_PROPERTY(QDeclarativeListProperty<QDeclarativeItem> children READ children NOTIFY childrenChanged DESIGNABLE false)
111 Q_CLASSINFO("DefaultProperty", "children")
114 QDeclarative1VisualItemModel(QObject *parent=0);
115 virtual ~QDeclarative1VisualItemModel() {}
117 virtual int count() const;
118 virtual bool isValid() const;
119 virtual QDeclarativeItem *item(int index, bool complete=true);
120 virtual ReleaseFlags release(QDeclarativeItem *item);
121 virtual bool completePending() const;
122 virtual void completeItem();
123 virtual QString stringValue(int index, const QString &role);
124 virtual void setWatchedRoles(QList<QByteArray>) {}
126 virtual int indexOf(QDeclarativeItem *item, QObject *objectContext) const;
128 QDeclarativeListProperty<QDeclarativeItem> children();
130 static QDeclarative1VisualItemModelAttached *qmlAttachedProperties(QObject *obj);
133 void childrenChanged();
136 Q_DISABLE_COPY(QDeclarative1VisualItemModel)
140 class Q_AUTOTEST_EXPORT QDeclarative1VisualDataModel : public QDeclarative1VisualModel
143 Q_DECLARE_PRIVATE(QDeclarative1VisualDataModel)
145 Q_PROPERTY(QVariant model READ model WRITE setModel)
146 Q_PROPERTY(QDeclarativeComponent *delegate READ delegate WRITE setDelegate)
147 Q_PROPERTY(QString part READ part WRITE setPart)
148 Q_PROPERTY(QObject *parts READ parts CONSTANT)
149 Q_PROPERTY(QVariant rootIndex READ rootIndex WRITE setRootIndex NOTIFY rootIndexChanged)
150 Q_CLASSINFO("DefaultProperty", "delegate")
152 QDeclarative1VisualDataModel();
153 QDeclarative1VisualDataModel(QDeclarativeContext *, QObject *parent=0);
154 virtual ~QDeclarative1VisualDataModel();
156 QVariant model() const;
157 void setModel(const QVariant &);
159 QDeclarativeComponent *delegate() const;
160 void setDelegate(QDeclarativeComponent *);
162 QVariant rootIndex() const;
163 void setRootIndex(const QVariant &root);
165 Q_INVOKABLE QVariant modelIndex(int idx) const;
166 Q_INVOKABLE QVariant parentModelIndex() const;
168 QString part() const;
169 void setPart(const QString &);
172 bool isValid() const { return delegate() != 0; }
173 QDeclarativeItem *item(int index, bool complete=true);
174 QDeclarativeItem *item(int index, const QByteArray &, bool complete=true);
175 ReleaseFlags release(QDeclarativeItem *item);
176 bool completePending() const;
178 virtual QString stringValue(int index, const QString &role);
179 virtual void setWatchedRoles(QList<QByteArray> roles);
181 int indexOf(QDeclarativeItem *item, QObject *objectContext) const;
186 void createdPackage(int index, QDeclarative1Package *package);
187 void destroyingPackage(QDeclarative1Package *package);
188 void rootIndexChanged();
191 void _q_itemsChanged(int, int, const QList<int> &);
192 void _q_itemsInserted(int index, int count);
193 void _q_itemsRemoved(int index, int count);
194 void _q_itemsMoved(int from, int to, int count);
195 void _q_rowsInserted(const QModelIndex &,int,int);
196 void _q_rowsRemoved(const QModelIndex &,int,int);
197 void _q_rowsMoved(const QModelIndex &, int, int, const QModelIndex &, int);
198 void _q_dataChanged(const QModelIndex&,const QModelIndex&);
199 void _q_layoutChanged();
200 void _q_modelReset();
201 void _q_createdPackage(int index, QDeclarative1Package *package);
202 void _q_destroyingPackage(QDeclarative1Package *package);
205 Q_DISABLE_COPY(QDeclarative1VisualDataModel)
208 class QDeclarative1VisualItemModelAttached : public QObject
213 QDeclarative1VisualItemModelAttached(QObject *parent)
214 : QObject(parent), m_index(0) {}
215 ~QDeclarative1VisualItemModelAttached() {
216 attachedProperties.remove(parent());
219 Q_PROPERTY(int index READ index NOTIFY indexChanged)
220 int index() const { return m_index; }
221 void setIndex(int idx) {
222 if (m_index != idx) {
228 static QDeclarative1VisualItemModelAttached *properties(QObject *obj) {
229 QDeclarative1VisualItemModelAttached *rv = attachedProperties.value(obj);
231 rv = new QDeclarative1VisualItemModelAttached(obj);
232 attachedProperties.insert(obj, rv);
243 static QHash<QObject*, QDeclarative1VisualItemModelAttached*> attachedProperties;
249 QML_DECLARE_TYPE(QDeclarative1VisualModel)
250 QML_DECLARE_TYPE(QDeclarative1VisualItemModel)
251 QML_DECLARE_TYPEINFO(QDeclarative1VisualItemModel, QML_HAS_ATTACHED_PROPERTIES)
252 QML_DECLARE_TYPE(QDeclarative1VisualDataModel)
256 #endif // QDECLARATIVEVISUALDATAMODEL_H