Skip to content

Commit

Permalink
allow to use icons too
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed Nov 29, 2018
1 parent d272f3c commit f24daa2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
3 changes: 2 additions & 1 deletion python/core/auto_generated/locator/qgslocatorfilter.sip.in
Expand Up @@ -55,9 +55,10 @@ Constructor for QgsLocatorResult.
%Docstring
Constructor for ResultAction
%End
ResultAction( int id, QString text );
ResultAction( int id, QString text, QString iconPath = QString() );
int id;
QString text;
QString iconPath;
};

QList<ResultAction> actions;
Expand Down
4 changes: 3 additions & 1 deletion src/core/locator/qgslocatorfilter.h
Expand Up @@ -107,12 +107,14 @@ class CORE_EXPORT QgsLocatorResult
public:
//! Constructor for ResultAction
ResultAction() = default;
ResultAction( int id, QString text )
ResultAction( int id, QString text, QString iconPath = QString() )
: id( id )
, text( text )
, iconPath( iconPath )
{}
int id = -1;
QString text;
QString iconPath;
};

/**
Expand Down
8 changes: 5 additions & 3 deletions src/gui/locator/qgslocatorwidget.cpp
Expand Up @@ -183,10 +183,12 @@ void QgsLocatorWidget::showContextMenu( const QPoint &point )

const QList<QgsLocatorResult::ResultAction> actions = mResultsView->model()->data( index, QgsLocatorModel::ResultActionsRole ).value<QList<QgsLocatorResult::ResultAction>>();
QMenu *contextMenu = new QMenu( mResultsView );
for ( auto action : actions )
for ( auto resultAction : actions )
{
QAction *menuAction = new QAction( action.text, contextMenu );
connect( menuAction, &QAction::triggered, this, [ = ]() {mModelBridge->triggerResult( index, action.id );} );
QAction *menuAction = new QAction( resultAction.text, contextMenu );
if ( !resultAction.iconPath.isEmpty() )
menuAction->setIcon( QIcon( resultAction.iconPath ) );
connect( menuAction, &QAction::triggered, this, [ = ]() {mModelBridge->triggerResult( index, resultAction.id );} );
contextMenu->addAction( menuAction );
}
contextMenu->exec( mResultsView->viewport()->mapToGlobal( point ) );
Expand Down

0 comments on commit f24daa2

Please sign in to comment.