From 613d0e407e80f6439951597592523ac772f4c87c Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Fri, 23 Dec 2011 13:13:08 +1000 Subject: [PATCH] Cleanup itemmodel autotests. Bring the code closer to compliance with Qt's coding style guidelines and eliminate excessive vertical whitespace. Change-Id: Iaa29f8edf326ddb80cbadb6c18cca4fea88fd9b2 Reviewed-by: Rohan McGovern --- .../qabstractitemmodel/tst_qabstractitemmodel.cpp | 311 ++++------- .../tst_qabstractproxymodel.cpp | 26 +- .../tst_qidentityproxymodel.cpp | 3 - .../qitemselectionmodel/qitemselectionmodel.pro | 2 - .../tst_qitemselectionmodel.cpp | 584 ++++++++++----------- .../tst_qsortfilterproxymodel.cpp | 213 ++++---- .../itemmodels/qstringlistmodel/qmodellistener.h | 5 +- .../qstringlistmodel/qstringlistmodel.pro | 6 +- .../qstringlistmodel/tst_qstringlistmodel.cpp | 30 +- 9 files changed, 530 insertions(+), 650 deletions(-) diff --git a/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp b/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp index 5028728..88b6139 100644 --- a/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp +++ b/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp @@ -682,7 +682,6 @@ void tst_QAbstractItemModel::dropMimeData() } } - void tst_QAbstractItemModel::changePersistentIndex() { QtTestModel model(3, 3); @@ -843,7 +842,6 @@ void tst_QAbstractItemModel::complexChangesWithPersistent() QVERIFY(!e[i].isValid()); for (int i=6; i <10 ; i++) QVERIFY(e[i] == model.index(2, i-2 , QModelIndex())); - } void tst_QAbstractItemModel::testMoveSameParentDown_data() @@ -871,20 +869,18 @@ void tst_QAbstractItemModel::testMoveSameParentDown_data() void tst_QAbstractItemModel::testMoveSameParentDown() { - QFETCH( int, startRow); - QFETCH( int, endRow); - QFETCH( int, destRow); - QFETCH( bool, topLevel); + QFETCH(int, startRow); + QFETCH(int, endRow); + QFETCH(int, destRow); + QFETCH(bool, topLevel); QModelIndex moveParent = topLevel ? QModelIndex() : m_model->index(5, 0); QList persistentList; QModelIndexList indexList; - for (int column = 0; column < m_model->columnCount(); ++column) - { - for (int row= 0; row < m_model->rowCount(); ++row) - { + for (int column = 0; column < m_model->columnCount(); ++column) { + for (int row = 0; row < m_model->rowCount(); ++row) { QModelIndex idx = m_model->index(row, column); QVERIFY(idx.isValid()); indexList << idx; @@ -893,10 +889,8 @@ void tst_QAbstractItemModel::testMoveSameParentDown() } QModelIndex parent = m_model->index(5, 0); - for (int column = 0; column < m_model->columnCount(); ++column) - { - for (int row= 0; row < m_model->rowCount(parent); ++row) - { + for (int column = 0; column < m_model->columnCount(); ++column) { + for (int row = 0; row < m_model->rowCount(parent); ++row) { QModelIndex idx = m_model->index(row, column, parent); QVERIFY(idx.isValid()); indexList << idx; @@ -938,37 +932,29 @@ void tst_QAbstractItemModel::testMoveSameParentDown() QCOMPARE(afterSignal.at(3).value(), moveParent); QCOMPARE(afterSignal.at(4).toInt(), destRow); - for (int i = 0; i < indexList.size(); i++) - { + for (int i = 0; i < indexList.size(); i++) { QModelIndex idx = indexList.at(i); QModelIndex persistentIndex = persistentList.at(i); - if (idx.parent() == moveParent) - { + if (idx.parent() == moveParent) { int row = idx.row(); - if ( row >= startRow) - { - if (row <= endRow) - { - QCOMPARE(row + destRow - endRow - 1, persistentIndex.row() ); + if ( row >= startRow) { + if (row <= endRow) { + QCOMPARE(row + destRow - endRow - 1, persistentIndex.row()); QCOMPARE(idx.column(), persistentIndex.column()); QCOMPARE(idx.parent(), persistentIndex.parent()); QCOMPARE(idx.model(), persistentIndex.model()); - } else if ( row < destRow) - { - QCOMPARE(row - (endRow - startRow + 1), persistentIndex.row() ); + } else if (row < destRow) { + QCOMPARE(row - (endRow - startRow + 1), persistentIndex.row()); QCOMPARE(idx.column(), persistentIndex.column()); QCOMPARE(idx.parent(), persistentIndex.parent()); QCOMPARE(idx.model(), persistentIndex.model()); - } else - { - QCOMPARE(idx, persistentIndex); + } else { + QCOMPARE(idx, persistentIndex); } - } else - { + } else { QCOMPARE(idx, persistentIndex); } - } else - { + } else { QCOMPARE(idx, persistentIndex); } } @@ -998,21 +984,18 @@ void tst_QAbstractItemModel::testMoveSameParentUp_data() void tst_QAbstractItemModel::testMoveSameParentUp() { - - QFETCH( int, startRow); - QFETCH( int, endRow); - QFETCH( int, destRow); - QFETCH( bool, topLevel); + QFETCH(int, startRow); + QFETCH(int, endRow); + QFETCH(int, destRow); + QFETCH(bool, topLevel); QModelIndex moveParent = topLevel ? QModelIndex() : m_model->index(5, 0); QList persistentList; QModelIndexList indexList; - for (int column = 0; column < m_model->columnCount(); ++column) - { - for (int row= 0; row < m_model->rowCount(); ++row) - { + for (int column = 0; column < m_model->columnCount(); ++column) { + for (int row = 0; row < m_model->rowCount(); ++row) { QModelIndex idx = m_model->index(row, column); QVERIFY(idx.isValid()); indexList << idx; @@ -1021,10 +1004,8 @@ void tst_QAbstractItemModel::testMoveSameParentUp() } QModelIndex parent = m_model->index(2, 0); - for (int column = 0; column < m_model->columnCount(); ++column) - { - for (int row= 0; row < m_model->rowCount(parent); ++row) - { + for (int column = 0; column < m_model->columnCount(); ++column) { + for (int row = 0; row < m_model->rowCount(parent); ++row) { QModelIndex idx = m_model->index(row, column, parent); QVERIFY(idx.isValid()); indexList << idx; @@ -1066,38 +1047,29 @@ void tst_QAbstractItemModel::testMoveSameParentUp() QCOMPARE(afterSignal.at(3).value(), moveParent); QCOMPARE(afterSignal.at(4).toInt(), destRow); - - for (int i = 0; i < indexList.size(); i++) - { + for (int i = 0; i < indexList.size(); i++) { QModelIndex idx = indexList.at(i); QModelIndex persistentIndex = persistentList.at(i); - if (idx.parent() == moveParent) - { + if (idx.parent() == moveParent) { int row = idx.row(); - if ( row >= destRow) - { - if (row < startRow) - { - QCOMPARE(row + endRow - startRow + 1, persistentIndex.row() ); + if ( row >= destRow) { + if (row < startRow) { + QCOMPARE(row + endRow - startRow + 1, persistentIndex.row()); QCOMPARE(idx.column(), persistentIndex.column()); QCOMPARE(idx.parent(), persistentIndex.parent()); QCOMPARE(idx.model(), persistentIndex.model()); - } else if ( row <= endRow) - { - QCOMPARE(row + destRow - startRow, persistentIndex.row() ); + } else if (row <= endRow) { + QCOMPARE(row + destRow - startRow, persistentIndex.row()); QCOMPARE(idx.column(), persistentIndex.column()); QCOMPARE(idx.parent(), persistentIndex.parent()); QCOMPARE(idx.model(), persistentIndex.model()); - } else - { + } else { QCOMPARE(idx, persistentIndex); } - } else - { + } else { QCOMPARE(idx, persistentIndex); } - } else - { + } else { QCOMPARE(idx, persistentIndex); } } @@ -1161,19 +1133,16 @@ void tst_QAbstractItemModel::testMoveToGrandParent_data() void tst_QAbstractItemModel::testMoveToGrandParent() { - - QFETCH( int, startRow); - QFETCH( int, endRow); - QFETCH( int, destRow); + QFETCH(int, startRow); + QFETCH(int, endRow); + QFETCH(int, destRow); QList persistentList; QModelIndexList indexList; QModelIndexList parentsList; - for (int column = 0; column < m_model->columnCount(); ++column) - { - for (int row= 0; row < m_model->rowCount(); ++row) - { + for (int column = 0; column < m_model->columnCount(); ++column) { + for (int row = 0; row < m_model->rowCount(); ++row) { QModelIndex idx = m_model->index(row, column); QVERIFY(idx.isValid()); indexList << idx; @@ -1183,10 +1152,8 @@ void tst_QAbstractItemModel::testMoveToGrandParent() } QModelIndex sourceIndex = m_model->index(5, 0); - for (int column = 0; column < m_model->columnCount(); ++column) - { - for (int row= 0; row < m_model->rowCount(sourceIndex); ++row) - { + for (int column = 0; column < m_model->columnCount(); ++column) { + for (int row = 0; row < m_model->rowCount(sourceIndex); ++row) { QModelIndex idx = m_model->index(row, column, sourceIndex); QVERIFY(idx.isValid()); indexList << idx; @@ -1228,46 +1195,37 @@ void tst_QAbstractItemModel::testMoveToGrandParent() QCOMPARE(afterSignal.at(3).value(), QModelIndex()); QCOMPARE(afterSignal.at(4).toInt(), destRow); - for (int i = 0; i < indexList.size(); i++) - { + for (int i = 0; i < indexList.size(); i++) { QModelIndex idx = indexList.at(i); QModelIndex idxParent = parentsList.at(i); QModelIndex persistentIndex = persistentList.at(i); int row = idx.row(); - if (idxParent == QModelIndex()) - { - if ( row >= destRow) - { - QCOMPARE(row + endRow - startRow + 1, persistentIndex.row() ); - QCOMPARE(idx.column(), persistentIndex.column()); - QCOMPARE(idxParent, persistentIndex.parent()); - QCOMPARE(idx.model(), persistentIndex.model()); - } else - { + if (idxParent == QModelIndex()) { + if (row >= destRow) { + QCOMPARE(row + endRow - startRow + 1, persistentIndex.row()); + QCOMPARE(idx.column(), persistentIndex.column()); + QCOMPARE(idxParent, persistentIndex.parent()); + QCOMPARE(idx.model(), persistentIndex.model()); + } else { QCOMPARE(idx, persistentIndex); } - } else - { - if (row < startRow) - { + } else { + if (row < startRow) { QCOMPARE(idx, persistentIndex); - } else if (row <= endRow) - { - QCOMPARE(row + destRow - startRow, persistentIndex.row() ); + } else if (row <= endRow) { + QCOMPARE(row + destRow - startRow, persistentIndex.row()); QCOMPARE(idx.column(), persistentIndex.column()); QCOMPARE(QModelIndex(), persistentIndex.parent()); QCOMPARE(idx.model(), persistentIndex.model()); } else { - QCOMPARE(row - (endRow - startRow + 1), persistentIndex.row() ); + QCOMPARE(row - (endRow - startRow + 1), persistentIndex.row()); QCOMPARE(idx.column(), persistentIndex.column()); - if (idxParent.row() >= destRow) - { + if (idxParent.row() >= destRow) { QModelIndex adjustedParent; - adjustedParent = idxParent.sibling( idxParent.row() + endRow - startRow + 1, idxParent.column()); + adjustedParent = idxParent.sibling(idxParent.row() + endRow - startRow + 1, idxParent.column()); QCOMPARE(adjustedParent, persistentIndex.parent()); - } else - { + } else { QCOMPARE(idxParent, persistentIndex.parent()); } QCOMPARE(idx.model(), persistentIndex.model()); @@ -1316,10 +1274,9 @@ void tst_QAbstractItemModel::testMoveToSibling_data() void tst_QAbstractItemModel::testMoveToSibling() { - - QFETCH( int, startRow); - QFETCH( int, endRow); - QFETCH( int, destRow); + QFETCH(int, startRow); + QFETCH(int, endRow); + QFETCH(int, destRow); QList persistentList; QModelIndexList indexList; @@ -1327,8 +1284,7 @@ void tst_QAbstractItemModel::testMoveToSibling() const int column = 0; - for (int i= 0; i < m_model->rowCount(); ++i) - { + for (int i = 0; i < m_model->rowCount(); ++i) { QModelIndex idx = m_model->index(i, column); QVERIFY(idx.isValid()); indexList << idx; @@ -1338,8 +1294,7 @@ void tst_QAbstractItemModel::testMoveToSibling() QModelIndex destIndex = m_model->index(5, 0); QModelIndex sourceIndex; - for (int i= 0; i < m_model->rowCount(destIndex); ++i) - { + for (int i = 0; i < m_model->rowCount(destIndex); ++i) { QModelIndex idx = m_model->index(i, column, destIndex); QVERIFY(idx.isValid()); indexList << idx; @@ -1380,51 +1335,41 @@ void tst_QAbstractItemModel::testMoveToSibling() QCOMPARE(afterSignal.at(3).value(), static_cast(persistentDest)); QCOMPARE(afterSignal.at(4).toInt(), destRow); - for (int i = 0; i < indexList.size(); i++) - { + for (int i = 0; i < indexList.size(); i++) { QModelIndex idx = indexList.at(i); QModelIndex idxParent = parentsList.at(i); QModelIndex persistentIndex = persistentList.at(i); QModelIndex adjustedDestination = destIndex.sibling(destIndex.row() - (endRow - startRow + 1), destIndex.column()); int row = idx.row(); - if (idxParent == destIndex) - { - if ( row >= destRow) - { - QCOMPARE(row + endRow - startRow + 1, persistentIndex.row() ); - QCOMPARE(idx.column(), persistentIndex.column()); - if (idxParent.row() > startRow) - { - QCOMPARE(adjustedDestination, persistentIndex.parent()); - } else { - QCOMPARE(destIndex, persistentIndex.parent()); - } - QCOMPARE(idx.model(), persistentIndex.model()); - } else - { + if (idxParent == destIndex) { + if (row >= destRow) { + QCOMPARE(row + endRow - startRow + 1, persistentIndex.row()); + QCOMPARE(idx.column(), persistentIndex.column()); + if (idxParent.row() > startRow) { + QCOMPARE(adjustedDestination, persistentIndex.parent()); + } else { + QCOMPARE(destIndex, persistentIndex.parent()); + } + QCOMPARE(idx.model(), persistentIndex.model()); + } else { QCOMPARE(idx, persistentIndex); } - } else - { - if (row < startRow) - { + } else { + if (row < startRow) { QCOMPARE(idx, persistentIndex); - } else if (row <= endRow) - { - QCOMPARE(row + destRow - startRow, persistentIndex.row() ); + } else if (row <= endRow) { + QCOMPARE(row + destRow - startRow, persistentIndex.row()); QCOMPARE(idx.column(), persistentIndex.column()); - if (destIndex.row() > startRow) - { + if (destIndex.row() > startRow) { QCOMPARE(adjustedDestination, persistentIndex.parent()); } else { QCOMPARE(destIndex, persistentIndex.parent()); } QCOMPARE(idx.model(), persistentIndex.model()); - } else { - QCOMPARE(row - (endRow - startRow + 1), persistentIndex.row() ); + QCOMPARE(row - (endRow - startRow + 1), persistentIndex.row()); QCOMPARE(idx.column(), persistentIndex.column()); QCOMPARE(idxParent, persistentIndex.parent()); QCOMPARE(idx.model(), persistentIndex.model()); @@ -1435,7 +1380,6 @@ void tst_QAbstractItemModel::testMoveToSibling() void tst_QAbstractItemModel::testMoveToUncle_data() { - QTest::addColumn("startRow"); QTest::addColumn("endRow"); QTest::addColumn("destRow"); @@ -1480,9 +1424,9 @@ void tst_QAbstractItemModel::testMoveToUncle() insertCommand->setEndRow(9); insertCommand->doCommand(); - QFETCH( int, startRow); - QFETCH( int, endRow); - QFETCH( int, destRow); + QFETCH(int, startRow); + QFETCH(int, endRow); + QFETCH(int, destRow); QList persistentList; QModelIndexList indexList; @@ -1491,8 +1435,7 @@ void tst_QAbstractItemModel::testMoveToUncle() const int column = 0; QModelIndex sourceIndex = m_model->index(9, 0); - for (int i= 0; i < m_model->rowCount(sourceIndex); ++i) - { + for (int i = 0; i < m_model->rowCount(sourceIndex); ++i) { QModelIndex idx = m_model->index(i, column, sourceIndex); QVERIFY(idx.isValid()); indexList << idx; @@ -1501,8 +1444,7 @@ void tst_QAbstractItemModel::testMoveToUncle() } QModelIndex destIndex = m_model->index(5, 0); - for (int i= 0; i < m_model->rowCount(destIndex); ++i) - { + for (int i = 0; i < m_model->rowCount(destIndex); ++i) { QModelIndex idx = m_model->index(i, column, destIndex); QVERIFY(idx.isValid()); indexList << idx; @@ -1542,39 +1484,31 @@ void tst_QAbstractItemModel::testMoveToUncle() QCOMPARE(afterSignal.at(3).value(), destIndex); QCOMPARE(afterSignal.at(4).toInt(), destRow); - for (int i = 0; i < indexList.size(); i++) - { + for (int i = 0; i < indexList.size(); i++) { QModelIndex idx = indexList.at(i); QModelIndex idxParent = parentsList.at(i); QModelIndex persistentIndex = persistentList.at(i); int row = idx.row(); - if (idxParent == destIndex) - { - if ( row >= destRow) - { - QCOMPARE(row + endRow - startRow + 1, persistentIndex.row() ); - QCOMPARE(idx.column(), persistentIndex.column()); - QCOMPARE(destIndex, persistentIndex.parent()); - QCOMPARE(idx.model(), persistentIndex.model()); - } else - { + if (idxParent == destIndex) { + if (row >= destRow) { + QCOMPARE(row + endRow - startRow + 1, persistentIndex.row()); + QCOMPARE(idx.column(), persistentIndex.column()); + QCOMPARE(destIndex, persistentIndex.parent()); + QCOMPARE(idx.model(), persistentIndex.model()); + } else { QCOMPARE(idx, persistentIndex); } - } else - { - if (row < startRow) - { + } else { + if (row < startRow) { QCOMPARE(idx, persistentIndex); - } else if (row <= endRow) - { - QCOMPARE(row + destRow - startRow, persistentIndex.row() ); + } else if (row <= endRow) { + QCOMPARE(row + destRow - startRow, persistentIndex.row()); QCOMPARE(idx.column(), persistentIndex.column()); QCOMPARE(destIndex, persistentIndex.parent()); QCOMPARE(idx.model(), persistentIndex.model()); - } else { - QCOMPARE(row - (endRow - startRow + 1), persistentIndex.row() ); + QCOMPARE(row - (endRow - startRow + 1), persistentIndex.row()); QCOMPARE(idx.column(), persistentIndex.column()); QCOMPARE(idxParent, persistentIndex.parent()); QCOMPARE(idx.model(), persistentIndex.model()); @@ -1591,8 +1525,7 @@ void tst_QAbstractItemModel::testMoveToDescendants() // Need to have some extra rows available in a tree. QList rows; ModelInsertCommand *insertCommand; - for (int i = 0; i < depth; i++) - { + for (int i = 0; i < depth; i++) { insertCommand = new ModelInsertCommand(m_model, this); insertCommand->setAncestorRowNumbers(rows); insertCommand->setNumCols(4); @@ -1609,8 +1542,7 @@ void tst_QAbstractItemModel::testMoveToDescendants() const int column = 0; QModelIndex sourceIndex = m_model->index(9, 0); - for (int i= 0; i < m_model->rowCount(sourceIndex); ++i) - { + for (int i = 0; i < m_model->rowCount(sourceIndex); ++i) { QModelIndex idx = m_model->index(i, column, sourceIndex); QVERIFY(idx.isValid()); indexList << idx; @@ -1619,8 +1551,7 @@ void tst_QAbstractItemModel::testMoveToDescendants() } QModelIndex destIndex = m_model->index(5, 0); - for (int i= 0; i < m_model->rowCount(destIndex); ++i) - { + for (int i = 0; i < m_model->rowCount(destIndex); ++i) { QModelIndex idx = m_model->index(i, column, destIndex); QVERIFY(idx.isValid()); indexList << idx; @@ -1636,11 +1567,9 @@ void tst_QAbstractItemModel::testMoveToDescendants() ModelMoveCommand *moveCommand; QList ancestors; - while (ancestors.size() < depth) - { + while (ancestors.size() < depth) { ancestors << 9; - for (int row = 0; row <= 9; row++) - { + for (int row = 0; row <= 9; row++) { moveCommand = new ModelMoveCommand(m_model, this); moveCommand->setNumCols(4); moveCommand->setStartRow(9); @@ -1686,16 +1615,13 @@ void tst_QAbstractItemModel::testMoveWithinOwnRange_data() QTest::newRow("move20") << 8 << 9 << 10; QTest::newRow("move21") << 9 << 9 << 9; QTest::newRow("move22") << 0 << 9 << 10; - } void tst_QAbstractItemModel::testMoveWithinOwnRange() { - - QFETCH( int, startRow); - QFETCH( int, endRow); - QFETCH( int, destRow); - + QFETCH(int, startRow); + QFETCH(int, endRow); + QFETCH(int, destRow); QSignalSpy beforeSpy(m_model, SIGNAL(rowsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int))); QSignalSpy afterSpy(m_model, SIGNAL(rowsMoved(const QModelIndex &, int, int, const QModelIndex &, int))); @@ -1712,13 +1638,11 @@ void tst_QAbstractItemModel::testMoveWithinOwnRange() QVERIFY(beforeSpy.size() == 0); QVERIFY(afterSpy.size() == 0); - - } class ListenerObject : public QObject { - Q_OBJECT + Q_OBJECT public: ListenerObject(QAbstractProxyModel *parent); @@ -1750,14 +1674,11 @@ void ListenerObject::fillIndexStores(const QModelIndex &parent) const int column = 0; int row = 0; QModelIndex idx = m_model->index(row, column, parent); - while (idx.isValid()) - { + while (idx.isValid()) { m_persistentIndexes << QPersistentModelIndex(idx); m_nonPersistentIndexes << idx; if (m_model->hasChildren(idx)) - { fillIndexStores(idx); - } ++row; idx = m_model->index(row, column, parent); } @@ -1766,8 +1687,7 @@ void ListenerObject::fillIndexStores(const QModelIndex &parent) void ListenerObject::slotAboutToBeReset() { // Nothing has been changed yet. All indexes should be the same. - for (int i = 0; i < m_persistentIndexes.size(); ++i) - { + for (int i = 0; i < m_persistentIndexes.size(); ++i) { QModelIndex idx = m_persistentIndexes.at(i); QVERIFY(idx == m_nonPersistentIndexes.at(i)); QVERIFY(m_model->mapToSource(idx).isValid()); @@ -1776,13 +1696,11 @@ void ListenerObject::slotAboutToBeReset() void ListenerObject::slotReset() { - foreach(const QModelIndex &idx, m_persistentIndexes) - { + foreach (const QModelIndex &idx, m_persistentIndexes) { QVERIFY(!idx.isValid()); } } - void tst_QAbstractItemModel::testReset() { QSignalSpy beforeResetSpy(m_model, SIGNAL(modelAboutToBeReset())); @@ -1814,7 +1732,6 @@ void tst_QAbstractItemModel::testReset() QVERIFY(m_model->rowCount() == 9); QModelIndex destIndex = m_model->index(4, 0); QVERIFY(m_model->rowCount(destIndex) == 11); - } class CustomRoleModel : public QStringListModel @@ -1831,7 +1748,6 @@ public: CustomRoleModel(QObject *parent = 0) : QStringListModel(QStringList() << "a" << "b" << "c", parent) { - } void emitSignals() @@ -1991,7 +1907,6 @@ void tst_QAbstractItemModel::testChildrenLayoutsChanged() QVERIFY(p1LastPersistent.row() == 0); QVERIFY(p2FirstPersistent.row() == 9); QVERIFY(p2LastPersistent.row() == 8); - } insertCommand = new ModelInsertCommand(&model, this); diff --git a/tests/auto/corelib/itemmodels/qabstractproxymodel/tst_qabstractproxymodel.cpp b/tests/auto/corelib/itemmodels/qabstractproxymodel/tst_qabstractproxymodel.cpp index 9373307..d99512e 100644 --- a/tests/auto/corelib/itemmodels/qabstractproxymodel/tst_qabstractproxymodel.cpp +++ b/tests/auto/corelib/itemmodels/qabstractproxymodel/tst_qabstractproxymodel.cpp @@ -39,7 +39,6 @@ ** ****************************************************************************/ - #include #include #include @@ -330,18 +329,18 @@ public: class AnotherStandardItemModelWithCustomRoleNames : public QStandardItemModel { - public: - enum CustomRole { - AnotherCustomRole1 = Qt::UserRole + 10, // Different to StandardItemModelWithCustomRoleNames::CustomRole1 - AnotherCustomRole2 - }; - - AnotherStandardItemModelWithCustomRoleNames() { - QHash _roleNames = roleNames(); - _roleNames.insert(AnotherCustomRole1, "another_custom1"); - _roleNames.insert(AnotherCustomRole2, "another_custom2"); - setRoleNames(_roleNames); - } +public: + enum CustomRole { + AnotherCustomRole1 = Qt::UserRole + 10, // Different to StandardItemModelWithCustomRoleNames::CustomRole1 + AnotherCustomRole2 + }; + + AnotherStandardItemModelWithCustomRoleNames() { + QHash _roleNames = roleNames(); + _roleNames.insert(AnotherCustomRole1, "another_custom1"); + _roleNames.insert(AnotherCustomRole2, "another_custom2"); + setRoleNames(_roleNames); + } }; /** @@ -390,7 +389,6 @@ void tst_QAbstractProxyModel::testRoleNames() QVERIFY( proxy2RoleNames.contains(StandardItemModelWithCustomRoleNames::CustomRole2)); QVERIFY( proxy2RoleNames.value(StandardItemModelWithCustomRoleNames::CustomRole1) == "custom1" ); QVERIFY( proxy2RoleNames.value(StandardItemModelWithCustomRoleNames::CustomRole2) == "custom2" ); - } QTEST_MAIN(tst_QAbstractProxyModel) diff --git a/tests/auto/corelib/itemmodels/qidentityproxymodel/tst_qidentityproxymodel.cpp b/tests/auto/corelib/itemmodels/qidentityproxymodel/tst_qidentityproxymodel.cpp index 9e00870..ec59bcd 100644 --- a/tests/auto/corelib/itemmodels/qidentityproxymodel/tst_qidentityproxymodel.cpp +++ b/tests/auto/corelib/itemmodels/qidentityproxymodel/tst_qidentityproxymodel.cpp @@ -39,7 +39,6 @@ ** ****************************************************************************/ - #include #include #include @@ -79,7 +78,6 @@ private: tst_QIdentityProxyModel::tst_QIdentityProxyModel() : m_model(0), m_proxy(0) { - } void tst_QIdentityProxyModel::initTestCase() @@ -177,7 +175,6 @@ void tst_QIdentityProxyModel::insertRows() QVERIFY(modelAfterSpy.first().at(2) == proxyAfterSpy.first().at(2)); verifyIdentity(m_model); - } void tst_QIdentityProxyModel::removeRows() diff --git a/tests/auto/corelib/itemmodels/qitemselectionmodel/qitemselectionmodel.pro b/tests/auto/corelib/itemmodels/qitemselectionmodel/qitemselectionmodel.pro index a4c7ba3..aff9b31 100644 --- a/tests/auto/corelib/itemmodels/qitemselectionmodel/qitemselectionmodel.pro +++ b/tests/auto/corelib/itemmodels/qitemselectionmodel/qitemselectionmodel.pro @@ -2,5 +2,3 @@ CONFIG += testcase TARGET = tst_qitemselectionmodel QT += widgets testlib SOURCES += tst_qitemselectionmodel.cpp - - diff --git a/tests/auto/corelib/itemmodels/qitemselectionmodel/tst_qitemselectionmodel.cpp b/tests/auto/corelib/itemmodels/qitemselectionmodel/tst_qitemselectionmodel.cpp index 6d2de19..12d0301 100644 --- a/tests/auto/corelib/itemmodels/qitemselectionmodel/tst_qitemselectionmodel.cpp +++ b/tests/auto/corelib/itemmodels/qitemselectionmodel/tst_qitemselectionmodel.cpp @@ -39,7 +39,6 @@ ** ****************************************************************************/ - #include #include @@ -114,7 +113,6 @@ typedef QList IntList; typedef QPair IntPair; typedef QList PairList; - Q_DECLARE_METATYPE(PairList) Q_DECLARE_METATYPE(QModelIndex) Q_DECLARE_METATYPE(QModelIndexList) @@ -184,7 +182,8 @@ QDataStream &operator>>(QDataStream &s, QModelIndexList &output) return s; } -tst_QItemSelectionModel::tst_QItemSelectionModel() : model(0), selection(0) +tst_QItemSelectionModel::tst_QItemSelectionModel() + : model(0), selection(0) { } @@ -315,7 +314,7 @@ void tst_QItemSelectionModel::clearAndSelect() // populate selectionmodel selection->select(model->index(1, 1, QModelIndex()), QItemSelectionModel::Select); QCOMPARE(selection->selectedIndexes().count(), 1); - QVERIFY(selection->hasSelection()); + QVERIFY(selection->hasSelection()); // ClearAndSelect with empty selection QItemSelection emptySelection; @@ -323,40 +322,38 @@ void tst_QItemSelectionModel::clearAndSelect() // verify the selectionmodel is empty QVERIFY(selection->selectedIndexes().isEmpty()); - QVERIFY(selection->hasSelection()==false); + QVERIFY(selection->hasSelection()==false); } void tst_QItemSelectionModel::toggleSelection() { - //test the toggle selection and checks whether selectedIndex - //and hasSelection returns the correct value + //test the toggle selection and checks whether selectedIndex + //and hasSelection returns the correct value - selection->clearSelection(); + selection->clearSelection(); QCOMPARE(selection->selectedIndexes().count(), 0); - QVERIFY(selection->hasSelection()==false); + QVERIFY(selection->hasSelection()==false); - QModelIndex index=model->index(1, 1, QModelIndex()); + QModelIndex index=model->index(1, 1, QModelIndex()); // populate selectionmodel selection->select(index, QItemSelectionModel::Toggle); QCOMPARE(selection->selectedIndexes().count(), 1); - QVERIFY(selection->hasSelection()==true); + QVERIFY(selection->hasSelection()==true); selection->select(index, QItemSelectionModel::Toggle); QCOMPARE(selection->selectedIndexes().count(), 0); - QVERIFY(selection->hasSelection()==false); + QVERIFY(selection->hasSelection()==false); // populate selectionmodel with rows selection->select(index, QItemSelectionModel::Toggle | QItemSelectionModel::Rows); QCOMPARE(selection->selectedIndexes().count(), model->columnCount()); - QVERIFY(selection->hasSelection()==true); + QVERIFY(selection->hasSelection()==true); selection->select(index, QItemSelectionModel::Toggle | QItemSelectionModel::Rows); QCOMPARE(selection->selectedIndexes().count(), 0); - QVERIFY(selection->hasSelection()==false); - + QVERIFY(selection->hasSelection()==false); } - void tst_QItemSelectionModel::select_data() { QTest::addColumn("indexList"); @@ -1181,54 +1178,54 @@ void tst_QItemSelectionModel::select_data() } { QModelIndexList indexes; - IntList commands; - QModelIndexList expected; - - indexes << model->index(0, 0, QModelIndex()) << model->index(0, 0, QModelIndex()) // press 0 - << model->index(0, 0, QModelIndex()) << model->index(0, 0, QModelIndex()) // release 0 - << model->index(1, 0, QModelIndex()) << model->index(1, 0, QModelIndex()) // press 1 - << model->index(1, 0, QModelIndex()) << model->index(1, 0, QModelIndex()) // release 1 - << model->index(2, 0, QModelIndex()) << model->index(2, 0, QModelIndex()) // press 2 - << model->index(2, 0, QModelIndex()) << model->index(2, 0, QModelIndex()) // release 2 - << model->index(3, 0, QModelIndex()) << model->index(3, 0, QModelIndex()) // press 3 - << model->index(3, 0, QModelIndex()) << model->index(3, 0, QModelIndex()) // release 3 - << model->index(2, 0, QModelIndex()) << model->index(2, 0, QModelIndex()) // press 2 again - << model->index(2, 0, QModelIndex()) << model->index(2, 0, QModelIndex());// move 2 - - commands << (QItemSelectionModel::NoUpdate) // press 0 - << (QItemSelectionModel::Toggle|QItemSelectionModel::Rows) // release 0 - << (QItemSelectionModel::NoUpdate) // press 1 - << (QItemSelectionModel::Toggle|QItemSelectionModel::Rows) // release 1 - << (QItemSelectionModel::NoUpdate) // press 2 - << (QItemSelectionModel::Toggle|QItemSelectionModel::Rows) // release 2 - << (QItemSelectionModel::NoUpdate) // press 3 - << (QItemSelectionModel::Toggle|QItemSelectionModel::Rows) // release 3 - << (QItemSelectionModel::NoUpdate) // press 2 again - << (QItemSelectionModel::Toggle/*Current*/|QItemSelectionModel::Rows);// move 2 - - expected << model->index(0, 0, QModelIndex()) - << model->index(0, 1, QModelIndex()) - << model->index(0, 2, QModelIndex()) - << model->index(0, 3, QModelIndex()) - << model->index(0, 4, QModelIndex()) - - << model->index(1, 0, QModelIndex()) - << model->index(1, 1, QModelIndex()) - << model->index(1, 2, QModelIndex()) - << model->index(1, 3, QModelIndex()) - << model->index(1, 4, QModelIndex()) - /* - << model->index(2, 0, QModelIndex()) - << model->index(2, 1, QModelIndex()) - << model->index(2, 2, QModelIndex()) - << model->index(2, 3, QModelIndex()) - << model->index(2, 4, QModelIndex()) - */ - << model->index(3, 0, QModelIndex()) - << model->index(3, 1, QModelIndex()) - << model->index(3, 2, QModelIndex()) - << model->index(3, 3, QModelIndex()) - << model->index(3, 4, QModelIndex()); + IntList commands; + QModelIndexList expected; + + indexes << model->index(0, 0, QModelIndex()) << model->index(0, 0, QModelIndex()) // press 0 + << model->index(0, 0, QModelIndex()) << model->index(0, 0, QModelIndex()) // release 0 + << model->index(1, 0, QModelIndex()) << model->index(1, 0, QModelIndex()) // press 1 + << model->index(1, 0, QModelIndex()) << model->index(1, 0, QModelIndex()) // release 1 + << model->index(2, 0, QModelIndex()) << model->index(2, 0, QModelIndex()) // press 2 + << model->index(2, 0, QModelIndex()) << model->index(2, 0, QModelIndex()) // release 2 + << model->index(3, 0, QModelIndex()) << model->index(3, 0, QModelIndex()) // press 3 + << model->index(3, 0, QModelIndex()) << model->index(3, 0, QModelIndex()) // release 3 + << model->index(2, 0, QModelIndex()) << model->index(2, 0, QModelIndex()) // press 2 again + << model->index(2, 0, QModelIndex()) << model->index(2, 0, QModelIndex());// move 2 + + commands << (QItemSelectionModel::NoUpdate) // press 0 + << (QItemSelectionModel::Toggle|QItemSelectionModel::Rows) // release 0 + << (QItemSelectionModel::NoUpdate) // press 1 + << (QItemSelectionModel::Toggle|QItemSelectionModel::Rows) // release 1 + << (QItemSelectionModel::NoUpdate) // press 2 + << (QItemSelectionModel::Toggle|QItemSelectionModel::Rows) // release 2 + << (QItemSelectionModel::NoUpdate) // press 3 + << (QItemSelectionModel::Toggle|QItemSelectionModel::Rows) // release 3 + << (QItemSelectionModel::NoUpdate) // press 2 again + << (QItemSelectionModel::Toggle/*Current*/|QItemSelectionModel::Rows);// move 2 + + expected << model->index(0, 0, QModelIndex()) + << model->index(0, 1, QModelIndex()) + << model->index(0, 2, QModelIndex()) + << model->index(0, 3, QModelIndex()) + << model->index(0, 4, QModelIndex()) + + << model->index(1, 0, QModelIndex()) + << model->index(1, 1, QModelIndex()) + << model->index(1, 2, QModelIndex()) + << model->index(1, 3, QModelIndex()) + << model->index(1, 4, QModelIndex()) + /* + << model->index(2, 0, QModelIndex()) + << model->index(2, 1, QModelIndex()) + << model->index(2, 2, QModelIndex()) + << model->index(2, 3, QModelIndex()) + << model->index(2, 4, QModelIndex()) + */ + << model->index(3, 0, QModelIndex()) + << model->index(3, 1, QModelIndex()) + << model->index(3, 2, QModelIndex()) + << model->index(3, 3, QModelIndex()) + << model->index(3, 4, QModelIndex()); QTest::newRow("simulated treeview multiselection behavior") << indexes @@ -1337,140 +1334,140 @@ void tst_QItemSelectionModel::persistentselections_data() << insertRows << insertColumns << deleteRows << deleteColumns << expected; - index.clear(); expected.clear(); command.clear(); - insertRows.clear(); insertColumns.clear(); deleteRows.clear(); deleteColumns.clear(); - index << IntPair(0, 0); - command << QItemSelectionModel::ClearAndSelect; - deleteRows << 0 << 1; - QTest::newRow("ClearAndSelect (0, 0). Delete first row.") - << index << command - << insertRows << insertColumns << deleteRows << deleteColumns - << expected; - - index.clear(); expected.clear(); command.clear(); - insertRows.clear(); insertColumns.clear(); deleteRows.clear(); deleteColumns.clear(); - index << IntPair(1, 0); - command << QItemSelectionModel::ClearAndSelect; - deleteRows << 0 << 1; - expected << IntPair(0, 0); - QTest::newRow("ClearAndSelect (1, 0). Delete first row.") - << index << command - << insertRows << insertColumns << deleteRows << deleteColumns - << expected; - - index.clear(); expected.clear(); command.clear(); - insertRows.clear(); insertColumns.clear(); deleteRows.clear(); deleteColumns.clear(); - index << IntPair(0, 0); - command << QItemSelectionModel::ClearAndSelect; - insertRows << 5 << 1; - expected << IntPair(0, 0); - QTest::newRow("ClearAndSelect (0, 0). Append row.") - << index << command - << insertRows << insertColumns << deleteRows << deleteColumns - << expected; - - index.clear(); expected.clear(); command.clear(); - insertRows.clear(); insertColumns.clear(); deleteRows.clear(); deleteColumns.clear(); - index << IntPair(0, 0); - command << QItemSelectionModel::ClearAndSelect; - insertRows << 0 << 1; - expected << IntPair(1, 0); - QTest::newRow("ClearAndSelect (0, 0). Insert before first row.") - << index << command - << insertRows << insertColumns << deleteRows << deleteColumns - << expected; - - index.clear(); expected.clear(); command.clear(); - insertRows.clear(); insertColumns.clear(); deleteRows.clear(); deleteColumns.clear(); - index << IntPair(0, 0) - << IntPair(4, 0); - command << QItemSelectionModel::ClearAndSelect; - insertRows << 5 << 1; - expected << IntPair(0, 0) - << IntPair(1, 0) - << IntPair(2, 0) - << IntPair(3, 0) - << IntPair(4, 0); - QTest::newRow("ClearAndSelect (0, 0) to (4, 0). Append row.") - << index << command - << insertRows << insertColumns << deleteRows << deleteColumns - << expected; - - index.clear(); expected.clear(); command.clear(); - insertRows.clear(); insertColumns.clear(); deleteRows.clear(); deleteColumns.clear(); - index << IntPair(0, 0) - << IntPair(4, 0); - command << QItemSelectionModel::ClearAndSelect; - insertRows << 0 << 1; - expected << IntPair(1, 0) - << IntPair(2, 0) - << IntPair(3, 0) - << IntPair(4, 0) - << IntPair(5, 0); - QTest::newRow("ClearAndSelect (0, 0) to (4, 0). Insert before first row.") - << index << command - << insertRows << insertColumns << deleteRows << deleteColumns - << expected; - - index.clear(); expected.clear(); command.clear(); - insertRows.clear(); insertColumns.clear(); deleteRows.clear(); deleteColumns.clear(); - index << IntPair(0, 0) - << IntPair(4, 0); - command << QItemSelectionModel::ClearAndSelect; - deleteRows << 0 << 1; - expected << IntPair(0, 0) - << IntPair(1, 0) - << IntPair(2, 0) - << IntPair(3, 0); - QTest::newRow("ClearAndSelect (0, 0) to (4, 0). Delete first row.") - << index << command - << insertRows << insertColumns << deleteRows << deleteColumns - << expected; - - index.clear(); expected.clear(); command.clear(); - insertRows.clear(); insertColumns.clear(); deleteRows.clear(); deleteColumns.clear(); - index << IntPair(0, 0) - << IntPair(4, 0); - command << QItemSelectionModel::ClearAndSelect; - deleteRows << 4 << 1; - expected << IntPair(0, 0) - << IntPair(1, 0) - << IntPair(2, 0) - << IntPair(3, 0); - QTest::newRow("ClearAndSelect (0, 0) to (4, 0). Delete last row.") - << index << command - << insertRows << insertColumns << deleteRows << deleteColumns - << expected; - - index.clear(); expected.clear(); command.clear(); - insertRows.clear(); insertColumns.clear(); deleteRows.clear(); deleteColumns.clear(); - index << IntPair(0, 0) - << IntPair(4, 0); - command << QItemSelectionModel::ClearAndSelect; - deleteRows << 1 << 3; - expected << IntPair(0, 0) - << IntPair(1, 0); - QTest::newRow("ClearAndSelect (0, 0) to (4, 0). Deleting all but first and last row.") - << index << command - << insertRows << insertColumns << deleteRows << deleteColumns - << expected; - - index.clear(); expected.clear(); command.clear(); - insertRows.clear(); insertColumns.clear(); deleteRows.clear(); deleteColumns.clear(); - index << IntPair(0, 0) - << IntPair(4, 0); - command << QItemSelectionModel::ClearAndSelect; - insertRows << 1 << 1; - expected << IntPair(0, 0) - // the inserted row should not be selected - << IntPair(2, 0) - << IntPair(3, 0) - << IntPair(4, 0) - << IntPair(5, 0); - QTest::newRow("ClearAndSelect (0, 0) to (4, 0). Insert after first row.") - << index << command - << insertRows << insertColumns << deleteRows << deleteColumns - << expected; + index.clear(); expected.clear(); command.clear(); + insertRows.clear(); insertColumns.clear(); deleteRows.clear(); deleteColumns.clear(); + index << IntPair(0, 0); + command << QItemSelectionModel::ClearAndSelect; + deleteRows << 0 << 1; + QTest::newRow("ClearAndSelect (0, 0). Delete first row.") + << index << command + << insertRows << insertColumns << deleteRows << deleteColumns + << expected; + + index.clear(); expected.clear(); command.clear(); + insertRows.clear(); insertColumns.clear(); deleteRows.clear(); deleteColumns.clear(); + index << IntPair(1, 0); + command << QItemSelectionModel::ClearAndSelect; + deleteRows << 0 << 1; + expected << IntPair(0, 0); + QTest::newRow("ClearAndSelect (1, 0). Delete first row.") + << index << command + << insertRows << insertColumns << deleteRows << deleteColumns + << expected; + + index.clear(); expected.clear(); command.clear(); + insertRows.clear(); insertColumns.clear(); deleteRows.clear(); deleteColumns.clear(); + index << IntPair(0, 0); + command << QItemSelectionModel::ClearAndSelect; + insertRows << 5 << 1; + expected << IntPair(0, 0); + QTest::newRow("ClearAndSelect (0, 0). Append row.") + << index << command + << insertRows << insertColumns << deleteRows << deleteColumns + << expected; + + index.clear(); expected.clear(); command.clear(); + insertRows.clear(); insertColumns.clear(); deleteRows.clear(); deleteColumns.clear(); + index << IntPair(0, 0); + command << QItemSelectionModel::ClearAndSelect; + insertRows << 0 << 1; + expected << IntPair(1, 0); + QTest::newRow("ClearAndSelect (0, 0). Insert before first row.") + << index << command + << insertRows << insertColumns << deleteRows << deleteColumns + << expected; + + index.clear(); expected.clear(); command.clear(); + insertRows.clear(); insertColumns.clear(); deleteRows.clear(); deleteColumns.clear(); + index << IntPair(0, 0) + << IntPair(4, 0); + command << QItemSelectionModel::ClearAndSelect; + insertRows << 5 << 1; + expected << IntPair(0, 0) + << IntPair(1, 0) + << IntPair(2, 0) + << IntPair(3, 0) + << IntPair(4, 0); + QTest::newRow("ClearAndSelect (0, 0) to (4, 0). Append row.") + << index << command + << insertRows << insertColumns << deleteRows << deleteColumns + << expected; + + index.clear(); expected.clear(); command.clear(); + insertRows.clear(); insertColumns.clear(); deleteRows.clear(); deleteColumns.clear(); + index << IntPair(0, 0) + << IntPair(4, 0); + command << QItemSelectionModel::ClearAndSelect; + insertRows << 0 << 1; + expected << IntPair(1, 0) + << IntPair(2, 0) + << IntPair(3, 0) + << IntPair(4, 0) + << IntPair(5, 0); + QTest::newRow("ClearAndSelect (0, 0) to (4, 0). Insert before first row.") + << index << command + << insertRows << insertColumns << deleteRows << deleteColumns + << expected; + + index.clear(); expected.clear(); command.clear(); + insertRows.clear(); insertColumns.clear(); deleteRows.clear(); deleteColumns.clear(); + index << IntPair(0, 0) + << IntPair(4, 0); + command << QItemSelectionModel::ClearAndSelect; + deleteRows << 0 << 1; + expected << IntPair(0, 0) + << IntPair(1, 0) + << IntPair(2, 0) + << IntPair(3, 0); + QTest::newRow("ClearAndSelect (0, 0) to (4, 0). Delete first row.") + << index << command + << insertRows << insertColumns << deleteRows << deleteColumns + << expected; + + index.clear(); expected.clear(); command.clear(); + insertRows.clear(); insertColumns.clear(); deleteRows.clear(); deleteColumns.clear(); + index << IntPair(0, 0) + << IntPair(4, 0); + command << QItemSelectionModel::ClearAndSelect; + deleteRows << 4 << 1; + expected << IntPair(0, 0) + << IntPair(1, 0) + << IntPair(2, 0) + << IntPair(3, 0); + QTest::newRow("ClearAndSelect (0, 0) to (4, 0). Delete last row.") + << index << command + << insertRows << insertColumns << deleteRows << deleteColumns + << expected; + + index.clear(); expected.clear(); command.clear(); + insertRows.clear(); insertColumns.clear(); deleteRows.clear(); deleteColumns.clear(); + index << IntPair(0, 0) + << IntPair(4, 0); + command << QItemSelectionModel::ClearAndSelect; + deleteRows << 1 << 3; + expected << IntPair(0, 0) + << IntPair(1, 0); + QTest::newRow("ClearAndSelect (0, 0) to (4, 0). Deleting all but first and last row.") + << index << command + << insertRows << insertColumns << deleteRows << deleteColumns + << expected; + + index.clear(); expected.clear(); command.clear(); + insertRows.clear(); insertColumns.clear(); deleteRows.clear(); deleteColumns.clear(); + index << IntPair(0, 0) + << IntPair(4, 0); + command << QItemSelectionModel::ClearAndSelect; + insertRows << 1 << 1; + expected << IntPair(0, 0) + // the inserted row should not be selected + << IntPair(2, 0) + << IntPair(3, 0) + << IntPair(4, 0) + << IntPair(5, 0); + QTest::newRow("ClearAndSelect (0, 0) to (4, 0). Insert after first row.") + << index << command + << insertRows << insertColumns << deleteRows << deleteColumns + << expected; } void tst_QItemSelectionModel::persistentselections() @@ -1783,7 +1780,7 @@ void tst_QItemSelectionModel::modelLayoutChanged() // verify that selection is as expected QItemSelection selection = selectionModel.selection(); QCOMPARE(selection.count(), expectedSelectedRanges.count()); - QVERIFY(selectionModel.hasSelection() == !expectedSelectedRanges.isEmpty()); + QVERIFY(selectionModel.hasSelection() == !expectedSelectedRanges.isEmpty()); for (int i = 0; i < expectedSelectedRanges.count(); ++i) { IntPairPair expectedRange = expectedSelectedRanges.at(i); @@ -2035,27 +2032,28 @@ void tst_QItemSelectionModel::task220420_selectedIndexes() class QtTestTableModel: public QAbstractTableModel { Q_OBJECT +public: + QtTestTableModel(int rows = 0, int columns = 0, QObject *parent = 0) + : QAbstractTableModel(parent) + , row_count(rows) + , column_count(columns) + { + } - public: - QtTestTableModel(int rows = 0, int columns = 0, QObject *parent = 0) - : QAbstractTableModel(parent), - row_count(rows), - column_count(columns) {} - - int rowCount(const QModelIndex& = QModelIndex()) const { return row_count; } - int columnCount(const QModelIndex& = QModelIndex()) const { return column_count; } - bool isEditable(const QModelIndex &) const { return true; } + int rowCount(const QModelIndex& = QModelIndex()) const { return row_count; } + int columnCount(const QModelIndex& = QModelIndex()) const { return column_count; } + bool isEditable(const QModelIndex &) const { return true; } - QVariant data(const QModelIndex &idx, int role) const - { - if (role == Qt::DisplayRole || role == Qt::EditRole) - return QString("[%1,%2]").arg(idx.row()).arg(idx.column()); - return QVariant(); - } + QVariant data(const QModelIndex &idx, int role) const + { + if (role == Qt::DisplayRole || role == Qt::EditRole) + return QString("[%1,%2]").arg(idx.row()).arg(idx.column()); + return QVariant(); + } - int row_count; - int column_count; - friend class tst_QItemSelectionModel; + int row_count; + int column_count; + friend class tst_QItemSelectionModel; }; @@ -2127,7 +2125,6 @@ void tst_QItemSelectionModel::merge_data() << r1; } - void tst_QItemSelectionModel::merge() { QFETCH(QItemSelection, init); @@ -2317,7 +2314,6 @@ void tst_QItemSelectionModel::QTBUG5671_layoutChangedWithAllSelected() } } - QCOMPARE(model.rowCount(), int(cNumRows)); QCOMPARE(proxy.rowCount(), int(cNumRows/2)); @@ -2381,7 +2377,6 @@ public slots: } QVERIFY(m_itemSelectionModel->selection().size() == 2); } - }; void tst_QItemSelectionModel::deselectRemovedMiddleRange() @@ -2434,9 +2429,9 @@ static QStandardItemModel* getModel(QObject *parent) } enum Result { - LessThan, - NotLessThan, - NotEqual + LessThan, + NotLessThan, + NotEqual }; Q_DECLARE_METATYPE(Result); @@ -2502,70 +2497,70 @@ void tst_QItemSelectionModel::rangeOperatorLessThan_data() void tst_QItemSelectionModel::rangeOperatorLessThan() { - QStandardItemModel *model1 = getModel(this); - QStandardItemModel *model2 = getModel(this); + QStandardItemModel *model1 = getModel(this); + QStandardItemModel *model2 = getModel(this); - QFETCH(int, parent1); - QFETCH(int, top1); - QFETCH(int, left1); - QFETCH(int, bottom1); - QFETCH(int, right1); - QFETCH(int, parent2); - QFETCH(int, top2); - QFETCH(int, left2); - QFETCH(int, bottom2); - QFETCH(int, right2); - QFETCH(Result, result); + QFETCH(int, parent1); + QFETCH(int, top1); + QFETCH(int, left1); + QFETCH(int, bottom1); + QFETCH(int, right1); + QFETCH(int, parent2); + QFETCH(int, top2); + QFETCH(int, left2); + QFETCH(int, bottom2); + QFETCH(int, right2); + QFETCH(Result, result); - QModelIndex p1 = model1->index(parent1, 0); + QModelIndex p1 = model1->index(parent1, 0); - QModelIndex tl1 = model1->index(top1, left1, p1); - QModelIndex br1 = model1->index(bottom1, right1, p1); + QModelIndex tl1 = model1->index(top1, left1, p1); + QModelIndex br1 = model1->index(bottom1, right1, p1); - QItemSelectionRange r1(tl1, br1); + QItemSelectionRange r1(tl1, br1); - QModelIndex p2 = model1->index(parent2, 0); + QModelIndex p2 = model1->index(parent2, 0); - QModelIndex tl2 = model1->index(top2, left2, p2); - QModelIndex br2 = model1->index(bottom2, right2, p2); + QModelIndex tl2 = model1->index(top2, left2, p2); + QModelIndex br2 = model1->index(bottom2, right2, p2); - QItemSelectionRange r2(tl2, br2); + QItemSelectionRange r2(tl2, br2); - if (result == LessThan) - QVERIFY(r1 < r2); - else if (result == NotLessThan) - QVERIFY(!(r1 < r2)); - else if (result == NotEqual) - if (!(r1 < r2)) - QVERIFY(r2 < r1); + if (result == LessThan) + QVERIFY(r1 < r2); + else if (result == NotLessThan) + QVERIFY(!(r1 < r2)); + else if (result == NotEqual) + if (!(r1 < r2)) + QVERIFY(r2 < r1); - // Ranges in different models are always non-equal + // Ranges in different models are always non-equal - QModelIndex p3 = model2->index(parent1, 0); + QModelIndex p3 = model2->index(parent1, 0); - QModelIndex tl3 = model2->index(top1, left1, p3); - QModelIndex br3 = model2->index(bottom1, right1, p3); + QModelIndex tl3 = model2->index(top1, left1, p3); + QModelIndex br3 = model2->index(bottom1, right1, p3); - QItemSelectionRange r3(tl3, br3); + QItemSelectionRange r3(tl3, br3); - if (!(r1 < r3)) - QVERIFY(r3 < r1); + if (!(r1 < r3)) + QVERIFY(r3 < r1); - if (!(r2 < r3)) - QVERIFY(r3 < r2); + if (!(r2 < r3)) + QVERIFY(r3 < r2); - QModelIndex p4 = model2->index(parent2, 0); + QModelIndex p4 = model2->index(parent2, 0); - QModelIndex tl4 = model2->index(top2, left2, p4); - QModelIndex br4 = model2->index(bottom2, right2, p4); + QModelIndex tl4 = model2->index(top2, left2, p4); + QModelIndex br4 = model2->index(bottom2, right2, p4); - QItemSelectionRange r4(tl4, br4); + QItemSelectionRange r4(tl4, br4); - if (!(r1 < r4)) - QVERIFY(r4 < r1); + if (!(r1 < r4)) + QVERIFY(r4 < r1); - if (!(r2 < r4)) - QVERIFY(r4 < r2); + if (!(r2 < r4)) + QVERIFY(r4 < r2); } void tst_QItemSelectionModel::testDifferentModels() @@ -2578,7 +2573,6 @@ void tst_QItemSelectionModel::testDifferentModels() model1.appendColumn(QList() << &top11 << &top12 << &top13); model2.appendColumn(QList() << &top21 << &top22 << &top23); - QModelIndex topIndex1 = model1.index(0, 0); QModelIndex bottomIndex1 = model1.index(2, 0); QModelIndex topIndex2 = model2.index(0, 0); @@ -2596,10 +2590,10 @@ void tst_QItemSelectionModel::testDifferentModels() class SelectionObserver : public QObject { - Q_OBJECT + Q_OBJECT public: SelectionObserver(QAbstractItemModel *model, QObject *parent = 0) - : QObject(parent), m_model(model), m_selectionModel(0) + : QObject(parent), m_model(model), m_selectionModel(0) { connect(model, SIGNAL(modelReset()), SLOT(modelReset())); } @@ -2610,7 +2604,7 @@ public: connect(m_selectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)), SLOT(selectionChanged(QItemSelection,QItemSelection))); } - private slots: +private slots: void modelReset() { const QModelIndex idx = m_model->index(2, 0); @@ -2660,37 +2654,35 @@ void tst_QItemSelectionModel::testValidRangesInSelectionsAfterReset() class DuplicateItemSelectionModel : public QItemSelectionModel { - Q_OBJECT + Q_OBJECT public: - DuplicateItemSelectionModel(QItemSelectionModel *target, QAbstractItemModel *model, QObject *parent = 0) - : QItemSelectionModel(model, parent), m_target(target) - { - - } + DuplicateItemSelectionModel(QItemSelectionModel *target, QAbstractItemModel *model, QObject *parent = 0) + : QItemSelectionModel(model, parent), m_target(target) + { + } - void select(const QItemSelection &selection, QItemSelectionModel::SelectionFlags command) - { - QItemSelectionModel::select(selection, command); - m_target->select(selection, command); - } + void select(const QItemSelection &selection, QItemSelectionModel::SelectionFlags command) + { + QItemSelectionModel::select(selection, command); + m_target->select(selection, command); + } - using QItemSelectionModel::select; + using QItemSelectionModel::select; - void setCurrentIndex(const QModelIndex &index, QItemSelectionModel::SelectionFlags command) - { - QItemSelectionModel::setCurrentIndex(index, command); - m_target->setCurrentIndex(index, command); - } + void setCurrentIndex(const QModelIndex &index, QItemSelectionModel::SelectionFlags command) + { + QItemSelectionModel::setCurrentIndex(index, command); + m_target->setCurrentIndex(index, command); + } - void clearCurrentIndex() - { - QItemSelectionModel::clearCurrentIndex(); - m_target->clearCurrentIndex(); - } + void clearCurrentIndex() + { + QItemSelectionModel::clearCurrentIndex(); + m_target->clearCurrentIndex(); + } private: - QItemSelectionModel *m_target; - + QItemSelectionModel *m_target; }; void tst_QItemSelectionModel::testChainedSelectionClear() diff --git a/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp b/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp index 1564070..ae9a420 100644 --- a/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp +++ b/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp @@ -39,7 +39,6 @@ ** ****************************************************************************/ - #include #include "dynamictreemodel.h" #include "modeltest.h" @@ -62,9 +61,7 @@ Q_DECLARE_METATYPE(QModelIndex) class tst_QSortFilterProxyModel : public QObject { Q_OBJECT - public: - tst_QSortFilterProxyModel(); public slots: @@ -173,7 +170,6 @@ void tst_QSortFilterProxyModel::getSetCheck() tst_QSortFilterProxyModel::tst_QSortFilterProxyModel() : m_model(0), m_proxy(0) { - } void tst_QSortFilterProxyModel::initTestCase() @@ -337,7 +333,6 @@ void tst_QSortFilterProxyModel::sort_data() << (QStringList() << "BETA" << "Gamma" << "alpha" << "delta"); - QStringList list; for (int i = 10000; i < 20000; ++i) list.append(QString("Number: %1").arg(i)); @@ -392,7 +387,6 @@ void tst_QSortFilterProxyModel::sort() QModelIndex index = m_proxy->index(row, 0, QModelIndex()); QCOMPARE(m_proxy->data(index, Qt::DisplayRole).toString(), initial.at(row)); } - } void tst_QSortFilterProxyModel::sortHierarchy_data() @@ -580,7 +574,7 @@ void tst_QSortFilterProxyModel::insertRows() for (int i = 0; i < insert.count(); ++i) { QModelIndex index = m_proxy->index(position + i, 0, QModelIndex()); m_proxy->setData(index, insert.at(i), Qt::DisplayRole); - } + } // make sure the model correct after insert for (int row = 0; row < m_model->rowCount(QModelIndex()); ++row) { @@ -599,7 +593,7 @@ void tst_QSortFilterProxyModel::prependRow() { //this tests that data is correctly handled by the sort filter when prepending a row QStandardItemModel model; - QSortFilterProxyModel proxy; + QSortFilterProxyModel proxy; proxy.setSourceModel(&model); QStandardItem item("root"); @@ -1171,7 +1165,6 @@ void tst_QSortFilterProxyModel::removeColumns() } } - void tst_QSortFilterProxyModel::filterColumns_data() { QTest::addColumn("pattern"); @@ -1398,8 +1391,6 @@ void tst_QSortFilterProxyModel::checkHierarchy(const QStringList &l, const QAbst } } - - class TestModel: public QAbstractTableModel { public: @@ -2320,7 +2311,6 @@ void tst_QSortFilterProxyModel::sourceInsertRows() void tst_QSortFilterProxyModel::sourceModelDeletion() { - QSortFilterProxyModel proxyModel; { QStandardItemModel model; @@ -2328,7 +2318,6 @@ void tst_QSortFilterProxyModel::sourceModelDeletion() QCOMPARE(proxyModel.sourceModel(), static_cast(&model)); } QCOMPARE(proxyModel.sourceModel(), static_cast(0)); - } void tst_QSortFilterProxyModel::sortColumnTracking1() @@ -2390,11 +2379,11 @@ void tst_QSortFilterProxyModel::sortColumnTracking2() void tst_QSortFilterProxyModel::sortStable() { QStandardItemModel* model = new QStandardItemModel(5, 2); - for (int r=0; r<5; r++) { - for (int c=0; c<2; c++) { + for (int r = 0; r < 5; r++) { + for (int c = 0; c < 2; c++) { QStandardItem* item = new QStandardItem( QString("Row:%0, Column:%1").arg(r).arg(c) ); - for( int i=0; i<3; i++ ) { + for (int i = 0; i < 3; i++) { QStandardItem* child = new QStandardItem( QString("Item %0").arg(i) ); item->appendRow( child ); @@ -2403,8 +2392,7 @@ void tst_QSortFilterProxyModel::sortStable() } } model->setHorizontalHeaderItem( 0, new QStandardItem( "Name" )); - model->setHorizontalHeaderItem( 1, new QStandardItem( "Value" ) ); - + model->setHorizontalHeaderItem( 1, new QStandardItem( "Value" )); QSortFilterProxyModel *filterModel = new QSortFilterProxyModel(model); filterModel->setSourceModel(model); @@ -2522,7 +2510,6 @@ void tst_QSortFilterProxyModel::task248868_staticSorting() QModelIndex index = proxy.index(row, 0, QModelIndex()); QCOMPARE(proxy.data(index, Qt::DisplayRole).toString(), expected.at(row)); } - } void tst_QSortFilterProxyModel::task248868_dynamicSorting() @@ -2587,71 +2574,82 @@ void tst_QSortFilterProxyModel::task248868_dynamicSorting() class QtTestModel: public QAbstractItemModel { - public: - QtTestModel(int _rows, int _cols, QObject *parent = 0): QAbstractItemModel(parent), - rows(_rows), cols(_cols), wrongIndex(false) { } +public: + QtTestModel(int _rows, int _cols, QObject *parent = 0) + : QAbstractItemModel(parent) + , rows(_rows) + , cols(_cols) + , wrongIndex(false) + { + } - bool canFetchMore(const QModelIndex &idx) const { - return !fetched.contains(idx); - } + bool canFetchMore(const QModelIndex &idx) const + { + return !fetched.contains(idx); + } - void fetchMore(const QModelIndex &idx) { - if (fetched.contains(idx)) - return; - beginInsertRows(idx, 0, rows-1); - fetched.insert(idx); - endInsertRows(); - } + void fetchMore(const QModelIndex &idx) + { + if (fetched.contains(idx)) + return; + beginInsertRows(idx, 0, rows-1); + fetched.insert(idx); + endInsertRows(); + } - bool hasChildren(const QModelIndex & = QModelIndex()) const { - return true; - } + bool hasChildren(const QModelIndex & = QModelIndex()) const + { + return true; + } - int rowCount(const QModelIndex& parent = QModelIndex()) const { - return fetched.contains(parent) ? rows : 0; - } - int columnCount(const QModelIndex& parent = QModelIndex()) const { - Q_UNUSED(parent); - return cols; - } + int rowCount(const QModelIndex& parent = QModelIndex()) const + { + return fetched.contains(parent) ? rows : 0; + } - QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const - { - if (row < 0 || column < 0 || column >= cols || row >= rows) { - return QModelIndex(); - } - QModelIndex i = createIndex(row, column, int(parent.internalId() + 1)); - parentHash[i] = parent; - return i; - } + int columnCount(const QModelIndex& parent = QModelIndex()) const + { + Q_UNUSED(parent); + return cols; + } - QModelIndex parent(const QModelIndex &index) const - { - if (!parentHash.contains(index)) - return QModelIndex(); - return parentHash[index]; + QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const + { + if (row < 0 || column < 0 || column >= cols || row >= rows) { + return QModelIndex(); } + QModelIndex i = createIndex(row, column, int(parent.internalId() + 1)); + parentHash[i] = parent; + return i; + } - QVariant data(const QModelIndex &idx, int role) const - { - if (!idx.isValid()) - return QVariant(); - - if (role == Qt::DisplayRole) { - if (idx.row() < 0 || idx.column() < 0 || idx.column() >= cols || idx.row() >= rows) { - wrongIndex = true; - qWarning("Invalid modelIndex [%d,%d,%p]", idx.row(), idx.column(), - idx.internalPointer()); - } - return QString("[%1,%2]").arg(idx.row()).arg(idx.column()); - } + QModelIndex parent(const QModelIndex &index) const + { + if (!parentHash.contains(index)) + return QModelIndex(); + return parentHash[index]; + } + + QVariant data(const QModelIndex &idx, int role) const + { + if (!idx.isValid()) return QVariant(); + + if (role == Qt::DisplayRole) { + if (idx.row() < 0 || idx.column() < 0 || idx.column() >= cols || idx.row() >= rows) { + wrongIndex = true; + qWarning("Invalid modelIndex [%d,%d,%p]", idx.row(), idx.column(), + idx.internalPointer()); + } + return QString("[%1,%2]").arg(idx.row()).arg(idx.column()); } + return QVariant(); + } - QSet fetched; - int rows, cols; - mutable bool wrongIndex; - mutable QMap parentHash; + QSet fetched; + int rows, cols; + mutable bool wrongIndex; + mutable QMap parentHash; }; void tst_QSortFilterProxyModel::task250023_fetchMore() @@ -2753,7 +2751,6 @@ static QStandardItem *addEntry(QStandardItem* pParent, const QString &descriptio return pItem; } - void tst_QSortFilterProxyModel::task255652_removeRowsRecursive() { QStandardItemModel pModel; @@ -2844,25 +2841,24 @@ void tst_QSortFilterProxyModel::taskQTBUG_7537_appearsAndSort() { class PModel : public QSortFilterProxyModel { - public: - PModel() : mVisible(false) {}; - protected: - bool filterAcceptsRow(int, const QModelIndex &) const - { - return mVisible; - } + public: + PModel() : mVisible(false) {}; + protected: + bool filterAcceptsRow(int, const QModelIndex &) const + { + return mVisible; + } - public: - void updateXX() - { - mVisible = true; - invalidate(); - } - private: - bool mVisible; + public: + void updateXX() + { + mVisible = true; + invalidate(); + } + private: + bool mVisible; } proxyModel; - QStringListModel sourceModel; QStringList list; list << "b" << "a" << "c"; @@ -2996,7 +2992,6 @@ private slots: private: QItemSelectionModel *selectionModel; - }; void tst_QSortFilterProxyModel::testMultipleProxiesWithSelection() @@ -3023,13 +3018,13 @@ void tst_QSortFilterProxyModel::testMultipleProxiesWithSelection() // trick the proxy into emitting begin/end reset signals. proxy.setSourceModel(0); - } -static bool isValid(const QItemSelection &selection) { - foreach(const QItemSelectionRange &range, selection) - if (!range.isValid()) - return false; +static bool isValid(const QItemSelection &selection) +{ + foreach (const QItemSelectionRange &range, selection) + if (!range.isValid()) + return false; return true; } @@ -3126,19 +3121,18 @@ void tst_QSortFilterProxyModel::taskQTBUG_10287_unnecessaryMapCreation() class FilteredColumnProxyModel : public QSortFilterProxyModel { - Q_OBJECT + Q_OBJECT public: - FilteredColumnProxyModel(QObject *parent = 0) - : QSortFilterProxyModel(parent) - { - - } + FilteredColumnProxyModel(QObject *parent = 0) + : QSortFilterProxyModel(parent) + { + } protected: - bool filterAcceptsColumn(int column, const QModelIndex & /* source_parent */) const - { - return column % 2 != 0; - } + bool filterAcceptsColumn(int column, const QModelIndex & /* source_parent */) const + { + return column % 2 != 0; + } }; void tst_QSortFilterProxyModel::filteredColumns() @@ -3176,10 +3170,12 @@ void tst_QSortFilterProxyModel::taskQTBUG_17812_resetInvalidate() struct Proxy : QSortFilterProxyModel { QString pattern; - virtual bool filterAcceptsRow(int source_row, const QModelIndex&) const { + virtual bool filterAcceptsRow(int source_row, const QModelIndex&) const + { return sourceModel()->data(sourceModel()->index(source_row, 0)).toString().contains(pattern); } - void notifyChange(int test) { + void notifyChange(int test) + { switch (test) { case 0: break; case 1: reset(); break; @@ -3313,7 +3309,6 @@ void tst_QSortFilterProxyModel::testParentLayoutChanged() QVERIFY(beforeParents.contains(proxy2.mapToSource(idx))); foreach (const QPersistentModelIndex &idx, proxy2AfterList) QVERIFY(afterParents.contains(proxy2.mapToSource(idx))); - } class SignalArgumentChecker : public QObject diff --git a/tests/auto/corelib/itemmodels/qstringlistmodel/qmodellistener.h b/tests/auto/corelib/itemmodels/qstringlistmodel/qmodellistener.h index f3ed3c1..a95de96 100644 --- a/tests/auto/corelib/itemmodels/qstringlistmodel/qmodellistener.h +++ b/tests/auto/corelib/itemmodels/qstringlistmodel/qmodellistener.h @@ -38,11 +38,11 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ + #include #include #include - QT_FORWARD_DECLARE_CLASS(QStringListModel) class QModelListener : public QObject @@ -56,7 +56,7 @@ public: virtual ~QModelListener() { } void setTestData(QStringList *pAboutToStringlist, QStringList *pExpectedStringlist, QStringListModel *pModel) - { + { m_pAboutToStringlist = pAboutToStringlist; m_pExpectedStringlist = pExpectedStringlist; m_pModel = pModel; @@ -70,6 +70,5 @@ private: public slots: void rowsAboutToBeRemovedOrInserted(const QModelIndex & parent, int start, int end ); void rowsRemovedOrInserted(const QModelIndex & parent, int start, int end ); - }; diff --git a/tests/auto/corelib/itemmodels/qstringlistmodel/qstringlistmodel.pro b/tests/auto/corelib/itemmodels/qstringlistmodel/qstringlistmodel.pro index ecdd30c..821a480 100644 --- a/tests/auto/corelib/itemmodels/qstringlistmodel/qstringlistmodel.pro +++ b/tests/auto/corelib/itemmodels/qstringlistmodel/qstringlistmodel.pro @@ -2,8 +2,4 @@ CONFIG += testcase TARGET = tst_qstringlistmodel QT += widgets testlib HEADERS += qmodellistener.h - -SOURCES += tst_qstringlistmodel.cpp - - - +SOURCES += tst_qstringlistmodel.cpp diff --git a/tests/auto/corelib/itemmodels/qstringlistmodel/tst_qstringlistmodel.cpp b/tests/auto/corelib/itemmodels/qstringlistmodel/tst_qstringlistmodel.cpp index d0da27d..eab8851 100644 --- a/tests/auto/corelib/itemmodels/qstringlistmodel/tst_qstringlistmodel.cpp +++ b/tests/auto/corelib/itemmodels/qstringlistmodel/tst_qstringlistmodel.cpp @@ -39,7 +39,6 @@ ** ****************************************************************************/ - #include #include #include @@ -52,20 +51,17 @@ void QModelListener::rowsAboutToBeRemovedOrInserted(const QModelIndex & parent, int start, int end ) { - int i; - for (i = 0; start + i <= end; i++) - { + for (int i = 0; start + i <= end; i++) { QModelIndex mIndex = m_pModel->index(start + i, 0, parent); QVariant var = m_pModel->data(mIndex, Qt::DisplayRole); QString str = var.toString(); - + QCOMPARE(str, m_pAboutToStringlist->at(i)); } } void QModelListener::rowsRemovedOrInserted(const QModelIndex & parent, int , int) { - int i; // Can the rows that *are* removed be iterated now ? // What about rowsAboutToBeInserted - what will the indices be? @@ -74,18 +70,16 @@ void QModelListener::rowsRemovedOrInserted(const QModelIndex & parent, int , int // RemoveColumn. Does that also fire the rowsRemoved-family signals? - for (i = 0; i < m_pExpectedStringlist->size(); i++) - { + for (int i = 0; i < m_pExpectedStringlist->size(); i++) { QModelIndex mIndex = m_pModel->index(i, 0, parent); QVariant var = m_pModel->data(mIndex, Qt::DisplayRole); QString str = var.toString(); - + //qDebug() << "index: " << i << " start: " << start << "end: " << end; QCOMPARE(str, m_pExpectedStringlist->at(i)); } } - class tst_QStringListModel : public QObject { Q_OBJECT @@ -152,21 +146,20 @@ void tst_QStringListModel::rowsAboutToBeRemoved_rowsRemoved() QStringListModel *model = new QStringListModel(input); QModelListener *pListener = new QModelListener(&aboutto, &res, model); - pListener->connect(model, SIGNAL( rowsAboutToBeRemoved(const QModelIndex & , int , int )), + pListener->connect(model, SIGNAL( rowsAboutToBeRemoved(const QModelIndex & , int , int )), pListener, SLOT( rowsAboutToBeRemovedOrInserted(const QModelIndex & , int , int )) ); - pListener->connect(model, SIGNAL( rowsRemoved(const QModelIndex & , int , int )), + pListener->connect(model, SIGNAL( rowsRemoved(const QModelIndex & , int , int )), pListener, SLOT( rowsRemovedOrInserted(const QModelIndex & , int , int )) ); model->removeRows(row,count); - // At this point, control goes to our connected slots inn this order: + // 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() @@ -217,24 +210,21 @@ void tst_QStringListModel::rowsAboutToBeInserted_rowsInserted() QStringListModel *model = new QStringListModel(input); QModelListener *pListener = new QModelListener(&aboutto, &res, model); - connect(model, SIGNAL( rowsAboutToBeInserted(const QModelIndex & , int , int )), + connect(model, SIGNAL( rowsAboutToBeInserted(const QModelIndex & , int , int )), pListener, SLOT( rowsAboutToBeRemovedOrInserted(const QModelIndex & , int , int )) ); - connect(model, SIGNAL( rowsInserted(const QModelIndex & , int , int )), + connect(model, SIGNAL( rowsInserted(const QModelIndex & , int , int )), pListener, SLOT( rowsRemovedOrInserted(const QModelIndex & , int , int )) ); model->insertRows(row,count); - // At this point, control goes to our connected slots inn this order: + // At this point, control goes to our connected slots inn this order: // 1. rowsAboutToBeRemovedOrInserted // 2. rowsRemovedOrInserted // Control returns here delete pListener; delete model; - } - QTEST_MAIN(tst_QStringListModel) #include "tst_qstringlistmodel.moc" - -- 2.7.4