Rename Qt Quick-specific classes to QQuick*
[profile/ivi/qtdeclarative.git] / src / declarative / items / qquickvisualdatamodel_p.h
1 // Commit: ac5c099cc3c5b8c7eec7a49fdeb8a21037230350
2 /****************************************************************************
3 **
4 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
5 ** All rights reserved.
6 ** Contact: Nokia Corporation (qt-info@nokia.com)
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
50 #include <QtCore/qabstractitemmodel.h>
51 #include <QtCore/qstringlist.h>
52
53 #include <private/qv8engine_p.h>
54
55 QT_BEGIN_HEADER
56
57 Q_DECLARE_METATYPE(QModelIndex)
58
59 QT_BEGIN_NAMESPACE
60
61 QT_MODULE(Declarative)
62
63
64 class QDeclarativeChangeSet;
65 class QDeclarativeComponent;
66 class QDeclarativePackage;
67 class QDeclarativeV8Function;
68 class QQuickVisualDataGroup;
69 class QQuickVisualDataModelAttached;
70 class QQuickVisualDataModelPrivate;
71
72
73 class Q_DECLARATIVE_EXPORT QQuickVisualDataModel : public QQuickVisualModel, public QDeclarativeParserStatus
74 {
75     Q_OBJECT
76     Q_DECLARE_PRIVATE(QQuickVisualDataModel)
77
78     Q_PROPERTY(QVariant model READ model WRITE setModel)
79     Q_PROPERTY(QDeclarativeComponent *delegate READ delegate WRITE setDelegate)
80     Q_PROPERTY(QString filterOnGroup READ filterGroup WRITE setFilterGroup NOTIFY filterGroupChanged RESET resetFilterGroup)
81     Q_PROPERTY(QQuickVisualDataGroup *items READ items CONSTANT)
82     Q_PROPERTY(QQuickVisualDataGroup *persistedItems READ persistedItems CONSTANT)
83     Q_PROPERTY(QDeclarativeListProperty<QQuickVisualDataGroup> groups READ groups CONSTANT)
84     Q_PROPERTY(QObject *parts READ parts CONSTANT)
85     Q_PROPERTY(QVariant rootIndex READ rootIndex WRITE setRootIndex NOTIFY rootIndexChanged)
86     Q_CLASSINFO("DefaultProperty", "delegate")
87     Q_INTERFACES(QDeclarativeParserStatus)
88 public:
89     QQuickVisualDataModel();
90     QQuickVisualDataModel(QDeclarativeContext *, QObject *parent=0);
91     virtual ~QQuickVisualDataModel();
92
93     void classBegin();
94     void componentComplete();
95
96     QVariant model() const;
97     void setModel(const QVariant &);
98
99     QDeclarativeComponent *delegate() const;
100     void setDelegate(QDeclarativeComponent *);
101
102     QVariant rootIndex() const;
103     void setRootIndex(const QVariant &root);
104
105     Q_INVOKABLE QVariant modelIndex(int idx) const;
106     Q_INVOKABLE QVariant parentModelIndex() const;
107
108     int count() const;
109     bool isValid() const { return delegate() != 0; }
110     QQuickItem *item(int index, bool complete=true);
111     ReleaseFlags release(QQuickItem *item);
112     bool completePending() const;
113     void completeItem();
114     virtual QString stringValue(int index, const QString &role);
115     virtual void setWatchedRoles(QList<QByteArray> roles);
116
117     int indexOf(QQuickItem *item, QObject *objectContext) const;
118
119     QString filterGroup() const;
120     void setFilterGroup(const QString &group);
121     void resetFilterGroup();
122
123     QQuickVisualDataGroup *items();
124     QQuickVisualDataGroup *persistedItems();
125     QDeclarativeListProperty<QQuickVisualDataGroup> groups();
126     QObject *parts();
127
128     bool event(QEvent *);
129
130     static QQuickVisualDataModelAttached *qmlAttachedProperties(QObject *obj);
131
132 Q_SIGNALS:
133     void filterGroupChanged();
134     void defaultGroupsChanged();
135     void rootIndexChanged();
136
137 private Q_SLOTS:
138     void _q_itemsChanged(int index, int count);
139     void _q_itemsInserted(int index, int count);
140     void _q_itemsRemoved(int index, int count);
141     void _q_itemsMoved(int from, int to, int count);
142     void _q_modelReset(int oldCount, int newCount);
143 private:
144     Q_DISABLE_COPY(QQuickVisualDataModel)
145 };
146
147 class QQuickVisualDataGroupPrivate;
148 class Q_AUTOTEST_EXPORT QQuickVisualDataGroup : public QObject
149 {
150     Q_OBJECT
151     Q_PROPERTY(int count READ count NOTIFY countChanged)
152     Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
153     Q_PROPERTY(bool includeByDefault READ defaultInclude WRITE setDefaultInclude NOTIFY defaultIncludeChanged)
154 public:
155     QQuickVisualDataGroup(QObject *parent = 0);
156     QQuickVisualDataGroup(const QString &name, QQuickVisualDataModel *model, int compositorType, QObject *parent = 0);
157     ~QQuickVisualDataGroup();
158
159     QString name() const;
160     void setName(const QString &name);
161
162     int count() const;
163
164     bool defaultInclude() const;
165     void setDefaultInclude(bool include);
166
167     Q_INVOKABLE QDeclarativeV8Handle get(int index);
168     Q_INVOKABLE QObject *create(int index);
169
170 public Q_SLOTS:
171     void remove(QDeclarativeV8Function *);
172     void addGroups(QDeclarativeV8Function *);
173     void removeGroups(QDeclarativeV8Function *);
174     void setGroups(QDeclarativeV8Function *);
175     void move(QDeclarativeV8Function *);
176
177 Q_SIGNALS:
178     void countChanged();
179     void nameChanged();
180     void defaultIncludeChanged();
181     void changed(const QDeclarativeV8Handle &removed, const QDeclarativeV8Handle &inserted);
182 private:
183     Q_DECLARE_PRIVATE(QQuickVisualDataGroup)
184 };
185
186 class QQuickVisualDataModelCacheItem;
187 class QQuickVisualDataModelAttachedMetaObject;
188 class QQuickVisualDataModelAttached : public QObject
189 {
190     Q_OBJECT
191     Q_PROPERTY(QQuickVisualDataModel *model READ model NOTIFY modelChanged)
192     Q_PROPERTY(QStringList groups READ groups WRITE setGroups NOTIFY groupsChanged)
193 public:
194     QQuickVisualDataModelAttached(QObject *parent)
195         : QObject(parent)
196         , m_cacheItem(0)
197         , m_previousGroups(0)
198         , m_modelChanged(false)
199     {}
200     ~QQuickVisualDataModelAttached() { attachedProperties.remove(parent()); }
201
202     QQuickVisualDataModel *model() const;
203
204     QStringList groups() const;
205     void setGroups(const QStringList &groups);
206
207     void emitChanges();
208
209     static QQuickVisualDataModelAttached *properties(QObject *obj)
210     {
211         QQuickVisualDataModelAttached *rv = attachedProperties.value(obj);
212         if (!rv) {
213             rv = new QQuickVisualDataModelAttached(obj);
214             attachedProperties.insert(obj, rv);
215         }
216         return rv;
217     }
218
219 Q_SIGNALS:
220     void modelChanged();
221     void groupsChanged();
222
223 public:
224     QQuickVisualDataModelCacheItem *m_cacheItem;
225     int m_previousGroups;
226     int m_previousIndex[QDeclarativeListCompositor::MaximumGroupCount];
227     bool m_modelChanged;
228
229     static QHash<QObject*, QQuickVisualDataModelAttached*> attachedProperties;
230
231     friend class QQuickVisualDataModelAttachedMetaObject;
232 };
233
234 QT_END_NAMESPACE
235
236 QML_DECLARE_TYPE(QQuickVisualDataModel)
237 QML_DECLARE_TYPEINFO(QQuickVisualDataModel, QML_HAS_ATTACHED_PROPERTIES)
238 QML_DECLARE_TYPE(QQuickVisualDataGroup)
239
240 QT_END_HEADER
241
242 #endif // QQUICKVISUALDATAMODEL_P_H