diff options
author | Liang Qi <liang.qi@qt.io> | 2016-08-16 07:58:32 +0200 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2016-08-16 07:58:32 +0200 |
commit | 17198e03ab36e5f579a1477b09cc3e601975eb5f (patch) | |
tree | 61ba826e9edd53469abdc1e1f58b1223d0336c56 /tests/auto/corelib/itemmodels | |
parent | a5e89005445ac8ca18ac046eaf55fe2230e47cd6 (diff) | |
parent | 2e2b32a9ab459f6618d02e4b454c75a787172def (diff) |
Merge remote-tracking branch 'origin/5.7' into dev
Conflicts:
qmake/doc/src/qmake-manual.qdoc
src/corelib/global/qglobal.cpp
src/corelib/tools/qstring.cpp
src/network/socket/qabstractsocket.cpp
src/network/socket/qnativesocketengine_unix.cpp
src/plugins/platforms/eglfs/api/qeglfsglobal.h
Change-Id: Id5dfdbd30fa996f9b4b66a0b030b7d3b8c0ef288
Diffstat (limited to 'tests/auto/corelib/itemmodels')
-rw-r--r-- | tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp | 10 | ||||
-rw-r--r-- | tests/auto/corelib/itemmodels/qstringlistmodel/tst_qstringlistmodel.cpp | 77 |
2 files changed, 66 insertions, 21 deletions
diff --git a/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp b/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp index 04a7129f01..38e3c6890d 100644 --- a/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp +++ b/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp @@ -2129,17 +2129,23 @@ void tst_QSortFilterProxyModel::changeSourceDataForwardsRoles_qtbug35440() QModelIndex index; + // QStringListModel doesn't distinguish between edit and display roles, + // so changing one always changes the other, too. + QVector<int> expectedChangedRoles; + expectedChangedRoles.append(Qt::DisplayRole); + expectedChangedRoles.append(Qt::EditRole); + index = model.index(0, 0); QVERIFY(index.isValid()); model.setData(index, QStringLiteral("teststring"), Qt::DisplayRole); QCOMPARE(spy.length(), 1); - QCOMPARE(spy.at(0).at(2).value<QVector<int> >(), QVector<int>() << Qt::DisplayRole); + QCOMPARE(spy.at(0).at(2).value<QVector<int> >(), expectedChangedRoles); index = model.index(1, 0); QVERIFY(index.isValid()); model.setData(index, QStringLiteral("teststring2"), Qt::EditRole); QCOMPARE(spy.length(), 2); - QCOMPARE(spy.at(1).at(2).value<QVector<int> >(), QVector<int>() << Qt::EditRole); + QCOMPARE(spy.at(1).at(2).value<QVector<int> >(), expectedChangedRoles); } void tst_QSortFilterProxyModel::sortFilterRole() diff --git a/tests/auto/corelib/itemmodels/qstringlistmodel/tst_qstringlistmodel.cpp b/tests/auto/corelib/itemmodels/qstringlistmodel/tst_qstringlistmodel.cpp index 61dda782d8..f99241da3b 100644 --- a/tests/auto/corelib/itemmodels/qstringlistmodel/tst_qstringlistmodel.cpp +++ b/tests/auto/corelib/itemmodels/qstringlistmodel/tst_qstringlistmodel.cpp @@ -35,6 +35,8 @@ #include "qmodellistener.h" #include <qstringlistmodel.h> +#include <algorithm> + void QModelListener::rowsAboutToBeRemovedOrInserted(const QModelIndex & parent, int start, int end ) { for (int i = 0; start + i <= end; i++) { @@ -75,6 +77,9 @@ private slots: void rowsAboutToBeInserted_rowsInserted(); void rowsAboutToBeInserted_rowsInserted_data(); + + void setData_emits_both_roles_data(); + void setData_emits_both_roles(); }; void tst_QStringListModel::rowsAboutToBeRemoved_rowsRemoved_data() @@ -129,22 +134,19 @@ void tst_QStringListModel::rowsAboutToBeRemoved_rowsRemoved() QFETCH(QStringList, aboutto); QFETCH(QStringList, res); - QStringListModel *model = new QStringListModel(input); - QModelListener *pListener = new QModelListener(&aboutto, &res, model); - pListener->connect(model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)), - pListener, SLOT(rowsAboutToBeRemovedOrInserted(QModelIndex,int,int)) ); + QStringListModel model(input); + QModelListener listener(&aboutto, &res, &model); + connect(&model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)), + &listener, SLOT(rowsAboutToBeRemovedOrInserted(QModelIndex,int,int))); - pListener->connect(model, SIGNAL(rowsRemoved(QModelIndex,int,int)), - pListener, SLOT(rowsRemovedOrInserted(QModelIndex,int,int)) ); + connect(&model, SIGNAL(rowsRemoved(QModelIndex,int,int)), + &listener, SLOT(rowsRemovedOrInserted(QModelIndex,int,int))); - model->removeRows(row,count); + model.removeRows(row, count); // At this point, control goes to our connected slots inn this order: // 1. rowsAboutToBeRemovedOrInserted // 2. rowsRemovedOrInserted // Control returns here - - delete pListener; - delete model; } void tst_QStringListModel::rowsAboutToBeInserted_rowsInserted_data() @@ -193,22 +195,59 @@ void tst_QStringListModel::rowsAboutToBeInserted_rowsInserted() QFETCH(QStringList, aboutto); QFETCH(QStringList, res); - QStringListModel *model = new QStringListModel(input); - QModelListener *pListener = new QModelListener(&aboutto, &res, model); - connect(model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)), - pListener, SLOT(rowsAboutToBeRemovedOrInserted(QModelIndex,int,int)) ); + QStringListModel model(input); + QModelListener listener(&aboutto, &res, &model); + connect(&model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)), + &listener, SLOT(rowsAboutToBeRemovedOrInserted(QModelIndex,int,int))); - connect(model, SIGNAL(rowsInserted(QModelIndex,int,int)), - pListener, SLOT(rowsRemovedOrInserted(QModelIndex,int,int)) ); + connect(&model, SIGNAL(rowsInserted(QModelIndex,int,int)), + &listener, SLOT(rowsRemovedOrInserted(QModelIndex,int,int))); - model->insertRows(row,count); + model.insertRows(row, count); // At this point, control goes to our connected slots inn this order: // 1. rowsAboutToBeRemovedOrInserted // 2. rowsRemovedOrInserted // Control returns here +} - delete pListener; - delete model; +void tst_QStringListModel::setData_emits_both_roles_data() +{ + QTest::addColumn<int>("row"); + QTest::addColumn<QString>("data"); + QTest::addColumn<int>("role"); + +#define ROW(row, string, role) \ + QTest::newRow(#row " -> " string) << row << QString(string) << int(Qt::role) + ROW(0, "1", EditRole); + ROW(1, "2", DisplayRole); +#undef ROW +} + +template <class C> +C sorted(C c) +{ + std::sort(c.begin(), c.end()); + return qMove(c); +} + +void tst_QStringListModel::setData_emits_both_roles() +{ + QFETCH(int, row); + QFETCH(QString, data); + QFETCH(int, role); + + QStringListModel model(QStringList() << "one" << "two"); + QVector<int> expected; + expected.reserve(2); + expected.append(Qt::DisplayRole); + expected.append(Qt::EditRole); + + QSignalSpy spy(&model, &QAbstractItemModel::dataChanged); + QVERIFY(spy.isValid()); + model.setData(model.index(row, 0), data, role); + QCOMPARE(spy.size(), 1); + QCOMPARE(sorted(spy.at(0).at(2).value<QVector<int> >()), + expected); } QTEST_MAIN(tst_QStringListModel) |