Skip to content
Permalink
Browse files

Add the ability to edit user expressions

  • Loading branch information
suricactus committed Mar 9, 2020
1 parent 465f8a5 commit e2725a9ec503ab57172407c2db7881a14ae65abd
@@ -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<QgsExpressionItem *> findExpressions( const QString &label );
@@ -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<QgsExpressionItem *>( 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()
{

@@ -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
@@ -356,6 +356,19 @@
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="btnEditExpression">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Edit selected expression from user expressions</string>
</property>
<property name="text">
<string>Edit</string>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="btnRemoveExpression">
<property name="enabled">

0 comments on commit e2725a9

Please sign in to comment.
You can’t perform that action at this time.