Integrate expression builder in configuration

This commit is contained in:
signedav 2024-08-21 08:08:38 +02:00
parent 0184eb1c77
commit 66fac268c8
4 changed files with 40 additions and 0 deletions

View File

@ -191,6 +191,10 @@ Update the configuration widget to represent the given configuration.
:param config: The configuration which should be represented by this widget
%End
void mEditExpression_clicked();
%Docstring
Opens an expression dialog and sets its value as filter expression for the linking dialog
%End
};

View File

@ -191,6 +191,10 @@ Update the configuration widget to represent the given configuration.
:param config: The configuration which should be represented by this widget
%End
void mEditExpression_clicked();
%Docstring
Opens an expression dialog and sets its value as filter expression for the linking dialog
%End
};

View File

@ -29,6 +29,8 @@
#include "qgsmessagebar.h"
#include "qgsmessagebaritem.h"
#include "qgsactionmenu.h"
#include "qgsexpressionbuilderdialog.h"
#include "qgsexpressioncontextutils.h"
#include <QHBoxLayout>
#include <QLabel>
@ -950,6 +952,32 @@ QgsRelationEditorConfigWidget::QgsRelationEditorConfigWidget( const QgsRelation
: QgsAbstractRelationEditorConfigWidget( relation, parent )
{
setupUi( this );
connect( mEditExpression, &QAbstractButton::clicked, this, &QgsRelationEditorConfigWidget::mEditExpression_clicked );
}
void QgsRelationEditorConfigWidget::mEditExpression_clicked()
{
QgsVectorLayer *vl = nullptr;
if ( nmRelation().isValid() )
{
vl = nmRelation().referencedLayer();
}
else
{
vl = relation().referencingLayer();
}
// Show expression builder
QgsExpressionContext context( QgsExpressionContextUtils::globalProjectLayerScopes( vl ) );
QgsExpressionBuilderDialog dlg( vl, mFilterExpression->toPlainText(), this, QStringLiteral( "generic" ), context );
dlg.setWindowTitle( tr( "Edit Filter Expression of Target Layer" ) );
if ( dlg.exec() == QDialog::Accepted )
{
mFilterExpression->setPlainText( dlg.expressionBuilder()->expressionText() );
}
}
QVariantMap QgsRelationEditorConfigWidget::config()

View File

@ -305,6 +305,10 @@ class GUI_EXPORT QgsRelationEditorConfigWidget : public QgsAbstractRelationEdito
*/
void setConfig( const QVariantMap &config ) override;
/**
* Opens an expression dialog and sets its value as filter expression for the linking dialog
*/
void mEditExpression_clicked();
};