aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/util/qqmladaptormodel_p.h
diff options
context:
space:
mode:
authorAlan Alpert <aalpert@rim.com>2013-01-15 14:26:59 -0800
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-01-24 17:14:23 +0100
commit7cad0e52c5a020bd29635e9912fd8946a6b48124 (patch)
tree2f1530f14b8c595d2ad85a229588a988f7f5aba9 /src/qml/util/qqmladaptormodel_p.h
parentbbb3d5b403511f6e0bc1966835983b2574596e25 (diff)
Move the model classes from QtQuick to QtQml
This is needed for proper support of non-GUI instantiators in QtQml. Only private C++ classes are affected. Aside from name changes, model classes now operate on QObjects instead of QQuickItems, leading to minor changes in the implementation of QtQuick classes using them. The old QML type names will still be registered in the QtQuick import for the forseeable future, but pointing to the new classes. The new QML types will be added in a second commit. Classes Affected: QQuickVisualDataGroup -> QQmlDataGroup QQuickVisualDataModel -> QQmlDelegateModel QQuickVisualItemModel -> QQmlObjectModel QQuickVisualModel -> QQmlInstanceModel QQuickChangeSet -> QQmlChangeSet QQuickListAccessor -> QQmlListAccessor QQuickListCompositor -> QQmlListCompositor QQuickPackage -> QQuickPackage (just moved for now) Change-Id: Ia19e630e53bfa9e5d459e289596cd11df1ea3930 Reviewed-by: Andrew den Exter <andrew.den.exter@qinetic.com.au>
Diffstat (limited to 'src/qml/util/qqmladaptormodel_p.h')
-rw-r--r--src/qml/util/qqmladaptormodel_p.h156
1 files changed, 156 insertions, 0 deletions
diff --git a/src/qml/util/qqmladaptormodel_p.h b/src/qml/util/qqmladaptormodel_p.h
new file mode 100644
index 0000000000..6e9af8ebda
--- /dev/null
+++ b/src/qml/util/qqmladaptormodel_p.h
@@ -0,0 +1,156 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QQMLADAPTORMODEL_P_H
+#define QQMLADAPTORMODEL_P_H
+
+#include <QtCore/qabstractitemmodel.h>
+
+#include "private/qqmllistaccessor_p.h"
+
+#include <private/qqmlguard_p.h>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+class QQmlEngine;
+
+class QQmlDelegateModel;
+class QQmlDelegateModelItem;
+class QQmlDelegateModelItemMetaType;
+
+class QQmlAdaptorModel : public QQmlGuard<QObject>
+{
+public:
+ class Accessors
+ {
+ public:
+ inline Accessors() {}
+ virtual ~Accessors();
+ virtual int count(const QQmlAdaptorModel &) const { return 0; }
+ virtual void cleanup(QQmlAdaptorModel &, QQmlDelegateModel * = 0) const {}
+
+ virtual QVariant value(const QQmlAdaptorModel &, int, const QString &) const {
+ return QVariant(); }
+
+ virtual QQmlDelegateModelItem *createItem(
+ QQmlAdaptorModel &,
+ QQmlDelegateModelItemMetaType *,
+ QQmlEngine *,
+ int) const { return 0; }
+
+ virtual bool notify(
+ const QQmlAdaptorModel &,
+ const QList<QQmlDelegateModelItem *> &,
+ int,
+ int,
+ const QVector<int> &) const { return false; }
+ virtual void replaceWatchedRoles(
+ QQmlAdaptorModel &,
+ const QList<QByteArray> &,
+ const QList<QByteArray> &) const {}
+ virtual QVariant parentModelIndex(const QQmlAdaptorModel &) const {
+ return QVariant(); }
+ virtual QVariant modelIndex(const QQmlAdaptorModel &, int) const {
+ return QVariant(); }
+ virtual bool canFetchMore(const QQmlAdaptorModel &) const { return false; }
+ virtual void fetchMore(QQmlAdaptorModel &) const {}
+ };
+
+ const Accessors *accessors;
+ QPersistentModelIndex rootIndex;
+ QQmlListAccessor list;
+
+ QQmlAdaptorModel();
+ ~QQmlAdaptorModel();
+
+ inline QVariant model() const { return list.list(); }
+ void setModel(const QVariant &variant, QQmlDelegateModel *vdm, QQmlEngine *engine);
+ void invalidateModel(QQmlDelegateModel *vdm);
+
+ bool isValid() const;
+
+ inline QAbstractItemModel *aim() { return static_cast<QAbstractItemModel *>(object()); }
+ inline const QAbstractItemModel *aim() const { return static_cast<const QAbstractItemModel *>(object()); }
+
+ inline int count() const { return qMax(0, accessors->count(*this)); }
+ inline QVariant value(int index, const QString &role) const {
+ return accessors->value(*this, index, role); }
+ inline QQmlDelegateModelItem *createItem(QQmlDelegateModelItemMetaType *metaType, QQmlEngine *engine, int index) {
+ return accessors->createItem(*this, metaType, engine, index); }
+ inline bool hasProxyObject() const {
+ return list.type() == QQmlListAccessor::Instance || list.type() == QQmlListAccessor::ListProperty; }
+
+ inline bool notify(
+ const QList<QQmlDelegateModelItem *> &items,
+ int index,
+ int count,
+ const QVector<int> &roles) const {
+ return accessors->notify(*this, items, index, count, roles); }
+ inline void replaceWatchedRoles(
+ const QList<QByteArray> &oldRoles, const QList<QByteArray> &newRoles) {
+ accessors->replaceWatchedRoles(*this, oldRoles, newRoles); }
+
+ inline QVariant modelIndex(int index) const { return accessors->modelIndex(*this, index); }
+ inline QVariant parentModelIndex() const { return accessors->parentModelIndex(*this); }
+ inline bool canFetchMore() const { return accessors->canFetchMore(*this); }
+ inline void fetchMore() { return accessors->fetchMore(*this); }
+
+protected:
+ void objectDestroyed(QObject *);
+};
+
+class QQmlAdaptorModelProxyInterface
+{
+public:
+ virtual ~QQmlAdaptorModelProxyInterface() {}
+
+ virtual QObject *proxiedObject() = 0;
+};
+
+#define QQmlAdaptorModelProxyInterface_iid "org.qt-project.Qt.QQmlAdaptorModelProxyInterface"
+
+Q_DECLARE_INTERFACE(QQmlAdaptorModelProxyInterface, QQmlAdaptorModelProxyInterface_iid)
+
+QT_END_NAMESPACE
+
+#endif