18#include "moc_qgsattributeactionpropertiesdialog.cpp"
29#include <QPlainTextEdit>
32#include <QImageWriter>
34QgsAttributeActionPropertiesDialog::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 )
40 populateActionTypes();
42 mActionType->setCurrentIndex( mActionType->findData(
static_cast<int>(
type ) ) );
46 mIconPreview->setPixmap( QPixmap(
iconPath ) );
48 mCaptureOutput->setChecked(
capture );
61 populateActionTypes();
63 QSet<QString> defaultActionScopes;
64 defaultActionScopes << QStringLiteral(
"Canvas" )
65 << QStringLiteral(
"FieldSpecific" )
66 << QStringLiteral(
"Feature" )
67 << QStringLiteral(
"FeatureForm" );
69 init( defaultActionScopes );
79 return mActionName->text();
84 return mShortTitle->text();
89 return mActionIcon->text();
94 return mActionText->text();
101 const auto constMActionScopeCheckBoxes = mActionScopeCheckBoxes;
102 for ( QCheckBox *cb : constMActionScopeCheckBoxes )
104 if ( cb->isChecked() )
105 actionScopes.insert( cb->property(
"ActionScopeName" ).toString() );
113 return mNotificationMessage->text();
118 return mIsEnabledOnlyWhenEditable->isChecked();
123 return mCaptureOutput->isChecked();
130 const auto constMActionScopeCheckBoxes = mActionScopeCheckBoxes;
131 for ( QCheckBox *cb : constMActionScopeCheckBoxes )
133 if ( cb->isChecked() )
145void QgsAttributeActionPropertiesDialog::browse()
148 const QString action = QFileDialog::getOpenFileName(
149 this, tr(
"Select an action",
"File dialog window title" ), QDir::homePath()
152 if ( !action.isNull() )
153 mActionText->insertText( action );
156void QgsAttributeActionPropertiesDialog::insertExpressionOrField()
158 QString selText = mActionText->selectedText();
161 if ( selText.startsWith( QLatin1String(
"[%" ) ) && selText.endsWith( QLatin1String(
"%]" ) ) )
162 selText = selText.mid( 2, selText.size() - 4 );
164 mActionText->insertText(
"[%" + mFieldExpression->currentField() +
"%]" );
167void QgsAttributeActionPropertiesDialog::chooseIcon()
169 const QList<QByteArray> list = QImageWriter::supportedImageFormats();
170 QStringList formatList;
171 const auto constList = list;
172 for (
const QByteArray &format : constList )
173 formatList << QStringLiteral(
"*.%1" ).arg( QString( format ) );
175 const QString filter = tr(
"Images( %1 ); All( *.* )" ).arg( formatList.join( QLatin1Char(
' ' ) ) );
176 const QString icon = QFileDialog::getOpenFileName(
this, tr(
"Choose Icon…" ), mActionIcon->text(), filter );
178 if ( !icon.isNull() )
180 mActionIcon->setText( icon );
181 mIconPreview->setPixmap( QPixmap( icon ) );
185void QgsAttributeActionPropertiesDialog::updateButtons()
187 if ( mActionName->text().isEmpty() || mActionText->text().isEmpty() )
189 mButtonBox->button( QDialogButtonBox::Ok )->setEnabled(
false );
193 mButtonBox->button( QDialogButtonBox::Ok )->setEnabled(
true );
197void QgsAttributeActionPropertiesDialog::init(
const QSet<QString> &actionScopes )
201 const auto constAvailableActionScopes = availableActionScopes;
204 QCheckBox *actionScopeCheckBox =
new QCheckBox( scope.title() );
206 actionScopeCheckBox->setChecked(
true );
207 const QStringList variables = scope.expressionContextScope().variableNames();
209 QString tooltip = scope.description();
210 if ( !variables.empty() )
212 tooltip += QLatin1String(
"<br><br>" );
213 tooltip += tr(
"Additional variables" );
214 tooltip += QLatin1String(
"<ul><li>" );
215 tooltip += variables.join( QLatin1String(
"</li><li>" ) );
216 tooltip += QLatin1String(
"</ul></li>" );
218 actionScopeCheckBox->setToolTip( tooltip );
219 actionScopeCheckBox->setProperty(
"ActionScopeName", scope.id() );
220 mActionScopeCheckBoxes.append( actionScopeCheckBox );
221 mActionScopesGroupBox->layout()->addWidget( actionScopeCheckBox );
228 mFieldExpression->setLayer( mLayer );
229 mFieldExpression->setGeomCalculator( myDa );
230 mFieldExpression->registerExpressionContextGenerator(
this );
232 connect( mBrowseButton, &QAbstractButton::clicked,
this, &QgsAttributeActionPropertiesDialog::browse );
233 connect( mInsertFieldOrExpression, &QAbstractButton::clicked,
this, &QgsAttributeActionPropertiesDialog::insertExpressionOrField );
234 connect( mActionName, &QLineEdit::textChanged,
this, &QgsAttributeActionPropertiesDialog::updateButtons );
235 connect( mActionText, &QsciScintilla::textChanged,
this, &QgsAttributeActionPropertiesDialog::updateButtons );
236 connect( mChooseIconButton, &QAbstractButton::clicked,
this, &QgsAttributeActionPropertiesDialog::chooseIcon );
238 connect( mButtonBox, &QDialogButtonBox::helpRequested,
this, &QgsAttributeActionPropertiesDialog::showHelp );
243void QgsAttributeActionPropertiesDialog::showHelp()
245 QgsHelp::openHelp( QStringLiteral(
"working_with_vector/vector_properties.html#actions-properties" ) );
248void 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
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...