Merge pull request #4820 from peterhieuvu/63301-comma-shortcut
fix #63301: comma shortcuts now save
This commit is contained in:
commit
236e74cf2d
2 changed files with 15 additions and 7 deletions
|
@ -4095,7 +4095,7 @@ void Shortcut::write(XmlWriter& xml) const
|
|||
if (_standardKey != QKeySequence::UnknownKey)
|
||||
xml.tag("std", QString("%1").arg(_standardKey));
|
||||
for (QKeySequence ks : _keys)
|
||||
xml.tag("seq", Shortcut::keySeqToString(ks, QKeySequence::PortableText));
|
||||
xml.tag("seq", Shortcut::keySeqToString(ks, QKeySequence::PortableText, true));
|
||||
xml.etag();
|
||||
}
|
||||
|
||||
|
@ -4325,7 +4325,7 @@ void Shortcut::reset()
|
|||
static const QString numPadPrefix("NumPad+");
|
||||
static const int NUMPADPREFIX_SIZE = 7; // the length in chars of the above string
|
||||
|
||||
QString Shortcut::keySeqToString(const QKeySequence& keySeq, QKeySequence::SequenceFormat fmt)
|
||||
QString Shortcut::keySeqToString(const QKeySequence& keySeq, QKeySequence::SequenceFormat fmt, bool escapeKeyStr /* = false */)
|
||||
{
|
||||
QString s;
|
||||
for (int i = 0; i < KEYSEQ_SIZE; ++i) {
|
||||
|
@ -4338,8 +4338,12 @@ QString Shortcut::keySeqToString(const QKeySequence& keySeq, QKeySequence::Seque
|
|||
s += numPadPrefix;
|
||||
code &= ~Qt::KeypadModifier;
|
||||
}
|
||||
QKeySequence kSeq(code);
|
||||
s += kSeq.toString(fmt);
|
||||
QString kStr = QKeySequence(code).toString(fmt);
|
||||
if (escapeKeyStr) {
|
||||
kStr.replace("\\", "\\\\");
|
||||
kStr.replace(",", "\\,");
|
||||
}
|
||||
s += kStr;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
@ -4350,12 +4354,16 @@ QKeySequence Shortcut::keySeqFromString(const QString& str, QKeySequence::Sequen
|
|||
for (i = 0; i < KEYSEQ_SIZE; ++i)
|
||||
code[i] = 0;
|
||||
|
||||
QStringList strList = str.split(",", QString::SkipEmptyParts, Qt::CaseSensitive);
|
||||
QStringList strList = str.split(QRegularExpression("(?<!\\\\),|(?<=\\\\\\\\),"), QString::SkipEmptyParts);
|
||||
//split based on commas that are not preceded by a single slash; two is okay
|
||||
//original regex: (?<!\\),|(?<=\\\\),
|
||||
|
||||
i = 0;
|
||||
for (const QString& s : strList) {
|
||||
QString keyStr = s.trimmed();
|
||||
if( keyStr.startsWith(numPadPrefix, Qt::CaseInsensitive) ) {
|
||||
if (keyStr.contains("\\"))
|
||||
keyStr.remove(keyStr.length() - 2, 1); //remove escaped characters which will always be second to last
|
||||
if (keyStr.startsWith(numPadPrefix, Qt::CaseInsensitive) ) {
|
||||
code[i] += Qt::KeypadModifier;
|
||||
keyStr.remove(0, NUMPADPREFIX_SIZE);
|
||||
}
|
||||
|
|
|
@ -181,7 +181,7 @@ class Shortcut {
|
|||
static QActionGroup* getActionGroupForWidget(MsWidget w);
|
||||
static QActionGroup* getActionGroupForWidget(MsWidget w, Qt::ShortcutContext newShortcutContext);
|
||||
|
||||
static QString keySeqToString(const QKeySequence& keySeq, QKeySequence::SequenceFormat fmt);
|
||||
static QString keySeqToString(const QKeySequence& keySeq, QKeySequence::SequenceFormat fmt, bool escapeKeyStr = false);
|
||||
static QKeySequence keySeqFromString(const QString& str, QKeySequence::SequenceFormat fmt);
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue