Skip to content

Commit

Permalink
use const and avoid copy
Browse files Browse the repository at this point in the history
  • Loading branch information
signedav committed Oct 18, 2018
1 parent 723df76 commit 5bcff46
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
17 changes: 8 additions & 9 deletions src/app/qgsmaptoolfeatureaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,28 +138,27 @@ bool QgsMapToolFeatureAction::doAction( QgsVectorLayer *layer, int x, int y )
else
{
QMenu *featureMenu = new QMenu();
for ( int i = 0; i < features.count(); i++ )
for ( int idx = 0; idx < features.count(); idx++ )
{
QAction *featureAction = featureMenu->addAction( FID_TO_STRING( features.at( i ).id() ) );
connect( featureAction, &QAction::triggered, this, [ = ] { doActionForFeature( layer, features.at( i ), point );} );
QAction *featureAction = featureMenu->addAction( FID_TO_STRING( features.at( idx ).id() ) );
connect( featureAction, &QAction::triggered, this, [ = ] { doActionForFeature( layer, features.at( idx ), point );} );
}
QAction *allFeatureAction = featureMenu->addAction( tr( "All Features" ) );
connect( allFeatureAction, &QAction::triggered, this, [ = ]
{
for ( int i = 0; i < features.count(); i++ )
for ( int idx = 0; idx < features.count(); idx++ )
{
doActionForFeature( layer, features.at( i ), point );
doActionForFeature( layer, features.at( idx ), point );
}
} );

featureMenu->exec( position );
}
return true;
}
return false;
}

void QgsMapToolFeatureAction::doActionForFeature( QgsVectorLayer *layer, QgsFeature feat, QgsPointXY point )
void QgsMapToolFeatureAction::doActionForFeature( QgsVectorLayer *layer, const QgsFeature &feature, const QgsPointXY &point )
{
QgsAction defaultAction = layer->actions()->defaultAction( QStringLiteral( "Canvas" ) );
if ( defaultAction.isValid() )
Expand All @@ -175,14 +174,14 @@ void QgsMapToolFeatureAction::doActionForFeature( QgsVectorLayer *layer, QgsFeat
actionScope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "action_scope" ), QStringLiteral( "Canvas" ), true ) );
context << actionScope;

defaultAction.run( layer, feat, context );
defaultAction.run( layer, feature, context );
}
else
{
QgsMapLayerAction *mapLayerAction = QgsGui::mapLayerActionRegistry()->defaultActionForLayer( layer );
if ( mapLayerAction )
{
mapLayerAction->triggerForFeature( layer, &feat );
mapLayerAction->triggerForFeature( layer, &feature );
}
}
}
2 changes: 1 addition & 1 deletion src/app/qgsmaptoolfeatureaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class APP_EXPORT QgsMapToolFeatureAction : public QgsMapTool

private:
bool doAction( QgsVectorLayer *layer, int x, int y );
void doActionForFeature( QgsVectorLayer *layer, QgsFeature feat, QgsPointXY point );
void doActionForFeature( QgsVectorLayer *layer, const QgsFeature &feature, const QgsPointXY &point );
};

#endif

0 comments on commit 5bcff46

Please sign in to comment.