source: trunk/src/declarative/graphicsitems/qdeclarativevisualitemmodel_p.h

Last change on this file was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

File size: 8.5 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation (qt-info@nokia.com)
6**
7** This file is part of the QtDeclarative module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
15**
16** GNU Lesser General Public License Usage
17** Alternatively, this file may be used under the terms of the GNU Lesser
18** General Public License version 2.1 as published by the Free Software
19** Foundation and appearing in the file LICENSE.LGPL included in the
20** packaging of this file. Please review the following information to
21** ensure the GNU Lesser General Public License version 2.1 requirements
22** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23**
24** In addition, as a special exception, Nokia gives you certain additional
25** rights. These rights are described in the Nokia Qt LGPL Exception
26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at qt-info@nokia.com.
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#ifndef QDECLARATIVEVISUALDATAMODEL_H
43#define QDECLARATIVEVISUALDATAMODEL_H
44
45#include <qdeclarative.h>
46
47#include <QtCore/qobject.h>
48#include <QtCore/qabstractitemmodel.h>
49
50QT_BEGIN_HEADER
51
52Q_DECLARE_METATYPE(QModelIndex)
53
54QT_BEGIN_NAMESPACE
55
56QT_MODULE(Declarative)
57
58class QDeclarativeItem;
59class QDeclarativeComponent;
60class QDeclarativePackage;
61class QDeclarativeVisualDataModelPrivate;
62
63class Q_AUTOTEST_EXPORT QDeclarativeVisualModel : public QObject
64{
65 Q_OBJECT
66
67 Q_PROPERTY(int count READ count NOTIFY countChanged)
68
69public:
70 virtual ~QDeclarativeVisualModel() {}
71
72 enum ReleaseFlag { Referenced = 0x01, Destroyed = 0x02 };
73 Q_DECLARE_FLAGS(ReleaseFlags, ReleaseFlag)
74
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;
83
84 virtual int indexOf(QDeclarativeItem *item, QObject *objectContext) const = 0;
85
86Q_SIGNALS:
87 void countChanged();
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);
92 void modelReset();
93 void createdItem(int index, QDeclarativeItem *item);
94 void destroyingItem(QDeclarativeItem *item);
95
96protected:
97 QDeclarativeVisualModel(QObjectPrivate &dd, QObject *parent = 0)
98 : QObject(dd, parent) {}
99
100private:
101 Q_DISABLE_COPY(QDeclarativeVisualModel)
102};
103
104class QDeclarativeVisualItemModelAttached;
105class QDeclarativeVisualItemModelPrivate;
106class Q_AUTOTEST_EXPORT QDeclarativeVisualItemModel : public QDeclarativeVisualModel
107{
108 Q_OBJECT
109 Q_DECLARE_PRIVATE(QDeclarativeVisualItemModel)
110
111 Q_PROPERTY(QDeclarativeListProperty<QDeclarativeItem> children READ children NOTIFY childrenChanged DESIGNABLE false)
112 Q_CLASSINFO("DefaultProperty", "children")
113
114public:
115 QDeclarativeVisualItemModel(QObject *parent=0);
116 virtual ~QDeclarativeVisualItemModel() {}
117
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>) {}
126
127 virtual int indexOf(QDeclarativeItem *item, QObject *objectContext) const;
128
129 QDeclarativeListProperty<QDeclarativeItem> children();
130
131 static QDeclarativeVisualItemModelAttached *qmlAttachedProperties(QObject *obj);
132
133Q_SIGNALS:
134 void childrenChanged();
135
136private:
137 Q_DISABLE_COPY(QDeclarativeVisualItemModel)
138};
139
140
141class Q_AUTOTEST_EXPORT QDeclarativeVisualDataModel : public QDeclarativeVisualModel
142{
143 Q_OBJECT
144 Q_DECLARE_PRIVATE(QDeclarativeVisualDataModel)
145
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")
152public:
153 QDeclarativeVisualDataModel();
154 QDeclarativeVisualDataModel(QDeclarativeContext *, QObject *parent=0);
155 virtual ~QDeclarativeVisualDataModel();
156
157 QVariant model() const;
158 void setModel(const QVariant &);
159
160 QDeclarativeComponent *delegate() const;
161 void setDelegate(QDeclarativeComponent *);
162
163 QVariant rootIndex() const;
164 void setRootIndex(const QVariant &root);
165
166 Q_INVOKABLE QVariant modelIndex(int idx) const;
167 Q_INVOKABLE QVariant parentModelIndex() const;
168
169 QString part() const;
170 void setPart(const QString &);
171
172 int count() const;
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;
178 void completeItem();
179 virtual QString stringValue(int index, const QString &role);
180 virtual void setWatchedRoles(QList<QByteArray> roles);
181
182 int indexOf(QDeclarativeItem *item, QObject *objectContext) const;
183
184 QObject *parts();
185
186Q_SIGNALS:
187 void createdPackage(int index, QDeclarativePackage *package);
188 void destroyingPackage(QDeclarativePackage *package);
189 void rootIndexChanged();
190
191private Q_SLOTS:
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, QDeclarativePackage *package);
203 void _q_destroyingPackage(QDeclarativePackage *package);
204
205private:
206 Q_DISABLE_COPY(QDeclarativeVisualDataModel)
207};
208
209class QDeclarativeVisualItemModelAttached : public QObject
210{
211 Q_OBJECT
212
213public:
214 QDeclarativeVisualItemModelAttached(QObject *parent)
215 : QObject(parent), m_index(0) {}
216 ~QDeclarativeVisualItemModelAttached() {
217 attachedProperties.remove(parent());
218 }
219
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) {
224 m_index = idx;
225 emit indexChanged();
226 }
227 }
228
229 static QDeclarativeVisualItemModelAttached *properties(QObject *obj) {
230 QDeclarativeVisualItemModelAttached *rv = attachedProperties.value(obj);
231 if (!rv) {
232 rv = new QDeclarativeVisualItemModelAttached(obj);
233 attachedProperties.insert(obj, rv);
234 }
235 return rv;
236 }
237
238Q_SIGNALS:
239 void indexChanged();
240
241public:
242 int m_index;
243
244 static QHash<QObject*, QDeclarativeVisualItemModelAttached*> attachedProperties;
245};
246
247
248QT_END_NAMESPACE
249
250QML_DECLARE_TYPE(QDeclarativeVisualModel)
251QML_DECLARE_TYPE(QDeclarativeVisualItemModel)
252QML_DECLARE_TYPEINFO(QDeclarativeVisualItemModel, QML_HAS_ATTACHED_PROPERTIES)
253QML_DECLARE_TYPE(QDeclarativeVisualDataModel)
254
255QT_END_HEADER
256
257#endif // QDECLARATIVEVISUALDATAMODEL_H
Note: See TracBrowser for help on using the repository browser.