30#include <QImageWriter>
32#include <QPlainTextEdit>
35#include "moc_qgsattributeactionpropertiesdialog.cpp"
37using namespace Qt::StringLiterals;
57 populateActionTypes();
59 mActionType->setCurrentIndex( mActionType->findData(
static_cast<int>(
type ) ) );
63 mIconPreview->setPixmap( QPixmap(
iconPath ) );
65 mCaptureOutput->setChecked(
capture );
78 populateActionTypes();
80 QSet<QString> defaultActionScopes;
81 defaultActionScopes << u
"Canvas"_s << u
"FieldSpecific"_s << u
"Feature"_s << u
"FeatureForm"_s;
83 init( defaultActionScopes );
93 return mActionName->text();
98 return mShortTitle->text();
103 return mActionIcon->text();
108 return mActionText->text();
115 const auto constMActionScopeCheckBoxes = mActionScopeCheckBoxes;
116 for ( QCheckBox *cb : constMActionScopeCheckBoxes )
118 if ( cb->isChecked() )
119 actionScopes.insert( cb->property(
"ActionScopeName" ).toString() );
127 return mNotificationMessage->text();
132 return mIsEnabledOnlyWhenEditable->isChecked();
137 return mCaptureOutput->isChecked();
144 const auto constMActionScopeCheckBoxes = mActionScopeCheckBoxes;
145 for ( QCheckBox *cb : constMActionScopeCheckBoxes )
147 if ( cb->isChecked() )
159void QgsAttributeActionPropertiesDialog::browse()
162 const QString action = QFileDialog::getOpenFileName(
this, tr(
"Select an action",
"File dialog window title" ), QDir::homePath() );
164 if ( !action.isNull() )
165 mActionText->insertText( action );
168void QgsAttributeActionPropertiesDialog::insertExpressionOrField()
170 QString selText = mActionText->selectedText();
173 if ( selText.startsWith(
"[%"_L1 ) && selText.endsWith(
"%]"_L1 ) )
174 selText = selText.mid( 2, selText.size() - 4 );
176 mActionText->insertText(
"[%" + mFieldExpression->currentField() +
"%]" );
179void QgsAttributeActionPropertiesDialog::chooseIcon()
181 const QList<QByteArray> list = QImageWriter::supportedImageFormats();
182 QStringList formatList;
183 const auto constList = list;
184 for (
const QByteArray &format : constList )
185 formatList << u
"*.%1"_s.arg( QString( format ) );
187 const QString filter = tr(
"Images( %1 ); All( *.* )" ).arg( formatList.join(
' '_L1 ) );
188 const QString icon = QFileDialog::getOpenFileName(
this, tr(
"Choose Icon…" ), mActionIcon->text(), filter );
190 if ( !icon.isNull() )
192 mActionIcon->setText( icon );
193 mIconPreview->setPixmap( QPixmap( icon ) );
197void QgsAttributeActionPropertiesDialog::updateButtons()
199 if ( mActionName->text().isEmpty() || mActionText->text().isEmpty() )
201 mButtonBox->button( QDialogButtonBox::Ok )->setEnabled(
false );
205 mButtonBox->button( QDialogButtonBox::Ok )->setEnabled(
true );
209void QgsAttributeActionPropertiesDialog::init(
const QSet<QString> &actionScopes )
213 const auto constAvailableActionScopes = availableActionScopes;
214 for (
const QgsActionScope &scope : constAvailableActionScopes )
216 QCheckBox *actionScopeCheckBox =
new QCheckBox( scope.title() );
218 actionScopeCheckBox->setChecked(
true );
219 const QStringList variables = scope.expressionContextScope().variableNames();
221 QString tooltip = scope.description();
222 if ( !variables.empty() )
224 tooltip +=
"<br><br>"_L1;
225 tooltip += tr(
"Additional variables" );
226 tooltip +=
"<ul><li>"_L1;
227 tooltip += variables.join(
"</li><li>"_L1 );
228 tooltip +=
"</ul></li>"_L1;
230 actionScopeCheckBox->setToolTip( tooltip );
231 actionScopeCheckBox->setProperty(
"ActionScopeName", scope.id() );
232 mActionScopeCheckBoxes.append( actionScopeCheckBox );
233 mActionScopesGroupBox->layout()->addWidget( actionScopeCheckBox );
236 QgsDistanceArea myDa;
240 mFieldExpression->setLayer( mLayer );
241 mFieldExpression->setGeomCalculator( myDa );
242 mFieldExpression->registerExpressionContextGenerator(
this );
244 connect( mBrowseButton, &QAbstractButton::clicked,
this, &QgsAttributeActionPropertiesDialog::browse );
245 connect( mInsertFieldOrExpression, &QAbstractButton::clicked,
this, &QgsAttributeActionPropertiesDialog::insertExpressionOrField );
246 connect( mActionName, &QLineEdit::textChanged,
this, &QgsAttributeActionPropertiesDialog::updateButtons );
247 connect( mActionText, &QsciScintilla::textChanged,
this, &QgsAttributeActionPropertiesDialog::updateButtons );
248 connect( mChooseIconButton, &QAbstractButton::clicked,
this, &QgsAttributeActionPropertiesDialog::chooseIcon );
250 connect( mButtonBox, &QDialogButtonBox::helpRequested,
this, &QgsAttributeActionPropertiesDialog::showHelp );
255void QgsAttributeActionPropertiesDialog::showHelp()
257 QgsHelp::openHelp( u
"working_with_vector/vector_properties.html#actions-properties"_s );
260void QgsAttributeActionPropertiesDialog::populateActionTypes()
AttributeActionType
Attribute action types.
@ 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...
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
Returns the expression context scope for the action scope.
static QgsActionScopeRegistry * actionScopeRegistry()
Returns the action scope registry.
QString notificationMessage() const
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
Qgis::AttributeActionType type() const
QString description() const
QgsAttributeActionPropertiesDialog(Qgis::AttributeActionType 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)
Constructor for QgsAttributeActionPropertiesDialog.
QString shortTitle() const
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.
static QgsProject * instance()
Returns the QgsProject singleton instance.
QgsCoordinateTransformContext transformContext
Represents a vector layer which manages a vector based dataset.