Skip to content

Commit

Permalink
Allow setting expression format help string for QgsExpressionLineEdit
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Sep 6, 2018
1 parent 06d37fc commit 7b85fd9
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 15 deletions.
15 changes: 6 additions & 9 deletions python/gui/auto_generated/qgsexpressionbuilderdialog.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,19 @@ The builder widget that is used by the dialog

QString expectedOutputFormat();
%Docstring
The set expected format string. This is pure text format and no expression validation
Returns the expected format string, which is shown in the dialog.
This is purely a text format and no expression validation
is done against it.

:return: The expected value format.
.. seealso:: :py:func:`setExpectedOutputFormat`
%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::
Set the ``expected`` format string, which is shown in the dialog.
This is purely a text format and no expression validation is done against it.

Only a UI hint and not used for expression validation.
.. seealso:: :py:func:`expectedOutputFormat`
%End

QgsExpressionContext expressionContext() const;
Expand Down
21 changes: 21 additions & 0 deletions python/gui/auto_generated/qgsexpressionlineedit.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,27 @@ Sets whether the widget should show a multiline text editor.
to show single line editor (the default).
%End

QString expectedOutputFormat() const;
%Docstring
Returns the expected format string, which is shown in the expression builder dialog for the widget.
This is purely a text format and no expression validation
is done against it.

.. seealso:: :py:func:`setExpectedOutputFormat`

.. versionadded:: 3.4
%End

void setExpectedOutputFormat( const QString &expected );
%Docstring
Set the ``expected`` format string, which is shown in the expression builder dialog for the widget.
This is purely a text format and no expression validation is done against it.

.. seealso:: :py:func:`expectedOutputFormat`

.. versionadded:: 3.4
%End

void setGeomCalculator( const QgsDistanceArea &distanceArea );
%Docstring
Set the geometry calculator used in the expression dialog.
Expand Down
12 changes: 6 additions & 6 deletions src/gui/qgsexpressionbuilderdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,17 @@ 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
* Returns the expected format string, which is shown in the dialog.
* This is purely a text format and no expression validation
* is done against it.
* \returns The expected value format.
* \see setExpectedOutputFormat()
*/
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.
* Set the \a expected format string, which is shown in the dialog.
* This is purely a text format and no expression validation is done against it.
* \see expectedOutputFormat()
*/
void setExpectedOutputFormat( const QString &expected );

Expand Down
11 changes: 11 additions & 0 deletions src/gui/qgsexpressionlineedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,16 @@ void QgsExpressionLineEdit::setMultiLine( bool multiLine )
}
}

QString QgsExpressionLineEdit::expectedOutputFormat() const
{
return mExpectedOutputFormat;
}

void QgsExpressionLineEdit::setExpectedOutputFormat( const QString &expected )
{
mExpectedOutputFormat = expected;
}

void QgsExpressionLineEdit::setGeomCalculator( const QgsDistanceArea &da )
{
mDa.reset( new QgsDistanceArea( da ) );
Expand Down Expand Up @@ -151,6 +161,7 @@ void QgsExpressionLineEdit::editExpression()
QgsExpressionContext context = mExpressionContextGenerator ? mExpressionContextGenerator->createExpressionContext() : mExpressionContext;

QgsExpressionBuilderDialog dlg( mLayer, currentExpression, this, QStringLiteral( "generic" ), context );
dlg.setExpectedOutputFormat( mExpectedOutputFormat );
if ( mDa )
{
dlg.setGeomCalculator( *mDa );
Expand Down
18 changes: 18 additions & 0 deletions src/gui/qgsexpressionlineedit.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,23 @@ class GUI_EXPORT QgsExpressionLineEdit : public QWidget
*/
void setMultiLine( bool multiLine );

/**
* Returns the expected format string, which is shown in the expression builder dialog for the widget.
* This is purely a text format and no expression validation
* is done against it.
* \see setExpectedOutputFormat()
* \since QGIS 3.4
*/
QString expectedOutputFormat() const;

/**
* Set the \a expected format string, which is shown in the expression builder dialog for the widget.
* This is purely a text format and no expression validation is done against it.
* \see expectedOutputFormat()
* \since QGIS 3.4
*/
void setExpectedOutputFormat( const QString &expected );

/**
* Set the geometry calculator used in the expression dialog.
* \param distanceArea calculator
Expand Down Expand Up @@ -160,6 +177,7 @@ class GUI_EXPORT QgsExpressionLineEdit : public QWidget
QgsExpressionContext mExpressionContext;
const QgsExpressionContextGenerator *mExpressionContextGenerator = nullptr;
QgsVectorLayer *mLayer = nullptr;
QString mExpectedOutputFormat;

bool isExpressionValid( const QString &expressionStr );

Expand Down

0 comments on commit 7b85fd9

Please sign in to comment.