Skip to content

Commit

Permalink
Show nicer tooltips for numeric processing parameters
Browse files Browse the repository at this point in the history
With min/max and default values (when set)
  • Loading branch information
nyalldawson committed Dec 1, 2017
1 parent 8303b94 commit 6b56565
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
9 changes: 9 additions & 0 deletions python/core/processing/qgsprocessingparameters.sip
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,13 @@ class QgsProcessingParameterDefinition
:rtype: QgsProcessingProvider
%End

virtual QString toolTip() const;
%Docstring
Returns a formatted tooltip for use with the parameter, which gives helpful information
like parameter description, ID, and extra content like default values (depending on parameter type).
:rtype: str
%End

protected:


Expand Down Expand Up @@ -1141,6 +1148,8 @@ class QgsProcessingParameterNumber : QgsProcessingParameterDefinition

virtual QString valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const;

virtual QString toolTip() const;


double minimum() const;
%Docstring
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/processing/gui/ParametersPanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def initWidgets(self):
widget = QWidget()
widget.setLayout(layout)

widget.setToolTip(self.formatParameterTooltip(param))
widget.setToolTip(param.toolTip())

if type(widget) is QCheckBox:
# checkbox widget - so description is embedded in widget rather than a separate
Expand Down Expand Up @@ -175,7 +175,7 @@ def initWidgets(self):
self.layoutMain.insertWidget(self.layoutMain.count() - 1, check)
self.checkBoxes[output.name()] = check

widget.setToolTip(self.formatParameterTooltip(param))
widget.setToolTip(param.toolTip())
self.outputWidgets[output.name()] = widget

for wrapper in list(self.wrappers.values()):
Expand Down
23 changes: 23 additions & 0 deletions src/core/processing/qgsprocessingparameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1249,6 +1249,13 @@ QgsProcessingProvider *QgsProcessingParameterDefinition::provider() const
return mAlgorithm ? mAlgorithm->provider() : nullptr;
}

QString QgsProcessingParameterDefinition::toolTip() const
{
return QStringLiteral( "<p><b>%1</b></p><p>%2</p>" ).arg(
description(),
QObject::tr( "Python identifier: ‘%1’" ).arg( QStringLiteral( "<i>%1</i>" ).arg( name() ) ) );
}

QgsProcessingParameterBoolean::QgsProcessingParameterBoolean( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
: QgsProcessingParameterDefinition( name, description, defaultValue, optional )
{}
Expand Down Expand Up @@ -1992,6 +1999,22 @@ QString QgsProcessingParameterNumber::valueAsPythonString( const QVariant &value
return value.toString();
}

QString QgsProcessingParameterNumber::toolTip() const
{
QString text = QgsProcessingParameterDefinition::toolTip();
QStringList parts;
if ( mMin > -DBL_MAX )
parts << QObject::tr( "Minimum value: %1" ).arg( mMin );
if ( mMax < DBL_MAX )
parts << QObject::tr( "Maximum value: %1" ).arg( mMax );
if ( mDefault.isValid() )
parts << QObject::tr( "Default value: %1" ).arg( mDataType == Integer ? mDefault.toInt() : mDefault.toDouble() );
QString extra = parts.join( QStringLiteral( "<br />" ) );
if ( !extra.isEmpty() )
text += QStringLiteral( "<p>%1</p>" ).arg( extra );
return text;
}

double QgsProcessingParameterNumber::minimum() const
{
return mMin;
Expand Down
7 changes: 7 additions & 0 deletions src/core/processing/qgsprocessingparameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,12 @@ class CORE_EXPORT QgsProcessingParameterDefinition
*/
QgsProcessingProvider *provider() const;

/**
* Returns a formatted tooltip for use with the parameter, which gives helpful information
* like parameter description, ID, and extra content like default values (depending on parameter type).
*/
virtual QString toolTip() const;

protected:

//! Parameter name
Expand Down Expand Up @@ -1105,6 +1111,7 @@ class CORE_EXPORT QgsProcessingParameterNumber : public QgsProcessingParameterDe
QString type() const override { return typeName(); }
bool checkValueIsAcceptable( const QVariant &input, QgsProcessingContext *context = nullptr ) const override;
QString valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const override;
QString toolTip() const override;

/**
* Returns the minimum value acceptable by the parameter.
Expand Down

0 comments on commit 6b56565

Please sign in to comment.