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() );
151 if ( !action.isNull() )
152 mActionText->insertText( action );
155void QgsAttributeActionPropertiesDialog::insertExpressionOrField()
157 QString selText = mActionText->selectedText();
160 if ( selText.startsWith( QLatin1String(
"[%" ) ) && selText.endsWith( QLatin1String(
"%]" ) ) )
161 selText = selText.mid( 2, selText.size() - 4 );
163 mActionText->insertText(
"[%" + mFieldExpression->currentField() +
"%]" );
166void QgsAttributeActionPropertiesDialog::chooseIcon()
168 const QList<QByteArray> list = QImageWriter::supportedImageFormats();
169 QStringList formatList;
170 const auto constList = list;
171 for (
const QByteArray &format : constList )
172 formatList << QStringLiteral(
"*.%1" ).arg( QString( format ) );
174 const QString filter = tr(
"Images( %1 ); All( *.* )" ).arg( formatList.join( QLatin1Char(
' ' ) ) );
175 const QString icon = QFileDialog::getOpenFileName(
this, tr(
"Choose Icon…" ), mActionIcon->text(), filter );
177 if ( !icon.isNull() )
179 mActionIcon->setText( icon );
180 mIconPreview->setPixmap( QPixmap( icon ) );
184void QgsAttributeActionPropertiesDialog::updateButtons()
186 if ( mActionName->text().isEmpty() || mActionText->text().isEmpty() )
188 mButtonBox->button( QDialogButtonBox::Ok )->setEnabled(
false );
192 mButtonBox->button( QDialogButtonBox::Ok )->setEnabled(
true );
196void QgsAttributeActionPropertiesDialog::init(
const QSet<QString> &actionScopes )
200 const auto constAvailableActionScopes = availableActionScopes;
203 QCheckBox *actionScopeCheckBox =
new QCheckBox( scope.title() );
205 actionScopeCheckBox->setChecked(
true );
206 const QStringList variables = scope.expressionContextScope().variableNames();
208 QString tooltip = scope.description();
209 if ( !variables.empty() )
211 tooltip += QLatin1String(
"<br><br>" );
212 tooltip += tr(
"Additional variables" );
213 tooltip += QLatin1String(
"<ul><li>" );
214 tooltip += variables.join( QLatin1String(
"</li><li>" ) );
215 tooltip += QLatin1String(
"</ul></li>" );
217 actionScopeCheckBox->setToolTip( tooltip );
218 actionScopeCheckBox->setProperty(
"ActionScopeName", scope.id() );
219 mActionScopeCheckBoxes.append( actionScopeCheckBox );
220 mActionScopesGroupBox->layout()->addWidget( actionScopeCheckBox );
227 mFieldExpression->setLayer( mLayer );
228 mFieldExpression->setGeomCalculator( myDa );
229 mFieldExpression->registerExpressionContextGenerator(
this );
231 connect( mBrowseButton, &QAbstractButton::clicked,
this, &QgsAttributeActionPropertiesDialog::browse );
232 connect( mInsertFieldOrExpression, &QAbstractButton::clicked,
this, &QgsAttributeActionPropertiesDialog::insertExpressionOrField );
233 connect( mActionName, &QLineEdit::textChanged,
this, &QgsAttributeActionPropertiesDialog::updateButtons );
234 connect( mActionText, &QsciScintilla::textChanged,
this, &QgsAttributeActionPropertiesDialog::updateButtons );
235 connect( mChooseIconButton, &QAbstractButton::clicked,
this, &QgsAttributeActionPropertiesDialog::chooseIcon );
237 connect( mButtonBox, &QDialogButtonBox::helpRequested,
this, &QgsAttributeActionPropertiesDialog::showHelp );
242void QgsAttributeActionPropertiesDialog::showHelp()
244 QgsHelp::openHelp( QStringLiteral(
"working_with_vector/vector_properties.html#actions-properties" ) );
247void 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...