summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorStephen Kelly <stephen.kelly@kdab.com>2013-02-10 16:06:05 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-08-13 16:34:16 +0200
commitdfde98db52452a8c4711b80793c679974aefeb94 (patch)
tree3a66ae22db4838c57cc26f787beccc055f9d2da3 /tests
parent45e5a6ff7c6165aa8dfa0cb4f0e8f54cbef45f6e (diff)
Make the QItemSelectionModel test widgets-independent.
Change-Id: I695afe535ff291bc98f43185469a434cd9178926 Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/itemmodels/itemmodels.pro2
-rw-r--r--tests/auto/corelib/itemmodels/qitemselectionmodel/qitemselectionmodel.pro2
-rw-r--r--tests/auto/corelib/itemmodels/qitemselectionmodel/tst_qitemselectionmodel.cpp101
3 files changed, 51 insertions, 54 deletions
diff --git a/tests/auto/corelib/itemmodels/itemmodels.pro b/tests/auto/corelib/itemmodels/itemmodels.pro
index e0bc2a8a4b..3f726692ff 100644
--- a/tests/auto/corelib/itemmodels/itemmodels.pro
+++ b/tests/auto/corelib/itemmodels/itemmodels.pro
@@ -3,9 +3,9 @@ TEMPLATE=subdirs
SUBDIRS = qabstractitemmodel \
qabstractproxymodel \
qidentityproxymodel \
+ qitemselectionmodel \
qstringlistmodel \
qtHaveModule(widgets): SUBDIRS += \
qitemmodel \
- qitemselectionmodel \
qsortfilterproxymodel \
diff --git a/tests/auto/corelib/itemmodels/qitemselectionmodel/qitemselectionmodel.pro b/tests/auto/corelib/itemmodels/qitemselectionmodel/qitemselectionmodel.pro
index 9241676076..1b6279ba1b 100644
--- a/tests/auto/corelib/itemmodels/qitemselectionmodel/qitemselectionmodel.pro
+++ b/tests/auto/corelib/itemmodels/qitemselectionmodel/qitemselectionmodel.pro
@@ -1,6 +1,6 @@
CONFIG += testcase
CONFIG += parallel_test
TARGET = tst_qitemselectionmodel
-QT += widgets testlib
+QT += testlib
SOURCES += tst_qitemselectionmodel.cpp
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0
diff --git a/tests/auto/corelib/itemmodels/qitemselectionmodel/tst_qitemselectionmodel.cpp b/tests/auto/corelib/itemmodels/qitemselectionmodel/tst_qitemselectionmodel.cpp
index 8fac2c19eb..9788b78771 100644
--- a/tests/auto/corelib/itemmodels/qitemselectionmodel/tst_qitemselectionmodel.cpp
+++ b/tests/auto/corelib/itemmodels/qitemselectionmodel/tst_qitemselectionmodel.cpp
@@ -42,7 +42,6 @@
#include <QtTest/QtTest>
#include <QtGui/QtGui>
-#include <QtWidgets/QtWidgets>
class tst_QItemSelectionModel : public QObject
{
@@ -1526,22 +1525,21 @@ public:
void tst_QItemSelectionModel::resetModel()
{
MyStandardItemModel model(20, 20);
- QTreeView view;
- view.setModel(&model);
+ QItemSelectionModel *selectionModel = new QItemSelectionModel(&model);
- QSignalSpy spy(view.selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)));
+ QSignalSpy spy(selectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)));
QVERIFY(spy.isValid());
- view.selectionModel()->select(QItemSelection(model.index(0, 0), model.index(5, 5)), QItemSelectionModel::Select);
+ selectionModel->select(QItemSelection(model.index(0, 0), model.index(5, 5)), QItemSelectionModel::Select);
QCOMPARE(spy.count(), 1);
model.reset();
- QVERIFY(view.selectionModel()->selection().isEmpty());
- QVERIFY(view.selectionModel()->hasSelection() == false);
+ QVERIFY(selectionModel->selection().isEmpty());
+ QVERIFY(selectionModel->hasSelection() == false);
- view.selectionModel()->select(QItemSelection(model.index(0, 0), model.index(5, 5)), QItemSelectionModel::Select);
+ selectionModel->select(QItemSelection(model.index(0, 0), model.index(5, 5)), QItemSelectionModel::Select);
QCOMPARE(spy.count(), 2);
QCOMPARE(spy.at(1).count(), 2);
@@ -1905,22 +1903,20 @@ void tst_QItemSelectionModel::selectedColumns()
void tst_QItemSelectionModel::setCurrentIndex()
{
// Build up a simple tree
- QStandardItemModel *treemodel = new QStandardItemModel(0, 1);
+ QScopedPointer<QStandardItemModel> treemodel(new QStandardItemModel(0, 1));
treemodel->insertRow(0, new QStandardItem(1));
treemodel->insertRow(1, new QStandardItem(2));
- QTreeView treeView;
- treeView.setModel(treemodel);
- QItemSelectionModel *selectionModel = treeView.selectionModel();
- selectionModel->setCurrentIndex(
+ QItemSelectionModel selectionModel(treemodel.data());
+ selectionModel.setCurrentIndex(
treemodel->index(0, 0, treemodel->index(0, 0)),
QItemSelectionModel::SelectCurrent);
- QSignalSpy currentSpy(selectionModel,
+ QSignalSpy currentSpy(&selectionModel,
SIGNAL(currentChanged(QModelIndex,QModelIndex)));
- QSignalSpy rowSpy(selectionModel,
+ QSignalSpy rowSpy(&selectionModel,
SIGNAL(currentRowChanged(QModelIndex,QModelIndex)));
- QSignalSpy columnSpy(selectionModel,
+ QSignalSpy columnSpy(&selectionModel,
SIGNAL(currentColumnChanged(QModelIndex,QModelIndex)));
QVERIFY(currentSpy.isValid());
@@ -1928,7 +1924,7 @@ void tst_QItemSelectionModel::setCurrentIndex()
QVERIFY(columnSpy.isValid());
// Select the same row and column indexes, but with a different parent
- selectionModel->setCurrentIndex(
+ selectionModel.setCurrentIndex(
treemodel->index(0, 0, treemodel->index(1, 0)),
QItemSelectionModel::SelectCurrent);
@@ -1937,15 +1933,13 @@ void tst_QItemSelectionModel::setCurrentIndex()
QCOMPARE(columnSpy.count(), 1);
// Select another row in the same parent
- selectionModel->setCurrentIndex(
+ selectionModel.setCurrentIndex(
treemodel->index(1, 0, treemodel->index(1, 0)),
QItemSelectionModel::SelectCurrent);
QCOMPARE(currentSpy.count(), 2);
QCOMPARE(rowSpy.count(), 2);
QCOMPARE(columnSpy.count(), 1);
-
- delete treemodel;
}
void tst_QItemSelectionModel::splitOnInsert()
@@ -1960,29 +1954,27 @@ void tst_QItemSelectionModel::splitOnInsert()
void tst_QItemSelectionModel::rowIntersectsSelection1()
{
- QTableWidget table;
- table.setColumnCount(1);
- table.setRowCount(1);
- table.setItem(0, 0, new QTableWidgetItem("foo"));
- QAbstractItemModel *model = table.model();
- QItemSelectionModel *selectionModel = table.selectionModel();
- QModelIndex index = model->index(0, 0, QModelIndex());
-
- selectionModel->select(index, QItemSelectionModel::Select);
- QVERIFY(selectionModel->rowIntersectsSelection(0, QModelIndex()));
- QVERIFY(selectionModel->columnIntersectsSelection(0, QModelIndex()));
-
- selectionModel->select(index, QItemSelectionModel::Deselect);
- QVERIFY(!selectionModel->rowIntersectsSelection(0, QModelIndex()));
- QVERIFY(!selectionModel->columnIntersectsSelection(0, QModelIndex()));
-
- selectionModel->select(index, QItemSelectionModel::Toggle);
- QVERIFY(selectionModel->rowIntersectsSelection(0, QModelIndex()));
- QVERIFY(selectionModel->columnIntersectsSelection(0, QModelIndex()));
-
- selectionModel->select(index, QItemSelectionModel::Toggle);
- QVERIFY(!selectionModel->rowIntersectsSelection(0, QModelIndex()));
- QVERIFY(!selectionModel->columnIntersectsSelection(0, QModelIndex()));
+ QStandardItemModel model;
+ model.setItem(0, 0, new QStandardItem("foo"));
+ QItemSelectionModel selectionModel(&model);
+
+ QModelIndex index = model.index(0, 0, QModelIndex());
+
+ selectionModel.select(index, QItemSelectionModel::Select);
+ QVERIFY(selectionModel.rowIntersectsSelection(0, QModelIndex()));
+ QVERIFY(selectionModel.columnIntersectsSelection(0, QModelIndex()));
+
+ selectionModel.select(index, QItemSelectionModel::Deselect);
+ QVERIFY(!selectionModel.rowIntersectsSelection(0, QModelIndex()));
+ QVERIFY(!selectionModel.columnIntersectsSelection(0, QModelIndex()));
+
+ selectionModel.select(index, QItemSelectionModel::Toggle);
+ QVERIFY(selectionModel.rowIntersectsSelection(0, QModelIndex()));
+ QVERIFY(selectionModel.columnIntersectsSelection(0, QModelIndex()));
+
+ selectionModel.select(index, QItemSelectionModel::Toggle);
+ QVERIFY(!selectionModel.rowIntersectsSelection(0, QModelIndex()));
+ QVERIFY(!selectionModel.columnIntersectsSelection(0, QModelIndex()));
}
void tst_QItemSelectionModel::rowIntersectsSelection2()
@@ -2057,16 +2049,21 @@ void tst_QItemSelectionModel::rowIntersectsSelection3()
void tst_QItemSelectionModel::unselectable()
{
- QTreeWidget w;
- for (int i = 0; i < 10; ++i)
- w.setItemSelected(new QTreeWidgetItem(&w), true);
- QCOMPARE(w.topLevelItemCount(), 10);
- QCOMPARE(w.selectionModel()->selectedIndexes().count(), 10);
- QCOMPARE(w.selectionModel()->selectedRows().count(), 10);
+ QStandardItemModel model;
+ QStandardItem *parentItem = model.invisibleRootItem();
+
+ for (int i = 0; i < 10; ++i) {
+ QStandardItem *item = new QStandardItem(QString("item %0").arg(i));
+ parentItem->appendRow(item);
+ }
+ QItemSelectionModel selectionModel(&model);
+ selectionModel.select(QItemSelection(model.index(0, 0), model.index(9, 0)), QItemSelectionModel::Select);
+ QCOMPARE(selectionModel.selectedIndexes().count(), 10);
+ QCOMPARE(selectionModel.selectedRows().count(), 10);
for (int j = 0; j < 10; ++j)
- w.topLevelItem(j)->setFlags(0);
- QCOMPARE(w.selectionModel()->selectedIndexes().count(), 0);
- QCOMPARE(w.selectionModel()->selectedRows().count(), 0);
+ model.item(j)->setFlags(0);
+ QCOMPARE(selectionModel.selectedIndexes().count(), 0);
+ QCOMPARE(selectionModel.selectedRows().count(), 0);
}
void tst_QItemSelectionModel::selectedIndexes()