Skip to content
Permalink
Browse files
Remove QListModelInterface.
Implement ListModel and XmlListModel using QAbstractListModel
instead.

Task-number: QTBUG-15728

Change-Id: I14e03d90883d341f4b1d89c1e9fc9dc1534fde78
Reviewed-by: Glenn Watson <glenn.watson@nokia.com>
  • Loading branch information
Andrew den Exter authored and Qt by Nokia committed Jul 25, 2012
1 parent b355aac commit 7daab8039abc32ab5be5706a08cb58905fe0e0b6
Showing with 426 additions and 974 deletions.
  1. +55 −44 src/imports/xmllistmodel/qqmlxmllistmodel.cpp
  2. +8 −8 src/imports/xmllistmodel/qqmlxmllistmodel_p.h
  3. +0 −104 src/qml/qml/qlistmodelinterface.cpp
  4. +0 −83 src/qml/qml/qlistmodelinterface_p.h
  5. +0 −2 src/qml/qml/qml.pri
  6. +63 −43 src/qml/qml/qquicklistmodel.cpp
  7. +10 −7 src/qml/qml/qquicklistmodel_p.h
  8. +3 −3 src/qml/qml/qquicklistmodel_p_p.h
  9. +21 −8 src/qml/qml/qquicklistmodelworkeragent.cpp
  10. +2 −2 src/qml/qml/qquicklistmodelworkeragent_p.h
  11. +0 −1 src/quick/items/qquickgridview.cpp
  12. +0 −1 src/quick/items/qquickitem.cpp
  13. +0 −1 src/quick/items/qquicklistview.cpp
  14. +0 −1 src/quick/items/qquickpathview.cpp
  15. +0 −1 src/quick/items/qquickrepeater.cpp
  16. +5 −135 src/quick/items/qquickvisualadaptormodel.cpp
  17. +2 −6 src/quick/items/qquickvisualadaptormodel_p.h
  18. +4 −4 src/quick/items/qquickvisualdatamodel.cpp
  19. +2 −2 src/quick/items/qquickvisualdatamodel_p.h
  20. +25 −34 tests/auto/qml/qquicklistmodel/tst_qquicklistmodel.cpp
  21. +19 −28 tests/auto/qml/qquicklistmodelworkerscript/tst_qquicklistmodelworkerscript.cpp
  22. +7 −7 tests/auto/quick/qquickgridview/tst_qquickgridview.cpp
  23. +60 −131 tests/auto/quick/qquicklistview/tst_qquicklistview.cpp
  24. +0 −1 tests/auto/quick/qquickpositioners/tst_qquickpositioners.cpp
  25. +0 −1 tests/auto/quick/qquickrepeater/tst_qquickrepeater.cpp
  26. +5 −5 tests/auto/quick/qquickvisualdatamodel/tst_qquickvisualdatamodel.cpp
  27. +129 −113 tests/auto/quick/qquickxmllistmodel/tst_qquickxmllistmodel.cpp
  28. +5 −155 tests/auto/quick/shared/viewtestutil.cpp
  29. +1 −43 tests/auto/quick/shared/viewtestutil.h
@@ -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,48 +734,46 @@ 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;
}

/*!
\qmlproperty int QtQuick.XmlListModel2::XmlListModel::count
The number of data entries in the model.
*/
int QQuickXmlListModel::count() const
QVariant QQuickXmlListModel::data(const QModelIndex &index, int role) const
{
Q_D(const QQuickXmlListModel);
return d->size;
const int roleIndex = d->roles.indexOf(role);
return (roleIndex == -1 || !index.isValid())
? QVariant()
: d->data.value(roleIndex).value(index.row());
}

QList<int> QQuickXmlListModel::roles() const
QHash<int, QByteArray> QQuickXmlListModel::roleNames() const
{
Q_D(const QQuickXmlListModel);
return d->roles;
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;
}

QString QQuickXmlListModel::toString(int role) const
/*!
\qmlproperty int QtQuick.XmlListModel2::XmlListModel::count
The number of data entries in the model.
*/
int QQuickXmlListModel::count() const
{
Q_D(const QQuickXmlListModel);
int index = d->roles.indexOf(role);
if (index == -1)
return QString();
return d->roleNames.at(index);
return d->size;
}

/*!
@@ -1071,11 +1069,11 @@ void QQuickXmlListModel::requestFinished()
d->errorString = d->reply->errorString();
d->deleteReply();

int count = this->count();
d->data.clear();
d->size = 0;
if (count > 0) {
emit itemsRemoved(0, count);
if (d->size > 0) {
beginRemoveRows(QModelIndex(), 0, d->size - 1);
d->data.clear();
d->size = 0;
endRemoveRows();
emit countChanged();
}

@@ -1157,21 +1155,34 @@ void QQuickXmlListModel::queryCompleted(const QQuickXmlQueryResult &result)
}
}
if (!hasKeys) {
if (!(origCount == 0 && d->size == 0)) {
emit itemsRemoved(0, origCount);
emit itemsInserted(0, d->size);
emit countChanged();
if (origCount > 0) {
beginRemoveRows(QModelIndex(), 0, origCount - 1);
endRemoveRows();
}
if (d->size > 0) {
beginInsertRows(QModelIndex(), 0, d->size - 1);
endInsertRows();
}

} else {
for (int i=0; i<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);
}
@@ -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 @@ class QQuickXmlListModel : public QListModelInterface, public QQmlParserStatus
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();

This file was deleted.

This file was deleted.

0 comments on commit 7daab80

Please sign in to comment.