Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
"Run feature action" tool does the action for all the matching featur…
…es (fix #5126)
  • Loading branch information
brushtyler committed Mar 14, 2012
1 parent 533ac4c commit db1c401
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions src/app/qgsmaptoolfeatureaction.cpp
Expand Up @@ -72,6 +72,12 @@ void QgsMapToolFeatureAction::canvasReleaseEvent( QMouseEvent *e )
return;
}

if ( !mCanvas->layers().contains( layer ) )
{
// do not run actions on hidden layers
return;
}

QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layer );
if ( vlayer->actions()->size() == 0 )
{
Expand Down Expand Up @@ -110,7 +116,7 @@ bool QgsMapToolFeatureAction::doAction( QgsVectorLayer *layer, int x, int y )
if ( identifyValue <= 0.0 )
identifyValue = QGis::DEFAULT_IDENTIFY_RADIUS;

QgsFeature feat;
QgsFeatureList featList;

// toLayerCoordinates will throw an exception for an 'invalid' point.
// For example, if you project a world map onto a globe using EPSG 2163
Expand All @@ -130,10 +136,8 @@ bool QgsMapToolFeatureAction::doAction( QgsVectorLayer *layer, int x, int y )

layer->select( layer->pendingAllAttributesList(), r, true, true );
QgsFeature f;
if ( layer->nextFeature( f ) )
feat = QgsFeature( f );
else
return false;
while ( layer->nextFeature( f ) )
featList << QgsFeature( f );
}
catch ( QgsCsException & cse )
{
Expand All @@ -142,15 +146,22 @@ bool QgsMapToolFeatureAction::doAction( QgsVectorLayer *layer, int x, int y )
QgsDebugMsg( QString( "Caught CRS exception %1" ).arg( cse.what() ) );
}

int action = layer->actions()->defaultAction();
if ( featList.size() == 0 )
return false;

// define custom substitutions: layer id and clicked coords
QMap<QString, QVariant> substitutionMap;
substitutionMap.insert( "$layerid", layer->id() );
point = toLayerCoordinates( layer, point );
substitutionMap.insert( "$clickx", point.x() );
substitutionMap.insert( "$clicky", point.y() );
foreach ( QgsFeature feat, featList )
{
int actionIdx = layer->actions()->defaultAction();

// define custom substitutions: layer id and clicked coords
QMap<QString, QVariant> substitutionMap;
substitutionMap.insert( "$layerid", layer->id() );
point = toLayerCoordinates( layer, point );
substitutionMap.insert( "$clickx", point.x() );
substitutionMap.insert( "$clicky", point.y() );

layer->actions()->doAction( actionIdx, feat, &substitutionMap );
}

layer->actions()->doAction( action, feat, &substitutionMap );
return true;
}

0 comments on commit db1c401

Please sign in to comment.