21 : QAction( icon, name, parent )
28 : QAction( icon, name, parent )
29 , mSingleLayer( true )
30 , mActionLayer( layer )
37 : QAction( icon, name, parent )
38 , mSpecificLayerType( true )
39 , mLayerType( layerType )
65 if ( !qobject_cast<QgsVectorLayer *>( layer )->isEditable() )
70 if ( !mSingleLayer && !mSpecificLayerType )
76 if ( mSingleLayer && layer == mActionLayer )
81 else if ( mSpecificLayerType && layer && layer->
type() == mLayerType )
127 QList< QgsMapLayerAction * > validActions;
132 if ( action->canRunUsingLayer( layer ) && ( targets & action->targets() ) )
134 validActions.append( action );
148 QMap<QgsMapLayer *, QgsMapLayerAction *>::iterator defaultIt;
149 for ( defaultIt = mDefaultLayerActionMap.begin(); defaultIt != mDefaultLayerActionMap.end(); ++defaultIt )
151 if ( defaultIt.value() == action )
153 defaultIt.value() =
nullptr;
165 mDefaultLayerActionMap[ layer ] = action;
170 if ( !mDefaultLayerActionMap.contains( layer ) )
175 return mDefaultLayerActionMap[ layer ];
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
static QgsMapLayerActionRegistry * mapLayerActionRegistry()
Returns the global map layer action registry, used for registering map layer actions.
QList< QgsMapLayerAction * > mapLayerActions(QgsMapLayer *layer, QgsMapLayerAction::Targets targets=QgsMapLayerAction::AllActions)
Returns the map layer actions which can run on the specified layer.
void addMapLayerAction(QgsMapLayerAction *action)
Adds a map layer action to the registry.
void changed()
Triggered when an action is added or removed from the registry.
bool removeMapLayerAction(QgsMapLayerAction *action)
Removes a map layer action from the registry.
QgsMapLayerActionRegistry(QObject *parent=nullptr)
Constructor for QgsMapLayerActionRegistry.
QList< QgsMapLayerAction * > mMapLayerActionList
void setDefaultActionForLayer(QgsMapLayer *layer, QgsMapLayerAction *action)
Sets the default action for a layer.
QgsMapLayerAction * defaultActionForLayer(QgsMapLayer *layer)
Returns the default action for a layer.
An action which can run on map layers The class can be used in two manners:
void triggeredForFeatures(QgsMapLayer *layer, const QList< QgsFeature > &featureList)
Triggered when action has been run for a specific list of features.
virtual bool canRunUsingLayer(QgsMapLayer *layer) const
True if action can run using the specified layer.
QgsMapLayerAction(const QString &name, QObject *parent, Targets targets=AllActions, const QIcon &icon=QIcon(), QgsMapLayerAction::Flags flags=QgsMapLayerAction::Flags())
Action behavior flags.
virtual void triggerForFeatures(QgsMapLayer *layer, const QList< QgsFeature > &featureList)
Triggers the action with the specified layer and list of feature.
QgsMapLayerAction::Flags flags() const
Layer behavior flags.
@ EnabledOnlyWhenEditable
Action should be shown only for editable layers.
virtual void triggerForLayer(QgsMapLayer *layer)
Triggers the action with the specified layer.
bool isEnabledOnlyWhenEditable() const
Returns true if the action is only enabled for layers in editable mode.
~QgsMapLayerAction() override
void triggeredForLayer(QgsMapLayer *layer)
Triggered when action has been run for a specific layer.
void triggeredForFeature(QgsMapLayer *layer, const QgsFeature &feature)
Triggered when action has been run for a specific feature.
virtual void triggerForFeature(QgsMapLayer *layer, const QgsFeature &feature)
Triggers the action with the specified layer and feature.
Base class for all map layer types.
QgsMapLayerType
Types of layers that can be added to a map.