1 // Commit: ac5c099cc3c5b8c7eec7a49fdeb8a21037230350
2 /****************************************************************************
4 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
5 ** All rights reserved.
6 ** Contact: http://www.qt-project.org/
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 <QtQuick/qtquickglobal.h>
47 #include <QtDeclarative/qdeclarative.h>
48 #include <QtCore/qobject.h>
55 class QDeclarativeChangeSet;
57 class Q_QUICK_EXPORT QQuickVisualModel : public QObject
61 Q_PROPERTY(int count READ count NOTIFY countChanged)
64 virtual ~QQuickVisualModel() {}
66 enum ReleaseFlag { Referenced = 0x01, Destroyed = 0x02 };
67 Q_DECLARE_FLAGS(ReleaseFlags, ReleaseFlag)
69 virtual int count() const = 0;
70 virtual bool isValid() const = 0;
71 virtual QQuickItem *item(int index, bool asynchronous=false) = 0;
72 virtual ReleaseFlags release(QQuickItem *item) = 0;
73 virtual QString stringValue(int, const QString &) = 0;
74 virtual void setWatchedRoles(QList<QByteArray> roles) = 0;
76 virtual int indexOf(QQuickItem *item, QObject *objectContext) const = 0;
80 void modelUpdated(const QDeclarativeChangeSet &changeSet, bool reset);
81 void createdItem(int index, QQuickItem *item);
82 void initItem(int index, QQuickItem *item);
83 void destroyingItem(QQuickItem *item);
86 QQuickVisualModel(QObjectPrivate &dd, QObject *parent = 0)
87 : QObject(dd, parent) {}
90 Q_DISABLE_COPY(QQuickVisualModel)
93 class QQuickVisualItemModelAttached;
94 class QQuickVisualItemModelPrivate;
95 class Q_QUICK_EXPORT QQuickVisualItemModel : public QQuickVisualModel
98 Q_DECLARE_PRIVATE(QQuickVisualItemModel)
100 Q_PROPERTY(QDeclarativeListProperty<QQuickItem> children READ children NOTIFY childrenChanged DESIGNABLE false)
101 Q_CLASSINFO("DefaultProperty", "children")
104 QQuickVisualItemModel(QObject *parent=0);
105 virtual ~QQuickVisualItemModel() {}
107 virtual int count() const;
108 virtual bool isValid() const;
109 virtual QQuickItem *item(int index, bool asynchronous=false);
110 virtual ReleaseFlags release(QQuickItem *item);
111 virtual QString stringValue(int index, const QString &role);
112 virtual void setWatchedRoles(QList<QByteArray>) {}
114 virtual int indexOf(QQuickItem *item, QObject *objectContext) const;
116 QDeclarativeListProperty<QQuickItem> children();
118 static QQuickVisualItemModelAttached *qmlAttachedProperties(QObject *obj);
121 void childrenChanged();
124 Q_DISABLE_COPY(QQuickVisualItemModel)
127 class QQuickVisualItemModelAttached : public QObject
132 QQuickVisualItemModelAttached(QObject *parent)
133 : QObject(parent), m_index(0) {}
134 ~QQuickVisualItemModelAttached() {
135 attachedProperties.remove(parent());
138 Q_PROPERTY(int index READ index NOTIFY indexChanged)
139 int index() const { return m_index; }
140 void setIndex(int idx) {
141 if (m_index != idx) {
147 static QQuickVisualItemModelAttached *properties(QObject *obj) {
148 QQuickVisualItemModelAttached *rv = attachedProperties.value(obj);
150 rv = new QQuickVisualItemModelAttached(obj);
151 attachedProperties.insert(obj, rv);
162 static QHash<QObject*, QQuickVisualItemModelAttached*> attachedProperties;
168 QML_DECLARE_TYPE(QQuickVisualModel)
169 QML_DECLARE_TYPE(QQuickVisualItemModel)
170 QML_DECLARE_TYPEINFO(QQuickVisualItemModel, QML_HAS_ATTACHED_PROPERTIES)
174 #endif // QQUICKVISUALITEMMODEL_P_H