1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtQml module of the Qt Toolkit.
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.
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.
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.
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.
40 ****************************************************************************/
42 #ifndef QQUICKVISUALDATAMODEL_P_H
43 #define QQUICKVISUALDATAMODEL_P_H
45 #include <private/qquicklistcompositor_p.h>
46 #include <private/qquickvisualitemmodel_p.h>
48 #include <QtCore/qabstractitemmodel.h>
49 #include <QtCore/qstringlist.h>
52 #include <private/qv8engine_p.h>
53 #include <private/qqmlglobal_p.h>
57 Q_DECLARE_METATYPE(QModelIndex)
61 class QQuickChangeSet;
65 class QQuickVisualDataGroup;
66 class QQuickVisualDataModelAttached;
67 class QQuickVisualDataModelPrivate;
70 class Q_QUICK_EXPORT QQuickVisualDataModel : public QQuickVisualModel, public QQmlParserStatus
73 Q_DECLARE_PRIVATE(QQuickVisualDataModel)
75 Q_PROPERTY(QVariant model READ model WRITE setModel)
76 Q_PROPERTY(QQmlComponent *delegate READ delegate WRITE setDelegate)
77 Q_PROPERTY(QString filterOnGroup READ filterGroup WRITE setFilterGroup NOTIFY filterGroupChanged RESET resetFilterGroup)
78 Q_PROPERTY(QQuickVisualDataGroup *items READ items CONSTANT)
79 Q_PROPERTY(QQuickVisualDataGroup *persistedItems READ persistedItems CONSTANT)
80 Q_PROPERTY(QQmlListProperty<QQuickVisualDataGroup> groups READ groups CONSTANT)
81 Q_PROPERTY(QObject *parts READ parts CONSTANT)
82 Q_PROPERTY(QVariant rootIndex READ rootIndex WRITE setRootIndex NOTIFY rootIndexChanged)
83 Q_CLASSINFO("DefaultProperty", "delegate")
84 Q_INTERFACES(QQmlParserStatus)
86 QQuickVisualDataModel();
87 QQuickVisualDataModel(QQmlContext *, QObject *parent=0);
88 virtual ~QQuickVisualDataModel();
91 void componentComplete();
93 QVariant model() const;
94 void setModel(const QVariant &);
96 QQmlComponent *delegate() const;
97 void setDelegate(QQmlComponent *);
99 QVariant rootIndex() const;
100 void setRootIndex(const QVariant &root);
102 Q_INVOKABLE QVariant modelIndex(int idx) const;
103 Q_INVOKABLE QVariant parentModelIndex() const;
106 bool isValid() const { return delegate() != 0; }
107 QQuickItem *item(int index, bool asynchronous=false);
108 ReleaseFlags release(QQuickItem *item);
109 void cancel(int index);
110 virtual QString stringValue(int index, const QString &role);
111 virtual void setWatchedRoles(QList<QByteArray> roles);
113 int indexOf(QQuickItem *item, QObject *objectContext) const;
115 QString filterGroup() const;
116 void setFilterGroup(const QString &group);
117 void resetFilterGroup();
119 QQuickVisualDataGroup *items();
120 QQuickVisualDataGroup *persistedItems();
121 QQmlListProperty<QQuickVisualDataGroup> groups();
124 bool event(QEvent *);
126 static QQuickVisualDataModelAttached *qmlAttachedProperties(QObject *obj);
129 void filterGroupChanged();
130 void defaultGroupsChanged();
131 void rootIndexChanged();
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);
140 Q_DISABLE_COPY(QQuickVisualDataModel)
143 class QQuickVisualDataGroupPrivate;
144 class Q_AUTOTEST_EXPORT QQuickVisualDataGroup : public QObject
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)
151 QQuickVisualDataGroup(QObject *parent = 0);
152 QQuickVisualDataGroup(const QString &name, QQuickVisualDataModel *model, int compositorType, QObject *parent = 0);
153 ~QQuickVisualDataGroup();
155 QString name() const;
156 void setName(const QString &name);
160 bool defaultInclude() const;
161 void setDefaultInclude(bool include);
163 Q_INVOKABLE QQmlV8Handle get(int index);
166 void insert(QQmlV8Function *);
167 void create(QQmlV8Function *);
168 void resolve(QQmlV8Function *);
169 void remove(QQmlV8Function *);
170 void addGroups(QQmlV8Function *);
171 void removeGroups(QQmlV8Function *);
172 void setGroups(QQmlV8Function *);
173 void move(QQmlV8Function *);
178 void defaultIncludeChanged();
179 void changed(const QQmlV8Handle &removed, const QQmlV8Handle &inserted);
181 Q_DECLARE_PRIVATE(QQuickVisualDataGroup)
184 class QQuickVisualDataModelItem;
185 class QQuickVisualDataModelAttachedMetaObject;
186 class QQuickVisualDataModelAttached : public QObject
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)
193 QQuickVisualDataModelAttached(QObject *parent)
195 , m_previousGroups(0)
196 , m_modelChanged(false)
198 QQml_setParent_noEvent(this, parent);
200 ~QQuickVisualDataModelAttached() { attachedProperties.remove(parent()); }
202 void setCacheItem(QQuickVisualDataModelItem *item);
204 QQuickVisualDataModel *model() const;
206 QStringList groups() const;
207 void setGroups(const QStringList &groups);
209 bool isUnresolved() const;
213 void emitUnresolvedChanged() { emit unresolvedChanged(); }
215 static QQuickVisualDataModelAttached *properties(QObject *obj)
217 QQuickVisualDataModelAttached *rv = attachedProperties.value(obj);
219 rv = new QQuickVisualDataModelAttached(obj);
220 attachedProperties.insert(obj, rv);
227 void groupsChanged();
228 void unresolvedChanged();
231 QQuickVisualDataModelItem *m_cacheItem;
232 int m_previousGroups;
233 int m_previousIndex[QQuickListCompositor::MaximumGroupCount];
236 static QHash<QObject*, QQuickVisualDataModelAttached*> attachedProperties;
238 friend class QQuickVisualDataModelAttachedMetaObject;
243 QML_DECLARE_TYPE(QQuickVisualDataModel)
244 QML_DECLARE_TYPEINFO(QQuickVisualDataModel, QML_HAS_ATTACHED_PROPERTIES)
245 QML_DECLARE_TYPE(QQuickVisualDataGroup)
249 #endif // QQUICKVISUALDATAMODEL_P_H