Skip to content
Permalink
Browse files

Merge pull request #34266 from 3nids/maplayeraction-multiple

Fix map layer actions rendering in attribute table
  • Loading branch information
3nids committed Feb 5, 2020
2 parents b8a12be + 7e7def8 commit 4fb42ae68dde644d450e8527110b7b50004195bc
Showing with 20 additions and 1 deletion.
  1. +20 −1 src/gui/attributetable/qgsdualview.cpp
@@ -706,7 +706,7 @@ void QgsDualView::viewWillShowContextMenu( QMenu *menu, const QModelIndex &atInd
return;
}
//add actions from QgsMapLayerActionRegistry to context menu
QList<QgsMapLayerAction *> registeredActions = QgsGui::mapLayerActionRegistry()->mapLayerActions( mLayer );
QList<QgsMapLayerAction *> registeredActions = QgsGui::mapLayerActionRegistry()->mapLayerActions( mLayer, QgsMapLayerAction::Layer | QgsMapLayerAction::SingleFeature );
if ( !registeredActions.isEmpty() )
{
//add a separator between user defined and standard actions
@@ -720,6 +720,25 @@ void QgsDualView::viewWillShowContextMenu( QMenu *menu, const QModelIndex &atInd
}
}

// entries for multiple features layer actions
// only show if the context menu is shown over a selected row
QgsFeatureId currentFid = masterModel()->rowToId( sourceIndex.row() );
if ( mLayer->selectedFeatureCount() > 1 && mLayer->selectedFeatureIds().contains( currentFid ) )
{
const QList<QgsMapLayerAction *> constRegisteredActions = QgsGui::mapLayerActionRegistry()->mapLayerActions( mLayer, QgsMapLayerAction::MultipleFeatures );
if ( !constRegisteredActions.isEmpty() )
{
menu->addSeparator();
QAction *action = menu->addAction( tr( "Actions on Selection (%1)" ).arg( mLayer->selectedFeatureCount() ) );
action->setEnabled( false );

for ( QgsMapLayerAction *action : constRegisteredActions )
{
menu->addAction( action->text(), action, [ = ]() {action->triggerForFeatures( mLayer, mLayer->selectedFeatures() );} );
}
}
}

menu->addSeparator();
QgsAttributeTableAction *a = new QgsAttributeTableAction( tr( "Open Form" ), this, QString(), rowSourceIndex );
menu->addAction( tr( "Open Form" ), a, &QgsAttributeTableAction::featureForm );

0 comments on commit 4fb42ae

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