From c11bb42cf3d09041ed76c81b5f9eadf8d692407b Mon Sep 17 00:00:00 2001 From: Yoann Quenach de Quivillic Date: Wed, 18 Dec 2024 08:40:08 +0100 Subject: [PATCH 1/2] Fix #59914 --- src/gui/qgsshortcutsmanager.cpp | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/gui/qgsshortcutsmanager.cpp b/src/gui/qgsshortcutsmanager.cpp index 8cb5d8287e2d..7001e4bc3d0c 100644 --- a/src/gui/qgsshortcutsmanager.cpp +++ b/src/gui/qgsshortcutsmanager.cpp @@ -369,9 +369,26 @@ void QgsShortcutsManager::shortcutDestroyed( QShortcut *shortcut ) void QgsShortcutsManager::updateActionToolTip( QAction *action, const QString &sequence ) { QString current = action->toolTip(); - // Remove the old shortcut. - const thread_local QRegularExpression rx( QStringLiteral( "\\(.*\\)" ) ); - current.replace( rx, QString() ); + const thread_local QRegularExpression rx( QStringLiteral( "\\((.*)\\)" ) ); + // Look for the last occurrence of text inside parentheses + QRegularExpressionMatch match; + if ( current.lastIndexOf( rx, -1, &match ) != -1 ) + { + // Check if it is a valid QKeySequence + bool validSequence = true; + for ( const QString &part : QKeySequence( match.captured( 1 ) ).toString().split( "," ) ) + { + if ( part.trimmed().isEmpty() ) + { + validSequence = false; + break; + } + } + if ( validSequence ) + { + current = current.remove( match.capturedStart( 0 ), match.capturedLength( 0 ) ); + } + } if ( !sequence.isEmpty() ) { From 8acedaed61da9a64f4602015e6c063e2cd673211 Mon Sep 17 00:00:00 2001 From: Yoann Quenach de Quivillic Date: Wed, 18 Dec 2024 18:26:59 +0100 Subject: [PATCH 2/2] Apply suggestion from review --- src/gui/qgsshortcutsmanager.cpp | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/gui/qgsshortcutsmanager.cpp b/src/gui/qgsshortcutsmanager.cpp index 7001e4bc3d0c..8fa1ce733ced 100644 --- a/src/gui/qgsshortcutsmanager.cpp +++ b/src/gui/qgsshortcutsmanager.cpp @@ -375,16 +375,8 @@ void QgsShortcutsManager::updateActionToolTip( QAction *action, const QString &s if ( current.lastIndexOf( rx, -1, &match ) != -1 ) { // Check if it is a valid QKeySequence - bool validSequence = true; - for ( const QString &part : QKeySequence( match.captured( 1 ) ).toString().split( "," ) ) - { - if ( part.trimmed().isEmpty() ) - { - validSequence = false; - break; - } - } - if ( validSequence ) + const QStringList parts = QKeySequence( match.captured( 1 ) ).toString().split( "," ); + if ( std::all_of( parts.constBegin(), parts.constEnd(), []( const QString &part ) { return !part.trimmed().isEmpty(); } ) ) { current = current.remove( match.capturedStart( 0 ), match.capturedLength( 0 ) ); }