From 7863be311570fa219066df5fe8720d5b92ddb680 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Sat, 8 Dec 2018 19:58:00 +0100 Subject: QTableView: Fix keyboard navigation with disabled rows The keyboard navigation with MovePageUp/Down and MoveEnd did not honor disabled cells in all cases which lead to inconsistencies in the navigation (esp. since MoveHome does honor them correctly). Therefore make sure that all four move operations work consistent by refactoring the code to use common functions. Fixes: QTBUG-72400 Change-Id: I63fa3b626510d21c66f4f9b2b1bfb3261728ecaf Reviewed-by: Friedemann Kleint Reviewed-by: Luca Beldi Reviewed-by: Samuel Gaist Reviewed-by: Richard Moe Gustavsen --- .../itemviews/qtableview/tst_qtableview.cpp | 40 ++++++++++++++++++---- 1 file changed, 34 insertions(+), 6 deletions(-) (limited to 'tests/auto/widgets') diff --git a/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp b/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp index ab746dfee8..1b95b5a3ca 100644 --- a/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp +++ b/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp @@ -1264,19 +1264,47 @@ void tst_QTableView::moveCursorStrikesBack_data() for (int i = 0; i < 7; ++i) fullList << i; - QTest::newRow("All disabled, wrap forward. Timeout => FAIL") << -1 << -1 + QTest::newRow("All disabled, wrap forward. => invalid index") << -1 << -1 << fullList << fullList << QRect() << 1 << 0 << (IntList() << int(QtTestTableView::MoveNext)) - << 1 << 0; + << -1 << -1; - QTest::newRow("All disabled, wrap backwards. Timeout => FAIL") << -1 << -1 + QTest::newRow("All disabled, wrap backwards. => invalid index") << -1 << -1 << fullList << fullList << QRect() << 1 << 0 << (IntList() << int(QtTestTableView::MovePrevious)) + << -1 << -1; + + QTest::newRow("Last column disabled, MoveEnd. QTBUG-72400") << -1 << -1 + << IntList() + << (IntList() << 6) + << QRect() + << 0 << 0 << (IntList() << int(QtTestTableView::MoveEnd)) + << 0 << 5; + + QTest::newRow("First column disabled, MoveHome. QTBUG-72400") << -1 << -1 + << IntList() + << (IntList() << 0) + << QRect() + << 0 << 6 << (IntList() << int(QtTestTableView::MoveHome)) + << 0 << 1; + + QTest::newRow("First row disabled, MovePageUp. QTBUG-72400") << -1 << -1 + << (IntList() << 0) + << IntList() + << QRect() + << 2 << 0 << (IntList() << int(QtTestTableView::MovePageUp)) << 1 << 0; + + QTest::newRow("Last row disabled, MovePageDown. QTBUG-72400") << -1 << -1 + << (IntList() << 6) + << IntList() + << QRect() + << 4 << 0 << (IntList() << int(QtTestTableView::MovePageDown)) + << 5 << 0; } void tst_QTableView::moveCursorStrikesBack() @@ -1302,6 +1330,9 @@ void tst_QTableView::moveCursorStrikesBack() if (span.height() && span.width()) view.setSpan(span.top(), span.left(), span.height(), span.width()); view.show(); + QVERIFY(QTest::qWaitForWindowActive(&view)); + // resize to make sure there are scrollbars + view.resize(view.columnWidth(0) * 7, view.rowHeight(0) * 7); QModelIndex index = model.index(startRow, startColumn); view.setCurrentIndex(index); @@ -1320,9 +1351,6 @@ void tst_QTableView::moveCursorStrikesBack() newColumn = newIndex.column(); } - // expected fails, task 119433 - if(newRow == -1) - return; QCOMPARE(newRow, expectedRow); QCOMPARE(newColumn, expectedColumn); } -- cgit v1.2.3 From d8bbb5ee0e60d44a70d29306e607a59caf7fe5bc Mon Sep 17 00:00:00 2001 From: Vitaly Fanaskov Date: Fri, 7 Dec 2018 16:04:33 +0100 Subject: Respect roles of buttons added to QMessageBox MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a button added to QMessageBox has AcceptRole or YesRole, the signal accepted() will be emitted upon click on the button. If the button has RejectRole or NoRole, the signal rejected() will be emitted upon click on the button. If a button has a different role, neither accepted() nor rejected() will be emitted. This works for both standard and custom buttons. The signal finished() with result code will be sent regardless of a clicked button role. Also added documentation strings for some methods of private classes in order to have better tooltips in IDE(s). Task-number: QTBUG-44131 Change-Id: I521a4e5112eb4cf168f6fbb4c002dbe119aeeb09 Reviewed-by: Tor Arne Vestbø --- .../dialogs/qmessagebox/tst_qmessagebox.cpp | 95 ++++++++++++++++++++++ 1 file changed, 95 insertions(+) (limited to 'tests/auto/widgets') diff --git a/tests/auto/widgets/dialogs/qmessagebox/tst_qmessagebox.cpp b/tests/auto/widgets/dialogs/qmessagebox/tst_qmessagebox.cpp index 3b31a74adf..eeda17074b 100644 --- a/tests/auto/widgets/dialogs/qmessagebox/tst_qmessagebox.cpp +++ b/tests/auto/widgets/dialogs/qmessagebox/tst_qmessagebox.cpp @@ -110,6 +110,10 @@ private slots: void setInformativeText(); void iconPixmap(); + // QTBUG-44131 + void acceptedRejectedSignals(); + void acceptedRejectedSignals_data(); + void cleanup(); }; @@ -717,5 +721,96 @@ void tst_QMessageBox::iconPixmap() QCOMPARE(messageBox.iconPixmap(), QPixmap()); } +using SignalSignature = void(QDialog::*)(); +Q_DECLARE_METATYPE(SignalSignature); +Q_DECLARE_METATYPE(QMessageBox::ButtonRole) + +using ButtonsCreator = std::function(QMessageBox &)>; +Q_DECLARE_METATYPE(ButtonsCreator); + +using RoleSet = QSet; +Q_DECLARE_METATYPE(RoleSet); + +void tst_QMessageBox::acceptedRejectedSignals() +{ + QMessageBox messageBox(QMessageBox::Information, "Test window", "Test text"); + + QFETCH(ButtonsCreator, buttonsCreator); + QVERIFY(buttonsCreator); + + const auto buttons = buttonsCreator(messageBox); + QVERIFY(!buttons.isEmpty()); + + QFETCH(RoleSet, roles); + QFETCH(SignalSignature, signalSignature); + for (auto button: buttons) { + QVERIFY(button); + + messageBox.show(); + QVERIFY(QTest::qWaitForWindowExposed(&messageBox)); + + QSignalSpy spy(&messageBox, signalSignature); + QVERIFY(spy.isValid()); + button->click(); + + if (roles.contains(messageBox.buttonRole(button))) + QCOMPARE(spy.count(), 1); + else + QVERIFY(spy.isEmpty()); + } +} + +static void addAcceptedRow(const char *title, ButtonsCreator bc) +{ + QTest::newRow(title) << (RoleSet() << QMessageBox::AcceptRole << QMessageBox::YesRole) + << &QDialog::accepted << bc; +} + +static void addRejectedRow(const char *title, ButtonsCreator bc) +{ + QTest::newRow(title) << (RoleSet() << QMessageBox::RejectRole << QMessageBox::NoRole) + << &QDialog::rejected << bc; +} + +static void addCustomButtonsData() +{ + ButtonsCreator buttonsCreator = [](QMessageBox &messageBox) { + QVector buttons(QMessageBox::NRoles); + for (int i = QMessageBox::AcceptRole; i < QMessageBox::NRoles; ++i) { + buttons[i] = messageBox.addButton( + QString("Button role: %1").arg(i), QMessageBox::ButtonRole(i)); + } + + return buttons; + }; + + addAcceptedRow("Accepted_CustomButtons", buttonsCreator); + addRejectedRow("Rejected_CustomButtons", buttonsCreator); +} + +static void addStandardButtonsData() +{ + ButtonsCreator buttonsCreator = [](QMessageBox &messageBox) { + QVector buttons; + for (int i = QMessageBox::FirstButton; i <= QMessageBox::LastButton; i <<= 1) + buttons << messageBox.addButton(QMessageBox::StandardButton(i)); + + return buttons; + }; + + addAcceptedRow("Accepted_StandardButtons", buttonsCreator); + addRejectedRow("Rejected_StandardButtons", buttonsCreator); +} + +void tst_QMessageBox::acceptedRejectedSignals_data() +{ + QTest::addColumn("roles"); + QTest::addColumn("signalSignature"); + QTest::addColumn("buttonsCreator"); + + addStandardButtonsData(); + addCustomButtonsData(); +} + QTEST_MAIN(tst_QMessageBox) #include "tst_qmessagebox.moc" -- cgit v1.2.3