Skip to content

Commit

Permalink
Show tooltip in locator actions results if different to action title
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed May 11, 2018
1 parent 0c24e29 commit b87a92b
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/app/locator/qgsinbuiltlocatorfilters.cpp
Expand Up @@ -144,6 +144,9 @@ void QgsActionLocatorFilter::searchActions( const QString &string, QWidget *pare
{
searchActions( string, widget, found );
}

QRegularExpression extractFromTooltip( QStringLiteral( "<b>(.*)</b>" ) );

Q_FOREACH ( QAction *action, parent->actions() )
{
if ( action->menu() )
Expand All @@ -159,6 +162,22 @@ void QgsActionLocatorFilter::searchActions( const QString &string, QWidget *pare

QString searchText = action->text();
searchText.replace( '&', QString() );

QString tooltip = action->toolTip();
QRegularExpressionMatch match = extractFromTooltip.match( tooltip );
if ( match.hasMatch() )
{
tooltip = match.captured( 1 );
}
tooltip.replace( QStringLiteral( "..." ), QString() );
tooltip.replace( QStringLiteral( "" ), QString() );
searchText.replace( QStringLiteral( "..." ), QString() );
searchText.replace( QStringLiteral( "" ), QString() );
if ( searchText.trimmed().compare( tooltip.trimmed(), Qt::CaseInsensitive ) != 0 )
{
searchText += QStringLiteral( " (%1)" ).arg( tooltip.trimmed() );
}

if ( stringMatches( searchText, string ) )
{
QgsLocatorResult result;
Expand Down

0 comments on commit b87a92b

Please sign in to comment.