Skip to content

Commit

Permalink
[FEATURE][needs-docs] Show data defined expected format in expression…
Browse files Browse the repository at this point in the history
… builder (#6839)
  • Loading branch information
NathanW2 committed Apr 23, 2018
1 parent 76b956a commit 53a384c
Show file tree
Hide file tree
Showing 8 changed files with 261 additions and 69 deletions.
20 changes: 20 additions & 0 deletions python/gui/qgsexpressionbuilderdialog.sip.in
Expand Up @@ -35,6 +35,26 @@ The builder widget that is used by the dialog

QString expressionText();

QString expectedOutputFormat();
%Docstring
The set expected format string. This is pure text format and no expression validation
is done against it.

:return: The expected value format.
%End

void setExpectedOutputFormat( const QString &expected );
%Docstring
The set expected format string. This is pure text format and no expression validation
is done against it.

:param expected: The expected value format for the expression.

.. note::

Only a UI hint and not used for expression validation.
%End

QgsExpressionContext expressionContext() const;
%Docstring
Returns the expression context for the dialog. The context is used for the expression
Expand Down
20 changes: 20 additions & 0 deletions python/gui/qgsexpressionbuilderwidget.sip.in
Expand Up @@ -153,6 +153,26 @@ Gets the expression string that has been set in the expression area.
Sets the expression string for the widget
%End

QString expectedOutputFormat();
%Docstring
The set expected format string. This is pure text format and no expression validation
is done against it.

:return: The expected value format.
%End

void setExpectedOutputFormat( const QString &expected );
%Docstring
The set expected format string. This is pure text format and no expression validation
is done against it.

:param expected: The expected value format for the expression.

.. note::

Only a UI hint and not used for expression validation.
%End

QgsExpressionContext expressionContext() const;
%Docstring
Returns the expression context for the widget. The context is used for the expression
Expand Down
10 changes: 10 additions & 0 deletions src/gui/qgsexpressionbuilderdialog.cpp
Expand Up @@ -52,6 +52,16 @@ QString QgsExpressionBuilderDialog::expressionText()
return builder->expressionText();
}

QString QgsExpressionBuilderDialog::expectedOutputFormat()
{
return builder->expectedOutputFormat();
}

void QgsExpressionBuilderDialog::setExpectedOutputFormat( const QString &expected )
{
builder->setExpectedOutputFormat( expected );
}

QgsExpressionContext QgsExpressionBuilderDialog::expressionContext() const
{
return builder->expressionContext();
Expand Down
15 changes: 15 additions & 0 deletions src/gui/qgsexpressionbuilderdialog.h
Expand Up @@ -47,6 +47,21 @@ class GUI_EXPORT QgsExpressionBuilderDialog : public QDialog, private Ui::QgsExp

QString expressionText();

/**
* The set expected format string. This is pure text format and no expression validation
* is done against it.
* \returns The expected value format.
*/
QString expectedOutputFormat();

/**
* The set expected format string. This is pure text format and no expression validation
* is done against it.
* \param expected The expected value format for the expression.
* \note Only a UI hint and not used for expression validation.
*/
void setExpectedOutputFormat( const QString &expected );

/**
* Returns the expression context for the dialog. The context is used for the expression
* preview result and for populating the list of available functions and variables.
Expand Down
13 changes: 13 additions & 0 deletions src/gui/qgsexpressionbuilderwidget.cpp
Expand Up @@ -143,6 +143,8 @@ QgsExpressionBuilderWidget::QgsExpressionBuilderWidget( QWidget *parent )
txtExpressionString->setIndicatorHoverStyle( QgsCodeEditor::DotsIndicator, FUNCTION_MARKER_ID );

connect( txtExpressionString, &QgsCodeEditorSQL::indicatorClicked, this, &QgsExpressionBuilderWidget::indicatorClicked );

setExpectedOutputFormat( QString() );
}


Expand Down Expand Up @@ -597,6 +599,17 @@ void QgsExpressionBuilderWidget::setExpressionText( const QString &expression )
txtExpressionString->setText( expression );
}

QString QgsExpressionBuilderWidget::expectedOutputFormat()
{
return lblExpected->text();
}

void QgsExpressionBuilderWidget::setExpectedOutputFormat( const QString &expected )
{
lblExpected->setText( expected );
mExpectedOutputFrame->setVisible( !expected.isNull() );
}

void QgsExpressionBuilderWidget::setExpressionContext( const QgsExpressionContext &context )
{
mExpressionContext = context;
Expand Down
15 changes: 15 additions & 0 deletions src/gui/qgsexpressionbuilderwidget.h
Expand Up @@ -173,6 +173,21 @@ class GUI_EXPORT QgsExpressionBuilderWidget : public QWidget, private Ui::QgsExp
//! Sets the expression string for the widget
void setExpressionText( const QString &expression );

/**
* The set expected format string. This is pure text format and no expression validation
* is done against it.
* \returns The expected value format.
*/
QString expectedOutputFormat();

/**
* The set expected format string. This is pure text format and no expression validation
* is done against it.
* \param expected The expected value format for the expression.
* \note Only a UI hint and not used for expression validation.
*/
void setExpectedOutputFormat( const QString &expected );

/**
* Returns the expression context for the widget. The context is used for the expression
* preview result and for populating the list of available functions and variables.
Expand Down
1 change: 1 addition & 0 deletions src/gui/qgspropertyoverridebutton.cpp
Expand Up @@ -596,6 +596,7 @@ void QgsPropertyOverrideButton::showExpressionDialog()
: mProperty.asExpression();

QgsExpressionBuilderDialog d( const_cast<QgsVectorLayer *>( mVectorLayer ), currentExpression, this, QStringLiteral( "generic" ), context );
d.setExpectedOutputFormat( mInputDescription );
if ( d.exec() == QDialog::Accepted )
{
mExpressionString = d.expressionText().trimmed();
Expand Down

0 comments on commit 53a384c

Please sign in to comment.