summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2015-12-08 20:35:11 +0100
committerGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2015-12-09 19:04:59 +0000
commit872b9b231ef966ce7b2b40785ee92a0d4a8d2851 (patch)
tree9eba2013979f957848f3f6af924966fa64b5430f /tests/auto
parent410aa20f073b5e45e73366773b7d173f840a9cfe (diff)
QLineEdit: fix the shortcut override events on a readonly line edit
When a QLineEdit is readonly there's a discrepancy between key press events and shortcut override events. For instance, presses Ctrl+C copies the text unless there's also a shortcut for the same key sequence. In this case, the shortcut override event is not handled, and no text is copied. Fix it by splitting the handling of shortcut override events between "read only" access (copy, select, etc.), which still makes sense on a read only line edit, and write access (paste, ...) which doesn't. [ChangeLog][Important Behavior Changes][QLineEdit] QLineEdit will now accept certain shortcut override events even if it is read only. Change-Id: Ie5b048259b99a1eff0581129e3ad97f27a88fe86 Task-number: QTBUG-21217 Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com> Reviewed-by: Frederik Gladhorn <frederik.gladhorn@theqtcompany.com>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp
index ba700ed58d..de896ea273 100644
--- a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp
+++ b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp
@@ -64,6 +64,7 @@
#include <qsortfilterproxymodel.h>
#include <qdebug.h>
#include <qscreen.h>
+#include <qshortcut.h>
#include "qcommonstyle.h"
#include "qstyleoption.h"
@@ -312,6 +313,9 @@ private slots:
void shouldShowPlaceholderText();
void QTBUG1266_setInputMaskEmittingTextEdited();
+ void shortcutOverrideOnReadonlyLineEdit_data();
+ void shortcutOverrideOnReadonlyLineEdit();
+
protected slots:
void editingFinished();
@@ -4487,5 +4491,61 @@ void tst_QLineEdit::QTBUG1266_setInputMaskEmittingTextEdited()
QCOMPARE(spy.count(), 0);
}
+void tst_QLineEdit::shortcutOverrideOnReadonlyLineEdit_data()
+{
+ QTest::addColumn<QKeySequence>("keySequence");
+ QTest::addColumn<bool>("shouldBeHandledByQLineEdit");
+
+ QTest::newRow("Copy") << QKeySequence(QKeySequence::Copy) << true;
+ QTest::newRow("MoveToNextChar") << QKeySequence(QKeySequence::MoveToNextChar) << true;
+ QTest::newRow("SelectAll") << QKeySequence(QKeySequence::SelectAll) << true;
+ QTest::newRow("Right press") << QKeySequence(Qt::Key_Right) << true;
+ QTest::newRow("Left press") << QKeySequence(Qt::Key_Left) << true;
+
+ QTest::newRow("Paste") << QKeySequence(QKeySequence::Paste) << false;
+ QTest::newRow("Paste") << QKeySequence(QKeySequence::Cut) << false;
+ QTest::newRow("Undo") << QKeySequence(QKeySequence::Undo) << false;
+ QTest::newRow("Redo") << QKeySequence(QKeySequence::Redo) << false;
+
+ QTest::newRow("a") << QKeySequence(Qt::Key_A) << false;
+ QTest::newRow("b") << QKeySequence(Qt::Key_B) << false;
+ QTest::newRow("c") << QKeySequence(Qt::Key_C) << false;
+ QTest::newRow("x") << QKeySequence(Qt::Key_X) << false;
+ QTest::newRow("X") << QKeySequence(Qt::ShiftModifier + Qt::Key_X) << false;
+
+ QTest::newRow("Alt+Home") << QKeySequence(Qt::AltModifier + Qt::Key_Home) << false;
+}
+
+void tst_QLineEdit::shortcutOverrideOnReadonlyLineEdit()
+{
+ QFETCH(QKeySequence, keySequence);
+ QFETCH(bool, shouldBeHandledByQLineEdit);
+
+ QWidget widget;
+
+ QShortcut *shortcut = new QShortcut(keySequence, &widget);
+ QSignalSpy spy(shortcut, &QShortcut::activated);
+ QVERIFY(spy.isValid());
+
+ QLineEdit *lineEdit = new QLineEdit(QStringLiteral("Test"), &widget);
+ lineEdit->setReadOnly(true);
+ lineEdit->setFocus();
+
+ widget.show();
+
+ QVERIFY(QTest::qWaitForWindowActive(&widget));
+
+ const int keySequenceCount = keySequence.count();
+ for (int i = 0; i < keySequenceCount; ++i) {
+ const uint key = keySequence[i];
+ QTest::keyClick(lineEdit,
+ Qt::Key(key & ~Qt::KeyboardModifierMask),
+ Qt::KeyboardModifier(key & Qt::KeyboardModifierMask));
+ }
+
+ const int activationCount = shouldBeHandledByQLineEdit ? 0 : 1;
+ QCOMPARE(spy.count(), activationCount);
+}
+
QTEST_MAIN(tst_QLineEdit)
#include "tst_qlineedit.moc"