25#include "moc_qgsactionwidgetwrapper.cpp"
29 , mMessageBar( messageBar )
32 const bool actionIsVisible {
37 mActionButton->setVisible( actionIsVisible );
56 mActionButton->setEnabled( !mAction.isEnabledOnlyWhenEditable() || enabled );
62 return mAction.
isValid() && mAction.runable();
67 return new QPushButton( parent );
72 mActionButton = qobject_cast<QPushButton *>( editor );
79 const QString shortTitle { mAction.shortTitle() };
80 const QString description { mAction.name() };
81 const QIcon icon { mAction.icon() };
86 mActionButton->setIcon( icon );
87 mActionButton->setToolTip( description );
91 mActionButton->setText( shortTitle.isEmpty() ? description : shortTitle );
92 if ( !shortTitle.isEmpty() )
94 mActionButton->setToolTip( description );
98 if ( mAction.isEnabledOnlyWhenEditable() && !
layer()->isEditable() )
100 mActionButton->setEnabled(
false );
104 connect( mActionButton, &QPushButton::clicked,
this, [&] {
109 switch ( mAction.type() )
116 if (
QgsAttributeForm *form = qobject_cast<QgsAttributeForm *>( parent() ) )
123 mMessageBar->pushMessage(
124 tr(
"Security warning" ),
125 tr(
"The action contains an embedded script which has been denied execution." ),
132 const QString formCode = QStringLiteral(
"locals()[\"form\"] = sip.wrapinstance( %1, qgis.gui.QgsAttributeForm )\n" )
133 .arg( ( quint64 ) form );
135 action.
setCommand( formCode + mAction.command() );
136 action.
run(
layer(), mFeature, expressionContext );
146 mAction.run(
layer(), mFeature, expressionContext );
@ 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.
Utility class that encapsulates an action based on vector attributes.
void run(QgsVectorLayer *layer, const QgsFeature &feature, const QgsExpressionContext &expressionContext) const
Run this action.
void setCommand(const QString &newCommand)
Sets the action command.
Contains context information for attribute editor widgets.
QString attributeFormModeString() const
Returns given attributeFormMode as string.
@ SingleEditMode
Single edit mode, for editing a single feature.
Mode attributeFormMode() const
Returns current attributeFormMode.
static QgsExpressionContextScope * formScope(const QgsFeature &formFeature=QgsFeature(), const QString &formMode=QString())
Creates a new scope which contains functions and variables from the current attribute form/table form...
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.
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 bool allowExecutionOfEmbeddedScripts(QgsProject *project, QgsMessageBar *messageBar=nullptr)
Returns true if python embedded in a project is currently allowed to be loaded.
A bar for displaying non-blocking messages to the user.
static QgsProject * instance()
Returns the QgsProject singleton instance.
Represents a vector layer which manages a vector based dataset.
QgsExpressionContext createExpressionContext() const final
This method needs to be reimplemented in all classes which implement this interface and return an exp...