1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtQml module of the Qt Toolkit.
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.
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.
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.
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.
40 ****************************************************************************/
42 #ifndef QQUICKVISUALADAPTORMODEL_P_H
43 #define QQUICKVISUALADAPTORMODEL_P_H
45 #include <QtCore/qabstractitemmodel.h>
47 #include "private/qlistmodelinterface_p.h"
48 #include "private/qquicklistaccessor_p.h"
50 #include <private/qqmlguard_p.h>
58 class QQuickVisualDataModel;
59 class QQuickVisualDataModelItem;
60 class QQuickVisualDataModelItemMetaType;
62 class QQuickVisualAdaptorModel : public QQmlGuard<QObject>
69 virtual int count(const QQuickVisualAdaptorModel &) const { return 0; }
70 virtual void cleanup(QQuickVisualAdaptorModel &, QQuickVisualDataModel * = 0) const {}
72 virtual QVariant value(const QQuickVisualAdaptorModel &, int, const QString &) const {
75 virtual QQuickVisualDataModelItem *createItem(
76 QQuickVisualAdaptorModel &,
77 QQuickVisualDataModelItemMetaType *,
79 int) const { return 0; }
82 const QQuickVisualAdaptorModel &,
83 const QList<QQuickVisualDataModelItem *> &,
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 {
93 virtual QVariant modelIndex(const QQuickVisualAdaptorModel &, int) const {
95 virtual bool canFetchMore(const QQuickVisualAdaptorModel &) const { return false; }
96 virtual void fetchMore(QQuickVisualAdaptorModel &) const {}
99 const Accessors *accessors;
100 QModelIndex rootIndex;
101 QQuickListAccessor list;
103 QQuickVisualAdaptorModel();
104 ~QQuickVisualAdaptorModel();
106 inline QVariant model() const { return list.list(); }
107 void setModel(const QVariant &variant, QQuickVisualDataModel *vdm, QQmlEngine *engine);
109 inline QAbstractItemModel *aim() { return static_cast<QAbstractItemModel *>(object()); }
110 inline const QAbstractItemModel *aim() const { return static_cast<const QAbstractItemModel *>(object()); }
112 inline QListModelInterface *lmi() { return static_cast<QListModelInterface *>(object()); }
113 inline const QListModelInterface *lmi() const { return static_cast<const QListModelInterface *>(object()); }
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; }
124 const QList<QQuickVisualDataModelItem *> &items,
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); }
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); }
139 void objectDestroyed(QObject *);
142 class QQuickVisualAdaptorModelProxyInterface
145 virtual ~QQuickVisualAdaptorModelProxyInterface() {}
147 virtual QObject *proxiedObject() = 0;
150 #define QQuickVisualAdaptorModelProxyInterface_iid "org.qt-project.Qt.QQuickVisualAdaptorModelProxyInterface"
152 Q_DECLARE_INTERFACE(QQuickVisualAdaptorModelProxyInterface, QQuickVisualAdaptorModelProxyInterface_iid)