Handle -1 (Invalid Key) and Qt::Key_unknown gracefully in encodeString.
Previously they would fall into the unicode handling and return very strange values. Change-Id: I62a53894c0983bf53fd79f924b40a6fd3ba02993 Reviewed-by: Morten Johan Sørvig <morten.sorvig@nokia.com>
This commit is contained in:
parent
628d3f85d2
commit
05ca21411e
@ -1342,6 +1342,11 @@ QString QKeySequencePrivate::encodeString(int key, QKeySequence::SequenceFormat
|
||||
{
|
||||
bool nativeText = (format == QKeySequence::NativeText);
|
||||
QString s;
|
||||
|
||||
// Handle -1 (Invalid Key) and Qt::Key_unknown gracefully
|
||||
if (key == -1 || key == Qt::Key_unknown)
|
||||
return s;
|
||||
|
||||
#if defined(Q_OS_MAC)
|
||||
if (nativeText) {
|
||||
// On Mac OS X the order (by default) is Meta, Alt, Shift, Control.
|
||||
|
@ -122,6 +122,8 @@ private slots:
|
||||
void mnemonic();
|
||||
void toString_data();
|
||||
void toString();
|
||||
void toStringFromKeycode_data();
|
||||
void toStringFromKeycode();
|
||||
void streamOperators_data();
|
||||
void streamOperators();
|
||||
void parseString_data();
|
||||
@ -476,6 +478,24 @@ void tst_QKeySequence::toString()
|
||||
|
||||
}
|
||||
|
||||
void tst_QKeySequence::toStringFromKeycode_data()
|
||||
{
|
||||
QTest::addColumn<QKeySequence>("keycode");
|
||||
QTest::addColumn<QString>("expectedString");
|
||||
|
||||
QTest::newRow("A") << QKeySequence(Qt::Key_A) << "A";
|
||||
QTest::newRow("-1") << QKeySequence(-1) << "";
|
||||
QTest::newRow("Unknown") << QKeySequence(Qt::Key_unknown) << "";
|
||||
}
|
||||
|
||||
void tst_QKeySequence::toStringFromKeycode()
|
||||
{
|
||||
QFETCH(QKeySequence, keycode);
|
||||
QFETCH(QString, expectedString);
|
||||
|
||||
QCOMPARE(QKeySequence(keycode).toString(), expectedString);
|
||||
}
|
||||
|
||||
void tst_QKeySequence::streamOperators_data()
|
||||
{
|
||||
operatorQString_data();
|
||||
|
Loading…
x
Reference in New Issue
Block a user