Skip to content
Permalink
Browse files

Allow setting expression format help string for QgsExpressionLineEdit

  • Loading branch information
nyalldawson committed Sep 6, 2018
1 parent 06d37fc commit 7b85fd99610d284d75fa37f86e8a427ae998892f
@@ -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;
@@ -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.
@@ -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 );

@@ -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 ) );
@@ -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 );
@@ -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
@@ -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 );

0 comments on commit 7b85fd9

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