From 20d5f8461f36596723fa324a12a4d7ad4ea679c6 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 18 May 2022 12:02:07 +0200 Subject: QKeySequenceEdit: Extract Method Private::rebuildKeySequence() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Factor the construction of Private::keySequence from Private::key into a helper function, as we'll need this functionality in more places when we add a maxKeyCount property to the class. Change-Id: I6b08a619c3b6b2a9ff660e9f51b02632c2359a47 Reviewed-by: Tor Arne Vestbø Reviewed-by: Volker Hilsheimer --- src/widgets/widgets/qkeysequenceedit.cpp | 5 ++--- src/widgets/widgets/qkeysequenceedit_p.h | 2 ++ 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/widgets/widgets/qkeysequenceedit.cpp b/src/widgets/widgets/qkeysequenceedit.cpp index a2239f8c16..3dafb9396b 100644 --- a/src/widgets/widgets/qkeysequenceedit.cpp +++ b/src/widgets/widgets/qkeysequenceedit.cpp @@ -283,9 +283,8 @@ void QKeySequenceEdit::keyPressEvent(QKeyEvent *e) d->key[d->keyNum] = QKeyCombination::fromCombined(nextKey); d->keyNum++; - QKeySequence key(d->key[0], d->key[1], d->key[2], d->key[3]); - d->keySequence = key; - QString text = key.toString(QKeySequence::NativeText); + d->rebuildKeySequence(); + QString text = d->keySequence.toString(QKeySequence::NativeText); if (d->keyNum < QKeySequencePrivate::MaxKeyCount) { //: This text is an "unfinished" shortcut, expands like "Ctrl+A, ..." text = tr("%1, ...").arg(text); diff --git a/src/widgets/widgets/qkeysequenceedit_p.h b/src/widgets/widgets/qkeysequenceedit_p.h index 0ef664a21d..eaaaf63e8a 100644 --- a/src/widgets/widgets/qkeysequenceedit_p.h +++ b/src/widgets/widgets/qkeysequenceedit_p.h @@ -36,6 +36,8 @@ public: int translateModifiers(Qt::KeyboardModifiers state, const QString &text); void resetState(); void finishEditing(); + void rebuildKeySequence() + { keySequence = QKeySequence(key[0], key[1], key[2], key[3]); } QLineEdit *lineEdit; QKeySequence keySequence; -- cgit v1.2.3