QQuickTableView: clear selection on tap directly in TableView
Before 6.4, it was only possible to make a selection in TableView by using a SelectionRectangle. But in 6.4, you can also make a selection directly in TableView by using the shift+arrow keys. To make sure that a selection is cleared either way on tap, move the implementation that clears the selection from SelectionRectangle to TableView. Pick-to: 6.4 Change-Id: Ic718763bf9b643cb3e3c04cc3b90c6ffcf9ca4b2 Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
This commit is contained in:
parent
e86a38f20f
commit
b51ad14bc6
|
@ -4039,15 +4039,19 @@ void QQuickTableViewPrivate::init()
|
|||
positionYAnimation.stop();
|
||||
if (keyNavigationEnabled)
|
||||
q->forceActiveFocus(Qt::MouseFocusReason);
|
||||
if (!q->isInteractive())
|
||||
setCurrentIndexFromTap(tapHandler->point().pressPosition());
|
||||
if (q->isInteractive())
|
||||
return;
|
||||
clearSelection();
|
||||
setCurrentIndexFromTap(tapHandler->point().pressPosition());
|
||||
});
|
||||
|
||||
QObject::connect(tapHandler, &QQuickTapHandler::tapped, [this, q, tapHandler] {
|
||||
if (!pointerNavigationEnabled)
|
||||
return;
|
||||
if (q->isInteractive())
|
||||
setCurrentIndexFromTap(tapHandler->point().pressPosition());
|
||||
if (!q->isInteractive())
|
||||
return;
|
||||
clearSelection();
|
||||
setCurrentIndexFromTap(tapHandler->point().pressPosition());
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -145,7 +145,6 @@ QQuickSelectionRectanglePrivate::QQuickSelectionRectanglePrivate()
|
|||
});
|
||||
|
||||
QObject::connect(m_tapHandler, &QQuickTapHandler::tapped, [this] {
|
||||
m_selectable->clearSelection();
|
||||
updateActiveState(false);
|
||||
});
|
||||
|
||||
|
|
|
@ -199,6 +199,7 @@ private slots:
|
|||
void testSelectableStartPosEndPosOutsideView();
|
||||
void testSelectableScrollTowardsPos();
|
||||
void setCurrentIndexFromSelectionModel();
|
||||
void clearSelectionOnTap();
|
||||
void moveCurrentIndexUsingArrowKeys();
|
||||
void moveCurrentIndexUsingHomeAndEndKeys();
|
||||
void moveCurrentIndexUsingPageUpDownKeys();
|
||||
|
@ -4443,6 +4444,29 @@ void tst_QQuickTableView::setCurrentIndexFromSelectionModel()
|
|||
QVERIFY(tableView->itemAtCell(cellAtEnd)->property(kCurrent).toBool());
|
||||
}
|
||||
|
||||
void tst_QQuickTableView::clearSelectionOnTap()
|
||||
{
|
||||
LOAD_TABLEVIEW("tableviewwithselected2.qml");
|
||||
|
||||
TestModel model(40, 40);
|
||||
tableView->setModel(QVariant::fromValue(&model));
|
||||
|
||||
WAIT_UNTIL_POLISHED;
|
||||
|
||||
// Select root item
|
||||
const auto index = tableView->selectionModel()->model()->index(0, 0);
|
||||
tableView->selectionModel()->select(index, QItemSelectionModel::Select);
|
||||
QCOMPARE(tableView->selectionModel()->selectedIndexes().count(), 1);
|
||||
|
||||
// Click on a cell. This should remove the selection
|
||||
const auto item = tableView->itemAtCell(0, 0);
|
||||
QVERIFY(item);
|
||||
QPoint localPos = QPoint(item->width() / 2, item->height() / 2);
|
||||
QPoint pos = item->window()->contentItem()->mapFromItem(item, localPos).toPoint();
|
||||
QTest::mouseClick(item->window(), Qt::LeftButton, Qt::NoModifier, pos);
|
||||
QCOMPARE(tableView->selectionModel()->selectedIndexes().count(), 0);
|
||||
}
|
||||
|
||||
void tst_QQuickTableView::moveCurrentIndexUsingArrowKeys()
|
||||
{
|
||||
LOAD_TABLEVIEW("tableviewwithselected1.qml");
|
||||
|
|
Loading…
Reference in New Issue