Skip to content

Commit

Permalink
Show helper text in expression builder for CRS values in modeler
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Sep 6, 2018
1 parent 7b85fd9 commit f83b3ec
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ various available values for QgsProcessingParameterDefinition.type() (for

The ``compatibleDataTypes`` list corresponds to the compatible data types
from QgsProcessing.SourceType.
%End

void setExpressionHelpText( const QString &text );
%Docstring
Set the expected expression format ``text``, which is shown in the expression builder dialog for the widget
when in the "pre-calculated" expression mode. This is purely a text format and no expression validation is made
against it.
%End

const QgsProcessingParameterDefinition *parameterDefinition() const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,17 @@ values which can be used as values for the parameter.
.. seealso:: :py:func:`compatibleParameterTypes`

.. seealso:: :py:func:`compatibleOutputTypes`
%End

virtual QString modelerExpressionFormatString() const;
%Docstring
Returns the expected expression format string for expression results for the parameter
within model child algorithms.

This is shown in modeler widget wrappers when using the "pre-calculated" expression mode,
and should give helpful text to users to indicate the expected results from the expression.

This is purely a text format and no expression validation is made against it.
%End

};
Expand Down
4 changes: 4 additions & 0 deletions src/gui/processing/qgsprocessingmodelerparameterwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,5 +293,9 @@ void QgsProcessingModelerParameterWidget::populateSources( const QStringList &co
}

}
}

void QgsProcessingModelerParameterWidget::setExpressionHelpText( const QString &text )
{
mExpressionWidget->setExpectedOutputFormat( text );
}
7 changes: 7 additions & 0 deletions src/gui/processing/qgsprocessingmodelerparameterwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ class GUI_EXPORT QgsProcessingModelerParameterWidget : public QWidget
const QStringList &compatibleOutputTypes,
const QList< int > &compatibleDataTypes );

/**
* Set the expected expression format \a text, which is shown in the expression builder dialog for the widget
* when in the "pre-calculated" expression mode. This is purely a text format and no expression validation is made
* against it.
*/
void setExpressionHelpText( const QString &text );

/**
* Returns the parameter definition associated with this wrapper.
*/
Expand Down
6 changes: 6 additions & 0 deletions src/gui/processing/qgsprocessingwidgetwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,5 +211,11 @@ QgsProcessingModelerParameterWidget *QgsProcessingParameterWidgetFactoryInterfac
{
std::unique_ptr< QgsProcessingModelerParameterWidget > widget = qgis::make_unique< QgsProcessingModelerParameterWidget >( model, childId, parameter, context );
widget->populateSources( compatibleParameterTypes(), compatibleOutputTypes(), compatibleDataTypes() );
widget->setExpressionHelpText( modelerExpressionFormatString() );
return widget.release();
}

QString QgsProcessingParameterWidgetFactoryInterface::modelerExpressionFormatString() const
{
return QString();
}
11 changes: 11 additions & 0 deletions src/gui/processing/qgsprocessingwidgetwrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,17 @@ class GUI_EXPORT QgsProcessingParameterWidgetFactoryInterface
*/
virtual QList< int > compatibleDataTypes() const = 0;

/**
* Returns the expected expression format string for expression results for the parameter
* within model child algorithms.
*
* This is shown in modeler widget wrappers when using the "pre-calculated" expression mode,
* and should give helpful text to users to indicate the expected results from the expression.
* This is purely a text format and no expression validation is made against it.
*/
virtual QString modelerExpressionFormatString() const;

};

#endif // QGSPROCESSINGWIDGETWRAPPER_H
5 changes: 5 additions & 0 deletions src/gui/processing/qgsprocessingwidgetwrapperimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,11 @@ QList<int> QgsProcessingCrsWidgetWrapper::compatibleDataTypes() const
return QList< int >();
}

QString QgsProcessingCrsWidgetWrapper::modelerExpressionFormatString() const
{
return tr( "string as EPSG code, WKT or PROJ format, or a string identifying a map layer" );
}

QString QgsProcessingCrsWidgetWrapper::parameterType() const
{
return QgsProcessingParameterCrs::typeName();
Expand Down
3 changes: 1 addition & 2 deletions src/gui/processing/qgsprocessingwidgetwrapperimpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,9 @@ class GUI_EXPORT QgsProcessingCrsWidgetWrapper : public QgsAbstractProcessingPar
QVariant widgetValue() const override;

QStringList compatibleParameterTypes() const override;

QStringList compatibleOutputTypes() const override;

QList< int > compatibleDataTypes() const override;
QString modelerExpressionFormatString() const override;

private:

Expand Down

0 comments on commit f83b3ec

Please sign in to comment.