29#include <QPlainTextEdit>
32#include <QImageWriter>
34QgsAttributeActionPropertiesDialog::QgsAttributeActionPropertiesDialog(
QgsAction::ActionType type,
const QString &description,
const QString &shortTitle,
const QString &iconPath,
const QString &actionText,
bool capture,
const QSet<QString> &actionScopes,
const QString ¬ificationMessage,
bool isEnabledOnlyWhenEditable,
QgsVectorLayer *layer, QWidget *parent )
40 mActionType->setCurrentIndex(
type );
44 mIconPreview->setPixmap( QPixmap(
iconPath ) );
46 mCaptureOutput->setChecked(
capture );
59 QSet<QString> defaultActionScopes;
60 defaultActionScopes << QStringLiteral(
"Canvas" )
61 << QStringLiteral(
"FieldSpecific" )
62 << QStringLiteral(
"Feature" )
63 << QStringLiteral(
"FeatureForm" );
65 init( defaultActionScopes );
75 return mActionName->text();
80 return mShortTitle->text();
85 return mActionIcon->text();
90 return mActionText->text();
97 const auto constMActionScopeCheckBoxes = mActionScopeCheckBoxes;
98 for ( QCheckBox *cb : constMActionScopeCheckBoxes )
100 if ( cb->isChecked() )
101 actionScopes.insert( cb->property(
"ActionScopeName" ).toString() );
109 return mNotificationMessage->text();
114 return mIsEnabledOnlyWhenEditable->isChecked();
119 return mCaptureOutput->isChecked();
126 const auto constMActionScopeCheckBoxes = mActionScopeCheckBoxes;
127 for ( QCheckBox *cb : constMActionScopeCheckBoxes )
129 if ( cb->isChecked() )
141void QgsAttributeActionPropertiesDialog::browse()
144 const QString action = QFileDialog::getOpenFileName(
145 this, tr(
"Select an action",
"File dialog window title" ), QDir::homePath() );
147 if ( !action.isNull() )
148 mActionText->insertText( action );
151void QgsAttributeActionPropertiesDialog::insertExpressionOrField()
153 QString selText = mActionText->selectedText();
156 if ( selText.startsWith( QLatin1String(
"[%" ) ) && selText.endsWith( QLatin1String(
"%]" ) ) )
157 selText = selText.mid( 2, selText.size() - 4 );
159 mActionText->insertText(
"[%" + mFieldExpression->currentField() +
"%]" );
162void QgsAttributeActionPropertiesDialog::chooseIcon()
164 const QList<QByteArray> list = QImageWriter::supportedImageFormats();
165 QStringList formatList;
166 const auto constList = list;
167 for (
const QByteArray &format : constList )
168 formatList << QStringLiteral(
"*.%1" ).arg( QString( format ) );
170 const QString filter = tr(
"Images( %1 ); All( *.* )" ).arg( formatList.join( QLatin1Char(
' ' ) ) );
171 const QString icon = QFileDialog::getOpenFileName(
this, tr(
"Choose Icon…" ), mActionIcon->text(), filter );
173 if ( !icon.isNull() )
175 mActionIcon->setText( icon );
176 mIconPreview->setPixmap( QPixmap( icon ) );
180void QgsAttributeActionPropertiesDialog::updateButtons()
182 if ( mActionName->text().isEmpty() || mActionText->text().isEmpty() )
184 mButtonBox->button( QDialogButtonBox::Ok )->setEnabled(
false );
188 mButtonBox->button( QDialogButtonBox::Ok )->setEnabled(
true );
192void QgsAttributeActionPropertiesDialog::init(
const QSet<QString> &actionScopes )
196 const auto constAvailableActionScopes = availableActionScopes;
199 QCheckBox *actionScopeCheckBox =
new QCheckBox( scope.title() );
201 actionScopeCheckBox->setChecked(
true );
202 const QStringList variables = scope.expressionContextScope().variableNames();
204 QString tooltip = scope.description();
205 if ( !variables.empty() )
207 tooltip += QLatin1String(
"<br><br>" );
208 tooltip += tr(
"Additional variables" );
209 tooltip += QLatin1String(
"<ul><li>" );
210 tooltip += variables.join( QLatin1String(
"</li><li>" ) );
211 tooltip += QLatin1String(
"</ul></li>" );
213 actionScopeCheckBox->setToolTip( tooltip );
214 actionScopeCheckBox->setProperty(
"ActionScopeName", scope.id() );
215 mActionScopeCheckBoxes.append( actionScopeCheckBox );
216 mActionScopesGroupBox->layout()->addWidget( actionScopeCheckBox );
223 mFieldExpression->setLayer( mLayer );
224 mFieldExpression->setGeomCalculator( myDa );
225 mFieldExpression->registerExpressionContextGenerator(
this );
227 connect( mBrowseButton, &QAbstractButton::clicked,
this, &QgsAttributeActionPropertiesDialog::browse );
228 connect( mInsertFieldOrExpression, &QAbstractButton::clicked,
this, &QgsAttributeActionPropertiesDialog::insertExpressionOrField );
229 connect( mActionName, &QLineEdit::textChanged,
this, &QgsAttributeActionPropertiesDialog::updateButtons );
230 connect( mActionText, &QsciScintilla::textChanged,
this, &QgsAttributeActionPropertiesDialog::updateButtons );
231 connect( mChooseIconButton, &QAbstractButton::clicked,
this, &QgsAttributeActionPropertiesDialog::chooseIcon );
233 connect( mButtonBox, &QDialogButtonBox::helpRequested,
this, &QgsAttributeActionPropertiesDialog::showHelp );
238void QgsAttributeActionPropertiesDialog::showHelp()
240 QgsHelp::openHelp( QStringLiteral(
"working_with_vector/vector_properties.html#actions-properties" ) );
QgsActionScope actionScope(const QString &id)
Gets an action scope by its id.
QSet< QgsActionScope > actionScopes
An action scope defines a "place" for an action to be shown and may add additional expression variabl...
QgsExpressionContextScope expressionContextScope() const
An expression scope may offer additional variables for an action scope.
static QgsActionScopeRegistry * actionScopeRegistry()
Returns the action scope registry.
QString notificationMessage() const
QgsAttributeActionPropertiesDialog(QgsAction::ActionType type, const QString &description, const QString &shortTitle, const QString &iconPath, const QString &actionText, bool capture, const QSet< QString > &actionScopes, const QString ¬ificationMessage, bool isEnabledOnlyWhenEditable, QgsVectorLayer *layer, QWidget *parent=nullptr)
QSet< QString > actionScopes() const
bool isEnabledOnlyWhenEditable() const
QgsExpressionContext createExpressionContext() const override
This method needs to be reimplemented in all classes which implement this interface and return an exp...
QString actionText() const
QgsAction::ActionType type() const
QString description() const
QString shortTitle() const
A general purpose distance and area calculator, capable of performing ellipsoid based calculations.
void setSourceCrs(const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context)
Sets source spatial reference system crs.
bool setEllipsoid(const QString &ellipsoid)
Sets the ellipsoid by its acronym.
Single scope for storing variables and functions for use within a QgsExpressionContext.
static QgsExpressionContextScope * notificationScope(const QString &message=QString())
Creates a new scope which contains variables and functions relating to provider notifications.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
QgsCoordinateReferenceSystem crs
static QgsProject * instance()
Returns the QgsProject singleton instance.
QgsCoordinateTransformContext transformContext
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...