summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel/qkeysequence.cpp
diff options
context:
space:
mode:
authorKevin Ottens <ervin@kde.org>2013-02-21 23:50:02 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-03-06 21:50:28 +0100
commit2d1f3d7c514ab1c9f725a0a5e940656278d53f34 (patch)
tree7681a463b5c9087c069039b8f1820f4f7a3da848 /src/gui/kernel/qkeysequence.cpp
parent6d0a685fc63355d355b576d5f47b3b93d777fedf (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 'src/gui/kernel/qkeysequence.cpp')
-rw-r--r--src/gui/kernel/qkeysequence.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/gui/kernel/qkeysequence.cpp b/src/gui/kernel/qkeysequence.cpp
index 07ec658818..cc0ecdf388 100644
--- a/src/gui/kernel/qkeysequence.cpp
+++ b/src/gui/kernel/qkeysequence.cpp
@@ -1681,6 +1681,47 @@ QKeySequence QKeySequence::fromString(const QString &str, SequenceFormat format)
return QKeySequence(str, format);
}
+/*!
+ \since 5.1
+
+ Return a list of QKeySequence from the string \a str based on \a format.
+
+ \sa fromString()
+ \sa listToString()
+*/
+QList<QKeySequence> QKeySequence::listFromString(const QString &str, SequenceFormat format)
+{
+ QList<QKeySequence> result;
+
+ QStringList strings = str.split(QLatin1String("; "));
+ foreach (const QString &string, strings) {
+ result << fromString(string, format);
+ }
+
+ return result;
+}
+
+/*!
+ \since 5.1
+
+ Return a string representation of \a list based on \a format.
+
+ \sa toString()
+ \sa listFromString()
+*/
+QString QKeySequence::listToString(const QList<QKeySequence> &list, SequenceFormat format)
+{
+ QString result;
+
+ foreach (const QKeySequence &sequence, list) {
+ result += sequence.toString(format);
+ result += QLatin1String("; ");
+ }
+ result.truncate(result.length() - 2);
+
+ return result;
+}
+
/*****************************************************************************
QKeySequence stream functions
*****************************************************************************/