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 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;