summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorLaszlo Papp <lpapp@kde.org>2022-05-18 12:06:53 +0200
committerMarc Mutz <marc.mutz@qt.io>2022-06-27 12:02:47 +0000
commit9521a07af2da735849ce92df049569de9a55ad30 (patch)
tree27f10714f50f3dc21e658149fd0e64aa0f5c975a /tests
parent4d60ba61dca7d50c8eaf9f4525cb9565b363ca81 (diff)
QKeySequenceEdit: add a maximumSquenceLength property
At the very least, it would be important to have a single combination key sequence. This is commonly seen in keyboard shortcut editors where QKeySequenceEdit is very much applicable. [ChangeLog][QtWidgets][QKeySequenceEdit] Added a maximumSquenceLength property. Done-with: Marc Mutz <marc.mutz@qt.io> Change-Id: Id7fa5a8593eb150fa67d7e89308492c0a200ac36 Reviewed-by: Marc Mutz <marc.mutz@qt.io> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/widgets/widgets/qkeysequenceedit/tst_qkeysequenceedit.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/auto/widgets/widgets/qkeysequenceedit/tst_qkeysequenceedit.cpp b/tests/auto/widgets/widgets/qkeysequenceedit/tst_qkeysequenceedit.cpp
index 14649fc345..d372505f8c 100644
--- a/tests/auto/widgets/widgets/qkeysequenceedit/tst_qkeysequenceedit.cpp
+++ b/tests/auto/widgets/widgets/qkeysequenceedit/tst_qkeysequenceedit.cpp
@@ -20,6 +20,7 @@ private slots:
void testKeys_data();
void testKeys();
void testLineEditContents();
+ void testMaximumSequenceLength();
};
void tst_QKeySequenceEdit::testSetters()
@@ -49,6 +50,42 @@ void tst_QKeySequenceEdit::testKeys_data()
QTest::newRow("4") << Qt::Key_N << Qt::KeyboardModifiers(Qt::ControlModifier | Qt::ShiftModifier) << QKeySequence("Ctrl+Shift+N");
}
+void tst_QKeySequenceEdit::testMaximumSequenceLength()
+{
+ //
+ // GIVEN:
+ // - A QKeySequenceEdit with maxKeyCount == 1
+ // - A QKeySequence with more than one key
+ //
+ QKeySequenceEdit edit;
+ edit.setMaximumSequenceLength(1);
+ QCOMPARE(edit.maximumSequenceLength(), 1);
+
+ QKeySequence multi("Ctrl+X, S");
+ QCOMPARE(multi.count(), 2);
+
+ //
+ // WHEN: setting the key sequence on the edit
+ //
+ QTest::ignoreMessage(QtWarningMsg,
+ "QKeySequenceEdit: setting a key sequence of length 2 when "
+ "maximumSequenceLength is 1, truncating.");
+ edit.setKeySequence(multi);
+
+ //
+ // THEN:
+ // - the maxKeyCount property doesn't change
+ // - the key sequence is truncated to maxKeyCount
+ // - and won't un-truncate by increasing maxKeyCount
+ //
+ QCOMPARE(edit.maximumSequenceLength(), 1);
+ const auto edited = edit.keySequence();
+ QCOMPARE(edited.count(), 1);
+ QCOMPARE(edited, QKeySequence("Ctrl+X"));
+ edit.setMaximumSequenceLength(2);
+ QCOMPARE(edit.keySequence(), edited);
+}
+
void tst_QKeySequenceEdit::testKeys()
{
QFETCH(Qt::Key, key);