17#include "moc_qgsactionmenu.cpp" 
   30  , mFeatureId( feature.id() )
 
   31  , mActionScope( actionScope )
 
 
   40  , mActionScope( actionScope )
 
 
   47  mContextGenerator = generator;
 
 
   51void QgsActionMenu::init()
 
   53  setTitle( tr( 
"&Actions" ) );
 
   85void QgsActionMenu::triggerAction()
 
   87  if ( !feature().isValid() )
 
   90  QAction *action = qobject_cast<QAction *>( sender() );
 
   94  if ( !action->data().isValid() || !action->data().canConvert<ActionData>() )
 
   97  const ActionData data = action->data().value<ActionData>();
 
   99  switch ( data.actionType )
 
  122      context << actionScope;
 
  130void QgsActionMenu::reloadActions()
 
  134  mVisibleActionCount = 0;
 
  138  const auto constMActions = mActions;
 
  139  for ( 
const QgsAction &action : constMActions )
 
  141    if ( !mLayer->
isEditable() && action.isEnabledOnlyWhenEditable() )
 
  148    act.setExpressionContextScope( mExpressionContextScope );
 
  150    QAction *qAction = 
new QAction( action.icon(), action.name(), 
this );
 
  151    qAction->setData( QVariant::fromValue<ActionData>( ActionData( act, mFeatureId, mLayer ) ) );
 
  152    qAction->setIcon( action.icon() );
 
  155    if ( !action.runable() )
 
  157      qAction->setEnabled( 
false );
 
  158      qAction->setToolTip( tr( 
"Not supported on your platform" ) );
 
  162      qAction->setToolTip( action.command() );
 
  164    connect( qAction, &QAction::triggered, 
this, &QgsActionMenu::triggerAction );
 
  165    addAction( qAction );
 
  167    mVisibleActionCount++;
 
  172  if ( !mapLayerActions.isEmpty() )
 
  175    if ( mVisibleActionCount > 0 )
 
  178    for ( 
int i = 0; i < mapLayerActions.size(); ++i )
 
  185      QAction *qAction = 
new QAction( mapLayerAction->icon(), mapLayerAction->text(), 
this );
 
  186      qAction->setData( QVariant::fromValue<ActionData>( ActionData( mapLayerAction, mFeatureId, mLayer ) ) );
 
  187      addAction( qAction );
 
  188      connect( qAction, &QAction::triggered, 
this, &QgsActionMenu::triggerAction );
 
  189      mVisibleActionCount++;
 
  196void QgsActionMenu::layerWillBeDeleted()
 
  207  : actionType( 
Qgis::ActionType::MapLayerAction )
 
  209  , featureId( featureId )
 
  210  , mapLayer( mapLayer )
 
 
  215  : actionType( 
Qgis::ActionType::AttributeAction )
 
  216  , actionData( QVariant::fromValue<
QgsAction>( action ) )
 
  217  , featureId( featureId )
 
  218  , mapLayer( mapLayer )
 
 
  224  mExpressionContextScope = scope;
 
 
  230  return mExpressionContextScope;
 
 
  240  return mVisibleActionCount == 0;
 
 
Provides global constants and enumerations for use throughout the application.
 
@ AttributeAction
Custom actions (manually defined in layer properties), corresponds to QgsAction class.
 
@ MapLayerAction
Standard actions (defined by core or plugins), corresponds to QgsMapLayerAction class.
 
@ SingleFeature
Action targets a single feature from a layer.
 
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)
Fetch next feature and stores in f, returns true on success.
 
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.
 
An interface for objects which can create a QgsMapLayerActionContext.
 
virtual QgsMapLayerActionContext createActionContext()=0
Creates a QgsMapLayerActionContext.
 
Encapsulates the context in which a QgsMapLayerAction action is executed.
 
void changed()
Triggered when an action is added or removed from the registry.
 
QList< QgsMapLayerAction * > mapLayerActions(QgsMapLayer *layer, Qgis::MapLayerActionTargets targets=Qgis::MapLayerActionTarget::AllActions, const QgsMapLayerActionContext &context=QgsMapLayerActionContext())
Returns the map layer actions which can run on the specified layer.
 
An action which can run on map layers.
 
bool isEnabledOnlyWhenEditable() const
Returns true if the action is only enabled for layers in editable mode.
 
virtual Q_DECL_DEPRECATED 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 dataset.
 
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.
 
#define Q_NOWARN_DEPRECATED_POP
 
#define Q_NOWARN_DEPRECATED_PUSH
 
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
 
Single variable definition for use within a QgsExpressionContextScope.