26#include "moc_qgsactionwidgetwrapper.cpp"
28using namespace Qt::StringLiterals;
32 , mMessageBar( messageBar )
35 const bool actionIsVisible {
40 mActionButton->setVisible( actionIsVisible );
59 mActionButton->setEnabled( !mAction.isEnabledOnlyWhenEditable() || enabled );
65 return mAction.
isValid() && mAction.runable();
70 return new QPushButton( parent );
75 mActionButton = qobject_cast<QPushButton *>( editor );
82 const QString shortTitle { mAction.shortTitle() };
83 const QString description { mAction.name() };
84 const QIcon icon { mAction.icon() };
89 mActionButton->setIcon( icon );
90 mActionButton->setToolTip( description );
94 mActionButton->setText( shortTitle.isEmpty() ? description : shortTitle );
95 if ( !shortTitle.isEmpty() )
97 mActionButton->setToolTip( description );
101 if ( mAction.isEnabledOnlyWhenEditable() && !
layer()->isEditable() )
103 mActionButton->setEnabled(
false );
107 connect( mActionButton, &QPushButton::clicked,
this, [&] {
112 switch ( mAction.type() )
119 if (
QgsAttributeForm *form = qobject_cast<QgsAttributeForm *>( parent() ) )
126 mMessageBar->pushMessage(
127 tr(
"Security warning" ),
128 tr(
"The action contains an embedded script which has been denied execution." ),
135 const QString formCode = u
"locals()[\"form\"] = sip.wrapinstance( %1, qgis.gui.QgsAttributeForm )\n"_s
136 .arg( ( quint64 ) form );
138 action.
setCommand( formCode + mAction.command() );
139 action.
run(
layer(), mFeature, expressionContext );
149 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...