mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-06 00:07:29 -04:00
Show nicer tooltips for numeric processing parameters
With min/max and default values (when set)
This commit is contained in:
parent
8303b94685
commit
6b56565f89
@ -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:
|
||||
|
||||
|
||||
@ -1141,6 +1148,8 @@ class QgsProcessingParameterNumber : QgsProcessingParameterDefinition
|
||||
|
||||
virtual QString valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const;
|
||||
|
||||
virtual QString toolTip() const;
|
||||
|
||||
|
||||
double minimum() const;
|
||||
%Docstring
|
||||
|
@ -137,7 +137,7 @@ class ParametersPanel(BASE, WIDGET):
|
||||
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
|
||||
@ -175,7 +175,7 @@ class ParametersPanel(BASE, WIDGET):
|
||||
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()):
|
||||
|
@ -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 )
|
||||
{}
|
||||
@ -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;
|
||||
|
@ -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
|
||||
@ -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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user