summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/itemviews
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/widgets/itemviews
parentd1be8b9ceb2c7b20bbe53a07154c79699540ea3d (diff)
parent06bb315beb6c2c398223cfe52cbc7f66e14a8557 (diff)
Merge remote-tracking branch 'origin/dev' into merge-dev
Diffstat (limited to 'tests/auto/widgets/itemviews')
-rw-r--r--tests/auto/widgets/itemviews/qdirmodel/tst_qdirmodel.cpp6
-rw-r--r--tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp40
-rw-r--r--tests/auto/widgets/itemviews/qtableview/BLACKLIST2
-rw-r--r--tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp2
-rw-r--r--tests/auto/widgets/itemviews/qtablewidget/tst_qtablewidget.cpp25
-rw-r--r--tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp84
-rw-r--r--tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp14
7 files changed, 132 insertions, 41 deletions
diff --git a/tests/auto/widgets/itemviews/qdirmodel/tst_qdirmodel.cpp b/tests/auto/widgets/itemviews/qdirmodel/tst_qdirmodel.cpp
index 5097f2e356..546b2ab3a8 100644
--- a/tests/auto/widgets/itemviews/qdirmodel/tst_qdirmodel.cpp
+++ b/tests/auto/widgets/itemviews/qdirmodel/tst_qdirmodel.cpp
@@ -697,7 +697,7 @@ void tst_QDirModel::roleNames_data()
{
QTest::addColumn<int>("role");
QTest::addColumn<QByteArray>("roleName");
- QTest::newRow("decoration") << int(Qt::DecorationRole) << QByteArray("decoration");
+ QTest::newRow("decoration") << int(Qt::DecorationRole) << QByteArray("fileIcon");
QTest::newRow("display") << int(Qt::DisplayRole) << QByteArray("display");
QTest::newRow("fileIcon") << int(QDirModel::FileIconRole) << QByteArray("fileIcon");
QTest::newRow("filePath") << int(QDirModel::FilePathRole) << QByteArray("filePath");
@@ -713,8 +713,8 @@ void tst_QDirModel::roleNames()
QVERIFY(roles.contains(role));
QFETCH(QByteArray, roleName);
- QList<QByteArray> values = roles.values(role);
- QVERIFY(values.contains(roleName));
+ QCOMPARE(roles.values(role).count(), 1);
+ QCOMPARE(roles.value(role), roleName);
}
diff --git a/tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp b/tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp
index cb083fdcbe..67d8764b61 100644
--- a/tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp
+++ b/tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp
@@ -177,8 +177,9 @@ void tst_QListWidget::moveRowsInvalid_data()
result->addItems({"A", "B", "C", "D", "E", "F"});
return result;
};
+ constexpr int rowCount = 6;
- QTest::addRow("destination_equal_source") << createWidget() << QModelIndex() << 0 << 1 << QModelIndex() << 1;
+ QTest::addRow("destination_equal_source") << createWidget() << QModelIndex() << 0 << 1 << QModelIndex() << 0;
QTest::addRow("count_equal_0") << createWidget() << QModelIndex() << 0 << 0 << QModelIndex() << 2;
QListWidget* tempWidget = createWidget();
QTest::addRow("move_child") << tempWidget << tempWidget->model()->index(0, 0) << 0 << 1 << QModelIndex() << 2;
@@ -187,10 +188,11 @@ void tst_QListWidget::moveRowsInvalid_data()
QTest::addRow("negative_count") << createWidget() << QModelIndex() << 0 << -1 << QModelIndex() << 2;
QTest::addRow("negative_source_row") << createWidget() << QModelIndex() << -1 << 1 << QModelIndex() << 2;
QTest::addRow("negative_destination_row") << createWidget() << QModelIndex() << 0 << 1 << QModelIndex() << -1;
- QTest::addRow("source_row_equal_rowCount") << createWidget() << QModelIndex() << 6 << 1 << QModelIndex() << 1;
- QTest::addRow("destination_row_greater_rowCount") << createWidget() << QModelIndex() << 0 << 1 << QModelIndex() << 6 + 1;
+ QTest::addRow("source_row_equal_rowCount") << createWidget() << QModelIndex() << rowCount << 1 << QModelIndex() << 1;
+ QTest::addRow("source_row_equal_destination_row") << createWidget() << QModelIndex() << 2 << 1 << QModelIndex() << 2;
+ QTest::addRow("source_row_equal_destination_row_plus1") << createWidget() << QModelIndex() << 2 << 1 << QModelIndex() << 3;
+ QTest::addRow("destination_row_greater_rowCount") << createWidget() << QModelIndex() << 0 << 1 << QModelIndex() << rowCount + 1;
QTest::addRow("move_row_within_source_range") << createWidget() << QModelIndex() << 0 << 3 << QModelIndex() << 2;
- QTest::addRow("destination_row_before_0") << createWidget() << QModelIndex() << 1 << 1 << QModelIndex() << 0;
}
void tst_QListWidget::moveRowsInvalid()
@@ -221,20 +223,20 @@ void tst_QListWidget::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"};
}
@@ -1512,6 +1514,20 @@ void tst_QListWidget::itemData()
QCOMPARE(flags.count(), 6);
for (int i = 0; i < 4; ++i)
QCOMPARE(flags[Qt::UserRole + i].toString(), QString::number(i + 1));
+
+ item.setBackground(QBrush(Qt::red));
+ item.setForeground(QBrush(Qt::red));
+ item.setSizeHint(QSize(10, 10));
+ QCOMPARE(item.data(Qt::BackgroundRole), QVariant(QBrush(Qt::red)));
+ QCOMPARE(item.data(Qt::ForegroundRole), QVariant(QBrush(Qt::red)));
+ QCOMPARE(item.data(Qt::SizeHintRole), QVariant(QSize(10, 10)));
+ // an empty brush should result in a QVariant()
+ item.setBackground(QBrush());
+ item.setForeground(QBrush());
+ item.setSizeHint(QSize());
+ QCOMPARE(item.data(Qt::BackgroundRole), QVariant());
+ QCOMPARE(item.data(Qt::ForegroundRole), QVariant());
+ QCOMPARE(item.data(Qt::SizeHintRole), QVariant());
}
void tst_QListWidget::changeDataWithSorting()
diff --git a/tests/auto/widgets/itemviews/qtableview/BLACKLIST b/tests/auto/widgets/itemviews/qtableview/BLACKLIST
index 9648cef3de..ff870915be 100644
--- a/tests/auto/widgets/itemviews/qtableview/BLACKLIST
+++ b/tests/auto/widgets/itemviews/qtableview/BLACKLIST
@@ -1,3 +1,5 @@
[moveCursorBiggerJump]
osx
+[mouseWheel:scroll down per pixel]
+macos
diff --git a/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp b/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp
index 1d0153213b..544069243f 100644
--- a/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp
+++ b/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp
@@ -1299,7 +1299,7 @@ void tst_QTableView::moveCursorStrikesBack()
int newRow = -1;
int newColumn = -1;
for (auto cursorMoveAction : cursorMoveActions) {
- QModelIndex newIndex = view.moveCursor(cursorMoveAction, nullptr);
+ QModelIndex newIndex = view.moveCursor(cursorMoveAction, {});
view.setCurrentIndex(newIndex);
newRow = newIndex.row();
newColumn = newIndex.column();
diff --git a/tests/auto/widgets/itemviews/qtablewidget/tst_qtablewidget.cpp b/tests/auto/widgets/itemviews/qtablewidget/tst_qtablewidget.cpp
index f640996690..38dae7743f 100644
--- a/tests/auto/widgets/itemviews/qtablewidget/tst_qtablewidget.cpp
+++ b/tests/auto/widgets/itemviews/qtablewidget/tst_qtablewidget.cpp
@@ -1404,9 +1404,17 @@ void tst_QTableWidget::setItemData()
QCOMPARE(table.currentRoles, QVector<int>({Qt::DisplayRole, Qt::EditRole, Qt::ToolTipRole}));
QCOMPARE(table.model()->data(idx, Qt::DisplayRole).toString(), QLatin1String("Display"));
+ QCOMPARE(table.model()->data(idx, Qt::EditRole).toString(), QLatin1String("Display"));
QCOMPARE(table.model()->data(idx, Qt::ToolTipRole).toString(), QLatin1String("ToolTip"));
QCOMPARE(dataChangedSpy.count(), 1);
- QCOMPARE(idx, qvariant_cast<QModelIndex>(dataChangedSpy.takeFirst().at(0)));
+ QCOMPARE(idx, qvariant_cast<QModelIndex>(dataChangedSpy.first().at(0)));
+ QCOMPARE(idx, qvariant_cast<QModelIndex>(dataChangedSpy.first().at(1)));
+ const auto roles = qvariant_cast<QVector<int>>(dataChangedSpy.first().at(2));
+ QCOMPARE(roles.size(), 3);
+ QVERIFY(roles.contains(Qt::DisplayRole));
+ QVERIFY(roles.contains(Qt::EditRole));
+ QVERIFY(roles.contains(Qt::ToolTipRole));
+ dataChangedSpy.clear();
table.model()->setItemData(idx, data);
QCOMPARE(dataChangedSpy.count(), 0);
@@ -1416,6 +1424,21 @@ void tst_QTableWidget::setItemData()
table.model()->setItemData(idx, data);
QCOMPARE(table.model()->data(idx, Qt::DisplayRole).toString(), QLatin1String("dizplaye"));
QCOMPARE(dataChangedSpy.count(), 1);
+ QCOMPARE(QVector<int>({Qt::DisplayRole, Qt::EditRole}), qvariant_cast<QVector<int>>(dataChangedSpy.first().at(2)));
+
+ item->setBackground(QBrush(Qt::red));
+ item->setForeground(QBrush(Qt::green));
+ item->setSizeHint(QSize(10, 10));
+ QCOMPARE(item->data(Qt::BackgroundRole), QVariant(QBrush(Qt::red)));
+ QCOMPARE(item->data(Qt::ForegroundRole), QVariant(QBrush(Qt::green)));
+ QCOMPARE(item->data(Qt::SizeHintRole), QVariant(QSize(10, 10)));
+ // an empty brush should result in a QVariant()
+ item->setBackground(QBrush());
+ item->setForeground(QBrush());
+ item->setSizeHint(QSize());
+ QCOMPARE(item->data(Qt::BackgroundRole), QVariant());
+ QCOMPARE(item->data(Qt::ForegroundRole), QVariant());
+ QCOMPARE(item->data(Qt::SizeHintRole), QVariant());
}
void tst_QTableWidget::cellWidget()
diff --git a/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp b/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp
index dcffe8043b..8396fd4ec7 100644
--- a/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp
+++ b/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp
@@ -77,6 +77,30 @@ static void initStandardTreeModel(QStandardItemModel *model)
model->insertRow(2, item);
}
+class TreeView : public QTreeView
+{
+ Q_OBJECT
+public:
+ using QTreeView::QTreeView;
+ using QTreeView::selectedIndexes;
+
+ void paintEvent(QPaintEvent *event) override
+ {
+ QTreeView::paintEvent(event);
+ wasPainted = true;
+ }
+ bool wasPainted = false;
+public slots:
+ void handleSelectionChanged()
+ {
+ //let's select the last item
+ QModelIndex idx = model()->index(0, 0);
+ selectionModel()->select(QItemSelection(idx, idx), QItemSelectionModel::Select);
+ disconnect(selectionModel(), &QItemSelectionModel::selectionChanged,
+ this, &TreeView::handleSelectionChanged);
+ }
+};
+
class tst_QTreeView : public QObject
{
Q_OBJECT
@@ -2868,6 +2892,7 @@ public:
};
Node *root;
+ bool crash = false;
EvilModel(QObject *parent = nullptr): QAbstractItemModel(parent), root(new Node)
{}
@@ -2876,6 +2901,11 @@ public:
delete root;
}
+ void setCrash()
+ {
+ crash = true;
+ }
+
void change()
{
emit layoutAboutToBeChanged();
@@ -2944,6 +2974,10 @@ public:
QVariant data(const QModelIndex &idx, int role) const override
{
+ if (crash) {
+ QTest::qFail("Should not get here...", __FILE__, __LINE__);
+ return QVariant();
+ }
if (idx.isValid() && role == Qt::DisplayRole) {
Node *parentNode = root;
if (idx.isValid()) {
@@ -2963,13 +2997,14 @@ void tst_QTreeView::evilModel_data()
{
QTest::addColumn<bool>("visible");
QTest::newRow("visible") << false;
+ QTest::newRow("visible") << true;
}
void tst_QTreeView::evilModel()
{
QFETCH(bool, visible);
// init
- QTreeView view;
+ TreeView view;
EvilModel model;
view.setModel(&model);
view.setVisible(visible);
@@ -3007,7 +3042,7 @@ void tst_QTreeView::evilModel()
view.scrollTo(thirdLevel);
model.change();
- view.repaint();
+ view.update(); // will not do anything since view is not visible
model.change();
QTest::mouseDClick(view.viewport(), Qt::LeftButton);
@@ -3132,6 +3167,9 @@ void tst_QTreeView::evilModel()
model.change();
view.setRootIndex(secondLevel);
+
+ model.setCrash();
+ view.setModel(nullptr);
}
void tst_QTreeView::indexRowSizeHint()
@@ -3161,7 +3199,7 @@ void tst_QTreeView::filterProxyModelCrash()
QSortFilterProxyModel proxy;
proxy.setSourceModel(&model);
- QTreeView view;
+ TreeView view;
view.setModel(&proxy);
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
@@ -3170,7 +3208,8 @@ void tst_QTreeView::filterProxyModelCrash()
QTest::qWait(20);
proxy.invalidate();
- view.repaint(); //used to crash
+ view.update(); //used to crash
+ QTRY_VERIFY(view.wasPainted);
}
void tst_QTreeView::renderToPixmap_data()
@@ -3638,10 +3677,7 @@ void tst_QTreeView::task220298_selectColumns()
}
};
- class TreeView : public QTreeView {
- public:
- using QTreeView::selectedIndexes;
- } view;
+ TreeView view;
Model model;
view.setModel(&model);
view.show();
@@ -3990,20 +4026,6 @@ void tst_QTreeView::task254234_proxySort()
QCOMPARE(view.model()->data(view.model()->index(1, 1)).toString(), QString::fromLatin1("g"));
}
-class TreeView : public QTreeView
-{
- Q_OBJECT
-public slots:
- void handleSelectionChanged()
- {
- //let's select the last item
- QModelIndex idx = model()->index(0, 0);
- selectionModel()->select(QItemSelection(idx, idx), QItemSelectionModel::Select);
- disconnect(selectionModel(), &QItemSelectionModel::selectionChanged,
- this, &TreeView::handleSelectionChanged);
- }
-};
-
void tst_QTreeView::task248022_changeSelection()
{
//we check that changing the selection between the mouse press and the mouse release
@@ -4900,10 +4922,24 @@ void tst_QTreeView::taskQTBUG_61476()
const QPoint pos = rect.center();
QTest::mousePress(tv.viewport(), Qt::LeftButton, {}, pos);
- if (tv.style()->styleHint(QStyle::SH_ListViewExpand_SelectMouseType, nullptr, &tv) ==
- QEvent::MouseButtonPress)
+ const bool expandsOnPress =
+ (tv.style()->styleHint(QStyle::SH_ListViewExpand_SelectMouseType, nullptr, &tv) == QEvent::MouseButtonPress);
+ if (expandsOnPress)
QTRY_VERIFY(!tv.isExpanded(mi));
+ QTest::mouseRelease(tv.viewport(), Qt::LeftButton, {}, pos);
+ QTRY_VERIFY(!tv.isExpanded(mi));
+ QCOMPARE(lastTopLevel->checkState(), Qt::Checked);
+
+ // Test that it does not toggle the check state of a previously selected item when collapsing an
+ // item causes it to position the item under the mouse to be the decoration for the selected item
+ tv.expandAll();
+ tv.verticalScrollBar()->setValue(tv.verticalScrollBar()->maximum());
+ // It is not enough to programmatically select the item, we need to have it clicked on
+ QTest::mouseClick(tv.viewport(), Qt::LeftButton, {}, tv.visualRect(lastTopLevel->index()).center());
+ QTest::mousePress(tv.viewport(), Qt::LeftButton, {}, pos);
+ if (expandsOnPress)
+ QTRY_VERIFY(!tv.isExpanded(mi));
QTest::mouseRelease(tv.viewport(), Qt::LeftButton, nullptr, pos);
QTRY_VERIFY(!tv.isExpanded(mi));
QCOMPARE(lastTopLevel->checkState(), Qt::Checked);
diff --git a/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp b/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp
index 2118bb5a29..7da56ab797 100644
--- a/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp
+++ b/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp
@@ -1994,6 +1994,20 @@ void tst_QTreeWidget::itemData()
QCOMPARE(flags[Qt::UserRole + i].toString(), QString::number(i + 1));
flags = widget.model()->itemData(widget.model()->index(0, 1));
QCOMPARE(flags.count(), 0);
+
+ item.setBackground(0, QBrush(Qt::red));
+ item.setForeground(0, QBrush(Qt::green));
+ item.setSizeHint(0, QSize(10, 10));
+ QCOMPARE(item.data(0, Qt::BackgroundRole), QVariant(QBrush(Qt::red)));
+ QCOMPARE(item.data(0, Qt::ForegroundRole), QVariant(QBrush(Qt::green)));
+ QCOMPARE(item.data(0, Qt::SizeHintRole), QVariant(QSize(10, 10)));
+ // an empty brush should result in a QVariant()
+ item.setBackground(0, QBrush());
+ item.setForeground(0, QBrush());
+ item.setSizeHint(0, QSize());
+ QCOMPARE(item.data(0, Qt::BackgroundRole), QVariant());
+ QCOMPARE(item.data(0, Qt::ForegroundRole), QVariant());
+ QCOMPARE(item.data(0, Qt::SizeHintRole), QVariant());
}
void tst_QTreeWidget::enableDisable()