1 // Commit: ac5c099cc3c5b8c7eec7a49fdeb8a21037230350
2 /****************************************************************************
4 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
5 ** All rights reserved.
6 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 ** This file is part of the QtDeclarative module of the Qt Toolkit.
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.
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.
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.
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.
41 ****************************************************************************/
43 #ifndef QQUICKVISUALITEMMODEL_P_H
44 #define QQUICKVISUALITEMMODEL_P_H
46 #include <QtDeclarative/qdeclarative.h>
47 #include <QtCore/qobject.h>
53 QT_MODULE(Declarative)
56 class QDeclarativeChangeSet;
58 class Q_DECLARATIVE_EXPORT QQuickVisualModel : public QObject
62 Q_PROPERTY(int count READ count NOTIFY countChanged)
65 virtual ~QQuickVisualModel() {}
67 enum ReleaseFlag { Referenced = 0x01, Destroyed = 0x02 };
68 Q_DECLARE_FLAGS(ReleaseFlags, ReleaseFlag)
70 virtual int count() const = 0;
71 virtual bool isValid() const = 0;
72 virtual QQuickItem *item(int index, bool complete=true) = 0;
73 virtual ReleaseFlags release(QQuickItem *item) = 0;
74 virtual bool completePending() const = 0;
75 virtual void completeItem() = 0;
76 virtual QString stringValue(int, const QString &) = 0;
77 virtual void setWatchedRoles(QList<QByteArray> roles) = 0;
79 virtual int indexOf(QQuickItem *item, QObject *objectContext) const = 0;
83 void modelUpdated(const QDeclarativeChangeSet &changeSet, bool reset);
84 void createdItem(int index, QQuickItem *item);
85 void destroyingItem(QQuickItem *item);
88 QQuickVisualModel(QObjectPrivate &dd, QObject *parent = 0)
89 : QObject(dd, parent) {}
92 Q_DISABLE_COPY(QQuickVisualModel)
95 class QQuickVisualItemModelAttached;
96 class QQuickVisualItemModelPrivate;
97 class Q_DECLARATIVE_EXPORT QQuickVisualItemModel : public QQuickVisualModel
100 Q_DECLARE_PRIVATE(QQuickVisualItemModel)
102 Q_PROPERTY(QDeclarativeListProperty<QQuickItem> children READ children NOTIFY childrenChanged DESIGNABLE false)
103 Q_CLASSINFO("DefaultProperty", "children")
106 QQuickVisualItemModel(QObject *parent=0);
107 virtual ~QQuickVisualItemModel() {}
109 virtual int count() const;
110 virtual bool isValid() const;
111 virtual QQuickItem *item(int index, bool complete=true);
112 virtual ReleaseFlags release(QQuickItem *item);
113 virtual bool completePending() const;
114 virtual void completeItem();
115 virtual QString stringValue(int index, const QString &role);
116 virtual void setWatchedRoles(QList<QByteArray>) {}
118 virtual int indexOf(QQuickItem *item, QObject *objectContext) const;
120 QDeclarativeListProperty<QQuickItem> children();
122 static QQuickVisualItemModelAttached *qmlAttachedProperties(QObject *obj);
125 void childrenChanged();
128 Q_DISABLE_COPY(QQuickVisualItemModel)
131 class QQuickVisualItemModelAttached : public QObject
136 QQuickVisualItemModelAttached(QObject *parent)
137 : QObject(parent), m_index(0) {}
138 ~QQuickVisualItemModelAttached() {
139 attachedProperties.remove(parent());
142 Q_PROPERTY(int index READ index NOTIFY indexChanged)
143 int index() const { return m_index; }
144 void setIndex(int idx) {
145 if (m_index != idx) {
151 static QQuickVisualItemModelAttached *properties(QObject *obj) {
152 QQuickVisualItemModelAttached *rv = attachedProperties.value(obj);
154 rv = new QQuickVisualItemModelAttached(obj);
155 attachedProperties.insert(obj, rv);
166 static QHash<QObject*, QQuickVisualItemModelAttached*> attachedProperties;
172 QML_DECLARE_TYPE(QQuickVisualModel)
173 QML_DECLARE_TYPE(QQuickVisualItemModel)
174 QML_DECLARE_TYPEINFO(QQuickVisualItemModel, QML_HAS_ATTACHED_PROPERTIES)
178 #endif // QQUICKVISUALITEMMODEL_P_H