diff options
author | Stephen Kelly <stephen.kelly@kdab.com> | 2011-11-21 13:34:24 +0100 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-11-21 14:24:36 +0100 |
commit | 100908e400be65fea74184caaee754abc3a5afcb (patch) | |
tree | 0e99ca3012c603cbbfc65f09245dba6d606bc67d /tests/auto/corelib | |
parent | 448e1e620ca206236bf6d03406fceb9b9eb20c15 (diff) |
Add a roles argument to the dataChanged signal.
This allows more granular reporting of what has changed.
This change is binary incompatible and source compatible.
Change-Id: I7c5beaee651a24780cc94e41383f7a80210bc603
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Diffstat (limited to 'tests/auto/corelib')
-rw-r--r-- | tests/auto/corelib/kernel/qabstractitemmodel/tst_qabstractitemmodel.cpp | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/tests/auto/corelib/kernel/qabstractitemmodel/tst_qabstractitemmodel.cpp b/tests/auto/corelib/kernel/qabstractitemmodel/tst_qabstractitemmodel.cpp index 5383446f22..4b09b455ad 100644 --- a/tests/auto/corelib/kernel/qabstractitemmodel/tst_qabstractitemmodel.cpp +++ b/tests/auto/corelib/kernel/qabstractitemmodel/tst_qabstractitemmodel.cpp @@ -43,6 +43,7 @@ #include <QtCore/QtCore> #include <QtWidgets/QSortFilterProxyModel> +#include <QtWidgets/QStringListModel> //TESTED_CLASS=QAbstractListModel QAbstractTableModel //TESTED_FILES= @@ -109,6 +110,8 @@ private slots: void testReset(); + void testDataChanged(); + private: DynamicTreeModel *m_model; }; @@ -1780,6 +1783,64 @@ void tst_QAbstractItemModel::testReset() } +class CustomRoleModel : public QStringListModel +{ + Q_OBJECT + Q_ENUMS(Roles) +public: + enum Roles { + Custom1 = Qt::UserRole + 1, + Custom2, + UserRole + }; + + CustomRoleModel(QObject *parent = 0) + : QStringListModel(QStringList() << "a" << "b" << "c", parent) + { + + } + + void emitSignals() + { + const QModelIndex top = index(0, 0); + const QModelIndex bottom = index(2, 0); + + emit dataChanged(top, bottom); + emit dataChanged(top, bottom, QSet<int>() << Qt::ToolTipRole); + emit dataChanged(top, bottom, QSet<int>() << Qt::ToolTipRole << Custom1); + } +}; + +Q_DECLARE_METATYPE(QSet<int>) + +void tst_QAbstractItemModel::testDataChanged() +{ + qRegisterMetaType<QSet<int> >(); + + CustomRoleModel model; + + QSignalSpy withRoles(&model, SIGNAL(dataChanged(QModelIndex,QModelIndex,QSet<int>))); + QSignalSpy withoutRoles(&model, SIGNAL(dataChanged(QModelIndex,QModelIndex))); + + model.emitSignals(); + + QCOMPARE(withRoles.size(), withoutRoles.size()); + QCOMPARE(withRoles.size(), 3); + + const QVariantList secondEmission = withRoles.at(1); + const QVariantList thirdEmission = withRoles.at(2); + + const QSet<int> secondRoles = secondEmission.at(2).value<QSet<int> >(); + const QSet<int> thirdRoles = thirdEmission.at(2).value<QSet<int> >(); + + QCOMPARE(secondRoles.size(), 1); + QVERIFY(secondRoles.contains(Qt::ToolTipRole)); + + QCOMPARE(thirdRoles.size(), 2); + QVERIFY(thirdRoles.contains(Qt::ToolTipRole)); + QVERIFY(thirdRoles.contains(CustomRoleModel::Custom1)); +} + QTEST_MAIN(tst_QAbstractItemModel) #include "tst_qabstractitemmodel.moc" |