summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAndy Shaw <andy.shaw@qt.io>2019-02-14 13:27:18 +0100
committerAndy Shaw <andy.shaw@qt.io>2019-02-26 14:18:18 +0000
commit7e60858cbc40b8958482ca2e77bed4fda69b161c (patch)
tree4b014069d18b53c6f4c27a192abfc5b6ed2224c0 /tests
parent9694d754b815abdf302aba26bd1eada5768adb97 (diff)
Don't edit the item if we did not get the press event on the same item
With a QTreeView it is possible that collapsing an item can cause the item under the mouse to be a new one and over the checkbox area for the new item. As a result, a release can cause it to change the check state even though it did not get the press for that item. This ensures that it only allows the edit if it got the press as well. Fixes: QTBUG-61476 Change-Id: I9a0821466afc84c97c9819755ccbacd729f7fbd7 Reviewed-by: Christian Ehrlicher <ch.ehrlicher@gmx.de>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp b/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp
index 8f9afeea4d..a9858ae420 100644
--- a/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp
+++ b/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp
@@ -199,6 +199,7 @@ private slots:
void taskQTBUG_45697_crash();
void taskQTBUG_7232_AllowUserToControlSingleStep();
void taskQTBUG_8376();
+ void taskQTBUG_61476();
void testInitialFocus();
};
@@ -4726,5 +4727,58 @@ void tst_QTreeView::taskQTBUG_8376()
QCOMPARE(rowHeightLvl1Visible, rowHeightLvl1Visible2);
}
+void tst_QTreeView::taskQTBUG_61476()
+{
+ // This checks that if a user clicks on an item to collapse it that it
+ // does not edit (in this case change the check state) the item that is
+ // now over the mouse just because it got a release event
+ QTreeView tv;
+ QStandardItemModel model;
+ QStandardItem *lastTopLevel = nullptr;
+ {
+ for (int i = 0; i < 4; ++i) {
+ QStandardItem *item = new QStandardItem(QLatin1String("Row Item"));
+ item->setCheckable(true);
+ item->setCheckState(Qt::Checked);
+ model.appendRow(item);
+ lastTopLevel = item;
+ for (int j = 0; j < 2; ++j) {
+ QStandardItem *childItem = new QStandardItem(QLatin1String("Child row Item"));
+ childItem->setCheckable(true);
+ childItem->setCheckState(Qt::Checked);
+ item->appendRow(childItem);
+ QStandardItem *grandChild = new QStandardItem(QLatin1String("Grand child row Item"));
+ grandChild->setCheckable(true);
+ grandChild->setCheckState(Qt::Checked);
+ childItem->appendRow(grandChild);
+ }
+ }
+ }
+ tv.setModel(&model);
+ tv.expandAll();
+ // We need it to be this size so that the effect of the collapsing will
+ // cause the parent item to move to be under the cursor
+ tv.resize(200, 200);
+ tv.show();
+ QVERIFY(QTest::qWaitForWindowActive(&tv));
+ tv.verticalScrollBar()->setValue(tv.verticalScrollBar()->maximum());
+
+ // We want to press specifically right around where a checkbox for the
+ // parent item could be when collapsing
+ QTreeViewPrivate *priv = static_cast<QTreeViewPrivate*>(qt_widget_private(&tv));
+ const QModelIndex mi = lastTopLevel->child(0)->index();
+ const QRect rect = priv->itemDecorationRect(mi);
+ const QPoint pos = rect.center();
+
+ QTest::mousePress(tv.viewport(), Qt::LeftButton, 0, pos);
+ if (tv.style()->styleHint(QStyle::SH_ListViewExpand_SelectMouseType, 0, &tv) ==
+ QEvent::MouseButtonPress)
+ QTRY_VERIFY(!tv.isExpanded(mi));
+
+ QTest::mouseRelease(tv.viewport(), Qt::LeftButton, 0, pos);
+ QTRY_VERIFY(!tv.isExpanded(mi));
+ QCOMPARE(lastTopLevel->checkState(), Qt::Checked);
+}
+
QTEST_MAIN(tst_QTreeView)
#include "tst_qtreeview.moc"