27   , mFeatureId( feature.id() )
 
   28   , mActionScope( actionScope )
 
   37   , mActionScope( actionScope )
 
   42 void QgsActionMenu::init()
 
   44   setTitle( tr( 
"&Actions" ) );
 
   76 void QgsActionMenu::triggerAction()
 
   78   if ( !feature().isValid() )
 
   81   QAction *action = qobject_cast<QAction *>( sender() );
 
   85   if ( !action->data().isValid() || !action->data().canConvert<ActionData>() )
 
   88   const ActionData data = action->data().value<ActionData>();
 
   90   if ( data.actionType == 
Invalid )
 
  106     context << actionScope;
 
  112 void QgsActionMenu::reloadActions()
 
  118   const auto constMActions = mActions;
 
  119   for ( 
const QgsAction &action : constMActions )
 
  121     if ( !mLayer->
isEditable() && action.isEnabledOnlyWhenEditable() )
 
  128     act.setExpressionContextScope( mExpressionContextScope );
 
  130     QAction *qAction = 
new QAction( action.icon(), action.name(), 
this );
 
  131     qAction->setData( QVariant::fromValue<ActionData>( ActionData( act, mFeatureId, mLayer ) ) );
 
  132     qAction->setIcon( action.icon() );
 
  135     if ( !action.runable() )
 
  137       qAction->setEnabled( 
false );
 
  138       qAction->setToolTip( tr( 
"Not supported on your platform" ) );
 
  142       qAction->setToolTip( action.command() );
 
  144     connect( qAction, &QAction::triggered, 
this, &QgsActionMenu::triggerAction );
 
  145     addAction( qAction );
 
  150   if ( !mapLayerActions.isEmpty() )
 
  155     for ( 
int i = 0; i < mapLayerActions.size(); ++i )
 
  162       QAction *qAction = 
new QAction( qaction->icon(), qaction->text(), 
this );
 
  163       qAction->setData( QVariant::fromValue<ActionData>( ActionData( qaction, mFeatureId, mLayer ) ) );
 
  164       addAction( qAction );
 
  165       connect( qAction, &QAction::triggered, 
this, &QgsActionMenu::triggerAction );
 
  172 void QgsActionMenu::layerWillBeDeleted()
 
  183   : actionType( MapLayerAction )
 
  185   , featureId( featureId )
 
  186   , mapLayer( mapLayer )
 
  192   , actionData( QVariant::fromValue<
QgsAction>( action ) )
 
  193   , featureId( featureId )
 
  194   , mapLayer( mapLayer )
 
  200   mExpressionContextScope = scope;
 
  206   return mExpressionContextScope;
 
QList< QgsAction > actions(const QString &actionScope=QString()) const
Returns a list of actions that are available in the given action scope.
Utility class that encapsulates an action based on vector attributes.
void run(QgsVectorLayer *layer, const QgsFeature &feature, const QgsExpressionContext &expressionContext) const
Run this action.
@ IdentifyMode
Identify the feature.
Single scope for storing variables and functions for use within a QgsExpressionContext.
void addVariable(const QgsExpressionContextScope::StaticVariable &variable)
Adds a variable into the context scope.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
bool nextFeature(QgsFeature &f)
This class wraps a request for features to a vector layer (or directly its vector data provider).
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
bool isValid() const
Returns the validity of this feature.
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 changed()
Triggered when an action is added or removed from the registry.
An action which can run on map layers The class can be used in two manners:
bool isEnabledOnlyWhenEditable() const
Returns true if the action is only enabled for layers in editable mode.
virtual void triggerForFeature(QgsMapLayer *layer, const QgsFeature &feature)
Triggers the action with the specified layer and feature.
Base class for all map layer types.
void editingStopped()
Emitted when edited changes have been successfully written to the data provider.
void editingStarted()
Emitted when editing on this layer has started.
void willBeDeleted()
Emitted in the destructor when the layer is about to be deleted, but it is still in a perfectly valid...
Represents a vector layer which manages a vector based data sets.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const FINAL
Queries the layer for features specified in request.
QgsExpressionContext createExpressionContext() const FINAL
This method needs to be reimplemented in all classes which implement this interface and return an exp...
bool isEditable() const FINAL
Returns true if the provider is in editing mode.
QgsActionManager * actions()
Returns all layer actions defined on this layer.
void readOnlyChanged()
Emitted when the read only state of this layer is changed.
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
Single variable definition for use within a QgsExpressionContextScope.