Remove "All rights reserved" line from license headers.
[profile/ivi/qtdeclarative.git] / src / qtquick1 / graphicsitems / qdeclarativevisualitemmodel_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtDeclarative module of the Qt Toolkit.
7 **
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.
16 **
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.
20 **
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.
28 **
29 ** Other Usage
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.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QDECLARATIVEVISUALDATAMODEL_H
43 #define QDECLARATIVEVISUALDATAMODEL_H
44
45 #include <QtDeclarative/qdeclarative.h>
46
47 #include <QtCore/qobject.h>
48 #include <QtCore/qabstractitemmodel.h>
49
50 QT_BEGIN_HEADER
51
52 Q_DECLARE_METATYPE(QModelIndex)
53
54 QT_BEGIN_NAMESPACE
55
56
57 class QDeclarativeComponent;
58 class QDeclarativeItem;
59 class QDeclarative1Package;
60 class QDeclarative1VisualDataModelPrivate;
61
62 class Q_AUTOTEST_EXPORT QDeclarative1VisualModel : public QObject
63 {
64     Q_OBJECT
65
66     Q_PROPERTY(int count READ count NOTIFY countChanged)
67
68 public:
69     virtual ~QDeclarative1VisualModel() {}
70
71     enum ReleaseFlag { Referenced = 0x01, Destroyed = 0x02 };
72     Q_DECLARE_FLAGS(ReleaseFlags, ReleaseFlag)
73
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;
82
83     virtual int indexOf(QDeclarativeItem *item, QObject *objectContext) const = 0;
84
85 Q_SIGNALS:
86     void countChanged();
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);
91     void modelReset();
92     void createdItem(int index, QDeclarativeItem *item);
93     void destroyingItem(QDeclarativeItem *item);
94
95 protected:
96     QDeclarative1VisualModel(QObjectPrivate &dd, QObject *parent = 0)
97         : QObject(dd, parent) {}
98
99 private:
100     Q_DISABLE_COPY(QDeclarative1VisualModel)
101 };
102
103 class QDeclarative1VisualItemModelAttached;
104 class QDeclarative1VisualItemModelPrivate;
105 class Q_AUTOTEST_EXPORT QDeclarative1VisualItemModel : public QDeclarative1VisualModel
106 {
107     Q_OBJECT
108     Q_DECLARE_PRIVATE(QDeclarative1VisualItemModel)
109
110     Q_PROPERTY(QDeclarativeListProperty<QDeclarativeItem> children READ children NOTIFY childrenChanged DESIGNABLE false)
111     Q_CLASSINFO("DefaultProperty", "children")
112
113 public:
114     QDeclarative1VisualItemModel(QObject *parent=0);
115     virtual ~QDeclarative1VisualItemModel() {}
116
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>) {}
125
126     virtual int indexOf(QDeclarativeItem *item, QObject *objectContext) const;
127
128     QDeclarativeListProperty<QDeclarativeItem> children();
129
130     static QDeclarative1VisualItemModelAttached *qmlAttachedProperties(QObject *obj);
131
132 Q_SIGNALS:
133     void childrenChanged();
134
135 private:
136     Q_DISABLE_COPY(QDeclarative1VisualItemModel)
137 };
138
139
140 class Q_AUTOTEST_EXPORT QDeclarative1VisualDataModel : public QDeclarative1VisualModel
141 {
142     Q_OBJECT
143     Q_DECLARE_PRIVATE(QDeclarative1VisualDataModel)
144
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")
151 public:
152     QDeclarative1VisualDataModel();
153     QDeclarative1VisualDataModel(QDeclarativeContext *, QObject *parent=0);
154     virtual ~QDeclarative1VisualDataModel();
155
156     QVariant model() const;
157     void setModel(const QVariant &);
158
159     QDeclarativeComponent *delegate() const;
160     void setDelegate(QDeclarativeComponent *);
161
162     QVariant rootIndex() const;
163     void setRootIndex(const QVariant &root);
164
165     Q_INVOKABLE QVariant modelIndex(int idx) const;
166     Q_INVOKABLE QVariant parentModelIndex() const;
167
168     QString part() const;
169     void setPart(const QString &);
170
171     int count() const;
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;
177     void completeItem();
178     virtual QString stringValue(int index, const QString &role);
179     virtual void setWatchedRoles(QList<QByteArray> roles);
180
181     int indexOf(QDeclarativeItem *item, QObject *objectContext) const;
182
183     QObject *parts();
184
185 Q_SIGNALS:
186     void createdPackage(int index, QDeclarative1Package *package);
187     void destroyingPackage(QDeclarative1Package *package);
188     void rootIndexChanged();
189
190 private Q_SLOTS:
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);
203
204 private:
205     Q_DISABLE_COPY(QDeclarative1VisualDataModel)
206 };
207
208 class QDeclarative1VisualItemModelAttached : public QObject
209 {
210     Q_OBJECT
211
212 public:
213     QDeclarative1VisualItemModelAttached(QObject *parent)
214         : QObject(parent), m_index(0) {}
215     ~QDeclarative1VisualItemModelAttached() {
216         attachedProperties.remove(parent());
217     }
218
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) {
223             m_index = idx;
224             emit indexChanged();
225         }
226     }
227
228     static QDeclarative1VisualItemModelAttached *properties(QObject *obj) {
229         QDeclarative1VisualItemModelAttached *rv = attachedProperties.value(obj);
230         if (!rv) {
231             rv = new QDeclarative1VisualItemModelAttached(obj);
232             attachedProperties.insert(obj, rv);
233         }
234         return rv;
235     }
236
237 Q_SIGNALS:
238     void indexChanged();
239
240 public:
241     int m_index;
242
243     static QHash<QObject*, QDeclarative1VisualItemModelAttached*> attachedProperties;
244 };
245
246
247 QT_END_NAMESPACE
248
249 QML_DECLARE_TYPE(QDeclarative1VisualModel)
250 QML_DECLARE_TYPE(QDeclarative1VisualItemModel)
251 QML_DECLARE_TYPEINFO(QDeclarative1VisualItemModel, QML_HAS_ATTACHED_PROPERTIES)
252 QML_DECLARE_TYPE(QDeclarative1VisualDataModel)
253
254 QT_END_HEADER
255
256 #endif // QDECLARATIVEVISUALDATAMODEL_H