Fix test fails related to QTBUG-22237
[profile/ivi/qtdeclarative.git] / src / declarative / items / qquickvisualitemmodel_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 QQUICKVISUALITEMMODEL_P_H
44 #define QQUICKVISUALITEMMODEL_P_H
45
46 #include <QtDeclarative/qdeclarative.h>
47 #include <QtCore/qobject.h>
48
49 QT_BEGIN_HEADER
50
51 QT_BEGIN_NAMESPACE
52
53 QT_MODULE(Declarative)
54
55 class QQuickItem;
56 class QDeclarativeChangeSet;
57
58 class Q_DECLARATIVE_EXPORT QQuickVisualModel : public QObject
59 {
60     Q_OBJECT
61
62     Q_PROPERTY(int count READ count NOTIFY countChanged)
63
64 public:
65     virtual ~QQuickVisualModel() {}
66
67     enum ReleaseFlag { Referenced = 0x01, Destroyed = 0x02 };
68     Q_DECLARE_FLAGS(ReleaseFlags, ReleaseFlag)
69
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;
78
79     virtual int indexOf(QQuickItem *item, QObject *objectContext) const = 0;
80
81 Q_SIGNALS:
82     void countChanged();
83     void modelUpdated(const QDeclarativeChangeSet &changeSet, bool reset);
84     void createdItem(int index, QQuickItem *item);
85     void destroyingItem(QQuickItem *item);
86
87 protected:
88     QQuickVisualModel(QObjectPrivate &dd, QObject *parent = 0)
89         : QObject(dd, parent) {}
90
91 private:
92     Q_DISABLE_COPY(QQuickVisualModel)
93 };
94
95 class QQuickVisualItemModelAttached;
96 class QQuickVisualItemModelPrivate;
97 class Q_DECLARATIVE_EXPORT QQuickVisualItemModel : public QQuickVisualModel
98 {
99     Q_OBJECT
100     Q_DECLARE_PRIVATE(QQuickVisualItemModel)
101
102     Q_PROPERTY(QDeclarativeListProperty<QQuickItem> children READ children NOTIFY childrenChanged DESIGNABLE false)
103     Q_CLASSINFO("DefaultProperty", "children")
104
105 public:
106     QQuickVisualItemModel(QObject *parent=0);
107     virtual ~QQuickVisualItemModel() {}
108
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>) {}
117
118     virtual int indexOf(QQuickItem *item, QObject *objectContext) const;
119
120     QDeclarativeListProperty<QQuickItem> children();
121
122     static QQuickVisualItemModelAttached *qmlAttachedProperties(QObject *obj);
123
124 Q_SIGNALS:
125     void childrenChanged();
126
127 private:
128     Q_DISABLE_COPY(QQuickVisualItemModel)
129 };
130
131 class QQuickVisualItemModelAttached : public QObject
132 {
133     Q_OBJECT
134
135 public:
136     QQuickVisualItemModelAttached(QObject *parent)
137         : QObject(parent), m_index(0) {}
138     ~QQuickVisualItemModelAttached() {
139         attachedProperties.remove(parent());
140     }
141
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) {
146             m_index = idx;
147             emit indexChanged();
148         }
149     }
150
151     static QQuickVisualItemModelAttached *properties(QObject *obj) {
152         QQuickVisualItemModelAttached *rv = attachedProperties.value(obj);
153         if (!rv) {
154             rv = new QQuickVisualItemModelAttached(obj);
155             attachedProperties.insert(obj, rv);
156         }
157         return rv;
158     }
159
160 Q_SIGNALS:
161     void indexChanged();
162
163 public:
164     int m_index;
165
166     static QHash<QObject*, QQuickVisualItemModelAttached*> attachedProperties;
167 };
168
169
170 QT_END_NAMESPACE
171
172 QML_DECLARE_TYPE(QQuickVisualModel)
173 QML_DECLARE_TYPE(QQuickVisualItemModel)
174 QML_DECLARE_TYPEINFO(QQuickVisualItemModel, QML_HAS_ATTACHED_PROPERTIES)
175
176 QT_END_HEADER
177
178 #endif // QQUICKVISUALITEMMODEL_P_H