26#include "moc_qgsactionmenu.cpp"
32 , mFeatureId( feature.id() )
33 , mActionScope( actionScope )
42 , mActionScope( actionScope )
49 mContextGenerator = generator;
53void QgsActionMenu::init()
55 setTitle( tr(
"&Actions" ) );
68 if ( !mFeature.isValid() )
70 mLayer->getFeatures( QgsFeatureRequest( mFeatureId ) ).nextFeature( mFeature );
87void QgsActionMenu::triggerAction()
89 if ( !feature().isValid() )
92 QAction *action = qobject_cast<QAction *>( sender() );
96 if ( !action->data().isValid() || !action->data().canConvert<ActionData>() )
99 const ActionData data = action->data().value<ActionData>();
101 switch ( data.actionType )
118 const QgsAction act = data.actionData.value<QgsAction>();
119 switch ( act.
type() )
145 QgsExpressionContext context = mLayer->createExpressionContext();
148 QgsExpressionContextScope *actionScope =
new QgsExpressionContextScope();
149 actionScope->
addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral(
"action_scope" ), mActionScope,
true ) );
150 context << actionScope;
157void QgsActionMenu::reloadActions()
161 mVisibleActionCount = 0;
163 mActions = mLayer->actions()->actions( mActionScope );
165 const auto constMActions = mActions;
166 for (
const QgsAction &action : constMActions )
168 if ( !mLayer->isEditable() && action.isEnabledOnlyWhenEditable() )
174 QgsAction act( action );
177 QAction *qAction =
new QAction( action.icon(), action.name(),
this );
178 qAction->setData( QVariant::fromValue<ActionData>(
ActionData( act, mFeatureId, mLayer ) ) );
179 qAction->setIcon( action.icon() );
182 if ( !action.runable() )
184 qAction->setEnabled(
false );
185 qAction->setToolTip( tr(
"Not supported on your platform" ) );
189 qAction->setToolTip( action.command() );
191 connect( qAction, &QAction::triggered,
this, &QgsActionMenu::triggerAction );
192 addAction( qAction );
194 mVisibleActionCount++;
199 if ( !mapLayerActions.isEmpty() )
202 if ( mVisibleActionCount > 0 )
205 for (
int i = 0; i < mapLayerActions.size(); ++i )
207 QgsMapLayerAction *mapLayerAction = mapLayerActions.at( i );
212 QAction *qAction =
new QAction( mapLayerAction->icon(), mapLayerAction->text(),
this );
213 qAction->setData( QVariant::fromValue<ActionData>(
ActionData( mapLayerAction, mFeatureId, mLayer ) ) );
214 addAction( qAction );
215 connect( qAction, &QAction::triggered,
this, &QgsActionMenu::triggerAction );
216 mVisibleActionCount++;
223void QgsActionMenu::layerWillBeDeleted()
251 mExpressionContextScope = scope;
257 return mExpressionContextScope;
267 return mVisibleActionCount == 0;
Provides global constants and enumerations for use throughout the application.
@ OpenUrl
Open URL action.
@ SubmitUrlMultipart
POST data to an URL using "multipart/form-data".
@ Windows
Windows specific.
@ SubmitUrlEncoded
POST data to an URL, using "application/x-www-form-urlencoded" or "application/json" if the body is v...
@ Warning
Warning message.
@ 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.
Utility class that encapsulates an action based on vector attributes.
Qgis::AttributeActionType type() const
The action type.
void run(QgsVectorLayer *layer, const QgsFeature &feature, const QgsExpressionContext &expressionContext) const
Run this action.
void setExpressionContextScope(const QgsExpressionContextScope &scope)
Sets an expression context scope to use for running the 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.
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
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.
static bool allowExecutionOfEmbeddedScripts(QgsProject *project, QgsMessageBar *messageBar=nullptr)
Returns true if python embedded in a project is currently allowed to be loaded.
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...
static QgsProject * instance()
Returns the QgsProject singleton instance.
Represents a vector layer which manages a vector based dataset.
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