Skip to content
Permalink
Browse files

allow to use icons too

  • Loading branch information
3nids committed Nov 29, 2018
1 parent d272f3c commit f24daa2b698a7507d7ecce7e232fbfa81c401ebd
@@ -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;
@@ -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;
};

/**
@@ -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 ) );

0 comments on commit f24daa2

Please sign in to comment.
You can’t perform that action at this time.