Skip to content

Commit 53a384c

Browse files
authored
[FEATURE][needs-docs] Show data defined expected format in expression builder (#6839)
1 parent 76b956a commit 53a384c

8 files changed

+261
-69
lines changed

python/gui/qgsexpressionbuilderdialog.sip.in

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,26 @@ The builder widget that is used by the dialog
3535

3636
QString expressionText();
3737

38+
QString expectedOutputFormat();
39+
%Docstring
40+
The set expected format string. This is pure text format and no expression validation
41+
is done against it.
42+
43+
:return: The expected value format.
44+
%End
45+
46+
void setExpectedOutputFormat( const QString &expected );
47+
%Docstring
48+
The set expected format string. This is pure text format and no expression validation
49+
is done against it.
50+
51+
:param expected: The expected value format for the expression.
52+
53+
.. note::
54+
55+
Only a UI hint and not used for expression validation.
56+
%End
57+
3858
QgsExpressionContext expressionContext() const;
3959
%Docstring
4060
Returns the expression context for the dialog. The context is used for the expression

python/gui/qgsexpressionbuilderwidget.sip.in

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,26 @@ Gets the expression string that has been set in the expression area.
153153
Sets the expression string for the widget
154154
%End
155155

156+
QString expectedOutputFormat();
157+
%Docstring
158+
The set expected format string. This is pure text format and no expression validation
159+
is done against it.
160+
161+
:return: The expected value format.
162+
%End
163+
164+
void setExpectedOutputFormat( const QString &expected );
165+
%Docstring
166+
The set expected format string. This is pure text format and no expression validation
167+
is done against it.
168+
169+
:param expected: The expected value format for the expression.
170+
171+
.. note::
172+
173+
Only a UI hint and not used for expression validation.
174+
%End
175+
156176
QgsExpressionContext expressionContext() const;
157177
%Docstring
158178
Returns the expression context for the widget. The context is used for the expression

src/gui/qgsexpressionbuilderdialog.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,16 @@ QString QgsExpressionBuilderDialog::expressionText()
5252
return builder->expressionText();
5353
}
5454

55+
QString QgsExpressionBuilderDialog::expectedOutputFormat()
56+
{
57+
return builder->expectedOutputFormat();
58+
}
59+
60+
void QgsExpressionBuilderDialog::setExpectedOutputFormat( const QString &expected )
61+
{
62+
builder->setExpectedOutputFormat( expected );
63+
}
64+
5565
QgsExpressionContext QgsExpressionBuilderDialog::expressionContext() const
5666
{
5767
return builder->expressionContext();

src/gui/qgsexpressionbuilderdialog.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,21 @@ class GUI_EXPORT QgsExpressionBuilderDialog : public QDialog, private Ui::QgsExp
4747

4848
QString expressionText();
4949

50+
/**
51+
* The set expected format string. This is pure text format and no expression validation
52+
* is done against it.
53+
* \returns The expected value format.
54+
*/
55+
QString expectedOutputFormat();
56+
57+
/**
58+
* The set expected format string. This is pure text format and no expression validation
59+
* is done against it.
60+
* \param expected The expected value format for the expression.
61+
* \note Only a UI hint and not used for expression validation.
62+
*/
63+
void setExpectedOutputFormat( const QString &expected );
64+
5065
/**
5166
* Returns the expression context for the dialog. The context is used for the expression
5267
* preview result and for populating the list of available functions and variables.

src/gui/qgsexpressionbuilderwidget.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ QgsExpressionBuilderWidget::QgsExpressionBuilderWidget( QWidget *parent )
143143
txtExpressionString->setIndicatorHoverStyle( QgsCodeEditor::DotsIndicator, FUNCTION_MARKER_ID );
144144

145145
connect( txtExpressionString, &QgsCodeEditorSQL::indicatorClicked, this, &QgsExpressionBuilderWidget::indicatorClicked );
146+
147+
setExpectedOutputFormat( QString() );
146148
}
147149

148150

@@ -597,6 +599,17 @@ void QgsExpressionBuilderWidget::setExpressionText( const QString &expression )
597599
txtExpressionString->setText( expression );
598600
}
599601

602+
QString QgsExpressionBuilderWidget::expectedOutputFormat()
603+
{
604+
return lblExpected->text();
605+
}
606+
607+
void QgsExpressionBuilderWidget::setExpectedOutputFormat( const QString &expected )
608+
{
609+
lblExpected->setText( expected );
610+
mExpectedOutputFrame->setVisible( !expected.isNull() );
611+
}
612+
600613
void QgsExpressionBuilderWidget::setExpressionContext( const QgsExpressionContext &context )
601614
{
602615
mExpressionContext = context;

src/gui/qgsexpressionbuilderwidget.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,21 @@ class GUI_EXPORT QgsExpressionBuilderWidget : public QWidget, private Ui::QgsExp
173173
//! Sets the expression string for the widget
174174
void setExpressionText( const QString &expression );
175175

176+
/**
177+
* The set expected format string. This is pure text format and no expression validation
178+
* is done against it.
179+
* \returns The expected value format.
180+
*/
181+
QString expectedOutputFormat();
182+
183+
/**
184+
* The set expected format string. This is pure text format and no expression validation
185+
* is done against it.
186+
* \param expected The expected value format for the expression.
187+
* \note Only a UI hint and not used for expression validation.
188+
*/
189+
void setExpectedOutputFormat( const QString &expected );
190+
176191
/**
177192
* Returns the expression context for the widget. The context is used for the expression
178193
* preview result and for populating the list of available functions and variables.

src/gui/qgspropertyoverridebutton.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,7 @@ void QgsPropertyOverrideButton::showExpressionDialog()
596596
: mProperty.asExpression();
597597

598598
QgsExpressionBuilderDialog d( const_cast<QgsVectorLayer *>( mVectorLayer ), currentExpression, this, QStringLiteral( "generic" ), context );
599+
d.setExpectedOutputFormat( mInputDescription );
599600
if ( d.exec() == QDialog::Accepted )
600601
{
601602
mExpressionString = d.expressionText().trimmed();

0 commit comments

Comments
 (0)