summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/itemmodels
diff options
context:
space:
mode:
authorLeander Beernaert <leander.beernaert@qt.io>2020-01-22 13:47:08 +0100
committerLeander Beernaert <leander.beernaert@qt.io>2020-01-24 13:17:33 +0100
commit502d3d6744913899da87acfda5ebdab42c40329e (patch)
tree16658a328503bfd5a62b4fd5d69ffb66e9854b18 /tests/auto/corelib/itemmodels
parentd1be8b9ceb2c7b20bbe53a07154c79699540ea3d (diff)
parent06bb315beb6c2c398223cfe52cbc7f66e14a8557 (diff)
Merge remote-tracking branch 'origin/dev' into merge-dev
Diffstat (limited to 'tests/auto/corelib/itemmodels')
-rw-r--r--tests/auto/corelib/itemmodels/qabstractproxymodel/tst_qabstractproxymodel.cpp2
-rw-r--r--tests/auto/corelib/itemmodels/qidentityproxymodel/tst_qidentityproxymodel.cpp102
-rw-r--r--tests/auto/corelib/itemmodels/qitemselectionmodel/tst_qitemselectionmodel.cpp6
-rw-r--r--tests/auto/corelib/itemmodels/qstringlistmodel/tst_qstringlistmodel.cpp53
4 files changed, 98 insertions, 65 deletions
diff --git a/tests/auto/corelib/itemmodels/qabstractproxymodel/tst_qabstractproxymodel.cpp b/tests/auto/corelib/itemmodels/qabstractproxymodel/tst_qabstractproxymodel.cpp
index adb93b7a75..4406d40986 100644
--- a/tests/auto/corelib/itemmodels/qabstractproxymodel/tst_qabstractproxymodel.cpp
+++ b/tests/auto/corelib/itemmodels/qabstractproxymodel/tst_qabstractproxymodel.cpp
@@ -136,7 +136,7 @@ void tst_QAbstractProxyModel::flags_data()
{
QTest::addColumn<QModelIndex>("index");
QTest::addColumn<Qt::ItemFlags>("flags");
- QTest::newRow("null") << QModelIndex() << (Qt::ItemFlags)0;
+ QTest::newRow("null") << QModelIndex() << Qt::ItemFlags{};
}
// public Qt::ItemFlags flags(QModelIndex const& index) const
diff --git a/tests/auto/corelib/itemmodels/qidentityproxymodel/tst_qidentityproxymodel.cpp b/tests/auto/corelib/itemmodels/qidentityproxymodel/tst_qidentityproxymodel.cpp
index c76052a38b..149d272594 100644
--- a/tests/auto/corelib/itemmodels/qidentityproxymodel/tst_qidentityproxymodel.cpp
+++ b/tests/auto/corelib/itemmodels/qidentityproxymodel/tst_qidentityproxymodel.cpp
@@ -32,6 +32,7 @@
#include <QStandardItemModel>
#include <QStringListModel>
#include <QTest>
+#include <QTransposeProxyModel>
#include <QLoggingCategory>
#include "dynamictreemodel.h"
@@ -69,6 +70,7 @@ private slots:
void insertRows();
void removeRows();
void moveRows();
+ void moveColumns();
void reset();
void dataChanged();
@@ -235,47 +237,24 @@ void tst_QIdentityProxyModel::removeRows()
void tst_QIdentityProxyModel::moveRows()
{
- DynamicTreeModel model;
-
- {
- ModelInsertCommand insertCommand(&model);
- insertCommand.setStartRow(0);
- insertCommand.setEndRow(9);
- insertCommand.doCommand();
- }
- {
- ModelInsertCommand insertCommand(&model);
- insertCommand.setAncestorRowNumbers(QList<int>() << 5);
- insertCommand.setStartRow(0);
- insertCommand.setEndRow(9);
- insertCommand.doCommand();
- }
+ QStringListModel model({"A", "B", "C", "D", "E", "F"});
m_proxy->setSourceModel(&model);
verifyIdentity(&model);
- QSignalSpy modelBeforeSpy(&model, &DynamicTreeModel::rowsAboutToBeMoved);
- QSignalSpy modelAfterSpy(&model, &DynamicTreeModel::rowsMoved);
- QSignalSpy proxyBeforeSpy(m_proxy, &QIdentityProxyModel::rowsAboutToBeMoved);
- QSignalSpy proxyAfterSpy(m_proxy, &QIdentityProxyModel::rowsMoved);
-
- QVERIFY(modelBeforeSpy.isValid());
- QVERIFY(modelAfterSpy.isValid());
- QVERIFY(proxyBeforeSpy.isValid());
- QVERIFY(proxyAfterSpy.isValid());
+ QSignalSpy modelBeforeSpy(&model, &QAbstractItemModel::rowsAboutToBeMoved);
+ QSignalSpy modelAfterSpy(&model, &QAbstractItemModel::rowsMoved);
+ QSignalSpy proxyBeforeSpy(m_proxy, &QAbstractItemModel::rowsAboutToBeMoved);
+ QSignalSpy proxyAfterSpy(m_proxy, &QAbstractItemModel::rowsMoved);
- {
- ModelMoveCommand moveCommand(&model, 0);
- moveCommand.setAncestorRowNumbers(QList<int>() << 5);
- moveCommand.setStartRow(3);
- moveCommand.setEndRow(4);
- moveCommand.setDestRow(1);
- moveCommand.doCommand();
- }
+ QVERIFY(m_proxy->moveRows(QModelIndex(), 1, 2, QModelIndex(), 5));
+ QCOMPARE(model.stringList(), QStringList({"A", "D", "E", "B", "C", "F"}));
- QVERIFY(modelBeforeSpy.size() == 1 && 1 == proxyBeforeSpy.size());
- QVERIFY(modelAfterSpy.size() == 1 && 1 == proxyAfterSpy.size());
+ QCOMPARE(modelBeforeSpy.size(), 1);
+ QCOMPARE(proxyBeforeSpy.size(), 1);
+ QCOMPARE(modelAfterSpy.size(), 1);
+ QCOMPARE(proxyAfterSpy.size(), 1);
QCOMPARE(modelBeforeSpy.first().first().value<QModelIndex>(), m_proxy->mapToSource(proxyBeforeSpy.first().first().value<QModelIndex>()));
QCOMPARE(modelBeforeSpy.first().at(1), proxyBeforeSpy.first().at(1));
@@ -289,9 +268,62 @@ void tst_QIdentityProxyModel::moveRows()
QCOMPARE(modelAfterSpy.first().at(3).value<QModelIndex>(), m_proxy->mapToSource(proxyAfterSpy.first().at(3).value<QModelIndex>()));
QCOMPARE(modelAfterSpy.first().at(4), proxyAfterSpy.first().at(4));
+ QVERIFY(m_proxy->moveRows(QModelIndex(), 3, 2, QModelIndex(), 1));
+ QCOMPARE(model.stringList(), QStringList({"A", "B", "C", "D", "E", "F"}));
+ QVERIFY(m_proxy->moveRows(QModelIndex(), 0, 3, QModelIndex(), 6));
+ QCOMPARE(model.stringList(), QStringList({"D", "E", "F", "A", "B", "C"}));
+
verifyIdentity(&model);
- m_proxy->setSourceModel(0);
+ m_proxy->setSourceModel(nullptr);
+}
+
+void tst_QIdentityProxyModel::moveColumns()
+{
+ // QStringListModel implements moveRows but not moveColumns
+ // so we have to use a QTransposeProxyModel inbetween to check if
+ // QIdentityProxyModel::moveColumns works as expected
+ QStringListModel model({"A", "B", "C", "D", "E", "F"});
+ QTransposeProxyModel tpm;
+ tpm.setSourceModel(&model);
+
+ m_proxy->setSourceModel(&tpm);
+
+ verifyIdentity(&tpm);
+
+ QSignalSpy modelBeforeSpy(&tpm, &QAbstractItemModel::columnsAboutToBeMoved);
+ QSignalSpy modelAfterSpy(&tpm, &QAbstractItemModel::columnsMoved);
+ QSignalSpy proxyBeforeSpy(m_proxy, &QAbstractItemModel::columnsAboutToBeMoved);
+ QSignalSpy proxyAfterSpy(m_proxy, &QAbstractItemModel::columnsMoved);
+
+ QVERIFY(m_proxy->moveColumns(QModelIndex(), 1, 2, QModelIndex(), 5));
+ QCOMPARE(model.stringList(), QStringList({"A", "D", "E", "B", "C", "F"}));
+
+ QCOMPARE(proxyBeforeSpy.size(), 1);
+ QCOMPARE(modelBeforeSpy.size(), 1);
+ QCOMPARE(modelAfterSpy.size(), 1);
+ QCOMPARE(proxyAfterSpy.size(), 1);
+
+ QCOMPARE(modelBeforeSpy.first().first().value<QModelIndex>(), m_proxy->mapToSource(proxyBeforeSpy.first().first().value<QModelIndex>()));
+ QCOMPARE(modelBeforeSpy.first().at(1), proxyBeforeSpy.first().at(1));
+ QCOMPARE(modelBeforeSpy.first().at(2), proxyBeforeSpy.first().at(2));
+ QCOMPARE(modelBeforeSpy.first().at(3).value<QModelIndex>(), m_proxy->mapToSource(proxyBeforeSpy.first().at(3).value<QModelIndex>()));
+ QCOMPARE(modelBeforeSpy.first().at(4), proxyBeforeSpy.first().at(4));
+
+ QCOMPARE(modelAfterSpy.first().first().value<QModelIndex>(), m_proxy->mapToSource(proxyAfterSpy.first().first().value<QModelIndex>()));
+ QCOMPARE(modelAfterSpy.first().at(1), proxyAfterSpy.first().at(1));
+ QCOMPARE(modelAfterSpy.first().at(2), proxyAfterSpy.first().at(2));
+ QCOMPARE(modelAfterSpy.first().at(3).value<QModelIndex>(), m_proxy->mapToSource(proxyAfterSpy.first().at(3).value<QModelIndex>()));
+ QCOMPARE(modelAfterSpy.first().at(4), proxyAfterSpy.first().at(4));
+
+ QVERIFY(m_proxy->moveColumns(QModelIndex(), 3, 2, QModelIndex(), 1));
+ QCOMPARE(model.stringList(), QStringList({"A", "B", "C", "D", "E", "F"}));
+ QVERIFY(m_proxy->moveColumns(QModelIndex(), 0, 3, QModelIndex(), 6));
+ QCOMPARE(model.stringList(), QStringList({"D", "E", "F", "A", "B", "C"}));
+
+ verifyIdentity(&tpm);
+
+ m_proxy->setSourceModel(nullptr);
}
void tst_QIdentityProxyModel::reset()
diff --git a/tests/auto/corelib/itemmodels/qitemselectionmodel/tst_qitemselectionmodel.cpp b/tests/auto/corelib/itemmodels/qitemselectionmodel/tst_qitemselectionmodel.cpp
index c74101928a..6b59a6f1af 100644
--- a/tests/auto/corelib/itemmodels/qitemselectionmodel/tst_qitemselectionmodel.cpp
+++ b/tests/auto/corelib/itemmodels/qitemselectionmodel/tst_qitemselectionmodel.cpp
@@ -2037,12 +2037,16 @@ void tst_QItemSelectionModel::rowIntersectsSelection3()
QModelIndex parent;
QVERIFY(!selectionModel.rowIntersectsSelection(0, parent));
+ QVERIFY(!selectionModel.columnIntersectsSelection(0, parent));
parent = model.index(0, 0, parent);
QVERIFY(selectionModel.rowIntersectsSelection(0, parent));
+ QVERIFY(selectionModel.columnIntersectsSelection(0, parent));
parent = model.index(0, 0, parent);
QVERIFY(!selectionModel.rowIntersectsSelection(0, parent));
+ QVERIFY(!selectionModel.columnIntersectsSelection(0, parent));
parent = model.index(0, 0, parent);
QVERIFY(!selectionModel.rowIntersectsSelection(0, parent));
+ QVERIFY(!selectionModel.columnIntersectsSelection(0, parent));
}
void tst_QItemSelectionModel::unselectable()
@@ -2059,7 +2063,7 @@ void tst_QItemSelectionModel::unselectable()
QCOMPARE(selectionModel.selectedIndexes().count(), 10);
QCOMPARE(selectionModel.selectedRows().count(), 10);
for (int j = 0; j < 10; ++j)
- model.item(j)->setFlags(0);
+ model.item(j)->setFlags({ });
QCOMPARE(selectionModel.selectedIndexes().count(), 0);
QCOMPARE(selectionModel.selectedRows().count(), 0);
}
diff --git a/tests/auto/corelib/itemmodels/qstringlistmodel/tst_qstringlistmodel.cpp b/tests/auto/corelib/itemmodels/qstringlistmodel/tst_qstringlistmodel.cpp
index 3919472b96..7182553f27 100644
--- a/tests/auto/corelib/itemmodels/qstringlistmodel/tst_qstringlistmodel.cpp
+++ b/tests/auto/corelib/itemmodels/qstringlistmodel/tst_qstringlistmodel.cpp
@@ -103,28 +103,25 @@ void tst_QStringListModel::moveRowsInvalid_data()
QTest::addColumn<QModelIndex>("destinationParent");
QTest::addColumn<int>("destination");
- QStringListModel* tempModel = new QStringListModel(QStringList{"A", "B", "C", "D", "E", "F"}, this);
- QTest::addRow("destination_equal_source") << tempModel << QModelIndex() << 0 << 1 << QModelIndex() << 1;
- tempModel = new QStringListModel(QStringList{"A", "B", "C", "D", "E", "F"}, this);
- QTest::addRow("count_equal_0") << tempModel << QModelIndex() << 0 << 0 << QModelIndex() << 2;
- tempModel = new QStringListModel(QStringList{"A", "B", "C", "D", "E", "F"}, this);
+ const auto createModel = [this]() {
+ return new QStringListModel(QStringList{"A", "B", "C", "D", "E", "F"}, this);
+ };
+ constexpr int rowCount = 6;
+
+ QTest::addRow("destination_equal_source") << createModel() << QModelIndex() << 0 << 1 << QModelIndex() << 0;
+ QTest::addRow("count_equal_0") << createModel() << QModelIndex() << 0 << 0 << QModelIndex() << 2;
+ QStringListModel *tempModel = createModel();
QTest::addRow("move_child") << tempModel << tempModel->index(0, 0) << 0 << 1 << QModelIndex() << 2;
- tempModel = new QStringListModel(QStringList{"A", "B", "C", "D", "E", "F"}, this);
+ tempModel = createModel();
QTest::addRow("move_to_child") << tempModel << QModelIndex() << 0 << 1 << tempModel->index(0, 0) << 2;
- tempModel = new QStringListModel(QStringList{"A", "B", "C", "D", "E", "F"}, this);
- QTest::addRow("negative_count") << tempModel << QModelIndex() << 0 << -1 << QModelIndex() << 2;
- tempModel = new QStringListModel(QStringList{"A", "B", "C", "D", "E", "F"}, this);
- QTest::addRow("negative_source_row") << tempModel << QModelIndex() << -1 << 1 << QModelIndex() << 2;
- tempModel = new QStringListModel(QStringList{"A", "B", "C", "D", "E", "F"}, this);
- QTest::addRow("negative_destination_row") << tempModel << QModelIndex() << 0 << 1 << QModelIndex() << -1;
- tempModel = new QStringListModel(QStringList{"A", "B", "C", "D", "E", "F"}, this);
- QTest::addRow("source_row_equal_rowCount") << tempModel << QModelIndex() << tempModel->rowCount() << 1 << QModelIndex() << 1;
- tempModel = new QStringListModel(QStringList{"A", "B", "C", "D", "E", "F"}, this);
- QTest::addRow("destination_row_greater_rowCount") << tempModel << QModelIndex() << 0 << 1 << QModelIndex() << tempModel->rowCount() + 1;
- tempModel = new QStringListModel(QStringList{"A", "B", "C", "D", "E", "F"}, this);
- QTest::addRow("move_row_within_source_range") << tempModel << QModelIndex() << 0 << 3 << QModelIndex() << 2;
- tempModel = new QStringListModel(QStringList{"A", "B", "C", "D", "E", "F"}, this);
- QTest::addRow("destination_row_before_0") << tempModel << QModelIndex() << 1 << 1 << QModelIndex() << 0;
+ QTest::addRow("negative_count") << createModel() << QModelIndex() << 0 << -1 << QModelIndex() << 2;
+ QTest::addRow("negative_source_row") << createModel() << QModelIndex() << -1 << 1 << QModelIndex() << 2;
+ QTest::addRow("negative_destination_row") << createModel() << QModelIndex() << 0 << 1 << QModelIndex() << -1;
+ QTest::addRow("source_row_equal_rowCount") << createModel() << QModelIndex() << rowCount << 1 << QModelIndex() << 1;
+ QTest::addRow("source_row_equal_destination_row") << createModel() << QModelIndex() << 2 << 1 << QModelIndex() << 2;
+ QTest::addRow("source_row_equal_destination_row_plus_1") << createModel() << QModelIndex() << 2 << 1 << QModelIndex() << 3;
+ QTest::addRow("destination_row_greater_rowCount") << createModel() << QModelIndex() << 0 << 1 << QModelIndex() << rowCount + 1;
+ QTest::addRow("move_row_within_source_range") << createModel() << QModelIndex() << 0 << 3 << QModelIndex() << 2;
}
void tst_QStringListModel::moveRowsInvalid()
@@ -155,20 +152,20 @@ void tst_QStringListModel::moveRows_data()
QTest::newRow("1_Item_from_top_to_middle") << 0 << 1 << 3 << QStringList{"B", "C", "A", "D", "E", "F"};
QTest::newRow("1_Item_from_top_to_bottom") << 0 << 1 << 6 << QStringList{"B", "C", "D", "E", "F", "A"};
- QTest::newRow("1_Item_from_middle_to_top") << 2 << 1 << 1 << QStringList{"C", "A", "B", "D", "E", "F"};
- QTest::newRow("1_Item_from_bottom_to_middle") << 5 << 1 << 3 << QStringList{"A", "B", "F", "C", "D", "E"};
- QTest::newRow("1_Item_from_bottom to_top") << 5 << 1 << 1 << QStringList{"F", "A", "B", "C", "D", "E"};
+ QTest::newRow("1_Item_from_middle_to_top") << 2 << 1 << 0 << QStringList{"C", "A", "B", "D", "E", "F"};
+ QTest::newRow("1_Item_from_bottom_to_middle") << 5 << 1 << 2 << QStringList{"A", "B", "F", "C", "D", "E"};
+ QTest::newRow("1_Item_from_bottom to_top") << 5 << 1 << 0 << QStringList{"F", "A", "B", "C", "D", "E"};
QTest::newRow("1_Item_from_middle_to_bottom") << 2 << 1 << 6 << QStringList{"A", "B", "D", "E", "F", "C"};
- QTest::newRow("1_Item_from_middle_to_middle_before") << 2 << 1 << 1 << QStringList{"C", "A", "B", "D", "E", "F"};
+ QTest::newRow("1_Item_from_middle_to_middle_before") << 2 << 1 << 1 << QStringList{"A", "C", "B", "D", "E", "F"};
QTest::newRow("1_Item_from_middle_to_middle_after") << 2 << 1 << 4 << QStringList{"A", "B", "D", "C", "E", "F"};
QTest::newRow("2_Items_from_top_to_middle") << 0 << 2 << 3 << QStringList{"C", "A", "B", "D", "E", "F"};
QTest::newRow("2_Items_from_top_to_bottom") << 0 << 2 << 6 << QStringList{"C", "D", "E", "F", "A", "B"};
- QTest::newRow("2_Items_from_middle_to_top") << 2 << 2 << 1 << QStringList{"C", "D", "A", "B", "E", "F"};
- QTest::newRow("2_Items_from_bottom_to_middle") << 4 << 2 << 3 << QStringList{"A", "B", "E", "F", "C", "D"};
- QTest::newRow("2_Items_from_bottom_to_top") << 4 << 2 << 1 << QStringList{"E", "F", "A", "B", "C", "D"};
+ QTest::newRow("2_Items_from_middle_to_top") << 2 << 2 << 0 << QStringList{"C", "D", "A", "B", "E", "F"};
+ QTest::newRow("2_Items_from_bottom_to_middle") << 4 << 2 << 2 << QStringList{"A", "B", "E", "F", "C", "D"};
+ QTest::newRow("2_Items_from_bottom_to_top") << 4 << 2 << 0 << QStringList{"E", "F", "A", "B", "C", "D"};
QTest::newRow("2_Items_from_middle_to_bottom") << 2 << 2 << 6 << QStringList{"A", "B", "E", "F", "C", "D"};
- QTest::newRow("2_Items_from_middle_to_middle_before") << 3 << 2 << 2 << QStringList{"A", "D", "E", "B", "C", "F"};
+ QTest::newRow("2_Items_from_middle_to_middle_before") << 3 << 2 << 1 << QStringList{"A", "D", "E", "B", "C", "F"};
QTest::newRow("2_Items_from_middle_to_middle_after") << 1 << 2 << 5 << QStringList{"A", "D", "E", "B", "C", "F"};
}