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/qquicklistaccessor_p.h"
49 #include <private/qqmlguard_p.h>
57 class QQuickVisualDataModel;
58 class QQuickVisualDataModelItem;
59 class QQuickVisualDataModelItemMetaType;
61 class QQuickVisualAdaptorModel : public QQmlGuard<QObject>
68 virtual int count(const QQuickVisualAdaptorModel &) const { return 0; }
69 virtual void cleanup(QQuickVisualAdaptorModel &, QQuickVisualDataModel * = 0) const {}
71 virtual QVariant value(const QQuickVisualAdaptorModel &, int, const QString &) const {
74 virtual QQuickVisualDataModelItem *createItem(
75 QQuickVisualAdaptorModel &,
76 QQuickVisualDataModelItemMetaType *,
78 int) const { return 0; }
81 const QQuickVisualAdaptorModel &,
82 const QList<QQuickVisualDataModelItem *> &,
85 const QVector<int> &) const { return false; }
86 virtual void replaceWatchedRoles(
87 QQuickVisualAdaptorModel &,
88 const QList<QByteArray> &,
89 const QList<QByteArray> &) const {}
90 virtual QVariant parentModelIndex(const QQuickVisualAdaptorModel &) const {
92 virtual QVariant modelIndex(const QQuickVisualAdaptorModel &, int) const {
94 virtual bool canFetchMore(const QQuickVisualAdaptorModel &) const { return false; }
95 virtual void fetchMore(QQuickVisualAdaptorModel &) const {}
98 const Accessors *accessors;
99 QPersistentModelIndex rootIndex;
100 QQuickListAccessor list;
102 QQuickVisualAdaptorModel();
103 ~QQuickVisualAdaptorModel();
105 inline QVariant model() const { return list.list(); }
106 void setModel(const QVariant &variant, QQuickVisualDataModel *vdm, QQmlEngine *engine);
107 void invalidateModel(QQuickVisualDataModel *vdm);
109 bool isValid() const;
111 inline QAbstractItemModel *aim() { return static_cast<QAbstractItemModel *>(object()); }
112 inline const QAbstractItemModel *aim() const { return static_cast<const QAbstractItemModel *>(object()); }
114 inline int count() const { return qMax(0, accessors->count(*this)); }
115 inline QVariant value(int index, const QString &role) const {
116 return accessors->value(*this, index, role); }
117 inline QQuickVisualDataModelItem *createItem(QQuickVisualDataModelItemMetaType *metaType, QQmlEngine *engine, int index) {
118 return accessors->createItem(*this, metaType, engine, index); }
119 inline bool hasProxyObject() const {
120 return list.type() == QQuickListAccessor::Instance || list.type() == QQuickListAccessor::ListProperty; }
123 const QList<QQuickVisualDataModelItem *> &items,
126 const QVector<int> &roles) const {
127 return accessors->notify(*this, items, index, count, roles); }
128 inline void replaceWatchedRoles(
129 const QList<QByteArray> &oldRoles, const QList<QByteArray> &newRoles) {
130 accessors->replaceWatchedRoles(*this, oldRoles, newRoles); }
132 inline QVariant modelIndex(int index) const { return accessors->modelIndex(*this, index); }
133 inline QVariant parentModelIndex() const { return accessors->parentModelIndex(*this); }
134 inline bool canFetchMore() const { return accessors->canFetchMore(*this); }
135 inline void fetchMore() { return accessors->fetchMore(*this); }
138 void objectDestroyed(QObject *);
141 class QQuickVisualAdaptorModelProxyInterface
144 virtual ~QQuickVisualAdaptorModelProxyInterface() {}
146 virtual QObject *proxiedObject() = 0;
149 #define QQuickVisualAdaptorModelProxyInterface_iid "org.qt-project.Qt.QQuickVisualAdaptorModelProxyInterface"
151 Q_DECLARE_INTERFACE(QQuickVisualAdaptorModelProxyInterface, QQuickVisualAdaptorModelProxyInterface_iid)