From 7b85fd99610d284d75fa37f86e8a427ae998892f Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Wed, 5 Sep 2018 17:49:06 +1000 Subject: [PATCH] Allow setting expression format help string for QgsExpressionLineEdit --- .../qgsexpressionbuilderdialog.sip.in | 15 ++++++------- .../qgsexpressionlineedit.sip.in | 21 +++++++++++++++++++ src/gui/qgsexpressionbuilderdialog.h | 12 +++++------ src/gui/qgsexpressionlineedit.cpp | 11 ++++++++++ src/gui/qgsexpressionlineedit.h | 18 ++++++++++++++++ 5 files changed, 62 insertions(+), 15 deletions(-) diff --git a/python/gui/auto_generated/qgsexpressionbuilderdialog.sip.in b/python/gui/auto_generated/qgsexpressionbuilderdialog.sip.in index 664e7ed426d..13d62aca0ef 100644 --- a/python/gui/auto_generated/qgsexpressionbuilderdialog.sip.in +++ b/python/gui/auto_generated/qgsexpressionbuilderdialog.sip.in @@ -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. +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. -:param expected: The expected value format for the expression. - -.. note:: - - Only a UI hint and not used for expression validation. +.. seealso:: :py:func:`expectedOutputFormat` %End QgsExpressionContext expressionContext() const; diff --git a/python/gui/auto_generated/qgsexpressionlineedit.sip.in b/python/gui/auto_generated/qgsexpressionlineedit.sip.in index 1f5e8e7a936..86b6ae2feb3 100644 --- a/python/gui/auto_generated/qgsexpressionlineedit.sip.in +++ b/python/gui/auto_generated/qgsexpressionlineedit.sip.in @@ -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. diff --git a/src/gui/qgsexpressionbuilderdialog.h b/src/gui/qgsexpressionbuilderdialog.h index 3e55425775f..6eb5f3f47b2 100644 --- a/src/gui/qgsexpressionbuilderdialog.h +++ b/src/gui/qgsexpressionbuilderdialog.h @@ -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 ); diff --git a/src/gui/qgsexpressionlineedit.cpp b/src/gui/qgsexpressionlineedit.cpp index 1a747ed85f6..a92c75cf00a 100644 --- a/src/gui/qgsexpressionlineedit.cpp +++ b/src/gui/qgsexpressionlineedit.cpp @@ -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 ); diff --git a/src/gui/qgsexpressionlineedit.h b/src/gui/qgsexpressionlineedit.h index 35296dd8e94..ec438219bc5 100644 --- a/src/gui/qgsexpressionlineedit.h +++ b/src/gui/qgsexpressionlineedit.h @@ -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 );