Skip to content

Commit

Permalink
Merge pull request #59915 from YoannQDQ/fix-action-tooltip
Browse files Browse the repository at this point in the history
Fix text inside parentheses disappears from action tooltip
  • Loading branch information
troopa81 authored Dec 19, 2024
2 parents 923b03d + 8acedae commit e55c6bb
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/gui/qgsshortcutsmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,9 +369,18 @@ 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
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 ) );
}
}

if ( !sequence.isEmpty() )
{
Expand Down

0 comments on commit e55c6bb

Please sign in to comment.