29 const bool actionIsVisible {
34 mActionButton->setVisible( actionIsVisible );
64 return new QPushButton( parent );
70 mActionButton = qobject_cast<QPushButton *>( editor );
77 const QString shortTitle { mAction.
shortTitle() };
78 const QString description { mAction.
name() };
79 const QIcon icon { mAction.
icon() };
82 if ( ! icon.isNull() )
84 mActionButton->setIcon( icon );
85 mActionButton->setToolTip( description );
89 mActionButton->setText( shortTitle.isEmpty() ? description : shortTitle );
90 if ( ! shortTitle.isEmpty() )
92 mActionButton->setToolTip( description );
98 mActionButton->setEnabled(
false );
102 connect( mActionButton, &QPushButton::clicked,
this, [ & ]
108 if ( mAction.
type() == QgsAction::ActionType::GenericPython )
110 if (
QgsAttributeForm *form = qobject_cast<QgsAttributeForm *>( parent() ) )
112 const QString formCode = QStringLiteral(
"locals()[\"form\"] = sip.wrapinstance( %1, qgis.gui.QgsAttributeForm )\n" )
113 .arg( ( quint64 ) form );
116 action.run(
layer(), mFeature, expressionContext );
121 mAction.
run(
layer(), mFeature, expressionContext );
Utility class that encapsulates an action based on vector attributes.
QString name() const
The name of the action. This may be a longer description.
void run(QgsVectorLayer *layer, const QgsFeature &feature, const QgsExpressionContext &expressionContext) const
Run this action.
void setCommand(const QString &newCommand)
Sets the action command.
bool runable() const
Checks if the action is runable on the current platform.
QIcon icon() const
The icon.
bool isValid() const
Returns true if this action was a default constructed one.
ActionType type() const
The action type.
QString command() const
Returns the command that is executed by this action.
QString shortTitle() const
The short title is used to label user interface elements like buttons.
bool isEnabledOnlyWhenEditable() const
Returns whether only enabled in editable mode.
This class contains context information for attribute editor widgets.
QString attributeFormModeString() const
Returns given attributeFormMode as string.
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...
Represents a vector layer which manages a vector based data sets.
QgsExpressionContext createExpressionContext() const FINAL
This method needs to be reimplemented in all classes which implement this interface and return an exp...