section.property cannot deal with nested properties
[profile/ivi/qtdeclarative.git] / src / quick / items / qquickvisualadaptormodel_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtQml module of the Qt Toolkit.
7 **
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.
16 **
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.
20 **
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.
28 **
29 ** Other Usage
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.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QQUICKVISUALADAPTORMODEL_P_H
43 #define QQUICKVISUALADAPTORMODEL_P_H
44
45 #include <QtCore/qabstractitemmodel.h>
46
47 #include "private/qlistmodelinterface_p.h"
48 #include "private/qquicklistaccessor_p.h"
49
50 #include <private/qqmlguard_p.h>
51
52 QT_BEGIN_HEADER
53
54 QT_BEGIN_NAMESPACE
55
56 class QQmlEngine;
57
58 class QQuickVisualDataModel;
59 class QQuickVisualDataModelItem;
60 class QQuickVisualDataModelItemMetaType;
61
62 class QQuickVisualAdaptorModel : public QQmlGuard<QObject>
63 {
64 public:
65     class Accessors
66     {
67     public:
68         inline Accessors() {}
69         virtual int count(const QQuickVisualAdaptorModel &) const { return 0; }
70         virtual void cleanup(QQuickVisualAdaptorModel &, QQuickVisualDataModel * = 0) const {}
71
72         virtual QVariant value(const QQuickVisualAdaptorModel &, int, const QString &) const {
73             return QVariant(); }
74
75         virtual QQuickVisualDataModelItem *createItem(
76                 QQuickVisualAdaptorModel &,
77                 QQuickVisualDataModelItemMetaType *,
78                 QQmlEngine *,
79                 int) const { return 0; }
80
81         virtual bool notify(
82                 const QQuickVisualAdaptorModel &,
83                 const QList<QQuickVisualDataModelItem *> &,
84                 int,
85                 int,
86                 const QList<int> &) const { return false; }
87         virtual void replaceWatchedRoles(
88                 QQuickVisualAdaptorModel &,
89                 const QList<QByteArray> &,
90                 const QList<QByteArray> &) const {}
91         virtual QVariant parentModelIndex(const QQuickVisualAdaptorModel &) const {
92             return QVariant(); }
93         virtual QVariant modelIndex(const QQuickVisualAdaptorModel &, int) const {
94             return QVariant(); }
95         virtual bool canFetchMore(const QQuickVisualAdaptorModel &) const { return false; }
96         virtual void fetchMore(QQuickVisualAdaptorModel &) const {}
97     };
98
99     const Accessors *accessors;
100     QModelIndex rootIndex;
101     QQuickListAccessor list;
102
103     QQuickVisualAdaptorModel();
104     ~QQuickVisualAdaptorModel();
105
106     inline QVariant model() const { return list.list(); }
107     void setModel(const QVariant &variant, QQuickVisualDataModel *vdm, QQmlEngine *engine);
108
109     inline QAbstractItemModel *aim() { return static_cast<QAbstractItemModel *>(object()); }
110     inline const QAbstractItemModel *aim() const { return static_cast<const QAbstractItemModel *>(object()); }
111
112     inline QListModelInterface *lmi() { return static_cast<QListModelInterface *>(object()); }
113     inline const QListModelInterface *lmi() const { return static_cast<const QListModelInterface *>(object()); }
114
115     inline int count() const { return qMax(0, accessors->count(*this)); }
116     inline QVariant value(int index, const QString &role) const {
117         return accessors->value(*this, index, role); }
118     inline QQuickVisualDataModelItem *createItem(QQuickVisualDataModelItemMetaType *metaType, QQmlEngine *engine, int index) {
119         return accessors->createItem(*this, metaType, engine, index); }
120     inline bool hasProxyObject() const {
121         return list.type() == QQuickListAccessor::Instance || list.type() == QQuickListAccessor::ListProperty; }
122
123     inline bool notify(
124             const QList<QQuickVisualDataModelItem *> &items,
125             int index,
126             int count,
127             const QList<int> &roles) const {
128         return accessors->notify(*this, items, index, count, roles); }
129     inline void replaceWatchedRoles(
130             const QList<QByteArray> &oldRoles, const QList<QByteArray> &newRoles) {
131         accessors->replaceWatchedRoles(*this, oldRoles, newRoles); }
132
133     inline QVariant modelIndex(int index) const { return accessors->modelIndex(*this, index); }
134     inline QVariant parentModelIndex() const { return accessors->parentModelIndex(*this); }
135     inline bool canFetchMore() const { return accessors->canFetchMore(*this); }
136     inline void fetchMore() { return accessors->fetchMore(*this); }
137
138 protected:
139     void objectDestroyed(QObject *);
140 };
141
142 class QQuickVisualAdaptorModelProxyInterface
143 {
144 public:
145     virtual ~QQuickVisualAdaptorModelProxyInterface() {}
146
147     virtual QObject *proxiedObject() = 0;
148 };
149
150 #define QQuickVisualAdaptorModelProxyInterface_iid "org.qt-project.Qt.QQuickVisualAdaptorModelProxyInterface"
151
152 Q_DECLARE_INTERFACE(QQuickVisualAdaptorModelProxyInterface, QQuickVisualAdaptorModelProxyInterface_iid)
153
154 QT_END_NAMESPACE
155
156 #endif