QAbstractItemView: fix selectionCommand() with no event
QAbstractItemView::selectionCommand() returned the wrong SelectionFlags when no event is given since c4366ff0183a9a4a5c6eff0312b713e9c5eb97ea. Therefore re-add the call to QGuiApplication::keyboardModifiers() when no event is given and add a unittest for them so it's not removed again. Fixes: QTBUG-89711 Change-Id: I107357df08c4ff1b1a14d49523401c5e7b428f56 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> (cherry picked from commit 672d2ea8f414fa5f79f1801d965533b705831921) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
696405b7f6
commit
f0a0c00a0a
@ -3998,10 +3998,10 @@ QItemSelectionModel::SelectionFlags QAbstractItemViewPrivate::multiSelectionComm
|
||||
QItemSelectionModel::SelectionFlags QAbstractItemViewPrivate::extendedSelectionCommand(
|
||||
const QModelIndex &index, const QEvent *event) const
|
||||
{
|
||||
Qt::KeyboardModifiers modifiers = Qt::NoModifier;
|
||||
Qt::KeyboardModifiers modifiers = event && event->isInputEvent()
|
||||
? static_cast<const QInputEvent*>(event)->modifiers()
|
||||
: QGuiApplication::keyboardModifiers();
|
||||
if (event) {
|
||||
if (event->isInputEvent())
|
||||
modifiers = static_cast<const QInputEvent*>(event)->modifiers();
|
||||
switch (event->type()) {
|
||||
case QEvent::MouseMove: {
|
||||
// Toggle on MouseMove
|
||||
|
@ -154,6 +154,8 @@ private slots:
|
||||
void checkFocusAfterActivationChanges_data();
|
||||
void checkFocusAfterActivationChanges();
|
||||
void dragSelectAfterNewPress();
|
||||
void selectionCommand_data();
|
||||
void selectionCommand();
|
||||
private:
|
||||
static QAbstractItemView *viewFromString(const QByteArray &viewType, QWidget *parent = nullptr)
|
||||
{
|
||||
@ -2598,5 +2600,49 @@ void tst_QAbstractItemView::dragSelectAfterNewPress()
|
||||
QVERIFY(selected.contains(model.index(i, 0)));
|
||||
}
|
||||
|
||||
void tst_QAbstractItemView::selectionCommand_data()
|
||||
{
|
||||
QTest::addColumn<QAbstractItemView::SelectionMode>("selectionMode");
|
||||
QTest::addColumn<Qt::KeyboardModifier>("keyboardModifier");
|
||||
QTest::addColumn<QItemSelectionModel::SelectionFlag>("selectionFlag");
|
||||
|
||||
QTest::newRow("NoSelection - NoModifier") << QAbstractItemView::NoSelection << Qt::NoModifier << QItemSelectionModel::NoUpdate;
|
||||
QTest::newRow("NoSelection - ShiftModifier") << QAbstractItemView::NoSelection << Qt::ShiftModifier << QItemSelectionModel::NoUpdate;
|
||||
QTest::newRow("NoSelection - ControlModifier") << QAbstractItemView::NoSelection << Qt::ControlModifier << QItemSelectionModel::NoUpdate;
|
||||
QTest::newRow("NoSelection - AltModifier") << QAbstractItemView::NoSelection << Qt::AltModifier << QItemSelectionModel::NoUpdate;
|
||||
|
||||
QTest::newRow("SingleSelection - NoModifier") << QAbstractItemView::SingleSelection << Qt::NoModifier << QItemSelectionModel::ClearAndSelect;
|
||||
QTest::newRow("SingleSelection - ShiftModifier") << QAbstractItemView::SingleSelection << Qt::ShiftModifier << QItemSelectionModel::ClearAndSelect;
|
||||
QTest::newRow("SingleSelection - ControlModifier") << QAbstractItemView::SingleSelection << Qt::ControlModifier << QItemSelectionModel::ClearAndSelect;
|
||||
QTest::newRow("SingleSelection - AltModifier") << QAbstractItemView::SingleSelection << Qt::AltModifier << QItemSelectionModel::ClearAndSelect;
|
||||
|
||||
QTest::newRow("MultiSelection - NoModifier") << QAbstractItemView::MultiSelection << Qt::NoModifier << QItemSelectionModel::Toggle;
|
||||
QTest::newRow("MultiSelection - ShiftModifier") << QAbstractItemView::MultiSelection << Qt::ShiftModifier << QItemSelectionModel::Toggle;
|
||||
QTest::newRow("MultiSelection - ControlModifier") << QAbstractItemView::MultiSelection << Qt::ControlModifier << QItemSelectionModel::Toggle;
|
||||
QTest::newRow("MultiSelection - AltModifier") << QAbstractItemView::MultiSelection << Qt::AltModifier << QItemSelectionModel::Toggle;
|
||||
|
||||
QTest::newRow("ExtendedSelection - NoModifier") << QAbstractItemView::ExtendedSelection << Qt::NoModifier << QItemSelectionModel::ClearAndSelect;
|
||||
QTest::newRow("ExtendedSelection - ShiftModifier") << QAbstractItemView::ExtendedSelection << Qt::ShiftModifier << QItemSelectionModel::SelectCurrent;
|
||||
QTest::newRow("ExtendedSelection - ControlModifier") << QAbstractItemView::ExtendedSelection << Qt::ControlModifier << QItemSelectionModel::Toggle;
|
||||
QTest::newRow("ExtendedSelection - AltModifier") << QAbstractItemView::ExtendedSelection << Qt::AltModifier << QItemSelectionModel::ClearAndSelect;
|
||||
|
||||
QTest::newRow("ContiguousSelection - NoModifier") << QAbstractItemView::ContiguousSelection << Qt::NoModifier << QItemSelectionModel::ClearAndSelect;
|
||||
QTest::newRow("ContiguousSelection - ShiftModifier") << QAbstractItemView::ContiguousSelection << Qt::ShiftModifier << QItemSelectionModel::SelectCurrent;
|
||||
QTest::newRow("ContiguousSelection - ControlModifier") << QAbstractItemView::ContiguousSelection << Qt::ControlModifier << QItemSelectionModel::SelectCurrent;
|
||||
QTest::newRow("ContiguousSelection - AltModifier") << QAbstractItemView::ContiguousSelection << Qt::AltModifier << QItemSelectionModel::ClearAndSelect;
|
||||
}
|
||||
|
||||
void tst_QAbstractItemView::selectionCommand()
|
||||
{
|
||||
QFETCH(QAbstractItemView::SelectionMode, selectionMode);
|
||||
QFETCH(Qt::KeyboardModifier, keyboardModifier);
|
||||
QFETCH(QItemSelectionModel::SelectionFlag, selectionFlag);
|
||||
|
||||
QTableView view;
|
||||
view.setSelectionMode(selectionMode);
|
||||
QTest::keyPress(&view, Qt::Key_A, keyboardModifier);
|
||||
QCOMPARE(selectionFlag, view.selectionCommand(QModelIndex(), nullptr));
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QAbstractItemView)
|
||||
#include "tst_qabstractitemview.moc"
|
||||
|
Loading…
x
Reference in New Issue
Block a user