Remove QListModelInterface.

Implement ListModel and XmlListModel using QAbstractListModel
instead.

Task-number: QTBUG-15728

Change-Id: I14e03d90883d341f4b1d89c1e9fc9dc1534fde78
Reviewed-by: Glenn Watson <glenn.watson@nokia.com>
This commit is contained in:
Andrew den Exter 2012-07-10 17:01:52 +10:00 committed by Qt by Nokia
parent b355aacb6e
commit 7daab8039a
29 changed files with 425 additions and 973 deletions

View File

@ -57,7 +57,7 @@
#include <QTimer>
#include <QMutex>
#include <private/qobject_p.h>
#include <private/qabstractitemmodel_p.h>
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<QQuickXmlListModelRo
*/
QQuickXmlListModel::QQuickXmlListModel(QObject *parent)
: QListModelInterface(*(new QQuickXmlListModelPrivate), parent)
: QAbstractListModel(*(new QQuickXmlListModelPrivate), parent)
{
}
@ -734,23 +734,36 @@ QQmlListProperty<QQuickXmlListModelRole> QQuickXmlListModel::roleObjects()
return list;
}
QHash<int,QVariant> QQuickXmlListModel::data(int index, const QList<int> &roles) const
QModelIndex QQuickXmlListModel::index(int row, int column, const QModelIndex &parent) const
{
Q_D(const QQuickXmlListModel);
QHash<int, QVariant> 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;
}
QVariant QQuickXmlListModel::data(const QModelIndex &index, int role) const
{
Q_D(const QQuickXmlListModel);
const int roleIndex = d->roles.indexOf(role);
return (roleIndex == -1 || !index.isValid())
? QVariant()
: d->data.value(roleIndex).value(index.row());
}
QHash<int, QByteArray> QQuickXmlListModel::roleNames() const
{
Q_D(const QQuickXmlListModel);
QHash<int,QByteArray> roleNames;
for (int i = 0; i < d->roles.count(); ++i)
roleNames.insert(d->roles.at(i), d->roleNames.at(i).toUtf8());
return roleNames;
}
/*!
@ -763,21 +776,6 @@ int QQuickXmlListModel::count() const
return d->size;
}
QList<int> QQuickXmlListModel::roles() const
{
Q_D(const QQuickXmlListModel);
return d->roles;
}
QString QQuickXmlListModel::toString(int role) const
{
Q_D(const QQuickXmlListModel);
int index = d->roles.indexOf(role);
if (index == -1)
return QString();
return d->roleNames.at(index);
}
/*!
\qmlproperty url QtQuick.XmlListModel2::XmlListModel::source
The location of the XML data source.
@ -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<result.removed.count(); i++)
emit itemsRemoved(result.removed[i].first, result.removed[i].second);
for (int i=0; i<result.inserted.count(); i++)
emit itemsInserted(result.inserted[i].first, result.inserted[i].second);
if (sizeChanged)
emit countChanged();
for (int i=0; i<result.removed.count(); i++) {
const int index = result.removed[i].first;
const int count = result.removed[i].second;
if (count > 0) {
beginRemoveRows(QModelIndex(), index, index + count - 1);
endRemoveRows();
}
}
for (int i=0; i<result.inserted.count(); i++) {
const int index = result.inserted[i].first;
const int count = result.inserted[i].second;
if (count > 0) {
beginInsertRows(QModelIndex(), index, index + count - 1);
endInsertRows();
}
}
}
if (sizeChanged)
emit countChanged();
emit statusChanged(d->status);
}

View File

@ -47,8 +47,7 @@
#include <QtCore/qurl.h>
#include <QtCore/qstringlist.h>
#include <private/qlistmodelinterface_p.h>
#include <QtCore/qabstractitemmodel.h>
#include <private/qv8engine_p.h>
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<int,QVariant> data(int index, const QList<int> &roles = (QList<int>())) const;
virtual QVariant data(int index, int role) const;
virtual int count() const;
virtual QList<int> 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<int, QByteArray> roleNames() const;
int count() const;
QQmlListProperty<QQuickXmlListModelRole> roleObjects();

View File

@ -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<int> 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<int> &roles)
Emit this signal when \a count items at \a index have had their
\a roles changed.
*/
QT_END_NAMESPACE

View File

@ -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 <QtCore/QHash>
#include <QtCore/QVariant>
#include <private/qtqmlglobal_p.h>
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<int> 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<int> &roles);
protected:
QListModelInterface(QObjectPrivate &dd, QObject *parent)
: QObject(dd, parent) {}
};
QT_END_NAMESPACE
QT_END_HEADER
#endif //QTREEMODELINTERFACE_H

View File

@ -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 \

View File

@ -45,6 +45,7 @@
#include <private/qqmljsast_p.h>
#include <private/qqmljsengine_p.h>
#include <private/qqmlcustomparser_p.h>
#include <private/qqmlscript_p.h>
#include <private/qqmlengine_p.h>
@ -55,8 +56,6 @@
#include <QtCore/qstack.h>
#include <QXmlStreamReader>
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<v8::Object> object, QList<int> *roles, QV8Engine *eng)
void ListModel::set(int elementIndex, v8::Handle<v8::Object> object, QVector<int> *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<int> roles;
QVector<int> roles;
roles << roleIndex;
e->m_objectCache->updateValues(roles);
}
@ -1226,7 +1225,7 @@ void ModelObject::updateValues()
}
}
void ModelObject::updateValues(const QList<int> &roles)
void ModelObject::updateValues(const QVector<int> &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<int> roles;
QVector<int> 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<int> roles;
QVector<int> roles;
object->updateValues(obj, roles);
return object;
}
@ -1308,7 +1307,7 @@ void DynamicRoleModelNode::sync(DynamicRoleModelNode *src, DynamicRoleModelNode
}
}
void DynamicRoleModelNode::updateValues(const QVariantMap &object, QList<int> &roles)
void DynamicRoleModelNode::updateValues(const QVariantMap &object, QVector<int> &roles)
{
const QList<QString> &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<int> roles;
QVector<int> 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<int> &roles)
void QQuickListModel::emitItemsChanged(int index, int count, const QVector<int> &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<int> &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<int> QQuickListModel::roles() const
QModelIndex QQuickListModel::index(int row, int column, const QModelIndex &parent) const
{
QList<int> 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;
return !parent.isValid() ? count() : 0;
}
if (m_dynamicRoles) {
roleName = m_roles[role];
} else {
const ListLayout::Role &r = m_listModel->getExistingRole(role);
roleName = r.name;
}
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<int, QByteArray> QQuickListModel::roleNames() const
{
QHash<int, QByteArray> 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<int> roles;
QVector<int> 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<int> roles;
QVector<int> 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<int> roles;
QVector<int> roles;
roles << roleIndex;
emitItemsChanged(index, 1, roles);

View File

@ -50,7 +50,7 @@
#include <QtCore/QHash>
#include <QtCore/QList>
#include <QtCore/QVariant>
#include "qlistmodelinterface_p.h"
#include <QtCore/qabstractitemmodel.h>
#include <private/qv8engine_p.h>
#include <private/qpodvector_p.h>
@ -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<int> 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<int,QByteArray> 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<int, QQuickListModel *> *targetModelHash);
static QQuickListModel *createWithOwner(QQuickListModel *newOwner);
void emitItemsChanged(int index, int count, const QList<int> &roles);
void emitItemsChanged(int index, int count, const QVector<int> &roles);
void emitItemsRemoved(int index, int count);
void emitItemsInserted(int index, int count);
void emitItemsMoved(int from, int to, int n);

View File

@ -89,7 +89,7 @@ public:
static DynamicRoleModelNode *create(const QVariantMap &obj, QQuickListModel *owner);
void updateValues(const QVariantMap &object, QList<int> &roles);
void updateValues(const QVariantMap &object, QVector<int> &roles);
QVariant getValue(const QString &name)
{
@ -162,7 +162,7 @@ public:
}
void updateValues();
void updateValues(const QList<int> &roles);
void updateValues(const QVector<int> &roles);
QQuickListModel *m_model;
int m_elementIndex;
@ -329,7 +329,7 @@ public:
return elements.count();
}
void set(int elementIndex, v8::Handle<v8::Object> object, QList<int> *roles, QV8Engine *eng);
void set(int elementIndex, v8::Handle<v8::Object> object, QVector<int> *roles, QV8Engine *eng);
void set(int elementIndex, v8::Handle<v8::Object> object, QV8Engine *eng);
int append(v8::Handle<v8::Object> object, QV8Engine *eng);

View File

@ -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<int>() };
Change c = { uid, Change::Inserted, index, count, 0, QVector<int>() };
changes << c;
}
void QQuickListModelWorkerAgent::Data::removeChange(int uid, int index, int count)
{
Change c = { uid, Change::Removed, index, count, 0, QList<int>() };
Change c = { uid, Change::Removed, index, count, 0, QVector<int>() };
changes << c;
}
void QQuickListModelWorkerAgent::Data::moveChange(int uid, int index, int count, int to)
{
Change c = { uid, Change::Moved, index, count, to, QList<int>() };
Change c = { uid, Change::Moved, index, count, to, QVector<int>() };
changes << c;
}
void QQuickListModelWorkerAgent::Data::changedChange(int uid, int index, int count, const QList<int> &roles)
void QQuickListModelWorkerAgent::Data::changedChange(int uid, int index, int count, const QVector<int> &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;
}
}

View File

@ -122,7 +122,7 @@ private:
int index; // Inserted/Removed/Moved/Changed
int count; // Inserted/Removed/Moved/Changed
int to; // Moved
QList<int> roles;
QVector<int> 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<int> &roles);
void changedChange(int uid, int index, int count, const QVector<int> &roles);
};
Data data;

View File

@ -45,7 +45,6 @@
#include "qquickitemview_p_p.h"
#include <private/qquicksmoothedanimation_p_p.h>
#include <private/qlistmodelinterface_p.h>
#include <QtGui/qevent.h>
#include <QtCore/qmath.h>

View File

@ -64,7 +64,6 @@
#include <QtQuick/private/qquickstategroup_p.h>
#include <private/qqmlopenmetaobject_p.h>
#include <QtQuick/private/qquickstate_p.h>
#include <private/qlistmodelinterface_p.h>
#include <private/qquickitem_p.h>
#include <private/qqmlaccessors_p.h>
#include <QtQuick/private/qquickaccessibleattached_p.h>

View File

@ -51,7 +51,6 @@
#include <QtCore/qcoreapplication.h>
#include <private/qquicksmoothedanimation_p_p.h>
#include <private/qlistmodelinterface_p.h>
#include "qplatformdefs.h"
QT_BEGIN_NAMESPACE

View File

@ -46,7 +46,6 @@
#include <QtQuick/private/qquickstate_p.h>
#include <private/qqmlglobal_p.h>
#include <private/qqmlopenmetaobject_p.h>
#include <private/qlistmodelinterface_p.h>
#include <private/qquickchangeset_p.h>
#include <QtGui/qevent.h>

View File

@ -45,7 +45,6 @@
#include <private/qqmlglobal_p.h>
#include <private/qquicklistaccessor_p.h>
#include <private/qlistmodelinterface_p.h>
#include <private/qquickchangeset_p.h>
QT_BEGIN_NAMESPACE

View File

@ -153,7 +153,7 @@ public:
const QList<QQuickVisualDataModelItem *> &items,
int index,
int count,
const QList<int> &roles) const
const QVector<int> &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<int>)),
vdm, SLOT(_q_dataChanged(QModelIndex,QModelIndex,QVector<int>)));
QObject::disconnect(aim, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)),
vdm, SLOT(_q_rowsMoved(QModelIndex,int,int,QModelIndex,int)));
QObject::disconnect(aim, SIGNAL(modelReset()),
@ -552,123 +552,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<v8::Value> get()
{
if (type->constructor.IsEmpty()) {
v8::HandleScope handleScope;
v8::Context::Scope contextScope(engine->context());
type->initializeConstructor(engineData(engine));
}
v8::Local<v8::Object> 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<int>)),
vdm, SLOT(_q_itemsChanged(int,int,QList<int>)));
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<VDMListModelInterfaceDataType *>(this)->release();
}
QVariant value(const QQuickVisualAdaptorModel &model, int index, const QString &role) const
{
QHash<QByteArray, int>::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<VDMListModelInterfaceDataType *>(this);
if (!metaObject)
dataType->initializeMetaType(model, engine);
return new QQuickVDMListModelInterfaceData(metaType, dataType, index);
}
void initializeMetaType(QQuickVisualAdaptorModel &model, QQmlEngine *engine)
{
QMetaObjectBuilder builder;
setModelDataType<QQuickVDMListModelInterfaceData>(&builder, this);
const QByteArray propertyType = QByteArrayLiteral("QVariant");
const QListModelInterface * const listModelInterface = model.lmi();
const QList<int> 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<QMetaObject *>(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<int>)),
vdm, QQuickVisualDataModel, SLOT(_q_dataChanged(QModelIndex,QModelIndex,QVector<int>)));
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<QListModelInterface *>(object)) {
accessors = new VDMListModelInterfaceDataType(this);
qmlobject_connect(model, QListModelInterface, SIGNAL(itemsChanged(int,int,QList<int>)),
vdm, QQuickVisualDataModel, SLOT(_q_itemsChanged(int,int,QList<int>)));
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 <qquickvisualadaptormodel.moc>

View File

@ -44,7 +44,6 @@
#include <QtCore/qabstractitemmodel.h>
#include "private/qlistmodelinterface_p.h"
#include "private/qquicklistaccessor_p.h"
#include <private/qqmlguard_p.h>
@ -83,7 +82,7 @@ public:
const QList<QQuickVisualDataModelItem *> &,
int,
int,
const QList<int> &) const { return false; }
const QVector<int> &) const { return false; }
virtual void replaceWatchedRoles(
QQuickVisualAdaptorModel &,
const QList<QByteArray> &,
@ -109,9 +108,6 @@ public:
inline QAbstractItemModel *aim() { return static_cast<QAbstractItemModel *>(object()); }
inline const QAbstractItemModel *aim() const { return static_cast<const QAbstractItemModel *>(object()); }
inline QListModelInterface *lmi() { return static_cast<QListModelInterface *>(object()); }
inline const QListModelInterface *lmi() const { return static_cast<const QListModelInterface *>(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<QQuickVisualDataModelItem *> &items,
int index,
int count,
const QList<int> &roles) const {
const QVector<int> &roles) const {
return accessors->notify(*this, items, index, count, roles); }
inline void replaceWatchedRoles(
const QList<QByteArray> &oldRoles, const QList<QByteArray> &newRoles) {

View File

@ -1060,7 +1060,7 @@ void QQuickVisualDataModelPrivate::itemsChanged(const QVector<Compositor::Change
QQuickVisualDataGroupPrivate::get(m_groups[i])->changeSet.apply(translatedChanges.at(i));
}
void QQuickVisualDataModel::_q_itemsChanged(int index, int count, const QList<int> &roles)
void QQuickVisualDataModel::_q_itemsChanged(int index, int count, const QVector<int> &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<int> &roles)
{
Q_D(QQuickVisualDataModel);
if (begin.parent() == d->m_adaptorModel.rootIndex)
_q_itemsChanged(begin.row(), end.row() - begin.row() + 1, QList<int>());
_q_itemsChanged(begin.row(), end.row() - begin.row() + 1, roles);
}
void QQuickVisualDataModel::_q_layoutChanged()
{
Q_D(QQuickVisualDataModel);
_q_itemsChanged(0, d->m_count, QList<int>());
_q_itemsChanged(0, d->m_count, QVector<int>());
}
QQuickVisualDataModelAttached *QQuickVisualDataModel::qmlAttachedProperties(QObject *obj)

View File

@ -131,7 +131,7 @@ Q_SIGNALS:
void rootIndexChanged();
private Q_SLOTS:
void _q_itemsChanged(int index, int count, const QList<int> &roles);
void _q_itemsChanged(int index, int count, const QVector<int> &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<int> &);
void _q_layoutChanged();
private:

View File

@ -86,7 +86,10 @@ class tst_qquicklistmodel : public QQmlDataTest
{
Q_OBJECT
public:
tst_qquicklistmodel() {}
tst_qquicklistmodel()
{
qRegisterMetaType<QVector<int> >();
}
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<int> &roles = model->roles();
const QHash<int, QByteArray> 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<int> roles = model->roles();
for (int i=0; i<roles.count(); i++) {
if (model->toString(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("<Unknown File>: 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<int>)));
QSignalSpy spy(model, SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector<int>)));
QQmlExpression expr(engine.rootContext(), model, expression);
expr.evaluate();
QVERIFY(!expr.hasError());
@ -777,9 +768,9 @@ void tst_qquicklistmodel::get()
QCOMPARE(spy.count(), 1);
QList<QVariant> 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<int> >(), (QList<int>() << role));
QCOMPARE(spyResult.at(0).value<QModelIndex>(), model->index(index, 0, QModelIndex()));
QCOMPARE(spyResult.at(1).value<QModelIndex>(), model->index(index, 0, QModelIndex())); // only 1 item is modified at a time
QCOMPARE(spyResult.at(2).value<QVector<int> >(), (QVector<int>() << 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<int>)));
QSignalSpy spy(childModel, SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector<int>)));
expr.evaluate();
QVERIFY(!expr.hasError());
@ -901,9 +892,9 @@ void tst_qquicklistmodel::get_nested()
QCOMPARE(spy.count(), 1);
QList<QVariant> 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<int> >(), (QList<int>() << role));
QCOMPARE(spyResult.at(0).value<QModelIndex>(), childModel->index(index, 0, QModelIndex()));
QCOMPARE(spyResult.at(1).value<QModelIndex>(), childModel->index(index, 0, QModelIndex())); // only 1 item is modified at a time
QCOMPARE(spyResult.at(2).value<QVector<int> >(), (QVector<int>() << 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<int>)));
QSignalSpy spyItemsChanged(&model, SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector<int>)));
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<QModelIndex>(), model.index(listIndex, 0, QModelIndex()));
QCOMPARE(spyItemsChanged.at(0).at(1).value<QModelIndex>(), 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<int> roles = model.roles();
QHash<int, QByteArray> 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()

View File

@ -85,7 +85,10 @@ class tst_qquicklistmodelworkerscript : public QQmlDataTest
{
Q_OBJECT
public:
tst_qquicklistmodelworkerscript() {}
tst_qquicklistmodelworkerscript()
{
qRegisterMetaType<QVector<int> >();
}
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<int> &roles = model->roles();
const QHash<int, QByteArray> 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<int> roles = model->roles();
for (int i=0; i<roles.count(); i++) {
if (model->toString(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<int>)));
QSignalSpy spy(&model, SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector<int>)));
// 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<QVariant> 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<QList<int> >().contains(role));
QCOMPARE(spyResult.at(0).value<QModelIndex>(), model.index(index, 0, QModelIndex()));
QCOMPARE(spyResult.at(1).value<QModelIndex>(), model.index(index, 0, QModelIndex())); // only 1 item is modified at a time
QVERIFY(spyResult.at(2).value<QVector<int> >().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<int>)));
QSignalSpy spyItemsChanged(&model, SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector<int>)));
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<QModelIndex>(), model.index(listIndex, 0, QModelIndex()));
QCOMPARE(spyItemsChanged.at(0).at(1).value<QModelIndex>(), 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);

View File

@ -53,7 +53,6 @@
#include <QtQuick/private/qquicktext_p.h>
#include <QtQuick/private/qquickvisualitemmodel_p.h>
#include <QtQml/private/qquicklistmodel_p.h>
#include <QtQml/private/qlistmodelinterface_p.h>
#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), "");

View File

@ -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<QmlListModel>(testFileUrl("listviewtest.qml"), false);
}
void tst_QQuickListView::qListModelInterface_package_items()
{
items<QmlListModel>(testFileUrl("listviewtest-package.qml"), true);
items<QaimModel>(testFileUrl("listviewtest-package.qml"), true);
}
void tst_QQuickListView::qAbstractItemModel_items()
@ -5029,14 +5014,9 @@ void tst_QQuickListView::qAbstractItemModel_items()
items<QaimModel>(testFileUrl("listviewtest.qml"), false);
}
void tst_QQuickListView::qListModelInterface_changed()
void tst_QQuickListView::qAbstractItemModel_package_changed()
{
changed<QmlListModel>(testFileUrl("listviewtest.qml"), false);
}
void tst_QQuickListView::qListModelInterface_package_changed()
{
changed<QmlListModel>(testFileUrl("listviewtest-package.qml"), true);
changed<QaimModel>(testFileUrl("listviewtest-package.qml"), true);
}
void tst_QQuickListView::qAbstractItemModel_changed()
@ -5044,24 +5024,9 @@ void tst_QQuickListView::qAbstractItemModel_changed()
changed<QaimModel>(testFileUrl("listviewtest.qml"), false);
}
void tst_QQuickListView::qListModelInterface_inserted()
void tst_QQuickListView::qAbstractItemModel_package_inserted()
{
inserted<QmlListModel>(testFileUrl("listviewtest.qml"));
}
void tst_QQuickListView::qListModelInterface_package_inserted()
{
inserted<QmlListModel>(testFileUrl("listviewtest-package.qml"));
}
void tst_QQuickListView::qListModelInterface_inserted_more()
{
inserted_more<QmlListModel>();
}
void tst_QQuickListView::qListModelInterface_inserted_more_data()
{
inserted_more_data();
inserted<QaimModel>(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()
void tst_QQuickListView::qAbstractItemModel_package_removed()
{
removed<QmlListModel>(testFileUrl("listviewtest.qml"), false);
removed<QmlListModel>(testFileUrl("listviewtest.qml"), true);
}
void tst_QQuickListView::qListModelInterface_removed_more()
{
removed_more<QmlListModel>(testFileUrl("listviewtest.qml"));
}
void tst_QQuickListView::qListModelInterface_removed_more_data()
{
removed_more_data();
}
void tst_QQuickListView::qListModelInterface_package_removed()
{
removed<QmlListModel>(testFileUrl("listviewtest-package.qml"), false);
removed<QmlListModel>(testFileUrl("listviewtest-package.qml"), true);
removed<QaimModel>(testFileUrl("listviewtest-package.qml"), false);
removed<QaimModel>(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<QmlListModel>(testFileUrl("listviewtest.qml"));
moved<QaimModel>(testFileUrl("listviewtest-package.qml"));
}
void tst_QQuickListView::qListModelInterface_moved_data()
{
moved_data();
}
void tst_QQuickListView::qListModelInterface_package_moved()
{
moved<QmlListModel>(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<QmlListModel>(testFileUrl("listviewtest.qml"));
}
void tst_QQuickListView::qListModelInterface_package_clear()
{
clear<QmlListModel>(testFileUrl("listviewtest-package.qml"));
clear<QaimModel>(testFileUrl("listviewtest-package.qml"));
}
void tst_QQuickListView::qAbstractItemModel_clear()
@ -5197,14 +5131,9 @@ void tst_QQuickListView::qAbstractItemModel_clear_bottomToTop()
clear<QaimModel>(testFileUrl("listviewtest.qml"), QQuickItemView::BottomToTop);
}
void tst_QQuickListView::qListModelInterface_sections()
void tst_QQuickListView::qAbstractItemModel_package_sections()
{
sections<QmlListModel>(testFileUrl("listview-sections.qml"));
}
void tst_QQuickListView::qListModelInterface_package_sections()
{
sections<QmlListModel>(testFileUrl("listview-sections-package.qml"));
sections<QaimModel>(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);

View File

@ -39,7 +39,6 @@
**
****************************************************************************/
#include <QtTest/QtTest>
#include <private/qlistmodelinterface_p.h>
#include <QtQuick/qquickview.h>
#include <qqmlengine.h>
#include <QtQuick/private/qquickrectangle_p.h>

View File

@ -41,7 +41,6 @@
#include <QtTest/QtTest>
#include <QtTest/QSignalSpy>
#include <private/qlistmodelinterface_p.h>
#include <QtQml/qqmlengine.h>
#include <QtQuick/qquickview.h>
#include <QtQml/qqmlcontext.h>

View File

@ -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), "");

View File

@ -56,7 +56,6 @@
#include <QtQml/qqmlengine.h>
#include <QtQml/qqmlcomponent.h>
#include <private/qlistmodelinterface_p.h>
#include "../../../../src/imports/xmllistmodel/qqmlxmllistmodel_p.h"
typedef QPair<int, int> 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<QListModelInterface*>(component.create());
QAbstractItemModel *model = qobject_cast<QAbstractItemModel *>(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<QListModelInterface*>(component.create());
QAbstractItemModel *model = qobject_cast<QAbstractItemModel *>(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<QListModelInterface*>(component.create());
QAbstractItemModel *model = qobject_cast<QAbstractItemModel *>(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("<html>")));
QVERIFY(model->data(model->index(2, 0), Qt::UserRole+2).toString().startsWith(QLatin1String("<html>")));
delete model;
}
@ -287,10 +282,10 @@ void tst_qquickxmllistmodel::cdata()
void tst_qquickxmllistmodel::attributes()
{
QQmlComponent component(&engine, testFileUrl("recipes.qml"));
QListModelInterface *model = qobject_cast<QListModelInterface*>(component.create());
QAbstractItemModel *model = qobject_cast<QAbstractItemModel *>(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<QListModelInterface*>(component.create());
QAbstractItemModel *model = qobject_cast<QAbstractItemModel *>(component.create());
QVERIFY(model != 0);
QTRY_COMPARE(model->count(), 9);
QTRY_COMPARE(model->rowCount(), 9);
QList<int> roles = model->roles();
QHash<int, QByteArray> 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<int> 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<QListModelInterface*>(component.create());
QAbstractItemModel *model = qobject_cast<QAbstractItemModel *>(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<QListModelInterface*>(component.create());
QAbstractItemModel *model = qobject_cast<QAbstractItemModel *>(component.create());
QVERIFY(model != 0);
QTRY_COMPARE(model->count(), 9);
QTRY_COMPARE(model->rowCount(), 9);
QList<int> roles = model->roles();
QCOMPARE(roles.count(), 1);
QHash<int, QByteArray> 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<QListModelInterface*>(component.create());
QAbstractItemModel *model = qobject_cast<QAbstractItemModel *>(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<QQuickXmlListModel::Status>(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<QListModelInterface*>(component.create());
QAbstractItemModel *model = qobject_cast<QAbstractItemModel *>(component.create());
QVERIFY(model != 0);
QTRY_COMPARE(qvariant_cast<QQuickXmlListModel::Status>(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<QListModelInterface*>(component.create());
QAbstractItemModel *model = qobject_cast<QAbstractItemModel *>(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<QQuickXmlListModel::Status>(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<QListModelInterface*>(component.create());
QAbstractItemModel *model = qobject_cast<QAbstractItemModel *>(component.create());
QVERIFY(model != 0);
for (int i=0; i<9; i++) {
for (int j=0; j<model->roles().count(); j++) {
QCOMPARE(model->data(i, j), QVariant());
QModelIndex index = model->index(i, 0);
for (int j=0; j<model->roleNames().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<QListModelInterface*>(component.create());
QAbstractItemModel *model = qobject_cast<QAbstractItemModel *>(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<QListModelInterface*>(component.create());
QAbstractItemModel *model = qobject_cast<QAbstractItemModel *>(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<QQuickXmlListRange>, removeRanges);
QQmlComponent component(&engine, testFileUrl("roleKeys.qml"));
QListModelInterface *model = qobject_cast<QListModelInterface*>(component.create());
QAbstractItemModel *model = qobject_cast<QAbstractItemModel *>(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<int> roles = model->roles();
for (int i=0; i<model->count(); i++) {
QList<int> roles = model->roleNames().keys();
qSort(roles);
for (int i=0; i<model->rowCount(); i++) {
QModelIndex index = model->index(i, 0);
for (int j=0; j<roles.count(); j++)
QCOMPARE(model->data(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<spyInsert.count(); i++) {
QCOMPARE(spyInsert[i][0].toInt(), insertRanges[i].first);
QCOMPARE(spyInsert[i][1].toInt(), insertRanges[i].second);
QCOMPARE(spyInsert[i][1].toInt(), insertRanges[i].first);
QCOMPARE(spyInsert[i][2].toInt(), insertRanges[i].first + insertRanges[i].second - 1);
}
QCOMPARE(spyRemove.count(), removeRanges.count());
for (int i=0; i<spyRemove.count(); i++) {
QCOMPARE(spyRemove[i][0].toInt(), removeRanges[i].first);
QCOMPARE(spyRemove[i][1].toInt(), removeRanges[i].second);
QCOMPARE(spyRemove[i][1].toInt(), removeRanges[i].first);
QCOMPARE(spyRemove[i][2].toInt(), removeRanges[i].first + removeRanges[i].second - 1);
}
delete model;
@ -734,33 +739,35 @@ void tst_qquickxmllistmodel::noKeysValueChanges()
// since 'sport' is not marked as a key.
QQmlComponent component(&engine, testFileUrl("roleKeys.qml"));
QListModelInterface *model = qobject_cast<QListModelInterface*>(component.create());
QAbstractItemModel *model = qobject_cast<QAbstractItemModel *>(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<int> 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<QListModelInterface*>(component.create());
QAbstractItemModel *model = qobject_cast<QAbstractItemModel *>(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<QListModelInterface*>(component.create());
QAbstractItemModel *m1 = qobject_cast<QAbstractItemModel *>(component.create());
QVERIFY(m1 != 0);
QListModelInterface *m2 = qobject_cast<QListModelInterface*>(component.create());
QAbstractItemModel *m2 = qobject_cast<QAbstractItemModel *>(component.create());
QVERIFY(m2 != 0);
QListModelInterface *m3 = qobject_cast<QListModelInterface*>(component.create());
QAbstractItemModel *m3 = qobject_cast<QAbstractItemModel *>(component.create());
QVERIFY(m3 != 0);
for (int dataCount=0; dataCount<xmlDataCount; dataCount++) {
@ -847,20 +854,29 @@ void tst_qquickxmllistmodel::threading()
m3->setProperty("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; i<dataCount; i++) {
QCOMPARE(m1->data(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"));
QModelIndex index = m1->index(i, 0);
QList<int> 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"));
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"));
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"));
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"));
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<QListModelInterface*>(component.create());
QAbstractItemModel *model = qobject_cast<QAbstractItemModel*>(component.create());
QVERIFY(model != 0);
QTRY_COMPARE(model->count(), 9);
QTRY_COMPARE(model->rowCount(), 9);
QObject *role = model->findChild<QObject*>("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<QListModelInterface*>(component.create());
QAbstractItemModel *model = qobject_cast<QAbstractItemModel *>(component.create());
QVERIFY(model != 0);
delete model;
}

View File

@ -141,148 +141,6 @@ QList<int> QQuickViewTestUtil::adjustIndexesForRemoveDisplaced(const QList<int>
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<int> QQuickViewTestUtil::QmlListModel::roles() const
{
return QList<int>() << 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<int, QVariant> QQuickViewTestUtil::QmlListModel::data(int index, const QList<int> &roles) const
{
QHash<int,QVariant> 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<QString,QString>(name, number));
emit itemsInserted(list.count()-1, 1);
}
void QQuickViewTestUtil::QmlListModel::insertItem(int index, const QString &name, const QString &number)
{
list.insert(index, QPair<QString,QString>(name, number));
emit itemsInserted(index, 1);
}
void QQuickViewTestUtil::QmlListModel::insertItems(int index, const QList<QPair<QString, QString> > &items)
{
for (int i=0; i<items.count(); i++)
list.insert(index + i, QPair<QString,QString>(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<QString,QString>(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<QPair<QString, QString> > &other, const QString &error1, const QString &error2) {
for (int i=0; i<other.count(); i++) {
QVERIFY2(list.contains(other[i]),
QTest::toString(other[i].first + " " + other[i].second + " " + error1));
}
for (int i=0; i<list.count(); i++) {
QVERIFY2(other.contains(list[i]),
QTest::toString(list[i].first + " " + list[i].second + " " + error2));
}
}
QQuickViewTestUtil::QaimModel::QaimModel(QObject *parent)
: QAbstractListModel(parent)
{
@ -392,9 +250,11 @@ void QQuickViewTestUtil::QaimModel::modifyItem(int idx, const QString &name, con
void QQuickViewTestUtil::QaimModel::clear()
{
int count = list.count();
emit beginRemoveRows(QModelIndex(), 0, count-1);
list.clear();
emit endRemoveRows();
if (count > 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<QPair<QString,QString> > QQuickViewTestUtil::ListRange::getModelDataValues(const QmlListModel &model)
{
QList<QPair<QString,QString> > data;
if (!valid)
return data;
for (int i=0; i<indexes.count(); i++)
data.append(qMakePair(model.name(indexes[i]), model.number(indexes[i])));
return data;
}
QList<QPair<QString,QString> > QQuickViewTestUtil::ListRange::getModelDataValues(const QaimModel &model)
{
QList<QPair<QString,QString> > data;

View File

@ -44,7 +44,6 @@
#include <QtQuick/QQuickItem>
#include <QtQml/QQmlExpression>
#include <QtQml/private/qlistmodelinterface_p.h>
#include <QtCore/QAbstractListModel>
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<int> roles() const;
QString toString(int role) const;
QVariant data(int index, int role) const;
QHash<int, QVariant> data(int index, const QList<int> &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<QPair<QString, QString> > &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<QPair<QString, QString> > &other, const QString &error1, const QString &error2);
private:
QList<QPair<QString,QString> > 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<QPair<QString, QString> > &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<QPair<QString,QString> > getModelDataValues(const QmlListModel &model);
QList<QPair<QString,QString> > getModelDataValues(const QaimModel &model);
QList<int> indexes;