diff --git a/python/gui/auto_generated/qgsexpressionbuilderwidget.sip.in b/python/gui/auto_generated/qgsexpressionbuilderwidget.sip.in index 3e1d5052dce1..490668d6c9cb 100644 --- a/python/gui/auto_generated/qgsexpressionbuilderwidget.sip.in +++ b/python/gui/auto_generated/qgsexpressionbuilderwidget.sip.in @@ -379,6 +379,14 @@ Removes the selected expression from the stored user expressions, the selected expression must be a user stored expression. .. versionadded:: 3.12 +%End + + void editSelectedUserExpression(); +%Docstring +Edits the selected expression from the stored user expressions, +the selected expression must be a user stored expression. + +.. versionadded:: 3.14 %End const QList findExpressions( const QString &label ); diff --git a/src/gui/qgsexpressionbuilderwidget.cpp b/src/gui/qgsexpressionbuilderwidget.cpp index c7163f344e1b..5c546dba340f 100644 --- a/src/gui/qgsexpressionbuilderwidget.cpp +++ b/src/gui/qgsexpressionbuilderwidget.cpp @@ -61,6 +61,7 @@ QgsExpressionBuilderWidget::QgsExpressionBuilderWidget( QWidget *parent ) connect( lblPreview, &QLabel::linkActivated, this, &QgsExpressionBuilderWidget::lblPreview_linkActivated ); connect( mValuesListView, &QListView::doubleClicked, this, &QgsExpressionBuilderWidget::mValuesListView_doubleClicked ); connect( btnSaveExpression, &QPushButton::pressed, this, &QgsExpressionBuilderWidget::storeCurrentUserExpression ); + connect( btnEditExpression, &QPushButton::pressed, this, &QgsExpressionBuilderWidget::editSelectedUserExpression ); connect( btnRemoveExpression, &QPushButton::pressed, this, &QgsExpressionBuilderWidget::removeSelectedUserExpression ); connect( btnClearEditor, &QPushButton::pressed, txtExpressionString, &QgsCodeEditorExpression::clear ); @@ -83,6 +84,7 @@ QgsExpressionBuilderWidget::QgsExpressionBuilderWidget( QWidget *parent ) // Set icons for tool buttons btnSaveExpression->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "mActionFileSave.svg" ) ) ); + btnEditExpression->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "mActionToggleEditing.svg" ) ) ); btnRemoveExpression->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "mActionDeleteSelected.svg" ) ) ); btnClearEditor->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "mActionFileNew.svg" ) ) ); @@ -267,8 +269,10 @@ void QgsExpressionBuilderWidget::currentChanged( const QModelIndex &index, const QString help = loadFunctionHelp( item ); txtHelpText->setText( help ); - btnRemoveExpression->setEnabled( item->parent() && - item->parent()->text() == mUserExpressionsGroupName ); + bool isUserExpression = item->parent() && item->parent()->text() == mUserExpressionsGroupName; + + btnRemoveExpression->setEnabled( isUserExpression ); + btnEditExpression->setEnabled( isUserExpression ); } @@ -1349,6 +1353,28 @@ void QgsExpressionBuilderWidget::storeCurrentUserExpression() } } +void QgsExpressionBuilderWidget::editSelectedUserExpression() +{ + // Get the item + QModelIndex idx = mProxyModel->mapToSource( expressionTree->currentIndex() ); + QgsExpressionItem *item = dynamic_cast( mModel->itemFromIndex( idx ) ); + if ( !item ) + return; + + // Don't handle remove if we are on a header node or the parent + // is not the user group + if ( item->getItemType() == QgsExpressionItem::Header || + ( item->parent() && item->parent()->text() != mUserExpressionsGroupName ) ) + return; + + QgsExpressionStoreDialog dlg { item->text(), item->getExpressionText(), item->getHelpText(), QStringList() }; + + if ( dlg.exec() == QDialog::DialogCode::Accepted ) + { + saveToUserExpressions( dlg.label(), dlg.expression(), dlg.helpText() ); + } +} + void QgsExpressionBuilderWidget::removeSelectedUserExpression() { diff --git a/src/gui/qgsexpressionbuilderwidget.h b/src/gui/qgsexpressionbuilderwidget.h index 6789d41c5468..bc4879055cec 100644 --- a/src/gui/qgsexpressionbuilderwidget.h +++ b/src/gui/qgsexpressionbuilderwidget.h @@ -380,6 +380,13 @@ class GUI_EXPORT QgsExpressionBuilderWidget : public QWidget, private Ui::QgsExp */ void removeSelectedUserExpression( ); + /** + * Edits the selected expression from the stored user expressions, + * the selected expression must be a user stored expression. + * \since QGIS 3.14 + */ + void editSelectedUserExpression(); + /** * Returns the list of expression items matching a \a label. * \since QGIS 3.12 diff --git a/src/ui/qgsexpressionbuilder.ui b/src/ui/qgsexpressionbuilder.ui index ddd0c09b744d..99b3fae26500 100644 --- a/src/ui/qgsexpressionbuilder.ui +++ b/src/ui/qgsexpressionbuilder.ui @@ -356,6 +356,19 @@ + + + + false + + + Edit selected expression from user expressions + + + Edit + + +