Fix QKeySequence::toString() returning gibberish for Qt::KeypadModifier
This is the patch from the bug report with a few alterations to get it to compile, and also with the GroupSwitchModifier code removed, as this patch just focuses on Qt::KeypadModifier. The problem was determined to be in QKeySequencePrivate::encodeString, which doesn't handle the Qt::KeypadModifier flag. Task-number: QTBUG-4022 Change-Id: Ic981eb8b5cd88c7b36892d3019b8175db4b7b6f2 Reviewed-by: David Faure (KDE) <faure@kde.org>
This commit is contained in:
parent
f898614b76
commit
7dd81686e8
@ -138,6 +138,10 @@ public:
|
||||
Q_DECLARE_FLAGS(KeyboardModifiers, KeyboardModifier)
|
||||
|
||||
//shorter names for shortcuts
|
||||
// The use of all-caps identifiers has the potential for clashing with
|
||||
// user-defined or third-party macros. More so when the identifiers are not
|
||||
// "namespace"-prefixed. This is considered bad practice and is why
|
||||
// KeypadModifier was not added to the Modifier enum.
|
||||
enum Modifier {
|
||||
META = Qt::MetaModifier,
|
||||
SHIFT = Qt::ShiftModifier,
|
||||
|
@ -1225,7 +1225,8 @@ int QKeySequencePrivate::decodeString(const QString &str, QKeySequence::Sequence
|
||||
*gmodifs << QModifKeyName(Qt::CTRL, QLatin1String("ctrl+"))
|
||||
<< QModifKeyName(Qt::SHIFT, QLatin1String("shift+"))
|
||||
<< QModifKeyName(Qt::ALT, QLatin1String("alt+"))
|
||||
<< QModifKeyName(Qt::META, QLatin1String("meta+"));
|
||||
<< QModifKeyName(Qt::META, QLatin1String("meta+"))
|
||||
<< QModifKeyName(Qt::KeypadModifier, QLatin1String("numpad+"));
|
||||
}
|
||||
} else {
|
||||
gmodifs = globalPortableModifs();
|
||||
@ -1233,7 +1234,8 @@ int QKeySequencePrivate::decodeString(const QString &str, QKeySequence::Sequence
|
||||
*gmodifs << QModifKeyName(Qt::CTRL, QLatin1String("ctrl+"))
|
||||
<< QModifKeyName(Qt::SHIFT, QLatin1String("shift+"))
|
||||
<< QModifKeyName(Qt::ALT, QLatin1String("alt+"))
|
||||
<< QModifKeyName(Qt::META, QLatin1String("meta+"));
|
||||
<< QModifKeyName(Qt::META, QLatin1String("meta+"))
|
||||
<< QModifKeyName(Qt::KeypadModifier, QLatin1String("numpad+"));
|
||||
}
|
||||
}
|
||||
if (!gmodifs) return ret;
|
||||
@ -1244,7 +1246,8 @@ int QKeySequencePrivate::decodeString(const QString &str, QKeySequence::Sequence
|
||||
modifs << QModifKeyName(Qt::CTRL, QCoreApplication::translate("QShortcut", "Ctrl").toLower().append(QLatin1Char('+')))
|
||||
<< QModifKeyName(Qt::SHIFT, QCoreApplication::translate("QShortcut", "Shift").toLower().append(QLatin1Char('+')))
|
||||
<< QModifKeyName(Qt::ALT, QCoreApplication::translate("QShortcut", "Alt").toLower().append(QLatin1Char('+')))
|
||||
<< QModifKeyName(Qt::META, QCoreApplication::translate("QShortcut", "Meta").toLower().append(QLatin1Char('+')));
|
||||
<< QModifKeyName(Qt::META, QCoreApplication::translate("QShortcut", "Meta").toLower().append(QLatin1Char('+')))
|
||||
<< QModifKeyName(Qt::KeypadModifier, QCoreApplication::translate("QShortcut", "Numpad").toLower().append(QLatin1Char('+')));
|
||||
}
|
||||
modifs += *gmodifs; // Test non-translated ones last
|
||||
|
||||
@ -1418,10 +1421,12 @@ QString QKeySequencePrivate::encodeString(int key, QKeySequence::SequenceFormat
|
||||
addKey(s, nativeText ? QCoreApplication::translate("QShortcut", "Alt") : QString::fromLatin1("Alt"), format);
|
||||
if ((key & Qt::SHIFT) == Qt::SHIFT)
|
||||
addKey(s, nativeText ? QCoreApplication::translate("QShortcut", "Shift") : QString::fromLatin1("Shift"), format);
|
||||
if ((key & Qt::KeypadModifier) == Qt::KeypadModifier)
|
||||
addKey(s, nativeText ? QCoreApplication::translate("QShortcut", "Numpad") : QString::fromLatin1("Numpad"), format);
|
||||
}
|
||||
|
||||
|
||||
key &= ~(Qt::ShiftModifier | Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier);
|
||||
key &= ~(Qt::ShiftModifier | Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier | Qt::KeypadModifier);
|
||||
QString p;
|
||||
|
||||
if (key && key < Qt::Key_Escape && key != Qt::Key_Space) {
|
||||
|
@ -510,6 +510,11 @@ void tst_QKeySequence::toStringFromKeycode_data()
|
||||
QTest::newRow("A") << QKeySequence(Qt::Key_A) << "A";
|
||||
QTest::newRow("-1") << QKeySequence(-1) << "";
|
||||
QTest::newRow("Unknown") << QKeySequence(Qt::Key_unknown) << "";
|
||||
QTest::newRow("Ctrl+Numpad+Ins") << QKeySequence(Qt::ControlModifier | Qt::KeypadModifier | Qt::Key_Insert) << "Ctrl+Numpad+Ins";
|
||||
QTest::newRow("Ctrl+Numpad+Del") << QKeySequence(Qt::ControlModifier | Qt::KeypadModifier | Qt::Key_Delete) << "Ctrl+Numpad+Del";
|
||||
QTest::newRow("Ctrl+Alt+Numpad+Del") << QKeySequence(Qt::ControlModifier | Qt::AltModifier | Qt::KeypadModifier | Qt::Key_Delete) << "Ctrl+Alt+Numpad+Del";
|
||||
QTest::newRow("Ctrl+Ins") << QKeySequence(Qt::ControlModifier | Qt::Key_Insert) << "Ctrl+Ins";
|
||||
QTest::newRow("Ctrl+Numpad+Ins(1)") << QKeySequence(Qt::Key_Insert | Qt::KeypadModifier | Qt::ControlModifier) << "Ctrl+Numpad+Ins";
|
||||
}
|
||||
|
||||
void tst_QKeySequence::toStringFromKeycode()
|
||||
|
Loading…
Reference in New Issue
Block a user