Remove "All rights reserved" line from license headers.
[profile/ivi/qtdeclarative.git] / src / quick / items / qquickvisualitemmodel_p.h
1 // Commit: ac5c099cc3c5b8c7eec7a49fdeb8a21037230350
2 /****************************************************************************
3 **
4 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
5 ** Contact: http://www.qt-project.org/
6 **
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 **
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 **
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
29 **
30 ** Other Usage
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
33 **
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 <QtQuick/qtquickglobal.h>
47 #include <QtDeclarative/qdeclarative.h>
48 #include <QtCore/qobject.h>
49
50 QT_BEGIN_HEADER
51
52 QT_BEGIN_NAMESPACE
53
54 class QQuickItem;
55 class QDeclarativeChangeSet;
56
57 class Q_QUICK_EXPORT QQuickVisualModel : public QObject
58 {
59     Q_OBJECT
60
61     Q_PROPERTY(int count READ count NOTIFY countChanged)
62
63 public:
64     virtual ~QQuickVisualModel() {}
65
66     enum ReleaseFlag { Referenced = 0x01, Destroyed = 0x02 };
67     Q_DECLARE_FLAGS(ReleaseFlags, ReleaseFlag)
68
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;
75
76     virtual int indexOf(QQuickItem *item, QObject *objectContext) const = 0;
77
78 Q_SIGNALS:
79     void countChanged();
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);
84
85 protected:
86     QQuickVisualModel(QObjectPrivate &dd, QObject *parent = 0)
87         : QObject(dd, parent) {}
88
89 private:
90     Q_DISABLE_COPY(QQuickVisualModel)
91 };
92
93 class QQuickVisualItemModelAttached;
94 class QQuickVisualItemModelPrivate;
95 class Q_QUICK_EXPORT QQuickVisualItemModel : public QQuickVisualModel
96 {
97     Q_OBJECT
98     Q_DECLARE_PRIVATE(QQuickVisualItemModel)
99
100     Q_PROPERTY(QDeclarativeListProperty<QQuickItem> children READ children NOTIFY childrenChanged DESIGNABLE false)
101     Q_CLASSINFO("DefaultProperty", "children")
102
103 public:
104     QQuickVisualItemModel(QObject *parent=0);
105     virtual ~QQuickVisualItemModel() {}
106
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>) {}
113
114     virtual int indexOf(QQuickItem *item, QObject *objectContext) const;
115
116     QDeclarativeListProperty<QQuickItem> children();
117
118     static QQuickVisualItemModelAttached *qmlAttachedProperties(QObject *obj);
119
120 Q_SIGNALS:
121     void childrenChanged();
122
123 private:
124     Q_DISABLE_COPY(QQuickVisualItemModel)
125 };
126
127 class QQuickVisualItemModelAttached : public QObject
128 {
129     Q_OBJECT
130
131 public:
132     QQuickVisualItemModelAttached(QObject *parent)
133         : QObject(parent), m_index(0) {}
134     ~QQuickVisualItemModelAttached() {
135         attachedProperties.remove(parent());
136     }
137
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) {
142             m_index = idx;
143             emit indexChanged();
144         }
145     }
146
147     static QQuickVisualItemModelAttached *properties(QObject *obj) {
148         QQuickVisualItemModelAttached *rv = attachedProperties.value(obj);
149         if (!rv) {
150             rv = new QQuickVisualItemModelAttached(obj);
151             attachedProperties.insert(obj, rv);
152         }
153         return rv;
154     }
155
156 Q_SIGNALS:
157     void indexChanged();
158
159 public:
160     int m_index;
161
162     static QHash<QObject*, QQuickVisualItemModelAttached*> attachedProperties;
163 };
164
165
166 QT_END_NAMESPACE
167
168 QML_DECLARE_TYPE(QQuickVisualModel)
169 QML_DECLARE_TYPE(QQuickVisualItemModel)
170 QML_DECLARE_TYPEINFO(QQuickVisualItemModel, QML_HAS_ATTACHED_PROPERTIES)
171
172 QT_END_HEADER
173
174 #endif // QQUICKVISUALITEMMODEL_P_H