From 53a384cba74576a400ded48d67c6008f397bbf4d Mon Sep 17 00:00:00 2001 From: Nathan Woodrow Date: Mon, 23 Apr 2018 13:32:51 +1000 Subject: [PATCH] [FEATURE][needs-docs] Show data defined expected format in expression builder (#6839) --- python/gui/qgsexpressionbuilderdialog.sip.in | 20 ++ python/gui/qgsexpressionbuilderwidget.sip.in | 20 ++ src/gui/qgsexpressionbuilderdialog.cpp | 10 + src/gui/qgsexpressionbuilderdialog.h | 15 ++ src/gui/qgsexpressionbuilderwidget.cpp | 13 + src/gui/qgsexpressionbuilderwidget.h | 15 ++ src/gui/qgspropertyoverridebutton.cpp | 1 + src/ui/qgsexpressionbuilder.ui | 236 +++++++++++++------ 8 files changed, 261 insertions(+), 69 deletions(-) diff --git a/python/gui/qgsexpressionbuilderdialog.sip.in b/python/gui/qgsexpressionbuilderdialog.sip.in index 8ae5c5b23dc6..664e7ed426d6 100644 --- a/python/gui/qgsexpressionbuilderdialog.sip.in +++ b/python/gui/qgsexpressionbuilderdialog.sip.in @@ -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 diff --git a/python/gui/qgsexpressionbuilderwidget.sip.in b/python/gui/qgsexpressionbuilderwidget.sip.in index d2d14e971dd6..e8f360c6d958 100644 --- a/python/gui/qgsexpressionbuilderwidget.sip.in +++ b/python/gui/qgsexpressionbuilderwidget.sip.in @@ -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 diff --git a/src/gui/qgsexpressionbuilderdialog.cpp b/src/gui/qgsexpressionbuilderdialog.cpp index b11344c1f5b4..7e5fab417655 100644 --- a/src/gui/qgsexpressionbuilderdialog.cpp +++ b/src/gui/qgsexpressionbuilderdialog.cpp @@ -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(); diff --git a/src/gui/qgsexpressionbuilderdialog.h b/src/gui/qgsexpressionbuilderdialog.h index 380c0509ee91..3e55425775fd 100644 --- a/src/gui/qgsexpressionbuilderdialog.h +++ b/src/gui/qgsexpressionbuilderdialog.h @@ -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. diff --git a/src/gui/qgsexpressionbuilderwidget.cpp b/src/gui/qgsexpressionbuilderwidget.cpp index a2e4586e58c5..3f1b32e2b03f 100644 --- a/src/gui/qgsexpressionbuilderwidget.cpp +++ b/src/gui/qgsexpressionbuilderwidget.cpp @@ -143,6 +143,8 @@ QgsExpressionBuilderWidget::QgsExpressionBuilderWidget( QWidget *parent ) txtExpressionString->setIndicatorHoverStyle( QgsCodeEditor::DotsIndicator, FUNCTION_MARKER_ID ); connect( txtExpressionString, &QgsCodeEditorSQL::indicatorClicked, this, &QgsExpressionBuilderWidget::indicatorClicked ); + + setExpectedOutputFormat( QString() ); } @@ -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; diff --git a/src/gui/qgsexpressionbuilderwidget.h b/src/gui/qgsexpressionbuilderwidget.h index 8592f9de1361..90972ca6ac2e 100644 --- a/src/gui/qgsexpressionbuilderwidget.h +++ b/src/gui/qgsexpressionbuilderwidget.h @@ -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. diff --git a/src/gui/qgspropertyoverridebutton.cpp b/src/gui/qgspropertyoverridebutton.cpp index 8ceb642827a2..807e492760d3 100644 --- a/src/gui/qgspropertyoverridebutton.cpp +++ b/src/gui/qgspropertyoverridebutton.cpp @@ -596,6 +596,7 @@ void QgsPropertyOverrideButton::showExpressionDialog() : mProperty.asExpression(); QgsExpressionBuilderDialog d( const_cast( mVectorLayer ), currentExpression, this, QStringLiteral( "generic" ), context ); + d.setExpectedOutputFormat( mInputDescription ); if ( d.exec() == QDialog::Accepted ) { mExpressionString = d.expressionText().trimmed(); diff --git a/src/ui/qgsexpressionbuilder.ui b/src/ui/qgsexpressionbuilder.ui index 2d7d983abdf7..2d122a333ce1 100644 --- a/src/ui/qgsexpressionbuilder.ui +++ b/src/ui/qgsexpressionbuilder.ui @@ -7,7 +7,7 @@ 0 0 989 - 520 + 519 @@ -99,23 +99,8 @@ 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - + + @@ -287,59 +272,172 @@ - - - - - - - 0 - 0 - - - - Output preview is generated <br> using the first feature from the layer. - - - Output preview: - + + + + + + + QLayout::SetMinAndMaxSize + + + 0 + + + + + + 3 + + + QLayout::SetMinAndMaxSize + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + Output preview is generated <br> using the first feature from the layer. + + + Output preview: + + + + + + + + 0 + 0 + + + + Output preview is generated <br> using the first feature from the layer. + + + QFrame::NoFrame + + + QFrame::Sunken + + + 0 + + + 0 + + + 123232 + + + false + + + false + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse + + + + - - - - - 0 - 0 - - - - Output preview is generated <br> using the first feature from the layer. - - - QFrame::NoFrame - - - QFrame::Sunken - - - 0 - - - 0 - - - - - - false - - - false - - - Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse - + + + + + 3 + + + QLayout::SetMinAndMaxSize + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + Output preview is generated <br> using the first feature from the layer. + + + Expected Format: + + + + + + + + 0 + 0 + + + + Output preview is generated <br> using the first feature from the layer. + + + QFrame::NoFrame + + + QFrame::Sunken + + + 0 + + + 0 + + + string [r,g,b,a] as int 0-255 or #RRGGBBAA as hex or color as color's name + + + Qt::RichText + + + false + + + true + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse + + + +