diff options
author | Kevin Ottens <ervin@kde.org> | 2013-02-21 23:50:02 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-03-06 21:50:28 +0100 |
commit | 2d1f3d7c514ab1c9f725a0a5e940656278d53f34 (patch) | |
tree | 7681a463b5c9087c069039b8f1820f4f7a3da848 /tests | |
parent | 6d0a685fc63355d355b576d5f47b3b93d777fedf (diff) |
Add methods to convert lists of QKeySequence to/from strings
QKeySequence provides conversion to and from strings. But a similar
convenience was missing for QList<QKeySequence>. It would come in handy
when you want for instance to save/restore the shortcuts of a QAction.
Change-Id: I9e4f2001c58a595392a5019a57c564992c39bf88
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
Reviewed-by: David Faure (KDE) <faure@kde.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/gui/kernel/qkeysequence/tst_qkeysequence.cpp | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/tests/auto/gui/kernel/qkeysequence/tst_qkeysequence.cpp b/tests/auto/gui/kernel/qkeysequence/tst_qkeysequence.cpp index a2ee14db45..a6134de497 100644 --- a/tests/auto/gui/kernel/qkeysequence/tst_qkeysequence.cpp +++ b/tests/auto/gui/kernel/qkeysequence/tst_qkeysequence.cpp @@ -133,6 +133,10 @@ private slots: void parseString(); void fromString_data(); void fromString(); + void listToString_data(); + void listToString(); + void listFromString_data(); + void listFromString(); #ifdef QT_BUILD_INTERNAL void ensureSorted(); #endif @@ -631,6 +635,104 @@ void tst_QKeySequence::fromString() QCOMPARE(ks4, ks1); } +void tst_QKeySequence::listToString_data() +{ + QTest::addColumn<QString>("strSequences"); + QTest::addColumn<QList<QKeySequence> >("sequences"); + + QList<QKeySequence> sequences; + + sequences << QKeySequence(Qt::CTRL + Qt::Key_Left) + << QKeySequence(Qt::META + Qt::Key_A); + QTest::newRow("Ctrl+Left; Meta+A") << "Ctrl+Left; Meta+A" << sequences; + + sequences.clear(); + sequences << QKeySequence(Qt::CTRL + Qt::Key_Semicolon) + << QKeySequence(Qt::META + Qt::Key_A); + QTest::newRow("Ctrl+;; Meta+A") << "Ctrl+;; Meta+A" << sequences; + + sequences.clear(); + sequences << QKeySequence(Qt::Key_Semicolon) + << QKeySequence(Qt::META + Qt::Key_A); + QTest::newRow(";; Meta+A") << ";; Meta+A" << sequences; + + sequences.clear(); + sequences << QKeySequence(Qt::CTRL + Qt::Key_Left) + << QKeySequence(Qt::META + Qt::Key_Semicolon); + QTest::newRow("Ctrl+Left; Meta+;") << "Ctrl+Left; Meta+;" << sequences; + + sequences.clear(); + sequences << QKeySequence(Qt::CTRL + Qt::Key_Left) + << QKeySequence(); + QTest::newRow("Ctrl+Left; ") << "Ctrl+Left; " << sequences; + + sequences.clear(); + sequences << QKeySequence(Qt::CTRL + Qt::Key_Left) + << QKeySequence() + << QKeySequence(Qt::META + Qt::Key_A); + QTest::newRow("Ctrl+Left; ; Meta+A") << "Ctrl+Left; ; Meta+A" << sequences; +} + +void tst_QKeySequence::listToString() +{ + QFETCH(QList<QKeySequence>, sequences); + QFETCH(QString, strSequences); + + QCOMPARE(QKeySequence::listToString(sequences), strSequences); +} + +void tst_QKeySequence::listFromString_data() +{ + QTest::addColumn<QString>("strSequences"); + QTest::addColumn<QList<QKeySequence> >("sequences"); + + QList<QKeySequence> sequences; + + sequences << QKeySequence(Qt::CTRL + Qt::Key_Left) + << QKeySequence(Qt::META + Qt::Key_A); + QTest::newRow("Ctrl+Left; Meta+A") << "Ctrl+Left; Meta+A" << sequences; + + sequences.clear(); + sequences << QKeySequence(Qt::CTRL + Qt::Key_Semicolon) + << QKeySequence(Qt::META + Qt::Key_A); + QTest::newRow("Ctrl+;; Meta+A") << "Ctrl+;; Meta+A" << sequences; + + sequences.clear(); + sequences << QKeySequence(Qt::Key_Semicolon) + << QKeySequence(Qt::META + Qt::Key_A); + QTest::newRow(";; Meta+A") << ";; Meta+A" << sequences; + + sequences.clear(); + sequences << QKeySequence(Qt::CTRL + Qt::Key_Left) + << QKeySequence(Qt::META + Qt::Key_Semicolon); + QTest::newRow("Ctrl+Left; Meta+;") << "Ctrl+Left; Meta+;" << sequences; + + sequences.clear(); + sequences << QKeySequence(Qt::CTRL + Qt::Key_Left) + << QKeySequence(); + QTest::newRow("Ctrl+Left; ") << "Ctrl+Left; " << sequences; + + sequences.clear(); + sequences << QKeySequence(Qt::CTRL + Qt::Key_Left) + << QKeySequence() + << QKeySequence(Qt::META + Qt::Key_A); + QTest::newRow("Ctrl+Left; ; Meta+A") << "Ctrl+Left; ; Meta+A" << sequences; + + sequences.clear(); + sequences << QKeySequence(Qt::CTRL + Qt::Key_Left) + << QKeySequence(Qt::Key_unknown) + << QKeySequence(Qt::META + Qt::Key_A); + QTest::newRow("Ctrl+Left; 4+3=2; Meta+A") << "Ctrl+Left; 4+3=2; Meta+A" << sequences; +} + +void tst_QKeySequence::listFromString() +{ + QFETCH(QList<QKeySequence>, sequences); + QFETCH(QString, strSequences); + + QCOMPARE(QKeySequence::listFromString(strSequences), sequences); +} + #if !defined (Q_OS_MAC) && !defined (Q_OS_WINCE) void tst_QKeySequence::translated_data() { |