df45a94211ffc4e82bc88023b7d14ce703081c36
[profile/ivi/qtdeclarative.git] / src / quick / items / qquickvisualdatamodel_p.h
1 // Commit: ac5c099cc3c5b8c7eec7a49fdeb8a21037230350
2 /****************************************************************************
3 **
4 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
5 ** All rights reserved.
6 ** Contact: http://www.qt-project.org/
7 **
8 ** This file is part of the QtDeclarative module of the Qt Toolkit.
9 **
10 ** $QT_BEGIN_LICENSE:LGPL$
11 ** GNU Lesser General Public License Usage
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this
15 ** file. Please review the following information to ensure the GNU Lesser
16 ** General Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 **
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 **
23 ** GNU General Public License Usage
24 ** Alternatively, this file may be used under the terms of the GNU General
25 ** Public License version 3.0 as published by the Free Software Foundation
26 ** and appearing in the file LICENSE.GPL included in the packaging of this
27 ** file. Please review the following information to ensure the GNU General
28 ** Public License version 3.0 requirements will be met:
29 ** http://www.gnu.org/copyleft/gpl.html.
30 **
31 ** Other Usage
32 ** Alternatively, this file may be used in accordance with the terms and
33 ** conditions contained in a signed written agreement between you and Nokia.
34 **
35 **
36 **
37 **
38 **
39 ** $QT_END_LICENSE$
40 **
41 ****************************************************************************/
42
43 #ifndef QQUICKVISUALDATAMODEL_P_H
44 #define QQUICKVISUALDATAMODEL_P_H
45
46 #include <private/qdeclarativelistcompositor_p.h>
47 #include <private/qquickvisualitemmodel_p.h>
48
49 #include <QtCore/qabstractitemmodel.h>
50 #include <QtCore/qstringlist.h>
51
52
53 #include <private/qv8engine_p.h>
54 #include <private/qdeclarativeglobal_p.h>
55
56 QT_BEGIN_HEADER
57
58 Q_DECLARE_METATYPE(QModelIndex)
59
60 QT_BEGIN_NAMESPACE
61
62 class QDeclarativeChangeSet;
63 class QDeclarativeComponent;
64 class QDeclarativePackage;
65 class QDeclarativeV8Function;
66 class QQuickVisualDataGroup;
67 class QQuickVisualDataModelAttached;
68 class QQuickVisualDataModelPrivate;
69
70
71 class Q_QUICK_EXPORT QQuickVisualDataModel : public QQuickVisualModel, public QDeclarativeParserStatus
72 {
73     Q_OBJECT
74     Q_DECLARE_PRIVATE(QQuickVisualDataModel)
75
76     Q_PROPERTY(QVariant model READ model WRITE setModel)
77     Q_PROPERTY(QDeclarativeComponent *delegate READ delegate WRITE setDelegate)
78     Q_PROPERTY(QString filterOnGroup READ filterGroup WRITE setFilterGroup NOTIFY filterGroupChanged RESET resetFilterGroup)
79     Q_PROPERTY(QQuickVisualDataGroup *items READ items CONSTANT)
80     Q_PROPERTY(QQuickVisualDataGroup *persistedItems READ persistedItems CONSTANT)
81     Q_PROPERTY(QDeclarativeListProperty<QQuickVisualDataGroup> groups READ groups CONSTANT)
82     Q_PROPERTY(QObject *parts READ parts CONSTANT)
83     Q_PROPERTY(QVariant rootIndex READ rootIndex WRITE setRootIndex NOTIFY rootIndexChanged)
84     Q_CLASSINFO("DefaultProperty", "delegate")
85     Q_INTERFACES(QDeclarativeParserStatus)
86 public:
87     QQuickVisualDataModel();
88     QQuickVisualDataModel(QDeclarativeContext *, QObject *parent=0);
89     virtual ~QQuickVisualDataModel();
90
91     void classBegin();
92     void componentComplete();
93
94     QVariant model() const;
95     void setModel(const QVariant &);
96
97     QDeclarativeComponent *delegate() const;
98     void setDelegate(QDeclarativeComponent *);
99
100     QVariant rootIndex() const;
101     void setRootIndex(const QVariant &root);
102
103     Q_INVOKABLE QVariant modelIndex(int idx) const;
104     Q_INVOKABLE QVariant parentModelIndex() const;
105
106     int count() const;
107     bool isValid() const { return delegate() != 0; }
108     QQuickItem *item(int index, bool asynchronous=false);
109     ReleaseFlags release(QQuickItem *item);
110     virtual QString stringValue(int index, const QString &role);
111     virtual void setWatchedRoles(QList<QByteArray> roles);
112
113     int indexOf(QQuickItem *item, QObject *objectContext) const;
114
115     QString filterGroup() const;
116     void setFilterGroup(const QString &group);
117     void resetFilterGroup();
118
119     QQuickVisualDataGroup *items();
120     QQuickVisualDataGroup *persistedItems();
121     QDeclarativeListProperty<QQuickVisualDataGroup> groups();
122     QObject *parts();
123
124     bool event(QEvent *);
125
126     static QQuickVisualDataModelAttached *qmlAttachedProperties(QObject *obj);
127
128 Q_SIGNALS:
129     void filterGroupChanged();
130     void defaultGroupsChanged();
131     void rootIndexChanged();
132
133 private Q_SLOTS:
134     void _q_itemsChanged(int index, int count);
135     void _q_itemsInserted(int index, int count);
136     void _q_itemsRemoved(int index, int count);
137     void _q_itemsMoved(int from, int to, int count);
138     void _q_modelReset(int oldCount, int newCount);
139 private:
140     Q_DISABLE_COPY(QQuickVisualDataModel)
141 };
142
143 class QQuickVisualDataGroupPrivate;
144 class Q_AUTOTEST_EXPORT QQuickVisualDataGroup : public QObject
145 {
146     Q_OBJECT
147     Q_PROPERTY(int count READ count NOTIFY countChanged)
148     Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
149     Q_PROPERTY(bool includeByDefault READ defaultInclude WRITE setDefaultInclude NOTIFY defaultIncludeChanged)
150 public:
151     QQuickVisualDataGroup(QObject *parent = 0);
152     QQuickVisualDataGroup(const QString &name, QQuickVisualDataModel *model, int compositorType, QObject *parent = 0);
153     ~QQuickVisualDataGroup();
154
155     QString name() const;
156     void setName(const QString &name);
157
158     int count() const;
159
160     bool defaultInclude() const;
161     void setDefaultInclude(bool include);
162
163     Q_INVOKABLE QDeclarativeV8Handle get(int index);
164
165 public Q_SLOTS:
166     void insert(QDeclarativeV8Function *);
167     void create(QDeclarativeV8Function *);
168     void resolve(QDeclarativeV8Function *);
169     void remove(QDeclarativeV8Function *);
170     void addGroups(QDeclarativeV8Function *);
171     void removeGroups(QDeclarativeV8Function *);
172     void setGroups(QDeclarativeV8Function *);
173     void move(QDeclarativeV8Function *);
174
175 Q_SIGNALS:
176     void countChanged();
177     void nameChanged();
178     void defaultIncludeChanged();
179     void changed(const QDeclarativeV8Handle &removed, const QDeclarativeV8Handle &inserted);
180 private:
181     Q_DECLARE_PRIVATE(QQuickVisualDataGroup)
182 };
183
184 class QQuickVisualDataModelItem;
185 class QQuickVisualDataModelAttachedMetaObject;
186 class QQuickVisualDataModelAttached : public QObject
187 {
188     Q_OBJECT
189     Q_PROPERTY(QQuickVisualDataModel *model READ model NOTIFY modelChanged)
190     Q_PROPERTY(QStringList groups READ groups WRITE setGroups NOTIFY groupsChanged)
191     Q_PROPERTY(bool isUnresolved READ isUnresolved NOTIFY unresolvedChanged)
192 public:
193     QQuickVisualDataModelAttached(QObject *parent)
194         : m_cacheItem(0)
195         , m_previousGroups(0)
196         , m_modelChanged(false)
197     {
198         QDeclarative_setParent_noEvent(this, parent);
199     }
200     ~QQuickVisualDataModelAttached() { attachedProperties.remove(parent()); }
201
202     void setCacheItem(QQuickVisualDataModelItem *item);
203
204     QQuickVisualDataModel *model() const;
205
206     QStringList groups() const;
207     void setGroups(const QStringList &groups);
208
209     bool isUnresolved() const;
210
211     void emitChanges();
212
213     void emitUnresolvedChanged() { emit unresolvedChanged(); }
214
215     static QQuickVisualDataModelAttached *properties(QObject *obj)
216     {
217         QQuickVisualDataModelAttached *rv = attachedProperties.value(obj);
218         if (!rv) {
219             rv = new QQuickVisualDataModelAttached(obj);
220             attachedProperties.insert(obj, rv);
221         }
222         return rv;
223     }
224
225 Q_SIGNALS:
226     void modelChanged();
227     void groupsChanged();
228     void unresolvedChanged();
229
230 public:
231     QQuickVisualDataModelItem *m_cacheItem;
232     int m_previousGroups;
233     int m_previousIndex[QDeclarativeListCompositor::MaximumGroupCount];
234     bool m_modelChanged;
235
236     static QHash<QObject*, QQuickVisualDataModelAttached*> attachedProperties;
237
238     friend class QQuickVisualDataModelAttachedMetaObject;
239 };
240
241 QT_END_NAMESPACE
242
243 QML_DECLARE_TYPE(QQuickVisualDataModel)
244 QML_DECLARE_TYPEINFO(QQuickVisualDataModel, QML_HAS_ATTACHED_PROPERTIES)
245 QML_DECLARE_TYPE(QQuickVisualDataGroup)
246
247 QT_END_HEADER
248
249 #endif // QQUICKVISUALDATAMODEL_P_H