From 7daab8039abc32ab5be5706a08cb58905fe0e0b6 Mon Sep 17 00:00:00 2001 From: Andrew den Exter Date: Tue, 10 Jul 2012 17:01:52 +1000 Subject: [PATCH] Remove QListModelInterface. Implement ListModel and XmlListModel using QAbstractListModel instead. Task-number: QTBUG-15728 Change-Id: I14e03d90883d341f4b1d89c1e9fc9dc1534fde78 Reviewed-by: Glenn Watson --- src/imports/xmllistmodel/qqmlxmllistmodel.cpp | 99 +++++---- src/imports/xmllistmodel/qqmlxmllistmodel_p.h | 16 +- src/qml/qml/qlistmodelinterface.cpp | 104 --------- src/qml/qml/qlistmodelinterface_p.h | 83 ------- src/qml/qml/qml.pri | 2 - src/qml/qml/qquicklistmodel.cpp | 106 +++++---- src/qml/qml/qquicklistmodel_p.h | 17 +- src/qml/qml/qquicklistmodel_p_p.h | 6 +- src/qml/qml/qquicklistmodelworkeragent.cpp | 29 ++- src/qml/qml/qquicklistmodelworkeragent_p.h | 4 +- src/quick/items/qquickgridview.cpp | 1 - src/quick/items/qquickitem.cpp | 1 - src/quick/items/qquicklistview.cpp | 1 - src/quick/items/qquickpathview.cpp | 1 - src/quick/items/qquickrepeater.cpp | 1 - src/quick/items/qquickvisualadaptormodel.cpp | 140 +----------- src/quick/items/qquickvisualadaptormodel_p.h | 8 +- src/quick/items/qquickvisualdatamodel.cpp | 8 +- src/quick/items/qquickvisualdatamodel_p.h | 4 +- .../qml/qquicklistmodel/tst_qquicklistmodel.cpp | 59 +++-- .../tst_qquicklistmodelworkerscript.cpp | 47 ++-- .../quick/qquickgridview/tst_qquickgridview.cpp | 14 +- .../quick/qquicklistview/tst_qquicklistview.cpp | 191 +++++----------- .../qquickpositioners/tst_qquickpositioners.cpp | 1 - .../quick/qquickrepeater/tst_qquickrepeater.cpp | 1 - .../tst_qquickvisualdatamodel.cpp | 10 +- .../qquickxmllistmodel/tst_qquickxmllistmodel.cpp | 242 +++++++++++---------- tests/auto/quick/shared/viewtestutil.cpp | 160 +------------- tests/auto/quick/shared/viewtestutil.h | 44 +--- 29 files changed, 426 insertions(+), 974 deletions(-) delete mode 100644 src/qml/qml/qlistmodelinterface.cpp delete mode 100644 src/qml/qml/qlistmodelinterface_p.h diff --git a/src/imports/xmllistmodel/qqmlxmllistmodel.cpp b/src/imports/xmllistmodel/qqmlxmllistmodel.cpp index 5a06855..6914861 100644 --- a/src/imports/xmllistmodel/qqmlxmllistmodel.cpp +++ b/src/imports/xmllistmodel/qqmlxmllistmodel.cpp @@ -57,7 +57,7 @@ #include #include -#include +#include Q_DECLARE_METATYPE(QQuickXmlQueryResult) @@ -528,7 +528,7 @@ void QQuickXmlQueryEngine::doSubQueryJob(XmlQueryJob *currentJob, QQuickXmlQuery }*/ } -class QQuickXmlListModelPrivate : public QObjectPrivate +class QQuickXmlListModelPrivate : public QAbstractItemModelPrivate { Q_DECLARE_PUBLIC(QQuickXmlListModel) public: @@ -712,7 +712,7 @@ void QQuickXmlListModelPrivate::clear_role(QQmlListProperty QQuickXmlListModel::roleObjects() return list; } -QHash QQuickXmlListModel::data(int index, const QList &roles) const +QModelIndex QQuickXmlListModel::index(int row, int column, const QModelIndex &parent) const { Q_D(const QQuickXmlListModel); - QHash rv; - for (int i = 0; i < roles.size(); ++i) { - int role = roles.at(i); - int roleIndex = d->roles.indexOf(role); - rv.insert(role, roleIndex == -1 ? QVariant() : d->data.value(roleIndex).value(index)); - } - return rv; + return !parent.isValid() && column == 0 && row >= 0 && row < d->size + ? createIndex(row, column) + : QModelIndex(); } -QVariant QQuickXmlListModel::data(int index, int role) const +int QQuickXmlListModel::rowCount(const QModelIndex &parent) const { Q_D(const QQuickXmlListModel); - int roleIndex = d->roles.indexOf(role); - return (roleIndex == -1) ? QVariant() : d->data.value(roleIndex).value(index); + return !parent.isValid() ? d->size : 0; } -/*! - \qmlproperty int QtQuick.XmlListModel2::XmlListModel::count - The number of data entries in the model. -*/ -int QQuickXmlListModel::count() const +QVariant QQuickXmlListModel::data(const QModelIndex &index, int role) const { Q_D(const QQuickXmlListModel); - return d->size; + const int roleIndex = d->roles.indexOf(role); + return (roleIndex == -1 || !index.isValid()) + ? QVariant() + : d->data.value(roleIndex).value(index.row()); } -QList QQuickXmlListModel::roles() const +QHash QQuickXmlListModel::roleNames() const { Q_D(const QQuickXmlListModel); - return d->roles; + QHash roleNames; + for (int i = 0; i < d->roles.count(); ++i) + roleNames.insert(d->roles.at(i), d->roleNames.at(i).toUtf8()); + return roleNames; } -QString QQuickXmlListModel::toString(int role) const +/*! + \qmlproperty int QtQuick.XmlListModel2::XmlListModel::count + The number of data entries in the model. +*/ +int QQuickXmlListModel::count() const { Q_D(const QQuickXmlListModel); - int index = d->roles.indexOf(role); - if (index == -1) - return QString(); - return d->roleNames.at(index); + return d->size; } /*! @@ -1071,11 +1069,11 @@ void QQuickXmlListModel::requestFinished() d->errorString = d->reply->errorString(); d->deleteReply(); - int count = this->count(); - d->data.clear(); - d->size = 0; - if (count > 0) { - emit itemsRemoved(0, count); + if (d->size > 0) { + beginRemoveRows(QModelIndex(), 0, d->size - 1); + d->data.clear(); + d->size = 0; + endRemoveRows(); emit countChanged(); } @@ -1157,21 +1155,34 @@ void QQuickXmlListModel::queryCompleted(const QQuickXmlQueryResult &result) } } if (!hasKeys) { - if (!(origCount == 0 && d->size == 0)) { - emit itemsRemoved(0, origCount); - emit itemsInserted(0, d->size); - emit countChanged(); + if (origCount > 0) { + beginRemoveRows(QModelIndex(), 0, origCount - 1); + endRemoveRows(); + } + if (d->size > 0) { + beginInsertRows(QModelIndex(), 0, d->size - 1); + endInsertRows(); } - } else { - for (int i=0; i 0) { + beginRemoveRows(QModelIndex(), index, index + count - 1); + endRemoveRows(); + } + } + for (int i=0; i 0) { + beginInsertRows(QModelIndex(), index, index + count - 1); + endInsertRows(); + } + } } + if (sizeChanged) + emit countChanged(); emit statusChanged(d->status); } diff --git a/src/imports/xmllistmodel/qqmlxmllistmodel_p.h b/src/imports/xmllistmodel/qqmlxmllistmodel_p.h index 5bc4c7b..4a2ea6c 100644 --- a/src/imports/xmllistmodel/qqmlxmllistmodel_p.h +++ b/src/imports/xmllistmodel/qqmlxmllistmodel_p.h @@ -47,8 +47,7 @@ #include #include - -#include +#include #include QT_BEGIN_HEADER @@ -69,7 +68,7 @@ struct QQuickXmlQueryResult { QStringList keyRoleResultsCache; }; -class QQuickXmlListModel : public QListModelInterface, public QQmlParserStatus +class QQuickXmlListModel : public QAbstractListModel, public QQmlParserStatus { Q_OBJECT Q_INTERFACES(QQmlParserStatus) @@ -89,11 +88,12 @@ public: QQuickXmlListModel(QObject *parent = 0); ~QQuickXmlListModel(); - virtual QHash data(int index, const QList &roles = (QList())) const; - virtual QVariant data(int index, int role) const; - virtual int count() const; - virtual QList roles() const; - virtual QString toString(int role) const; + QModelIndex index(int row, int column, const QModelIndex &parent) const; + int rowCount(const QModelIndex &parent) const; + QVariant data(const QModelIndex &index, int role) const; + QHash roleNames() const; + + int count() const; QQmlListProperty roleObjects(); diff --git a/src/qml/qml/qlistmodelinterface.cpp b/src/qml/qml/qlistmodelinterface.cpp deleted file mode 100644 index 3ea0d3f..0000000 --- a/src/qml/qml/qlistmodelinterface.cpp +++ /dev/null @@ -1,104 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the QtDeclaractive module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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, Nokia gives you certain additional -** rights. These rights are described in the Nokia 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qlistmodelinterface_p.h" - -QT_BEGIN_NAMESPACE - -/*! - \internal - \class QListModelInterface - \brief The QListModelInterface class can be subclassed to provide C++ models to QQuickGraphics Views - - This class is comprised primarily of pure virtual functions which - you must implement in a subclass. You can then use the subclass - as a model for a QQuickGraphics view, such as a QQuickListView. -*/ - -/*! \fn QListModelInterface::QListModelInterface(QObject *parent) - Constructs a QListModelInterface with the specified \a parent. -*/ - - /*! \fn QListModelInterface::QListModelInterface(QObjectPrivate &dd, QObject *parent) - - \internal - */ - -/*! \fn QListModelInterface::~QListModelInterface() - The destructor is virtual. - */ - -/*! \fn int QListModelInterface::count() const - Returns the number of data entries in the model. -*/ - -/*! \fn QVariant QListModelInterface::data(int index, int role) const - Returns the data at the given \a index for the specified \a roles. -*/ - -/*! \fn QList QListModelInterface::roles() const - Returns the list of roles for which the list model interface - provides data. -*/ - -/*! \fn QString QListModelInterface::toString(int role) const - Returns a string description of the specified \a role. -*/ - -/*! \fn void QListModelInterface::itemsInserted(int index, int count) - Emit this signal when \a count items are inserted at \a index. - */ - -/*! \fn void QListModelInterface::itemsRemoved(int index, int count) - Emit this signal when \a count items are removed at \a index. - */ - -/*! \fn void QListModelInterface::itemsMoved(int from, int to, int count) - Emit this signal when \a count items are moved from index \a from - to index \a to. - */ - -/*! \fn void QListModelInterface::itemsChanged(int index, int count, const QList &roles) - Emit this signal when \a count items at \a index have had their - \a roles changed. - */ - -QT_END_NAMESPACE diff --git a/src/qml/qml/qlistmodelinterface_p.h b/src/qml/qml/qlistmodelinterface_p.h deleted file mode 100644 index c644ce8..0000000 --- a/src/qml/qml/qlistmodelinterface_p.h +++ /dev/null @@ -1,83 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the QtQml module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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, Nokia gives you certain additional -** rights. These rights are described in the Nokia 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QLISTMODELINTERFACE_H -#define QLISTMODELINTERFACE_H - -#include -#include - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - - -class Q_QML_PRIVATE_EXPORT QListModelInterface : public QObject -{ - Q_OBJECT - public: - QListModelInterface(QObject *parent = 0) : QObject(parent) {} - virtual ~QListModelInterface() {} - - virtual int count() const = 0; - virtual QVariant data(int index, int role) const = 0; - - virtual QList roles() const = 0; - virtual QString toString(int role) const = 0; - - Q_SIGNALS: - void itemsInserted(int index, int count); - void itemsRemoved(int index, int count); - void itemsMoved(int from, int to, int count); - void itemsChanged(int index, int count, const QList &roles); - - protected: - QListModelInterface(QObjectPrivate &dd, QObject *parent) - : QObject(dd, parent) {} -}; - - -QT_END_NAMESPACE - -QT_END_HEADER -#endif //QTREEMODELINTERFACE_H diff --git a/src/qml/qml/qml.pri b/src/qml/qml/qml.pri index fbbdc84..e7286c2 100644 --- a/src/qml/qml/qml.pri +++ b/src/qml/qml/qml.pri @@ -45,7 +45,6 @@ SOURCES += \ $$PWD/qqmlimport.cpp \ $$PWD/qqmllist.cpp \ $$PWD/qqmllocale.cpp \ - $$PWD/qlistmodelinterface.cpp \ $$PWD/qqmlabstractexpression.cpp \ $$PWD/qqmljavascriptexpression.cpp \ $$PWD/qqmlabstractbinding.cpp \ @@ -119,7 +118,6 @@ HEADERS += \ $$PWD/qqmlnullablevalue_p_p.h \ $$PWD/qqmlscriptstring_p.h \ $$PWD/qqmllocale_p.h \ - $$PWD/qlistmodelinterface_p.h \ $$PWD/qqmlcomponentattached_p.h \ $$PWD/qqmlabstractexpression_p.h \ $$PWD/qqmljavascriptexpression_p.h \ diff --git a/src/qml/qml/qquicklistmodel.cpp b/src/qml/qml/qquicklistmodel.cpp index e865d84..11aa372 100644 --- a/src/qml/qml/qquicklistmodel.cpp +++ b/src/qml/qml/qquicklistmodel.cpp @@ -45,6 +45,7 @@ #include #include + #include #include #include @@ -55,8 +56,6 @@ #include #include -Q_DECLARE_METATYPE(QListModelInterface *) - QT_BEGIN_NAMESPACE // Set to 1024 as a debugging aid - easier to distinguish uids from indices of elements/models. @@ -408,7 +407,7 @@ ListModel *ListModel::getListProperty(int elementIndex, const ListLayout::Role & return e->getListProperty(role); } -void ListModel::set(int elementIndex, v8::Handle object, QList *roles, QV8Engine *eng) +void ListModel::set(int elementIndex, v8::Handle object, QVector *roles, QV8Engine *eng) { ListElement *e = elements[elementIndex]; @@ -595,7 +594,7 @@ int ListModel::setOrCreateProperty(int elementIndex, const QString &key, const Q roleIndex = e->setVariantProperty(*r, data); if (roleIndex != -1 && e->m_objectCache) { - QList roles; + QVector roles; roles << roleIndex; e->m_objectCache->updateValues(roles); } @@ -1226,7 +1225,7 @@ void ModelObject::updateValues() } } -void ModelObject::updateValues(const QList &roles) +void ModelObject::updateValues(const QVector &roles) { int roleCount = roles.count(); for (int i=0 ; i < roleCount ; ++i) { @@ -1264,7 +1263,7 @@ void ModelNodeMetaObject::propertyWritten(int index) int roleIndex = m_obj->m_model->m_listModel->setExistingProperty(m_obj->m_elementIndex, propName, v, eng); if (roleIndex != -1) { - QList roles; + QVector roles; roles << roleIndex; m_obj->m_model->emitItemsChanged(m_obj->m_elementIndex, 1, roles); } @@ -1278,7 +1277,7 @@ DynamicRoleModelNode::DynamicRoleModelNode(QQuickListModel *owner, int uid) : m_ DynamicRoleModelNode *DynamicRoleModelNode::create(const QVariantMap &obj, QQuickListModel *owner) { DynamicRoleModelNode *object = new DynamicRoleModelNode(owner, uidCounter.fetchAndAddOrdered(1)); - QList roles; + QVector roles; object->updateValues(obj, roles); return object; } @@ -1308,7 +1307,7 @@ void DynamicRoleModelNode::sync(DynamicRoleModelNode *src, DynamicRoleModelNode } } -void DynamicRoleModelNode::updateValues(const QVariantMap &object, QList &roles) +void DynamicRoleModelNode::updateValues(const QVariantMap &object, QVector &roles) { const QList &keys = object.keys(); @@ -1410,7 +1409,8 @@ void DynamicRoleModelNodeMetaObject::propertyWritten(int index) int roleIndex = parentModel->m_roles.indexOf(QString::fromLatin1(name(index).constData())); if (elementIndex != -1 && roleIndex != -1) { - QList roles; + + QVector roles; roles << roleIndex; parentModel->emitItemsChanged(elementIndex, 1, roles); @@ -1515,7 +1515,7 @@ QQuickListModelParser::ListInstruction *QQuickListModelParser::ListModelData::in */ QQuickListModel::QQuickListModel(QObject *parent) -: QListModelInterface(parent) +: QAbstractListModel(parent) { m_mainThread = true; m_primary = true; @@ -1530,7 +1530,7 @@ QQuickListModel::QQuickListModel(QObject *parent) } QQuickListModel::QQuickListModel(const QQuickListModel *owner, ListModel *data, QV8Engine *eng, QObject *parent) -: QListModelInterface(parent) +: QAbstractListModel(parent) { m_mainThread = owner->m_mainThread; m_primary = false; @@ -1545,7 +1545,7 @@ QQuickListModel::QQuickListModel(const QQuickListModel *owner, ListModel *data, } QQuickListModel::QQuickListModel(QQuickListModel *orig, QQuickListModelWorkerAgent *agent) -: QListModelInterface(agent) +: QAbstractListModel(agent) { m_mainThread = false; m_primary = true; @@ -1671,10 +1671,13 @@ void QQuickListModel::sync(QQuickListModel *src, QQuickListModel *target, QHash< } } -void QQuickListModel::emitItemsChanged(int index, int count, const QList &roles) +void QQuickListModel::emitItemsChanged(int index, int count, const QVector &roles) { + if (count <= 0) + return; + if (m_mainThread) { - emit itemsChanged(index, count, roles); + emit dataChanged(createIndex(index, 0), createIndex(index + count - 1, 0), roles);; } else { int uid = m_dynamicRoles ? getUid() : m_listModel->getUid(); m_agent->data.changedChange(uid, index, count, roles); @@ -1683,9 +1686,13 @@ void QQuickListModel::emitItemsChanged(int index, int count, const QList &r void QQuickListModel::emitItemsRemoved(int index, int count) { + if (count <= 0) + return; + if (m_mainThread) { - emit itemsRemoved(index, count); - emit countChanged(); + beginRemoveRows(QModelIndex(), index, index + count - 1); + endRemoveRows(); + emit countChanged(); } else { int uid = m_dynamicRoles ? getUid() : m_listModel->getUid(); if (index == 0 && count == this->count()) @@ -1696,8 +1703,12 @@ void QQuickListModel::emitItemsRemoved(int index, int count) void QQuickListModel::emitItemsInserted(int index, int count) { + if (count <= 0) + return; + if (m_mainThread) { - emit itemsInserted(index, count); + beginInsertRows(QModelIndex(), index, index + count - 1); + endInsertRows(); emit countChanged(); } else { int uid = m_dynamicRoles ? getUid() : m_listModel->getUid(); @@ -1707,8 +1718,12 @@ void QQuickListModel::emitItemsInserted(int index, int count) void QQuickListModel::emitItemsMoved(int from, int to, int n) { + if (n <= 0) + return; + if (m_mainThread) { - emit itemsMoved(from, to, n); + beginMoveRows(QModelIndex(), from, from + n - 1, QModelIndex(), to > from ? to + n : to); + endMoveRows(); } else { int uid = m_dynamicRoles ? getUid() : m_listModel->getUid(); m_agent->data.moveChange(uid, from, n, to); @@ -1724,33 +1739,21 @@ QQuickListModelWorkerAgent *QQuickListModel::agent() return m_agent; } -QList QQuickListModel::roles() const +QModelIndex QQuickListModel::index(int row, int column, const QModelIndex &parent) const { - QList rolesArray; - - if (m_dynamicRoles) { - for (int i=0 ; i < m_roles.count() ; ++i) - rolesArray << i; - } else { - for (int i=0 ; i < m_listModel->roleCount() ; ++i) - rolesArray << i; - } - - return rolesArray; + return row >= 0 && row < count() && column == 0 && !parent.isValid() + ? createIndex(row, column) + : QModelIndex(); } -QString QQuickListModel::toString(int role) const +int QQuickListModel::rowCount(const QModelIndex &parent) const { - QString roleName; - - if (m_dynamicRoles) { - roleName = m_roles[role]; - } else { - const ListLayout::Role &r = m_listModel->getExistingRole(role); - roleName = r.name; - } + return !parent.isValid() ? count() : 0; +} - return roleName; +QVariant QQuickListModel::data(const QModelIndex &index, int role) const +{ + return data(index.row(), role); } QVariant QQuickListModel::data(int index, int role) const @@ -1768,6 +1771,23 @@ QVariant QQuickListModel::data(int index, int role) const return v; } +QHash QQuickListModel::roleNames() const +{ + QHash roleNames; + + if (m_dynamicRoles) { + for (int i = 0 ; i < m_roles.count() ; ++i) + roleNames.insert(i, m_roles.at(i).toUtf8()); + } else { + for (int i = 0 ; i < m_listModel->roleCount() ; ++i) { + const ListLayout::Role &r = m_listModel->getExistingRole(i); + roleNames.insert(i, r.name.toUtf8()); + } + } + + return roleNames; +} + /*! \qmlproperty bool QtQuick2::ListModel::dynamicRoles @@ -2147,7 +2167,7 @@ void QQuickListModel::set(int index, const QQmlV8Handle &handle) emitItemsInserted(index, 1); } else { - QList roles; + QVector roles; if (m_dynamicRoles) { m_modelObjects[index]->updateValues(engine()->variantMapFromJS(object), roles); @@ -2187,7 +2207,7 @@ void QQuickListModel::setProperty(int index, const QString& property, const QVar m_roles.append(property); } if (m_modelObjects[index]->setValue(property.toUtf8(), value)) { - QList roles; + QVector roles; roles << roleIndex; emitItemsChanged(index, 1, roles); } @@ -2195,7 +2215,7 @@ void QQuickListModel::setProperty(int index, const QString& property, const QVar int roleIndex = m_listModel->setOrCreateProperty(index, property, value); if (roleIndex != -1) { - QList roles; + QVector roles; roles << roleIndex; emitItemsChanged(index, 1, roles); diff --git a/src/qml/qml/qquicklistmodel_p.h b/src/qml/qml/qquicklistmodel_p.h index 2941de9..827831e 100644 --- a/src/qml/qml/qquicklistmodel_p.h +++ b/src/qml/qml/qquicklistmodel_p.h @@ -50,7 +50,7 @@ #include #include #include -#include "qlistmodelinterface_p.h" +#include #include #include @@ -64,7 +64,7 @@ class QQuickListModelWorkerAgent; class ListModel; class ListLayout; -class Q_QML_PRIVATE_EXPORT QQuickListModel : public QListModelInterface +class Q_QML_PRIVATE_EXPORT QQuickListModel : public QAbstractListModel { Q_OBJECT Q_PROPERTY(int count READ count NOTIFY countChanged) @@ -74,10 +74,13 @@ public: QQuickListModel(QObject *parent=0); ~QQuickListModel(); - virtual QList roles() const; - virtual QString toString(int role) const; - virtual int count() const; - virtual QVariant data(int index, int role) const; + QModelIndex index(int row, int column, const QModelIndex &parent) const; + int rowCount(const QModelIndex &parent) const; + QVariant data(const QModelIndex &index, int role) const; + QHash roleNames() const; + + QVariant data(int index, int role) const; + int count() const; Q_INVOKABLE void clear(); Q_INVOKABLE void remove(QQmlV8Function *args); @@ -142,7 +145,7 @@ private: static void sync(QQuickListModel *src, QQuickListModel *target, QHash *targetModelHash); static QQuickListModel *createWithOwner(QQuickListModel *newOwner); - void emitItemsChanged(int index, int count, const QList &roles); + void emitItemsChanged(int index, int count, const QVector &roles); void emitItemsRemoved(int index, int count); void emitItemsInserted(int index, int count); void emitItemsMoved(int from, int to, int n); diff --git a/src/qml/qml/qquicklistmodel_p_p.h b/src/qml/qml/qquicklistmodel_p_p.h index a006721..3214213 100644 --- a/src/qml/qml/qquicklistmodel_p_p.h +++ b/src/qml/qml/qquicklistmodel_p_p.h @@ -89,7 +89,7 @@ public: static DynamicRoleModelNode *create(const QVariantMap &obj, QQuickListModel *owner); - void updateValues(const QVariantMap &object, QList &roles); + void updateValues(const QVariantMap &object, QVector &roles); QVariant getValue(const QString &name) { @@ -162,7 +162,7 @@ public: } void updateValues(); - void updateValues(const QList &roles); + void updateValues(const QVector &roles); QQuickListModel *m_model; int m_elementIndex; @@ -329,7 +329,7 @@ public: return elements.count(); } - void set(int elementIndex, v8::Handle object, QList *roles, QV8Engine *eng); + void set(int elementIndex, v8::Handle object, QVector *roles, QV8Engine *eng); void set(int elementIndex, v8::Handle object, QV8Engine *eng); int append(v8::Handle object, QV8Engine *eng); diff --git a/src/qml/qml/qquicklistmodelworkeragent.cpp b/src/qml/qml/qquicklistmodelworkeragent.cpp index c50b348..63c6bd4 100644 --- a/src/qml/qml/qquicklistmodelworkeragent.cpp +++ b/src/qml/qml/qquicklistmodelworkeragent.cpp @@ -65,23 +65,23 @@ void QQuickListModelWorkerAgent::Data::clearChange(int uid) void QQuickListModelWorkerAgent::Data::insertChange(int uid, int index, int count) { - Change c = { uid, Change::Inserted, index, count, 0, QList() }; + Change c = { uid, Change::Inserted, index, count, 0, QVector() }; changes << c; } void QQuickListModelWorkerAgent::Data::removeChange(int uid, int index, int count) { - Change c = { uid, Change::Removed, index, count, 0, QList() }; + Change c = { uid, Change::Removed, index, count, 0, QVector() }; changes << c; } void QQuickListModelWorkerAgent::Data::moveChange(int uid, int index, int count, int to) { - Change c = { uid, Change::Moved, index, count, to, QList() }; + Change c = { uid, Change::Moved, index, count, to, QVector() }; changes << c; } -void QQuickListModelWorkerAgent::Data::changedChange(int uid, int index, int count, const QList &roles) +void QQuickListModelWorkerAgent::Data::changedChange(int uid, int index, int count, const QVector &roles) { Change c = { uid, Change::Changed, index, count, 0, roles }; changes << c; @@ -215,16 +215,29 @@ bool QQuickListModelWorkerAgent::event(QEvent *e) if (model) { switch (change.type) { case Change::Inserted: - emit model->itemsInserted(change.index, change.count); + model->beginInsertRows( + QModelIndex(), change.index, change.index + change.count - 1); + model->endInsertRows(); break; case Change::Removed: - emit model->itemsRemoved(change.index, change.count); + model->beginRemoveRows( + QModelIndex(), change.index, change.index + change.count - 1); + model->endRemoveRows(); break; case Change::Moved: - emit model->itemsMoved(change.index, change.to, change.count); + model->beginMoveRows( + QModelIndex(), + change.index, + change.index + change.count - 1, + QModelIndex(), + change.to > change.index ? change.to + change.count : change.to); + model->endMoveRows(); break; case Change::Changed: - emit model->itemsChanged(change.index, change.count, change.roles); + emit model->dataChanged( + model->createIndex(change.index, 0), + model->createIndex(change.index + change.count - 1, 0), + change.roles); break; } } diff --git a/src/qml/qml/qquicklistmodelworkeragent_p.h b/src/qml/qml/qquicklistmodelworkeragent_p.h index 24198b0..bd805da 100644 --- a/src/qml/qml/qquicklistmodelworkeragent_p.h +++ b/src/qml/qml/qquicklistmodelworkeragent_p.h @@ -122,7 +122,7 @@ private: int index; // Inserted/Removed/Moved/Changed int count; // Inserted/Removed/Moved/Changed int to; // Moved - QList roles; + QVector roles; }; struct Data @@ -133,7 +133,7 @@ private: void insertChange(int uid, int index, int count); void removeChange(int uid, int index, int count); void moveChange(int uid, int index, int count, int to); - void changedChange(int uid, int index, int count, const QList &roles); + void changedChange(int uid, int index, int count, const QVector &roles); }; Data data; diff --git a/src/quick/items/qquickgridview.cpp b/src/quick/items/qquickgridview.cpp index 7ca22b9..8f330b9 100644 --- a/src/quick/items/qquickgridview.cpp +++ b/src/quick/items/qquickgridview.cpp @@ -45,7 +45,6 @@ #include "qquickitemview_p_p.h" #include -#include #include #include diff --git a/src/quick/items/qquickitem.cpp b/src/quick/items/qquickitem.cpp index d4eea2b..fefddad 100644 --- a/src/quick/items/qquickitem.cpp +++ b/src/quick/items/qquickitem.cpp @@ -64,7 +64,6 @@ #include #include #include -#include #include #include #include diff --git a/src/quick/items/qquicklistview.cpp b/src/quick/items/qquicklistview.cpp index 547b033..18b9947 100644 --- a/src/quick/items/qquicklistview.cpp +++ b/src/quick/items/qquicklistview.cpp @@ -51,7 +51,6 @@ #include #include -#include #include "qplatformdefs.h" QT_BEGIN_NAMESPACE diff --git a/src/quick/items/qquickpathview.cpp b/src/quick/items/qquickpathview.cpp index c4ee8bc..b5304c3 100644 --- a/src/quick/items/qquickpathview.cpp +++ b/src/quick/items/qquickpathview.cpp @@ -46,7 +46,6 @@ #include #include #include -#include #include #include diff --git a/src/quick/items/qquickrepeater.cpp b/src/quick/items/qquickrepeater.cpp index 8ebdccf..61b1392 100644 --- a/src/quick/items/qquickrepeater.cpp +++ b/src/quick/items/qquickrepeater.cpp @@ -45,7 +45,6 @@ #include #include -#include #include QT_BEGIN_NAMESPACE diff --git a/src/quick/items/qquickvisualadaptormodel.cpp b/src/quick/items/qquickvisualadaptormodel.cpp index f7cd3e2..b17ab26 100644 --- a/src/quick/items/qquickvisualadaptormodel.cpp +++ b/src/quick/items/qquickvisualadaptormodel.cpp @@ -153,7 +153,7 @@ public: const QList &items, int index, int count, - const QList &roles) const + const QVector &roles) const { bool changed = roles.isEmpty() && !watchedRoles.isEmpty(); if (!changed && !watchedRoles.isEmpty() && watchedRoleIds.isEmpty()) { @@ -461,8 +461,8 @@ public: vdm, SLOT(_q_rowsInserted(QModelIndex,int,int))); QObject::disconnect(aim, SIGNAL(rowsRemoved(QModelIndex,int,int)), vdm, SLOT(_q_rowsRemoved(QModelIndex,int,int))); - QObject::disconnect(aim, SIGNAL(dataChanged(QModelIndex,QModelIndex)), - vdm, SLOT(_q_dataChanged(QModelIndex,QModelIndex))); + QObject::disconnect(aim, SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector)), + vdm, SLOT(_q_dataChanged(QModelIndex,QModelIndex,QVector))); QObject::disconnect(aim, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)), vdm, SLOT(_q_rowsMoved(QModelIndex,int,int,QModelIndex,int))); QObject::disconnect(aim, SIGNAL(modelReset()), @@ -553,123 +553,6 @@ public: }; //----------------------------------------------------------------- -// QListModelInterface -//----------------------------------------------------------------- - -class QQuickVDMListModelInterfaceData : public QQuickVDMCachedModelData -{ -public: - QQuickVDMListModelInterfaceData(QQuickVisualDataModelItemMetaType *metaType, VDMModelDelegateDataType *dataType, int index) - : QQuickVDMCachedModelData(metaType, dataType, index) - { - } - - QVariant value(int role) const - { - return type->model->lmi()->data(index, role); - } - - void setValue(int, const QVariant &) {} - - v8::Handle get() - { - if (type->constructor.IsEmpty()) { - v8::HandleScope handleScope; - v8::Context::Scope contextScope(engine->context()); - type->initializeConstructor(engineData(engine)); - } - v8::Local data = type->constructor->NewInstance(); - data->SetExternalResource(this); - ++scriptRef; - return data; - } -}; - -class VDMListModelInterfaceDataType : public VDMModelDelegateDataType -{ -public: - VDMListModelInterfaceDataType(QQuickVisualAdaptorModel *model) - : VDMModelDelegateDataType(model) - { - } - - int count(const QQuickVisualAdaptorModel &model) const - { - return model.lmi()->count(); - } - - void cleanup(QQuickVisualAdaptorModel &model, QQuickVisualDataModel *vdm) const - { - QListModelInterface *lmi = model.lmi(); - if (lmi && vdm) { - QObject::disconnect(lmi, SIGNAL(itemsChanged(int,int,QList)), - vdm, SLOT(_q_itemsChanged(int,int,QList))); - QObject::disconnect(lmi, SIGNAL(itemsInserted(int,int)), - vdm, SLOT(_q_itemsInserted(int,int))); - QObject::disconnect(lmi, SIGNAL(itemsRemoved(int,int)), - vdm, SLOT(_q_itemsRemoved(int,int))); - QObject::disconnect(lmi, SIGNAL(itemsMoved(int,int,int)), - vdm, SLOT(_q_itemsMoved(int,int,int))); - } - const_cast(this)->release(); - } - - QVariant value(const QQuickVisualAdaptorModel &model, int index, const QString &role) const - { - QHash::const_iterator it = roleNames.find(role.toUtf8()); - return it != roleNames.end() && model - ? model.lmi()->data(index, *it) - : QVariant(); - } - - QQuickVisualDataModelItem *createItem( - QQuickVisualAdaptorModel &model, - QQuickVisualDataModelItemMetaType *metaType, - QQmlEngine *engine, - int index) const - { - VDMListModelInterfaceDataType *dataType = const_cast(this); - if (!metaObject) - dataType->initializeMetaType(model, engine); - return new QQuickVDMListModelInterfaceData(metaType, dataType, index); - } - - void initializeMetaType(QQuickVisualAdaptorModel &model, QQmlEngine *engine) - { - QMetaObjectBuilder builder; - setModelDataType(&builder, this); - - const QByteArray propertyType = QByteArrayLiteral("QVariant"); - - const QListModelInterface * const listModelInterface = model.lmi(); - const QList roles = listModelInterface->roles(); - for (int propertyId = 0; propertyId < roles.count(); ++propertyId) { - const int role = roles.at(propertyId); - const QString roleName = listModelInterface->toString(role); - const QByteArray propertyName = roleName.toUtf8(); - - propertyRoles.append(role); - roleNames.insert(propertyName, role); - addProperty(&builder, propertyId, propertyName, propertyType); - - } - if (propertyRoles.count() == 1) { - hasModelData = true; - const int role = roles.first(); - const QByteArray propertyName = QByteArrayLiteral("modelData"); - - propertyRoles.append(role); - roleNames.insert(propertyName, role); - addProperty(&builder, 1, propertyName, propertyType); - } - - metaObject = builder.toMetaObject(); - *static_cast(this) = *metaObject; - propertyCache = new QQmlPropertyCache(engine, metaObject); - } -}; - -//----------------------------------------------------------------- // QQuickListAccessor //----------------------------------------------------------------- @@ -1015,25 +898,14 @@ void QQuickVisualAdaptorModel::setModel(const QVariant &variant, QQuickVisualDat vdm, QQuickVisualDataModel, SLOT(_q_rowsInserted(QModelIndex,int,int))); qmlobject_connect(model, QAbstractItemModel, SIGNAL(rowsRemoved(QModelIndex,int,int)), vdm, QQuickVisualDataModel, SLOT(_q_rowsRemoved(QModelIndex,int,int))); - qmlobject_connect(model, QAbstractItemModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), - vdm, QQuickVisualDataModel, SLOT(_q_dataChanged(QModelIndex,QModelIndex))); + qmlobject_connect(model, QAbstractItemModel, SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector)), + vdm, QQuickVisualDataModel, SLOT(_q_dataChanged(QModelIndex,QModelIndex,QVector))); qmlobject_connect(model, QAbstractItemModel, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)), vdm, QQuickVisualDataModel, SLOT(_q_rowsMoved(QModelIndex,int,int,QModelIndex,int))); qmlobject_connect(model, QAbstractItemModel, SIGNAL(modelReset()), vdm, QQuickVisualDataModel, SLOT(_q_modelReset())); qmlobject_connect(model, QAbstractItemModel, SIGNAL(layoutChanged()), vdm, QQuickVisualDataModel, SLOT(_q_layoutChanged())); - } else if (QListModelInterface *model = qobject_cast(object)) { - accessors = new VDMListModelInterfaceDataType(this); - - qmlobject_connect(model, QListModelInterface, SIGNAL(itemsChanged(int,int,QList)), - vdm, QQuickVisualDataModel, SLOT(_q_itemsChanged(int,int,QList))); - qmlobject_connect(model, QListModelInterface, SIGNAL(itemsInserted(int,int)), - vdm, QQuickVisualDataModel, SLOT(_q_itemsInserted(int,int))); - qmlobject_connect(model, QListModelInterface, SIGNAL(itemsRemoved(int,int)), - vdm, QQuickVisualDataModel, SLOT(_q_itemsRemoved(int,int))); - qmlobject_connect(model, QListModelInterface, SIGNAL(itemsMoved(int,int,int)), - vdm, QQuickVisualDataModel, SLOT(_q_itemsMoved(int,int,int))); } else { accessors = new VDMObjectDelegateDataType; } @@ -1080,6 +952,4 @@ QQuickVisualAdaptorModelEngineData::~QQuickVisualAdaptorModelEngineData() QT_END_NAMESPACE -QML_DECLARE_TYPE(QListModelInterface) - #include diff --git a/src/quick/items/qquickvisualadaptormodel_p.h b/src/quick/items/qquickvisualadaptormodel_p.h index 5176921..d1b66a9 100644 --- a/src/quick/items/qquickvisualadaptormodel_p.h +++ b/src/quick/items/qquickvisualadaptormodel_p.h @@ -44,7 +44,6 @@ #include -#include "private/qlistmodelinterface_p.h" #include "private/qquicklistaccessor_p.h" #include @@ -83,7 +82,7 @@ public: const QList &, int, int, - const QList &) const { return false; } + const QVector &) const { return false; } virtual void replaceWatchedRoles( QQuickVisualAdaptorModel &, const QList &, @@ -109,9 +108,6 @@ public: inline QAbstractItemModel *aim() { return static_cast(object()); } inline const QAbstractItemModel *aim() const { return static_cast(object()); } - inline QListModelInterface *lmi() { return static_cast(object()); } - inline const QListModelInterface *lmi() const { return static_cast(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); } @@ -124,7 +120,7 @@ public: const QList &items, int index, int count, - const QList &roles) const { + const QVector &roles) const { return accessors->notify(*this, items, index, count, roles); } inline void replaceWatchedRoles( const QList &oldRoles, const QList &newRoles) { diff --git a/src/quick/items/qquickvisualdatamodel.cpp b/src/quick/items/qquickvisualdatamodel.cpp index 728240d..63b4d58 100644 --- a/src/quick/items/qquickvisualdatamodel.cpp +++ b/src/quick/items/qquickvisualdatamodel.cpp @@ -1060,7 +1060,7 @@ void QQuickVisualDataModelPrivate::itemsChanged(const QVectorchangeSet.apply(translatedChanges.at(i)); } -void QQuickVisualDataModel::_q_itemsChanged(int index, int count, const QList &roles) +void QQuickVisualDataModel::_q_itemsChanged(int index, int count, const QVector &roles) { Q_D(QQuickVisualDataModel); if (count <= 0 || !d->m_complete) @@ -1454,17 +1454,17 @@ void QQuickVisualDataModel::_q_rowsMoved( } } -void QQuickVisualDataModel::_q_dataChanged(const QModelIndex &begin, const QModelIndex &end) +void QQuickVisualDataModel::_q_dataChanged(const QModelIndex &begin, const QModelIndex &end, const QVector &roles) { Q_D(QQuickVisualDataModel); if (begin.parent() == d->m_adaptorModel.rootIndex) - _q_itemsChanged(begin.row(), end.row() - begin.row() + 1, QList()); + _q_itemsChanged(begin.row(), end.row() - begin.row() + 1, roles); } void QQuickVisualDataModel::_q_layoutChanged() { Q_D(QQuickVisualDataModel); - _q_itemsChanged(0, d->m_count, QList()); + _q_itemsChanged(0, d->m_count, QVector()); } QQuickVisualDataModelAttached *QQuickVisualDataModel::qmlAttachedProperties(QObject *obj) diff --git a/src/quick/items/qquickvisualdatamodel_p.h b/src/quick/items/qquickvisualdatamodel_p.h index 38939b6..fc29336 100644 --- a/src/quick/items/qquickvisualdatamodel_p.h +++ b/src/quick/items/qquickvisualdatamodel_p.h @@ -131,7 +131,7 @@ Q_SIGNALS: void rootIndexChanged(); private Q_SLOTS: - void _q_itemsChanged(int index, int count, const QList &roles); + void _q_itemsChanged(int index, int count, const QVector &roles); void _q_itemsInserted(int index, int count); void _q_itemsRemoved(int index, int count); void _q_itemsMoved(int from, int to, int count); @@ -139,7 +139,7 @@ private Q_SLOTS: void _q_rowsInserted(const QModelIndex &,int,int); void _q_rowsRemoved(const QModelIndex &,int,int); void _q_rowsMoved(const QModelIndex &, int, int, const QModelIndex &, int); - void _q_dataChanged(const QModelIndex&,const QModelIndex&); + void _q_dataChanged(const QModelIndex&,const QModelIndex&,const QVector &); void _q_layoutChanged(); private: diff --git a/tests/auto/qml/qquicklistmodel/tst_qquicklistmodel.cpp b/tests/auto/qml/qquicklistmodel/tst_qquicklistmodel.cpp index e4045eb..4c1a472 100644 --- a/tests/auto/qml/qquicklistmodel/tst_qquicklistmodel.cpp +++ b/tests/auto/qml/qquicklistmodel/tst_qquicklistmodel.cpp @@ -86,7 +86,10 @@ class tst_qquicklistmodel : public QQmlDataTest { Q_OBJECT public: - tst_qquicklistmodel() {} + tst_qquicklistmodel() + { + qRegisterMetaType >(); + } private: int roleFromName(const QQuickListModel *model, const QString &roleName); @@ -146,7 +149,7 @@ bool tst_qquicklistmodel::compareVariantList(const QVariantList &testList, QVari return false; const QVariantMap &map = testVariant.toMap(); - const QList &roles = model->roles(); + const QHash roleNames = model->roleNames(); QVariantMap::const_iterator it = map.begin(); QVariantMap::const_iterator end = map.end(); @@ -155,14 +158,7 @@ bool tst_qquicklistmodel::compareVariantList(const QVariantList &testList, QVari const QString &testKey = it.key(); const QVariant &testData = it.value(); - int roleIndex = -1; - for (int j=0 ; j < roles.count() ; ++j) { - if (model->toString(roles[j]).compare(testKey) == 0) { - roleIndex = j; - break; - } - } - + int roleIndex = roleNames.key(testKey.toUtf8(), -1); if (roleIndex == -1) return false; @@ -184,12 +180,7 @@ bool tst_qquicklistmodel::compareVariantList(const QVariantList &testList, QVari int tst_qquicklistmodel::roleFromName(const QQuickListModel *model, const QString &roleName) { - QList roles = model->roles(); - for (int i=0; itoString(roles[i]) == roleName) - return roles[i]; - } - return -1; + return model->roleNames().key(roleName.toUtf8(), -1); } void tst_qquicklistmodel::static_types_data() @@ -720,11 +711,11 @@ void tst_qquicklistmodel::set() RUNEXPR("model.set(0, {test:true})"); QCOMPARE(RUNEXPR("model.get(0).test").toBool(), true); // triggers creation of model cache - QCOMPARE(model.data(0, model.roles()[0]), qVariantFromValue(true)); + QCOMPARE(model.data(0, 0), qVariantFromValue(true)); RUNEXPR("model.set(0, {test:false})"); QCOMPARE(RUNEXPR("model.get(0).test").toBool(), false); // tests model cache is updated - QCOMPARE(model.data(0, model.roles()[0]), qVariantFromValue(false)); + QCOMPARE(model.data(0, 0), qVariantFromValue(false)); QString warning = QString::fromLatin1(": Can't create role for unsupported data type"); if (isValidErrorMessage(warning, dynamicRoles)) @@ -759,7 +750,7 @@ void tst_qquicklistmodel::get() RUNEXPR("model.append({roleC: {} })"); RUNEXPR("model.append({roleD: [ { a:1, b:2 }, { c: 3 } ] })"); - QSignalSpy spy(model, SIGNAL(itemsChanged(int, int, QList))); + QSignalSpy spy(model, SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector))); QQmlExpression expr(engine.rootContext(), model, expression); expr.evaluate(); QVERIFY(!expr.hasError()); @@ -777,9 +768,9 @@ void tst_qquicklistmodel::get() QCOMPARE(spy.count(), 1); QList spyResult = spy.takeFirst(); - QCOMPARE(spyResult.at(0).toInt(), index); - QCOMPARE(spyResult.at(1).toInt(), 1); // only 1 item is modified at a time - QCOMPARE(spyResult.at(2).value >(), (QList() << role)); + QCOMPARE(spyResult.at(0).value(), model->index(index, 0, QModelIndex())); + QCOMPARE(spyResult.at(1).value(), model->index(index, 0, QModelIndex())); // only 1 item is modified at a time + QCOMPARE(spyResult.at(2).value >(), (QVector() << role)); delete model; } @@ -887,7 +878,7 @@ void tst_qquicklistmodel::get_nested() QString extendedExpression = QString("get(%1).%2.%3").arg(outerListIndex).arg(outerListRoleName).arg(expression); QQmlExpression expr(engine.rootContext(), model, extendedExpression); - QSignalSpy spy(childModel, SIGNAL(itemsChanged(int, int, QList))); + QSignalSpy spy(childModel, SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector))); expr.evaluate(); QVERIFY(!expr.hasError()); @@ -901,9 +892,9 @@ void tst_qquicklistmodel::get_nested() QCOMPARE(spy.count(), 1); QList spyResult = spy.takeFirst(); - QCOMPARE(spyResult.at(0).toInt(), index); - QCOMPARE(spyResult.at(1).toInt(), 1); // only 1 item is modified at a time - QCOMPARE(spyResult.at(2).value >(), (QList() << role)); + QCOMPARE(spyResult.at(0).value(), childModel->index(index, 0, QModelIndex())); + QCOMPARE(spyResult.at(1).value(), childModel->index(index, 0, QModelIndex())); // only 1 item is modified at a time + QCOMPARE(spyResult.at(2).value >(), (QVector() << role)); } delete model; @@ -978,7 +969,7 @@ void tst_qquicklistmodel::property_changes() QObject *connectionsObject = component.create(); QVERIFY2(component.errorString().isEmpty(), QTest::toString(component.errorString())); - QSignalSpy spyItemsChanged(&model, SIGNAL(itemsChanged(int, int, QList))); + QSignalSpy spyItemsChanged(&model, SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector))); expr.setExpression(script_change); expr.evaluate(); @@ -990,8 +981,8 @@ void tst_qquicklistmodel::property_changes() // test itemsChanged() is emitted correctly if (itemsChanged) { QCOMPARE(spyItemsChanged.count(), 1); - QCOMPARE(spyItemsChanged.at(0).at(0).toInt(), listIndex); - QCOMPARE(spyItemsChanged.at(0).at(1).toInt(), 1); + QCOMPARE(spyItemsChanged.at(0).at(0).value(), model.index(listIndex, 0, QModelIndex())); + QCOMPARE(spyItemsChanged.at(0).at(1).value(), model.index(listIndex, 0, QModelIndex())); } else { QCOMPARE(spyItemsChanged.count(), 0); } @@ -1111,13 +1102,13 @@ void tst_qquicklistmodel::clear() // clearing does not remove the roles RUNEXPR("model.append({propertyA: \"value a\", propertyB: \"value b\", propertyC: \"value c\"})"); - QList roles = model.roles(); + QHash roleNames = model.roleNames(); model.clear(); QCOMPARE(model.count(), 0); - QCOMPARE(model.roles(), roles); - QCOMPARE(model.toString(roles[0]), QString("propertyA")); - QCOMPARE(model.toString(roles[1]), QString("propertyB")); - QCOMPARE(model.toString(roles[2]), QString("propertyC")); + QCOMPARE(model.roleNames(), roleNames); + QCOMPARE(roleNames[0], QByteArray("propertyA")); + QCOMPARE(roleNames[1], QByteArray("propertyB")); + QCOMPARE(roleNames[2], QByteArray("propertyC")); } void tst_qquicklistmodel::signal_handlers_data() diff --git a/tests/auto/qml/qquicklistmodelworkerscript/tst_qquicklistmodelworkerscript.cpp b/tests/auto/qml/qquicklistmodelworkerscript/tst_qquicklistmodelworkerscript.cpp index c5d16e5..8227eb5 100644 --- a/tests/auto/qml/qquicklistmodelworkerscript/tst_qquicklistmodelworkerscript.cpp +++ b/tests/auto/qml/qquicklistmodelworkerscript/tst_qquicklistmodelworkerscript.cpp @@ -85,7 +85,10 @@ class tst_qquicklistmodelworkerscript : public QQmlDataTest { Q_OBJECT public: - tst_qquicklistmodelworkerscript() {} + tst_qquicklistmodelworkerscript() + { + qRegisterMetaType >(); + } private: int roleFromName(const QQuickListModel *model, const QString &roleName); @@ -133,7 +136,7 @@ bool tst_qquicklistmodelworkerscript::compareVariantList(const QVariantList &tes return false; const QVariantMap &map = testVariant.toMap(); - const QList &roles = model->roles(); + const QHash roleNames = model->roleNames(); QVariantMap::const_iterator it = map.begin(); QVariantMap::const_iterator end = map.end(); @@ -142,18 +145,11 @@ bool tst_qquicklistmodelworkerscript::compareVariantList(const QVariantList &tes const QString &testKey = it.key(); const QVariant &testData = it.value(); - int roleIndex = -1; - for (int j=0 ; j < roles.count() ; ++j) { - if (model->toString(roles[j]).compare(testKey) == 0) { - roleIndex = j; - break; - } - } - + int roleIndex = roleNames.key(testKey.toUtf8(), -1); if (roleIndex == -1) return false; - const QVariant &modelData = model->data(i, roleIndex); + const QVariant &modelData = model->data(model->index(i, 0, QModelIndex()), roleIndex); if (testData.type() == QVariant::List) { const QVariantList &subList = testData.toList(); @@ -171,12 +167,7 @@ bool tst_qquicklistmodelworkerscript::compareVariantList(const QVariantList &tes int tst_qquicklistmodelworkerscript::roleFromName(const QQuickListModel *model, const QString &roleName) { - QList roles = model->roles(); - for (int i=0; itoString(roles[i]) == roleName) - return roles[i]; - } - return -1; + return model->roleNames().key(roleName.toUtf8(), -1); } QQuickItem *tst_qquicklistmodelworkerscript::createWorkerTest(QQmlEngine *eng, QQmlComponent *component, QQuickListModel *model) @@ -497,7 +488,7 @@ void tst_qquicklistmodelworkerscript::get_worker() int role = roleFromName(&model, roleName); QVERIFY(role >= 0); - QSignalSpy spy(&model, SIGNAL(itemsChanged(int, int, QList))); + QSignalSpy spy(&model, SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector))); // in the worker thread, change the model data and call sync() QVERIFY(QMetaObject::invokeMethod(item, "evalExpressionViaWorker", @@ -515,9 +506,9 @@ void tst_qquicklistmodelworkerscript::get_worker() QCOMPARE(spy.count(), 1); QList spyResult = spy.takeFirst(); - QCOMPARE(spyResult.at(0).toInt(), index); - QCOMPARE(spyResult.at(1).toInt(), 1); // only 1 item is modified at a time - QVERIFY(spyResult.at(2).value >().contains(role)); + QCOMPARE(spyResult.at(0).value(), model.index(index, 0, QModelIndex())); + QCOMPARE(spyResult.at(1).value(), model.index(index, 0, QModelIndex())); // only 1 item is modified at a time + QVERIFY(spyResult.at(2).value >().contains(role)); delete item; } @@ -621,7 +612,7 @@ void tst_qquicklistmodelworkerscript::property_changes_worker() expr.evaluate(); QVERIFY2(!expr.hasError(), QTest::toString(expr.error().toString())); - QSignalSpy spyItemsChanged(&model, SIGNAL(itemsChanged(int, int, QList))); + QSignalSpy spyItemsChanged(&model, SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector))); QVERIFY(QMetaObject::invokeMethod(item, "evalExpressionViaWorker", Q_ARG(QVariant, QStringList(script_change)))); @@ -630,8 +621,8 @@ void tst_qquicklistmodelworkerscript::property_changes_worker() // test itemsChanged() is emitted correctly if (itemsChanged) { QCOMPARE(spyItemsChanged.count(), 1); - QCOMPARE(spyItemsChanged.at(0).at(0).toInt(), listIndex); - QCOMPARE(spyItemsChanged.at(0).at(1).toInt(), 1); + QCOMPARE(spyItemsChanged.at(0).at(0).value(), model.index(listIndex, 0, QModelIndex())); + QCOMPARE(spyItemsChanged.at(0).at(1).value(), model.index(listIndex, 0, QModelIndex())); } else { QCOMPARE(spyItemsChanged.count(), 0); } @@ -674,8 +665,8 @@ void tst_qquicklistmodelworkerscript::worker_sync() QVERIFY(childModel); QVERIFY(childModel->count() == 1); - QSignalSpy spyModelInserted(&model, SIGNAL(itemsInserted(int,int))); - QSignalSpy spyChildInserted(childModel, SIGNAL(itemsInserted(int,int))); + QSignalSpy spyModelInserted(&model, SIGNAL(rowsInserted(QModelIndex,int,int))); + QSignalSpy spyChildInserted(childModel, SIGNAL(rowsInserted(QModelIndex,int,int))); QVERIFY(QMetaObject::invokeMethod(item, "addItemViaWorker")); waitForWorker(item); @@ -729,7 +720,7 @@ void tst_qquicklistmodelworkerscript::worker_remove_element() QQuickItem *item = createWorkerTest(&eng, &component, &model); QVERIFY(item != 0); - QSignalSpy spyModelRemoved(&model, SIGNAL(itemsRemoved(int,int))); + QSignalSpy spyModelRemoved(&model, SIGNAL(rowsRemoved(QModelIndex,int,int))); QVERIFY(model.count() == 0); QVERIFY(spyModelRemoved.count() == 0); @@ -792,7 +783,7 @@ void tst_qquicklistmodelworkerscript::worker_remove_list() QQuickItem *item = createWorkerTest(&eng, &component, &model); QVERIFY(item != 0); - QSignalSpy spyModelRemoved(&model, SIGNAL(itemsRemoved(int,int))); + QSignalSpy spyModelRemoved(&model, SIGNAL(rowsRemoved(QModelIndex,int,int))); QVERIFY(model.count() == 0); QVERIFY(spyModelRemoved.count() == 0); diff --git a/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp b/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp index ef4b27b..c8991cc 100644 --- a/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp +++ b/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp @@ -53,7 +53,6 @@ #include #include #include -#include #include "../../shared/util.h" #include "../shared/viewtestutil.h" #include "../shared/visualtestutil.h" @@ -1832,7 +1831,7 @@ void tst_QQuickGridView::currentIndex() QCOMPARE(gridview->contentY(), 400.0); // changing model should reset currentIndex to 0 - QmlListModel model; + QaimModel model; for (int i = 0; i < 60; i++) model.addItem("Item" + QString::number(i), QString::number(i)); ctxt->setContextProperty("testModel", &model); @@ -1947,7 +1946,7 @@ void tst_QQuickGridView::keyNavigation() QFETCH(int, indexUpFrom7); QFETCH(int, indexDownFrom7); - QmlListModel model; + QaimModel model; for (int i = 0; i < 18; i++) model.addItem("Item" + QString::number(i), ""); @@ -3577,8 +3576,9 @@ void tst_QQuickGridView::extents() QQuickView *window = getView(); - QmlListModel model; + QaimModel model; QQmlContext *ctxt = window->rootContext(); + ctxt->setContextProperty("testModel", &model); window->setSource(testFileUrl("headerfooter.qml")); window->show(); @@ -3940,7 +3940,7 @@ void tst_QQuickGridView::resizeGrid_data() void tst_QQuickGridView::changeColumnCount() { - QmlListModel model; + QaimModel model; for (int i = 0; i < 40; i++) model.addItem("Item" + QString::number(i), ""); @@ -5620,7 +5620,7 @@ void tst_QQuickGridView::multipleTransitions() QPointF removeTargets_transitionTo(-100, 300); QPointF removeDisplaced_transitionFrom(100, 300); - QmlListModel model; + QaimModel model; for (int i = 0; i < initialCount; i++) model.addItem("Original item" + QString::number(i), ""); @@ -5795,7 +5795,7 @@ void tst_QQuickGridView::multipleDisplaced() // moved from previously set positions, and not those that have moved from their current // item positions (which may e.g. still be changing from easing bounces in the last transition) - QmlListModel model; + QaimModel model; for (int i = 0; i < 30; i++) model.addItem("Original item" + QString::number(i), ""); diff --git a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp index 50c4a0a..0ca2c6a 100644 --- a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp +++ b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp @@ -75,39 +75,29 @@ public: private slots: void init(); void cleanupTestCase(); - // Test both QListModelInterface and QAbstractItemModel model types - void qListModelInterface_items(); - void qListModelInterface_package_items(); + // Test QAbstractItemModel model types + void qAbstractItemModel_package_items(); void qAbstractItemModel_items(); - void qListModelInterface_changed(); - void qListModelInterface_package_changed(); + void qAbstractItemModel_package_changed(); void qAbstractItemModel_changed(); - void qListModelInterface_inserted(); - void qListModelInterface_inserted_more(); - void qListModelInterface_inserted_more_data(); - void qListModelInterface_package_inserted(); + void qAbstractItemModel_package_inserted(); void qAbstractItemModel_inserted(); void qAbstractItemModel_inserted_more(); void qAbstractItemModel_inserted_more_data(); void qAbstractItemModel_inserted_more_bottomToTop(); void qAbstractItemModel_inserted_more_bottomToTop_data(); - void qListModelInterface_removed(); - void qListModelInterface_removed_more(); - void qListModelInterface_removed_more_data(); - void qListModelInterface_package_removed(); + void qAbstractItemModel_package_removed(); void qAbstractItemModel_removed(); void qAbstractItemModel_removed_more(); void qAbstractItemModel_removed_more_data(); void qAbstractItemModel_removed_more_bottomToTop(); void qAbstractItemModel_removed_more_bottomToTop_data(); - void qListModelInterface_moved(); - void qListModelInterface_moved_data(); - void qListModelInterface_package_moved(); - void qListModelInterface_package_moved_data(); + void qAbstractItemModel_package_moved(); + void qAbstractItemModel_package_moved_data(); void qAbstractItemModel_moved(); void qAbstractItemModel_moved_data(); void qAbstractItemModel_moved_bottomToTop(); @@ -118,8 +108,7 @@ private slots: void multipleChanges_uncondensed() { multipleChanges(false); } void multipleChanges_uncondensed_data() { multipleChanges_data(); } - void qListModelInterface_clear(); - void qListModelInterface_package_clear(); + void qAbstractItemModel_package_clear(); void qAbstractItemModel_clear(); void qAbstractItemModel_clear_bottomToTop(); @@ -137,8 +126,7 @@ private slots: void enforceRange(); void enforceRange_withoutHighlight(); void spacing(); - void qListModelInterface_sections(); - void qListModelInterface_package_sections(); + void qAbstractItemModel_package_sections(); void qAbstractItemModel_sections(); void sectionsPositioning(); void sectionsDelegate(); @@ -740,7 +728,7 @@ void tst_QQuickListView::insertBeforeVisible() QQuickText *name; QQuickView *window = getView(); - QmlListModel model; + QaimModel model; for (int i = 0; i < 30; i++) model.addItem("Item" + QString::number(i), ""); @@ -1485,7 +1473,7 @@ void tst_QQuickListView::multipleChanges(bool condensed) QQuickView *window = getView(); - QmlListModel model; + QaimModel model; for (int i = 0; i < startCount; i++) model.addItem("Item" + QString::number(i), ""); @@ -1733,7 +1721,7 @@ void tst_QQuickListView::swapWithFirstItem() { QQuickView *window = createView(); - QmlListModel model; + QaimModel model; for (int i = 0; i < 30; i++) model.addItem("Item" + QString::number(i), ""); @@ -1764,7 +1752,7 @@ void tst_QQuickListView::enforceRange() { QQuickView *window = createView(); - QmlListModel model; + QaimModel model; for (int i = 0; i < 30; i++) model.addItem("Item" + QString::number(i), ""); @@ -1804,7 +1792,7 @@ void tst_QQuickListView::enforceRange() QTRY_COMPARE(listview->currentIndex(), 6); // change model - QmlListModel model2; + QaimModel model2; for (int i = 0; i < 5; i++) model2.addItem("Item" + QString::number(i), ""); @@ -1823,7 +1811,7 @@ void tst_QQuickListView::enforceRange_withoutHighlight() QQuickView *window = createView(); - QmlListModel model; + QaimModel model; model.addItem("Item 0", "a"); model.addItem("Item 1", "b"); model.addItem("Item 2", "b"); @@ -1865,7 +1853,7 @@ void tst_QQuickListView::spacing() { QQuickView *window = createView(); - QmlListModel model; + QaimModel model; for (int i = 0; i < 30; i++) model.addItem("Item" + QString::number(i), ""); @@ -2024,7 +2012,7 @@ void tst_QQuickListView::sectionsDelegate() { QQuickView *window = createView(); - QmlListModel model; + QaimModel model; for (int i = 0; i < 30; i++) model.addItem("Item" + QString::number(i), QString::number(i/5)); @@ -2133,7 +2121,7 @@ void tst_QQuickListView::sectionsDragOutsideBounds() QQuickView *window = getView(); - QmlListModel model; + QaimModel model; for (int i = 0; i < 10; i++) model.addItem("Item" + QString::number(i), QString::number(i/5)); @@ -2181,7 +2169,7 @@ void tst_QQuickListView::sectionsDelegate_headerVisibility() QQuickView *window = createView(); - QmlListModel model; + QaimModel model; for (int i = 0; i < 30; i++) model.addItem("Item" + QString::number(i), QString::number(i/5)); @@ -2212,7 +2200,7 @@ void tst_QQuickListView::sectionsPositioning() { QQuickView *window = createView(); - QmlListModel model; + QaimModel model; for (int i = 0; i < 30; i++) model.addItem("Item" + QString::number(i), QString::number(i/5)); @@ -2358,7 +2346,7 @@ void tst_QQuickListView::sectionsPositioning() window->rootObject()->setProperty("sectionPositioning", QVariant(int(QQuickViewSection::InlineLabels | QQuickViewSection::CurrentLabelAtStart | QQuickViewSection::NextLabelAtEnd))); QTRY_VERIFY(findVisibleChild(contentItem, "sect_aaa")); // section header QTRY_VERIFY(findVisibleChild(contentItem, "sect_new")); // section footer - QmlListModel model1; + QaimModel model1; ctxt->setContextProperty("testModel", &model1); QTRY_VERIFY(!findVisibleChild(contentItem, "sect_aaa")); // section header QTRY_VERIFY(!findVisibleChild(contentItem, "sect_new")); // section footer @@ -2515,7 +2503,8 @@ void tst_QQuickListView::currentIndex_delayedItemCreation_data() void tst_QQuickListView::currentIndex() { - QmlListModel initModel; + QaimModel initModel; + for (int i = 0; i < 30; i++) initModel.addItem("Item" + QString::number(i), QString::number(i)); @@ -2545,7 +2534,7 @@ void tst_QQuickListView::currentIndex() QCOMPARE(listview->highlightItem()->y(), listview->currentItem()->y()); // changing model should reset currentIndex to 0 - QmlListModel model; + QaimModel model; for (int i = 0; i < 30; i++) model.addItem("Item" + QString::number(i), QString::number(i)); ctxt->setContextProperty("testModel", &model); @@ -2610,7 +2599,7 @@ void tst_QQuickListView::currentIndex() void tst_QQuickListView::noCurrentIndex() { - QmlListModel model; + QaimModel model; for (int i = 0; i < 30; i++) model.addItem("Item" + QString::number(i), QString::number(i)); @@ -2656,7 +2645,7 @@ void tst_QQuickListView::keyNavigation() QFETCH(QPointF, contentPosAtFirstItem); QFETCH(QPointF, contentPosAtLastItem); - QmlListModel model; + QaimModel model; for (int i = 0; i < 30; i++) model.addItem("Item" + QString::number(i), ""); @@ -2863,7 +2852,7 @@ void tst_QQuickListView::cacheBuffer() { QQuickView *window = createView(); - QmlListModel model; + QaimModel model; for (int i = 0; i < 90; i++) model.addItem("Item" + QString::number(i), ""); @@ -2964,7 +2953,7 @@ void tst_QQuickListView::positionViewAtIndex() { QQuickView *window = createView(); - QmlListModel model; + QaimModel model; for (int i = 0; i < 40; i++) model.addItem("Item" + QString::number(i), ""); @@ -3390,7 +3379,7 @@ void tst_QQuickListView::QTBUG_11105() { QQuickView *window = createView(); - QmlListModel model; + QaimModel model; for (int i = 0; i < 30; i++) model.addItem("Item" + QString::number(i), ""); @@ -3422,7 +3411,7 @@ void tst_QQuickListView::QTBUG_11105() listview->positionViewAtIndex(20, QQuickListView::Beginning); QCOMPARE(listview->contentY(), 280.); - QmlListModel model2; + QaimModel model2; for (int i = 0; i < 5; i++) model2.addItem("Item" + QString::number(i), ""); @@ -3467,7 +3456,7 @@ void tst_QQuickListView::header() QFETCH(QPointF, firstDelegatePos); QFETCH(QPointF, resizeContentPos); - QmlListModel model; + QaimModel model; for (int i = 0; i < 30; i++) model.addItem("Item" + QString::number(i), ""); @@ -3639,7 +3628,7 @@ void tst_QQuickListView::header_delayItemCreation() { QQuickView *window = createView(); - QmlListModel model; + QaimModel model; window->rootContext()->setContextProperty("setCurrentToZero", QVariant(false)); window->setSource(testFileUrl("fillModelOnComponentCompleted.qml")); @@ -3677,7 +3666,7 @@ void tst_QQuickListView::footer() QQuickView *window = getView(); - QmlListModel model; + QaimModel model; for (int i = 0; i < 3; i++) model.addItem("Item" + QString::number(i), ""); @@ -3868,8 +3857,9 @@ void tst_QQuickListView::extents() QQuickView *window = getView(); - QmlListModel model; + QaimModel model; QQmlContext *ctxt = window->rootContext(); + ctxt->setContextProperty("testModel", &model); window->setSource(testFileUrl("headerfooter.qml")); window->show(); @@ -3995,7 +3985,7 @@ void tst_QQuickListView::resizeView() { QQuickView *window = createView(); - QmlListModel model; + QaimModel model; for (int i = 0; i < 40; i++) model.addItem("Item" + QString::number(i), ""); @@ -4075,7 +4065,7 @@ void tst_QQuickListView::resizeViewAndRepaint() { QQuickView *window = createView(); - QmlListModel model; + QaimModel model; for (int i = 0; i < 40; i++) model.addItem("Item" + QString::number(i), ""); @@ -4110,7 +4100,7 @@ void tst_QQuickListView::sizeLessThan1() { QQuickView *window = createView(); - QmlListModel model; + QaimModel model; for (int i = 0; i < 30; i++) model.addItem("Item" + QString::number(i), ""); @@ -4251,7 +4241,7 @@ void tst_QQuickListView::resizeFirstDelegate() QQuickView *window = createView(); // bug only occurs when all items in the model are visible - QmlListModel model; + QaimModel model; for (int i = 0; i < 10; i++) model.addItem("Item" + QString::number(i), ""); @@ -4462,7 +4452,7 @@ void tst_QQuickListView::indexAt_itemAt() QQuickView *window = getView(); - QmlListModel model; + QaimModel model; for (int i = 0; i < 30; i++) model.addItem("Item" + QString::number(i), ""); @@ -5014,14 +5004,9 @@ void tst_QQuickListView::snapToItem() releaseView(window); } -void tst_QQuickListView::qListModelInterface_items() +void tst_QQuickListView::qAbstractItemModel_package_items() { - items(testFileUrl("listviewtest.qml"), false); -} - -void tst_QQuickListView::qListModelInterface_package_items() -{ - items(testFileUrl("listviewtest-package.qml"), true); + items(testFileUrl("listviewtest-package.qml"), true); } void tst_QQuickListView::qAbstractItemModel_items() @@ -5029,14 +5014,9 @@ void tst_QQuickListView::qAbstractItemModel_items() items(testFileUrl("listviewtest.qml"), false); } -void tst_QQuickListView::qListModelInterface_changed() -{ - changed(testFileUrl("listviewtest.qml"), false); -} - -void tst_QQuickListView::qListModelInterface_package_changed() +void tst_QQuickListView::qAbstractItemModel_package_changed() { - changed(testFileUrl("listviewtest-package.qml"), true); + changed(testFileUrl("listviewtest-package.qml"), true); } void tst_QQuickListView::qAbstractItemModel_changed() @@ -5044,24 +5024,9 @@ void tst_QQuickListView::qAbstractItemModel_changed() changed(testFileUrl("listviewtest.qml"), false); } -void tst_QQuickListView::qListModelInterface_inserted() -{ - inserted(testFileUrl("listviewtest.qml")); -} - -void tst_QQuickListView::qListModelInterface_package_inserted() +void tst_QQuickListView::qAbstractItemModel_package_inserted() { - inserted(testFileUrl("listviewtest-package.qml")); -} - -void tst_QQuickListView::qListModelInterface_inserted_more() -{ - inserted_more(); -} - -void tst_QQuickListView::qListModelInterface_inserted_more_data() -{ - inserted_more_data(); + inserted(testFileUrl("listviewtest-package.qml")); } void tst_QQuickListView::qAbstractItemModel_inserted() @@ -5089,26 +5054,10 @@ void tst_QQuickListView::qAbstractItemModel_inserted_more_bottomToTop_data() inserted_more_data(); } -void tst_QQuickListView::qListModelInterface_removed() -{ - removed(testFileUrl("listviewtest.qml"), false); - removed(testFileUrl("listviewtest.qml"), true); -} - -void tst_QQuickListView::qListModelInterface_removed_more() -{ - removed_more(testFileUrl("listviewtest.qml")); -} - -void tst_QQuickListView::qListModelInterface_removed_more_data() -{ - removed_more_data(); -} - -void tst_QQuickListView::qListModelInterface_package_removed() +void tst_QQuickListView::qAbstractItemModel_package_removed() { - removed(testFileUrl("listviewtest-package.qml"), false); - removed(testFileUrl("listviewtest-package.qml"), true); + removed(testFileUrl("listviewtest-package.qml"), false); + removed(testFileUrl("listviewtest-package.qml"), true); } void tst_QQuickListView::qAbstractItemModel_removed() @@ -5137,22 +5086,12 @@ void tst_QQuickListView::qAbstractItemModel_removed_more_bottomToTop_data() removed_more_data(); } -void tst_QQuickListView::qListModelInterface_moved() +void tst_QQuickListView::qAbstractItemModel_package_moved() { - moved(testFileUrl("listviewtest.qml")); + moved(testFileUrl("listviewtest-package.qml")); } -void tst_QQuickListView::qListModelInterface_moved_data() -{ - moved_data(); -} - -void tst_QQuickListView::qListModelInterface_package_moved() -{ - moved(testFileUrl("listviewtest-package.qml")); -} - -void tst_QQuickListView::qListModelInterface_package_moved_data() +void tst_QQuickListView::qAbstractItemModel_package_moved_data() { moved_data(); } @@ -5177,14 +5116,9 @@ void tst_QQuickListView::qAbstractItemModel_moved_bottomToTop_data() moved_data(); } -void tst_QQuickListView::qListModelInterface_clear() +void tst_QQuickListView::qAbstractItemModel_package_clear() { - clear(testFileUrl("listviewtest.qml")); -} - -void tst_QQuickListView::qListModelInterface_package_clear() -{ - clear(testFileUrl("listviewtest-package.qml")); + clear(testFileUrl("listviewtest-package.qml")); } void tst_QQuickListView::qAbstractItemModel_clear() @@ -5197,14 +5131,9 @@ void tst_QQuickListView::qAbstractItemModel_clear_bottomToTop() clear(testFileUrl("listviewtest.qml"), QQuickItemView::BottomToTop); } -void tst_QQuickListView::qListModelInterface_sections() -{ - sections(testFileUrl("listview-sections.qml")); -} - -void tst_QQuickListView::qListModelInterface_package_sections() +void tst_QQuickListView::qAbstractItemModel_package_sections() { - sections(testFileUrl("listview-sections-package.qml")); + sections(testFileUrl("listview-sections-package.qml")); } void tst_QQuickListView::qAbstractItemModel_sections() @@ -5427,7 +5356,7 @@ void tst_QQuickListView::snapOneItem() void tst_QQuickListView::unrequestedVisibility() { - QmlListModel model; + QaimModel model; for (int i = 0; i < 30; i++) model.addItem("Item" + QString::number(i), QString::number(i)); @@ -6558,7 +6487,7 @@ void tst_QQuickListView::multipleTransitions() QPointF removeTargets_transitionTo(-100, 300); QPointF removeDisplaced_transitionFrom(100, 300); - QmlListModel model; + QaimModel model; for (int i = 0; i < initialCount; i++) model.addItem("Original item" + QString::number(i), ""); @@ -6724,7 +6653,7 @@ void tst_QQuickListView::multipleDisplaced() // moved from previously set positions, and not those that have moved from their current // item positions (which may e.g. still be changing from easing bounces in the last transition) - QmlListModel model; + QaimModel model; for (int i = 0; i < 30; i++) model.addItem("Original item" + QString::number(i), ""); @@ -6853,7 +6782,7 @@ void tst_QQuickListView::flickBeyondBounds() void tst_QQuickListView::destroyItemOnCreation() { - QmlListModel model; + QaimModel model; QQuickView *window = createView(); window->rootContext()->setContextProperty("testModel", &model); diff --git a/tests/auto/quick/qquickpositioners/tst_qquickpositioners.cpp b/tests/auto/quick/qquickpositioners/tst_qquickpositioners.cpp index 3fb20f7..32ec41b 100644 --- a/tests/auto/quick/qquickpositioners/tst_qquickpositioners.cpp +++ b/tests/auto/quick/qquickpositioners/tst_qquickpositioners.cpp @@ -39,7 +39,6 @@ ** ****************************************************************************/ #include -#include #include #include #include diff --git a/tests/auto/quick/qquickrepeater/tst_qquickrepeater.cpp b/tests/auto/quick/qquickrepeater/tst_qquickrepeater.cpp index 0fb2416..8e58a02 100644 --- a/tests/auto/quick/qquickrepeater/tst_qquickrepeater.cpp +++ b/tests/auto/quick/qquickrepeater/tst_qquickrepeater.cpp @@ -41,7 +41,6 @@ #include #include -#include #include #include #include diff --git a/tests/auto/quick/qquickvisualdatamodel/tst_qquickvisualdatamodel.cpp b/tests/auto/quick/qquickvisualdatamodel/tst_qquickvisualdatamodel.cpp index 533085b..0ec7e51 100644 --- a/tests/auto/quick/qquickvisualdatamodel/tst_qquickvisualdatamodel.cpp +++ b/tests/auto/quick/qquickvisualdatamodel/tst_qquickvisualdatamodel.cpp @@ -877,7 +877,7 @@ void tst_qquickvisualdatamodel::packagesDestroyed() void tst_qquickvisualdatamodel::qaimRowsMoved() { // Test parameters passed in QAIM::rowsMoved() signal are converted correctly - // when translated and emitted as the QListModelInterface::itemsMoved() signal + // when translated to (from, to count) semantics. QFETCH(int, sourceFirst); QFETCH(int, sourceLast); QFETCH(int, destinationChild); @@ -3579,7 +3579,7 @@ void tst_qquickvisualdatamodel::asynchronousInsert() QQmlComponent c(&engine, testFileUrl("visualdatamodel.qml")); - QmlListModel model; + QaimModel model; for (int i = 0; i < 8; i++) model.addItem("Original item" + QString::number(i), ""); @@ -3644,7 +3644,7 @@ void tst_qquickvisualdatamodel::asynchronousRemove() QQmlComponent c(&engine, testFileUrl("visualdatamodel.qml")); - QmlListModel model; + QaimModel model; for (int i = 0; i < 8; i++) model.addItem("Original item" + QString::number(i), ""); @@ -3722,7 +3722,7 @@ void tst_qquickvisualdatamodel::asynchronousMove() QQmlComponent c(&engine, testFileUrl("visualdatamodel.qml")); - QmlListModel model; + QaimModel model; for (int i = 0; i < 8; i++) model.addItem("Original item" + QString::number(i), ""); @@ -3770,7 +3770,7 @@ void tst_qquickvisualdatamodel::asynchronousCancel() QQmlComponent c(&engine, testFileUrl("visualdatamodel.qml")); - QmlListModel model; + QaimModel model; for (int i = 0; i < 8; i++) model.addItem("Original item" + QString::number(i), ""); diff --git a/tests/auto/quick/qquickxmllistmodel/tst_qquickxmllistmodel.cpp b/tests/auto/quick/qquickxmllistmodel/tst_qquickxmllistmodel.cpp index 4d33756..53df019 100644 --- a/tests/auto/quick/qquickxmllistmodel/tst_qquickxmllistmodel.cpp +++ b/tests/auto/quick/qquickxmllistmodel/tst_qquickxmllistmodel.cpp @@ -56,7 +56,6 @@ #include #include -#include #include "../../../../src/imports/xmllistmodel/qqmlxmllistmodel_p.h" typedef QPair QQuickXmlListRange; @@ -106,7 +105,7 @@ private slots: void roleCrash(); private: - QString errorString(QListModelInterface* model) { + QString errorString(QAbstractItemModel *model) { QString ret; QMetaObject::invokeMethod(model, "errorString", Q_RETURN_ARG(QString, ret)); return ret; @@ -196,14 +195,15 @@ QNetworkAccessManager *CustomNetworkAccessManagerFactory::create(QObject *parent void tst_qquickxmllistmodel::buildModel() { QQmlComponent component(&engine, testFileUrl("model.qml")); - QListModelInterface *model = qobject_cast(component.create()); + QAbstractItemModel *model = qobject_cast(component.create()); QVERIFY(model != 0); - QTRY_COMPARE(model->count(), 9); + QTRY_COMPARE(model->rowCount(), 9); - QCOMPARE(model->data(3, Qt::UserRole).toString(), QLatin1String("Spot")); - QCOMPARE(model->data(3, Qt::UserRole+1).toString(), QLatin1String("Dog")); - QCOMPARE(model->data(3, Qt::UserRole+2).toInt(), 9); - QCOMPARE(model->data(3, Qt::UserRole+3).toString(), QLatin1String("Medium")); + QModelIndex index = model->index(3, 0); + QCOMPARE(model->data(index, Qt::UserRole).toString(), QLatin1String("Spot")); + QCOMPARE(model->data(index, Qt::UserRole+1).toString(), QLatin1String("Dog")); + QCOMPARE(model->data(index, Qt::UserRole+2).toInt(), 9); + QCOMPARE(model->data(index, Qt::UserRole+3).toString(), QLatin1String("Medium")); delete model; } @@ -215,25 +215,20 @@ void tst_qquickxmllistmodel::testTypes() QFETCH(QVariant, expectedValue); QQmlComponent component(&engine, testFileUrl("testtypes.qml")); - QListModelInterface *model = qobject_cast(component.create()); + QAbstractItemModel *model = qobject_cast(component.create()); QVERIFY(model != 0); model->setProperty("xml",xml.toUtf8()); QMetaObject::invokeMethod(model, "reload"); - QTRY_COMPARE(model->count(), 1); + QTRY_COMPARE(model->rowCount(), 1); - int role = -1; - foreach (int i, model->roles()) { - if (model->toString(i) == roleName) { - role = i; - break; - } - } + int role = model->roleNames().key(roleName.toUtf8(), -1); QVERIFY(role >= 0); + QModelIndex index = model->index(0, 0); if (expectedValue.toString() == "nan") - QVERIFY(qIsNaN(model->data(0, role).toDouble())); + QVERIFY(qIsNaN(model->data(index, role).toDouble())); else - QCOMPARE(model->data(0, role), expectedValue); + QCOMPARE(model->data(index, role), expectedValue); delete model; } @@ -275,11 +270,11 @@ void tst_qquickxmllistmodel::testTypes_data() void tst_qquickxmllistmodel::cdata() { QQmlComponent component(&engine, testFileUrl("recipes.qml")); - QListModelInterface *model = qobject_cast(component.create()); + QAbstractItemModel *model = qobject_cast(component.create()); QVERIFY(model != 0); - QTRY_COMPARE(model->count(), 5); + QTRY_COMPARE(model->rowCount(), 5); - QVERIFY(model->data(2, Qt::UserRole+2).toString().startsWith(QLatin1String(""))); + QVERIFY(model->data(model->index(2, 0), Qt::UserRole+2).toString().startsWith(QLatin1String(""))); delete model; } @@ -287,10 +282,10 @@ void tst_qquickxmllistmodel::cdata() void tst_qquickxmllistmodel::attributes() { QQmlComponent component(&engine, testFileUrl("recipes.qml")); - QListModelInterface *model = qobject_cast(component.create()); + QAbstractItemModel *model = qobject_cast(component.create()); QVERIFY(model != 0); - QTRY_COMPARE(model->count(), 5); - QCOMPARE(model->data(2, Qt::UserRole).toString(), QLatin1String("Vegetable Soup")); + QTRY_COMPARE(model->rowCount(), 5); + QCOMPARE(model->data(model->index(2, 0), Qt::UserRole).toString(), QLatin1String("Vegetable Soup")); delete model; } @@ -298,16 +293,23 @@ void tst_qquickxmllistmodel::attributes() void tst_qquickxmllistmodel::roles() { QQmlComponent component(&engine, testFileUrl("model.qml")); - QListModelInterface *model = qobject_cast(component.create()); + QAbstractItemModel *model = qobject_cast(component.create()); QVERIFY(model != 0); - QTRY_COMPARE(model->count(), 9); - - QList roles = model->roles(); + QTRY_COMPARE(model->rowCount(), 9); + + QHash roleNames = model->roleNames(); + QCOMPARE(roleNames.count(), 4); + QVERIFY(roleNames.key("name", -1) >= 0); + QVERIFY(roleNames.key("type", -1) >= 0); + QVERIFY(roleNames.key("age", -1) >= 0); + QVERIFY(roleNames.key("size", -1) >= 0); + + QSet roles; + roles.insert(roleNames.key("name")); + roles.insert(roleNames.key("type")); + roles.insert(roleNames.key("age")); + roles.insert(roleNames.key("size")); QCOMPARE(roles.count(), 4); - QCOMPARE(model->toString(roles.at(0)), QLatin1String("name")); - QCOMPARE(model->toString(roles.at(1)), QLatin1String("type")); - QCOMPARE(model->toString(roles.at(2)), QLatin1String("age")); - QCOMPARE(model->toString(roles.at(3)), QLatin1String("size")); delete model; } @@ -319,18 +321,18 @@ void tst_qquickxmllistmodel::roleErrors() QTest::ignoreMessage(QtWarningMsg, (testFileUrl("roleErrors.qml").toString() + ":10:5: QML XmlRole: invalid query: \"age/\"").toUtf8().constData()); //### make sure we receive all expected warning messages. - QListModelInterface *model = qobject_cast(component.create()); + QAbstractItemModel *model = qobject_cast(component.create()); QVERIFY(model != 0); - QTRY_COMPARE(model->count(), 9); - + QTRY_COMPARE(model->rowCount(), 9); + QModelIndex index = model->index(3, 0); //### should any of these return valid values? - QCOMPARE(model->data(3, Qt::UserRole), QVariant()); - QCOMPARE(model->data(3, Qt::UserRole+1), QVariant()); - QCOMPARE(model->data(3, Qt::UserRole+2), QVariant()); + QCOMPARE(model->data(index, Qt::UserRole), QVariant()); + QCOMPARE(model->data(index, Qt::UserRole+1), QVariant()); + QCOMPARE(model->data(index, Qt::UserRole+2), QVariant()); QEXPECT_FAIL("", "QTBUG-10797", Continue); - QCOMPARE(model->data(3, Qt::UserRole+3), QVariant()); + QCOMPARE(model->data(index, Qt::UserRole+3), QVariant()); delete model; } @@ -339,12 +341,12 @@ void tst_qquickxmllistmodel::uniqueRoleNames() { QQmlComponent component(&engine, testFileUrl("unique.qml")); QTest::ignoreMessage(QtWarningMsg, (testFileUrl("unique.qml").toString() + ":8:5: QML XmlRole: \"name\" duplicates a previous role name and will be disabled.").toUtf8().constData()); - QListModelInterface *model = qobject_cast(component.create()); + QAbstractItemModel *model = qobject_cast(component.create()); QVERIFY(model != 0); - QTRY_COMPARE(model->count(), 9); + QTRY_COMPARE(model->rowCount(), 9); - QList roles = model->roles(); - QCOMPARE(roles.count(), 1); + QHash roleNames = model->roleNames(); + QCOMPARE(roleNames.count(), 1); delete model; } @@ -356,7 +358,7 @@ void tst_qquickxmllistmodel::xml() QFETCH(int, count); QQmlComponent component(&engine, testFileUrl("model.qml")); - QListModelInterface *model = qobject_cast(component.create()); + QAbstractItemModel *model = qobject_cast(component.create()); QSignalSpy spy(model, SIGNAL(statusChanged(QQuickXmlListModel::Status))); QVERIFY(errorString(model).isEmpty()); @@ -369,7 +371,7 @@ void tst_qquickxmllistmodel::xml() QQuickXmlListModel::Ready); QVERIFY(errorString(model).isEmpty()); QCOMPARE(model->property("progress").toDouble(), qreal(1.0)); - QCOMPARE(model->count(), 9); + QCOMPARE(model->rowCount(), 9); // if xml is empty (i.e. clearing) it won't have any effect if a source is set if (xml.isEmpty()) @@ -387,7 +389,7 @@ void tst_qquickxmllistmodel::xml() QCOMPARE(qvariant_cast(model->property("status")), QQuickXmlListModel::Ready); QVERIFY(errorString(model).isEmpty()); - QCOMPARE(model->count(), count); + QCOMPARE(model->rowCount(), count); delete model; } @@ -411,7 +413,7 @@ void tst_qquickxmllistmodel::headers() qmlEng.setNetworkAccessManagerFactory(&factory); QQmlComponent component(&qmlEng, testFileUrl("model.qml")); - QListModelInterface *model = qobject_cast(component.create()); + QAbstractItemModel *model = qobject_cast(component.create()); QVERIFY(model != 0); QTRY_COMPARE(qvariant_cast(model->property("status")), QQuickXmlListModel::Ready); @@ -435,7 +437,7 @@ void tst_qquickxmllistmodel::source() QFETCH(QQuickXmlListModel::Status, status); QQmlComponent component(&engine, testFileUrl("model.qml")); - QListModelInterface *model = qobject_cast(component.create()); + QAbstractItemModel *model = qobject_cast(component.create()); QSignalSpy spy(model, SIGNAL(statusChanged(QQuickXmlListModel::Status))); QVERIFY(errorString(model).isEmpty()); @@ -447,7 +449,7 @@ void tst_qquickxmllistmodel::source() QQuickXmlListModel::Ready); QVERIFY(errorString(model).isEmpty()); QCOMPARE(model->property("progress").toDouble(), qreal(1.0)); - QCOMPARE(model->count(), 9); + QCOMPARE(model->rowCount(), 9); model->setProperty("source",source); if (model->property("source").toString().isEmpty()) @@ -474,7 +476,7 @@ void tst_qquickxmllistmodel::source() } QCOMPARE(qvariant_cast(model->property("status")), status); - QCOMPARE(model->count(), count); + QCOMPARE(model->rowCount(), count); if (status == QQuickXmlListModel::Ready) QCOMPARE(model->property("progress").toDouble(), qreal(1.0)); @@ -506,15 +508,16 @@ void tst_qquickxmllistmodel::source_data() void tst_qquickxmllistmodel::data() { QQmlComponent component(&engine, testFileUrl("model.qml")); - QListModelInterface *model = qobject_cast(component.create()); + QAbstractItemModel *model = qobject_cast(component.create()); QVERIFY(model != 0); for (int i=0; i<9; i++) { - for (int j=0; jroles().count(); j++) { - QCOMPARE(model->data(i, j), QVariant()); + QModelIndex index = model->index(i, 0); + for (int j=0; jroleNames().count(); j++) { + QCOMPARE(model->data(index, j), QVariant()); } } - QTRY_COMPARE(model->count(), 9); + QTRY_COMPARE(model->rowCount(), 9); delete model; } @@ -522,14 +525,14 @@ void tst_qquickxmllistmodel::data() void tst_qquickxmllistmodel::get() { QQmlComponent component(&engine, testFileUrl("get.qml")); - QListModelInterface *model = qobject_cast(component.create()); + QAbstractItemModel *model = qobject_cast(component.create()); QVERIFY(model != 0); QVERIFY(QMetaObject::invokeMethod(model, "runPreTest")); QCOMPARE(model->property("preTest").toBool(), true); - QTRY_COMPARE(model->count(), 9); + QTRY_COMPARE(model->rowCount(), 9); QVERIFY(QMetaObject::invokeMethod(model, "runPostTest")); QCOMPARE(model->property("postTest").toBool(), true); @@ -543,12 +546,12 @@ void tst_qquickxmllistmodel::reload() // reload() is called. QQmlComponent component(&engine, testFileUrl("model.qml")); - QListModelInterface *model = qobject_cast(component.create()); + QAbstractItemModel *model = qobject_cast(component.create()); QVERIFY(model != 0); - QTRY_COMPARE(model->count(), 9); + QTRY_COMPARE(model->rowCount(), 9); - QSignalSpy spyInsert(model, SIGNAL(itemsInserted(int,int))); - QSignalSpy spyRemove(model, SIGNAL(itemsRemoved(int,int))); + QSignalSpy spyInsert(model, SIGNAL(rowsInserted(QModelIndex,int,int))); + QSignalSpy spyRemove(model, SIGNAL(rowsRemoved(QModelIndex,int,int))); QSignalSpy spyCount(model, SIGNAL(countChanged())); //reload multiple times to test the xml query aborting QMetaObject::invokeMethod(model, "reload"); @@ -556,15 +559,15 @@ void tst_qquickxmllistmodel::reload() QCoreApplication::processEvents(); QMetaObject::invokeMethod(model, "reload"); QMetaObject::invokeMethod(model, "reload"); - QTRY_COMPARE(spyCount.count(), 1); + QTRY_COMPARE(spyCount.count(), 0); QTRY_COMPARE(spyInsert.count(), 1); QTRY_COMPARE(spyRemove.count(), 1); - QCOMPARE(spyInsert[0][0].toInt(), 0); - QCOMPARE(spyInsert[0][1].toInt(), 9); + QCOMPARE(spyInsert[0][1].toInt(), 0); + QCOMPARE(spyInsert[0][2].toInt(), 8); - QCOMPARE(spyRemove[0][0].toInt(), 0); - QCOMPARE(spyRemove[0][1].toInt(), 9); + QCOMPARE(spyRemove[0][1].toInt(), 0); + QCOMPARE(spyRemove[0][2].toInt(), 8); delete model; } @@ -583,42 +586,44 @@ void tst_qquickxmllistmodel::useKeys() QFETCH(QList, removeRanges); QQmlComponent component(&engine, testFileUrl("roleKeys.qml")); - QListModelInterface *model = qobject_cast(component.create()); + QAbstractItemModel *model = qobject_cast(component.create()); QVERIFY(model != 0); model->setProperty("xml",oldXml); - QTRY_COMPARE(model->count(), oldCount); + QTRY_COMPARE(model->rowCount(), oldCount); - QSignalSpy spyInsert(model, SIGNAL(itemsInserted(int,int))); - QSignalSpy spyRemove(model, SIGNAL(itemsRemoved(int,int))); + QSignalSpy spyInsert(model, SIGNAL(rowsInserted(QModelIndex,int,int))); + QSignalSpy spyRemove(model, SIGNAL(rowsRemoved(QModelIndex,int,int))); QSignalSpy spyCount(model, SIGNAL(countChanged())); model->setProperty("xml",newXml); if (oldCount != newData.count()) { - QTRY_COMPARE(model->count(), newData.count()); + QTRY_COMPARE(model->rowCount(), newData.count()); QCOMPARE(spyCount.count(), 1); } else { QTRY_VERIFY(spyInsert.count() > 0 || spyRemove.count() > 0); QCOMPARE(spyCount.count(), 0); } - QList roles = model->roles(); - for (int i=0; icount(); i++) { + QList roles = model->roleNames().keys(); + qSort(roles); + for (int i=0; irowCount(); i++) { + QModelIndex index = model->index(i, 0); for (int j=0; jdata(i, roles[j]), newData[i][j]); + QCOMPARE(model->data(index, roles.at(j)), newData[i][j]); } QCOMPARE(spyInsert.count(), insertRanges.count()); for (int i=0; i(component.create()); + QAbstractItemModel *model = qobject_cast(component.create()); QVERIFY(model != 0); QString xml; xml = makeItemXmlAndData("name=A,age=25,sport=Football;name=B,age=35,sport=Athletics"); model->setProperty("xml",xml); - QTRY_COMPARE(model->count(), 2); + QTRY_COMPARE(model->rowCount(), 2); model->setProperty("xml",""); - QSignalSpy spyInsert(model, SIGNAL(itemsInserted(int,int))); - QSignalSpy spyRemove(model, SIGNAL(itemsRemoved(int,int))); + QSignalSpy spyInsert(model, SIGNAL(rowsInserted(QModelIndex,int,int))); + QSignalSpy spyRemove(model, SIGNAL(rowsRemoved(QModelIndex,int,int))); QSignalSpy spyCount(model, SIGNAL(countChanged())); xml = makeItemXmlAndData("name=A,age=25,sport=AussieRules;name=B,age=35,sport=Athletics"); model->setProperty("xml",xml); + QList roles = model->roleNames().keys(); + qSort(roles); // wait for the new xml data to be set, and verify no signals were emitted - QTRY_VERIFY(model->data(0, model->roles()[2]).toString() != QLatin1String("Football")); - QCOMPARE(model->data(0, model->roles()[2]).toString(), QLatin1String("AussieRules")); + QTRY_VERIFY(model->data(model->index(0, 0), roles.at(2)).toString() != QLatin1String("Football")); + QCOMPARE(model->data(model->index(0, 0), roles.at(2)).toString(), QLatin1String("AussieRules")); QVERIFY(spyInsert.count() == 0); QVERIFY(spyRemove.count() == 0); QVERIFY(spyCount.count() == 0); - QCOMPARE(model->count(), 2); + QCOMPARE(model->rowCount(), 2); delete model; } @@ -772,17 +779,17 @@ void tst_qquickxmllistmodel::keysChanged() // if no keys are set). QQmlComponent component(&engine, testFileUrl("roleKeys.qml")); - QListModelInterface *model = qobject_cast(component.create()); + QAbstractItemModel *model = qobject_cast(component.create()); QVERIFY(model != 0); QString xml = makeItemXmlAndData("name=A,age=25,sport=Football;name=B,age=35,sport=Athletics"); model->setProperty("xml",xml); - QTRY_COMPARE(model->count(), 2); + QTRY_COMPARE(model->rowCount(), 2); model->setProperty("xml",""); - QSignalSpy spyInsert(model, SIGNAL(itemsInserted(int,int))); - QSignalSpy spyRemove(model, SIGNAL(itemsRemoved(int,int))); + QSignalSpy spyInsert(model, SIGNAL(rowsInserted(QModelIndex,int,int))); + QSignalSpy spyRemove(model, SIGNAL(rowsRemoved(QModelIndex,int,int))); QSignalSpy spyCount(model, SIGNAL(countChanged())); QVERIFY(QMetaObject::invokeMethod(model, "disableNameKey")); @@ -791,12 +798,12 @@ void tst_qquickxmllistmodel::keysChanged() QTRY_VERIFY(spyInsert.count() > 0 && spyRemove.count() > 0); QCOMPARE(spyInsert.count(), 1); - QCOMPARE(spyInsert[0][0].toInt(), 0); - QCOMPARE(spyInsert[0][1].toInt(), 2); + QCOMPARE(spyInsert[0][1].toInt(), 0); + QCOMPARE(spyInsert[0][2].toInt(), 1); QCOMPARE(spyRemove.count(), 1); - QCOMPARE(spyRemove[0][0].toInt(), 0); - QCOMPARE(spyRemove[0][1].toInt(), 2); + QCOMPARE(spyRemove[0][1].toInt(), 0); + QCOMPARE(spyRemove[0][2].toInt(), 1); QCOMPARE(spyCount.count(), 0); @@ -809,11 +816,11 @@ void tst_qquickxmllistmodel::threading() QQmlComponent component(&engine, testFileUrl("roleKeys.qml")); - QListModelInterface *m1 = qobject_cast(component.create()); + QAbstractItemModel *m1 = qobject_cast(component.create()); QVERIFY(m1 != 0); - QListModelInterface *m2 = qobject_cast(component.create()); + QAbstractItemModel *m2 = qobject_cast(component.create()); QVERIFY(m2 != 0); - QListModelInterface *m3 = qobject_cast(component.create()); + QAbstractItemModel *m3 = qobject_cast(component.create()); QVERIFY(m3 != 0); for (int dataCount=0; dataCountsetProperty("xml",makeItemXmlAndData(data3)); QCoreApplication::processEvents(); - QTRY_VERIFY(m1->count() == dataCount && m2->count() == dataCount && m3->count() == dataCount); + QTRY_VERIFY(m1->rowCount() == dataCount && m2->rowCount() == dataCount && m3->rowCount() == dataCount); for (int i=0; idata(i, m1->roles()[0]).toString(), QString("A" + QString::number(i))); - QCOMPARE(m1->data(i, m1->roles()[1]).toString(), QString("1" + QString::number(i))); - QCOMPARE(m1->data(i, m1->roles()[2]).toString(), QString("Football")); - - QCOMPARE(m2->data(i, m2->roles()[0]).toString(), QString("B" + QString::number(i))); - QCOMPARE(m2->data(i, m2->roles()[1]).toString(), QString("2" + QString::number(i))); - QCOMPARE(m2->data(i, m2->roles()[2]).toString(), QString("Athletics")); - - QCOMPARE(m3->data(i, m3->roles()[0]).toString(), QString("C" + QString::number(i))); - QCOMPARE(m3->data(i, m3->roles()[1]).toString(), QString("3" + QString::number(i))); - QCOMPARE(m3->data(i, m3->roles()[2]).toString(), QString("Curling")); + QModelIndex index = m1->index(i, 0); + QList roles = m1->roleNames().keys(); + qSort(roles); + QCOMPARE(m1->data(index, roles.at(0)).toString(), QString("A" + QString::number(i))); + QCOMPARE(m1->data(index, roles.at(1)).toString(), QString("1" + QString::number(i))); + QCOMPARE(m1->data(index, roles.at(2)).toString(), QString("Football")); + + index = m2->index(i, 0); + roles = m2->roleNames().keys(); + qSort(roles); + QCOMPARE(m2->data(index, roles.at(0)).toString(), QString("B" + QString::number(i))); + QCOMPARE(m2->data(index, roles.at(1)).toString(), QString("2" + QString::number(i))); + QCOMPARE(m2->data(index, roles.at(2)).toString(), QString("Athletics")); + + index = m3->index(i, 0); + roles = m3->roleNames().keys(); + qSort(roles); + QCOMPARE(m3->data(index, roles.at(0)).toString(), QString("C" + QString::number(i))); + QCOMPARE(m3->data(index, roles.at(1)).toString(), QString("3" + QString::number(i))); + QCOMPARE(m3->data(index, roles.at(2)).toString(), QString("Curling")); } } @@ -881,9 +897,9 @@ void tst_qquickxmllistmodel::threading_data() void tst_qquickxmllistmodel::propertyChanges() { QQmlComponent component(&engine, testFileUrl("propertychanges.qml")); - QListModelInterface *model = qobject_cast(component.create()); + QAbstractItemModel *model = qobject_cast(component.create()); QVERIFY(model != 0); - QTRY_COMPARE(model->count(), 9); + QTRY_COMPARE(model->rowCount(), 9); QObject *role = model->findChild("role"); QVERIFY(role); @@ -927,7 +943,7 @@ void tst_qquickxmllistmodel::propertyChanges() QCOMPARE(model->property("query").toString(), QString("/Pets")); QCOMPARE(model->property("namespaceDeclarations").toString(), QString("declare namespace media=\"http://search.yahoo.com/mrss/\";")); - QTRY_VERIFY(model->count() == 1); + QTRY_VERIFY(model->rowCount() == 1); QCOMPARE(sourceSpy.count(),1); QCOMPARE(xmlSpy.count(),1); @@ -944,7 +960,7 @@ void tst_qquickxmllistmodel::propertyChanges() QCOMPARE(modelQuerySpy.count(),1); QCOMPARE(namespaceDeclarationsSpy.count(),1); - QTRY_VERIFY(model->count() == 1); + QTRY_VERIFY(model->rowCount() == 1); delete model; } @@ -952,7 +968,7 @@ void tst_qquickxmllistmodel::roleCrash() { // don't crash QQmlComponent component(&engine, testFileUrl("roleCrash.qml")); - QListModelInterface *model = qobject_cast(component.create()); + QAbstractItemModel *model = qobject_cast(component.create()); QVERIFY(model != 0); delete model; } diff --git a/tests/auto/quick/shared/viewtestutil.cpp b/tests/auto/quick/shared/viewtestutil.cpp index f68ca1f..63da97b 100644 --- a/tests/auto/quick/shared/viewtestutil.cpp +++ b/tests/auto/quick/shared/viewtestutil.cpp @@ -141,148 +141,6 @@ QList QQuickViewTestUtil::adjustIndexesForRemoveDisplaced(const QList return result; } - -QQuickViewTestUtil::QmlListModel::QmlListModel(QObject *parent) - : QListModelInterface(parent) -{ -} - -QQuickViewTestUtil::QmlListModel::~QmlListModel() -{ -} - -QString QQuickViewTestUtil::QmlListModel::name(int index) const -{ - return list.at(index).first; -} - -QString QQuickViewTestUtil::QmlListModel::number(int index) const -{ - return list.at(index).second; -} - -int QQuickViewTestUtil::QmlListModel::count() const -{ - return list.count(); -} - -QList QQuickViewTestUtil::QmlListModel::roles() const -{ - return QList() << Name << Number; -} - -QString QQuickViewTestUtil::QmlListModel::toString(int role) const -{ - switch (role) { - case Name: - return "name"; - case Number: - return "number"; - default: - return ""; - } -} - -QVariant QQuickViewTestUtil::QmlListModel::data(int index, int role) const -{ - if (role==0) - return list.at(index).first; - if (role==1) - return list.at(index).second; - return QVariant(); -} - -QHash QQuickViewTestUtil::QmlListModel::data(int index, const QList &roles) const -{ - QHash returnHash; - - for (int i = 0; i < roles.size(); ++i) { - int role = roles.at(i); - QVariant info; - switch (role) { - case Name: - info = list.at(index).first; - break; - case Number: - info = list.at(index).second; - break; - default: - break; - } - returnHash.insert(role, info); - } - return returnHash; -} - -void QQuickViewTestUtil::QmlListModel::addItem(const QString &name, const QString &number) -{ - list.append(QPair(name, number)); - emit itemsInserted(list.count()-1, 1); -} - -void QQuickViewTestUtil::QmlListModel::insertItem(int index, const QString &name, const QString &number) -{ - list.insert(index, QPair(name, number)); - emit itemsInserted(index, 1); -} - -void QQuickViewTestUtil::QmlListModel::insertItems(int index, const QList > &items) -{ - for (int i=0; i(items[i].first, items[i].second)); - emit itemsInserted(index, items.count()); -} - -void QQuickViewTestUtil::QmlListModel::removeItem(int index) -{ - list.removeAt(index); - emit itemsRemoved(index, 1); -} - -void QQuickViewTestUtil::QmlListModel::removeItems(int index, int count) -{ - int c = count; - while (c--) - list.removeAt(index); - emit itemsRemoved(index, count); -} - -void QQuickViewTestUtil::QmlListModel::moveItem(int from, int to) -{ - list.move(from, to); - emit itemsMoved(from, to, 1); -} - -void QQuickViewTestUtil::QmlListModel::moveItems(int from, int to, int count) -{ - qquickmodelviewstestutil_move(from, to, count, &list); - emit itemsMoved(from, to, count); -} - -void QQuickViewTestUtil::QmlListModel::modifyItem(int index, const QString &name, const QString &number) -{ - list[index] = QPair(name, number); - emit itemsChanged(index, 1, roles()); -} - -void QQuickViewTestUtil::QmlListModel::clear() { - int count = list.count(); - list.clear(); - emit itemsRemoved(0, count); -} - -void QQuickViewTestUtil::QmlListModel::matchAgainst(const QList > &other, const QString &error1, const QString &error2) { - for (int i=0; i 0) { + beginRemoveRows(QModelIndex(), 0, count-1); + list.clear(); + endRemoveRows(); + } } void QQuickViewTestUtil::QaimModel::reset() @@ -474,16 +334,6 @@ int QQuickViewTestUtil::ListRange::count() const return indexes.count(); } -QList > QQuickViewTestUtil::ListRange::getModelDataValues(const QmlListModel &model) -{ - QList > data; - if (!valid) - return data; - for (int i=0; i > QQuickViewTestUtil::ListRange::getModelDataValues(const QaimModel &model) { QList > data; diff --git a/tests/auto/quick/shared/viewtestutil.h b/tests/auto/quick/shared/viewtestutil.h index 3108030..771be0a 100644 --- a/tests/auto/quick/shared/viewtestutil.h +++ b/tests/auto/quick/shared/viewtestutil.h @@ -44,7 +44,6 @@ #include #include -#include #include QT_FORWARD_DECLARE_CLASS(QQuickView) @@ -74,46 +73,6 @@ namespace QQuickViewTestUtil static ListChange polish() { ListChange c = { Polish, -1, -1, -1, 0.0 }; return c; } }; - class QmlListModel : public QListModelInterface - { - Q_OBJECT - public: - QmlListModel(QObject *parent = 0); - ~QmlListModel(); - - enum Roles { Name, Number }; - - QString name(int index) const; - QString number(int index) const; - - int count() const; - - QList roles() const; - QString toString(int role) const; - - QVariant data(int index, int role) const; - QHash data(int index, const QList &roles) const; - - Q_INVOKABLE void addItem(const QString &name, const QString &number); - void insertItem(int index, const QString &name, const QString &number); - void insertItems(int index, const QList > &items); - - Q_INVOKABLE void removeItem(int index); - Q_INVOKABLE void removeItems(int index, int count); - - void moveItem(int from, int to); - void moveItems(int from, int to, int count); - - void modifyItem(int index, const QString &name, const QString &number); - - void clear(); - - void matchAgainst(const QList > &other, const QString &error1, const QString &error2); - - private: - QList > list; - }; - class QaimModel : public QAbstractListModel { Q_OBJECT @@ -134,7 +93,7 @@ namespace QQuickViewTestUtil void insertItem(int index, const QString &name, const QString &number); void insertItems(int index, const QList > &items); - void removeItem(int index); + Q_INVOKABLE void removeItem(int index); void removeItems(int index, int count); void moveItem(int from, int to); @@ -168,7 +127,6 @@ namespace QQuickViewTestUtil bool isValid() const; int count() const; - QList > getModelDataValues(const QmlListModel &model); QList > getModelDataValues(const QaimModel &model); QList indexes; -- 2.7.4