28#include <QPlainTextEdit>
31#include <QImageWriter>
33QgsAttributeActionPropertiesDialog::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 )
39 populateActionTypes();
41 mActionType->setCurrentIndex( mActionType->findData(
static_cast< int >(
type ) ) );
45 mIconPreview->setPixmap( QPixmap(
iconPath ) );
47 mCaptureOutput->setChecked(
capture );
60 populateActionTypes();
62 QSet<QString> defaultActionScopes;
63 defaultActionScopes << QStringLiteral(
"Canvas" )
64 << QStringLiteral(
"FieldSpecific" )
65 << QStringLiteral(
"Feature" )
66 << QStringLiteral(
"FeatureForm" );
68 init( defaultActionScopes );
78 return mActionName->text();
83 return mShortTitle->text();
88 return mActionIcon->text();
93 return mActionText->text();
100 const auto constMActionScopeCheckBoxes = mActionScopeCheckBoxes;
101 for ( QCheckBox *cb : constMActionScopeCheckBoxes )
103 if ( cb->isChecked() )
104 actionScopes.insert( cb->property(
"ActionScopeName" ).toString() );
112 return mNotificationMessage->text();
117 return mIsEnabledOnlyWhenEditable->isChecked();
122 return mCaptureOutput->isChecked();
129 const auto constMActionScopeCheckBoxes = mActionScopeCheckBoxes;
130 for ( QCheckBox *cb : constMActionScopeCheckBoxes )
132 if ( cb->isChecked() )
144void QgsAttributeActionPropertiesDialog::browse()
147 const QString action = QFileDialog::getOpenFileName(
148 this, tr(
"Select an action",
"File dialog window title" ), QDir::homePath() );
150 if ( !action.isNull() )
151 mActionText->insertText( action );
154void QgsAttributeActionPropertiesDialog::insertExpressionOrField()
156 QString selText = mActionText->selectedText();
159 if ( selText.startsWith( QLatin1String(
"[%" ) ) && selText.endsWith( QLatin1String(
"%]" ) ) )
160 selText = selText.mid( 2, selText.size() - 4 );
162 mActionText->insertText(
"[%" + mFieldExpression->currentField() +
"%]" );
165void QgsAttributeActionPropertiesDialog::chooseIcon()
167 const QList<QByteArray> list = QImageWriter::supportedImageFormats();
168 QStringList formatList;
169 const auto constList = list;
170 for (
const QByteArray &format : constList )
171 formatList << QStringLiteral(
"*.%1" ).arg( QString( format ) );
173 const QString filter = tr(
"Images( %1 ); All( *.* )" ).arg( formatList.join( QLatin1Char(
' ' ) ) );
174 const QString icon = QFileDialog::getOpenFileName(
this, tr(
"Choose Icon…" ), mActionIcon->text(), filter );
176 if ( !icon.isNull() )
178 mActionIcon->setText( icon );
179 mIconPreview->setPixmap( QPixmap( icon ) );
183void QgsAttributeActionPropertiesDialog::updateButtons()
185 if ( mActionName->text().isEmpty() || mActionText->text().isEmpty() )
187 mButtonBox->button( QDialogButtonBox::Ok )->setEnabled(
false );
191 mButtonBox->button( QDialogButtonBox::Ok )->setEnabled(
true );
195void QgsAttributeActionPropertiesDialog::init(
const QSet<QString> &actionScopes )
199 const auto constAvailableActionScopes = availableActionScopes;
202 QCheckBox *actionScopeCheckBox =
new QCheckBox( scope.title() );
204 actionScopeCheckBox->setChecked(
true );
205 const QStringList variables = scope.expressionContextScope().variableNames();
207 QString tooltip = scope.description();
208 if ( !variables.empty() )
210 tooltip += QLatin1String(
"<br><br>" );
211 tooltip += tr(
"Additional variables" );
212 tooltip += QLatin1String(
"<ul><li>" );
213 tooltip += variables.join( QLatin1String(
"</li><li>" ) );
214 tooltip += QLatin1String(
"</ul></li>" );
216 actionScopeCheckBox->setToolTip( tooltip );
217 actionScopeCheckBox->setProperty(
"ActionScopeName", scope.id() );
218 mActionScopeCheckBoxes.append( actionScopeCheckBox );
219 mActionScopesGroupBox->layout()->addWidget( actionScopeCheckBox );
226 mFieldExpression->setLayer( mLayer );
227 mFieldExpression->setGeomCalculator( myDa );
228 mFieldExpression->registerExpressionContextGenerator(
this );
230 connect( mBrowseButton, &QAbstractButton::clicked,
this, &QgsAttributeActionPropertiesDialog::browse );
231 connect( mInsertFieldOrExpression, &QAbstractButton::clicked,
this, &QgsAttributeActionPropertiesDialog::insertExpressionOrField );
232 connect( mActionName, &QLineEdit::textChanged,
this, &QgsAttributeActionPropertiesDialog::updateButtons );
233 connect( mActionText, &QsciScintilla::textChanged,
this, &QgsAttributeActionPropertiesDialog::updateButtons );
234 connect( mChooseIconButton, &QAbstractButton::clicked,
this, &QgsAttributeActionPropertiesDialog::chooseIcon );
236 connect( mButtonBox, &QDialogButtonBox::helpRequested,
this, &QgsAttributeActionPropertiesDialog::showHelp );
241void QgsAttributeActionPropertiesDialog::showHelp()
243 QgsHelp::openHelp( QStringLiteral(
"working_with_vector/vector_properties.html#actions-properties" ) );
246void 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...