Skip to content
Permalink
Browse files

[processing] Fix modeler help/description generation, allow setting

of model short description text

Fixes #18767
  • Loading branch information
nyalldawson committed Sep 25, 2018
1 parent aa55de8 commit e2082a09358008b6ee8be09ebf24feb46ac6c705
@@ -45,7 +45,7 @@ Constructor for QgsProcessingModelAlgorithm.

virtual QString shortHelpString() const;

virtual QString helpUrl() const;
virtual QString shortDescription() const;

virtual Flags flags() const;

@@ -52,6 +52,7 @@ class HelpEditionDialog(BASE, WIDGET):
ALG_CREATOR = 'ALG_CREATOR'
ALG_HELP_CREATOR = 'ALG_HELP_CREATOR'
ALG_VERSION = 'ALG_VERSION'
SHORT_DESCRIPTION = 'SHORT_DESCRIPTION'

def __init__(self, alg):
super(HelpEditionDialog, self).__init__(None)
@@ -103,6 +104,8 @@ def getHtml(self):
def fillTree(self):
item = TreeDescriptionItem(self.tr('Algorithm description'), self.ALG_DESC)
self.tree.addTopLevelItem(item)
item = TreeDescriptionItem(self.tr('Short description'), self.SHORT_DESCRIPTION)
self.tree.addTopLevelItem(item)
parametersItem = TreeDescriptionItem(self.tr('Input parameters'), None)
self.tree.addTopLevelItem(parametersItem)
for param in self.alg.parameterDefinitions():
@@ -70,14 +70,15 @@ QString QgsProcessingModelAlgorithm::svgIconPath() const

QString QgsProcessingModelAlgorithm::shortHelpString() const
{
if ( mHelpContent.contains( QStringLiteral( "ALG_DESC" ) ) )
return mHelpContent.value( QStringLiteral( "ALG_DESC" ) ).toString();
return QString();
if ( mHelpContent.empty() )
return QString();

return QgsProcessingUtils::formatHelpMapAsHtml( mHelpContent, this );
}

QString QgsProcessingModelAlgorithm::helpUrl() const
QString QgsProcessingModelAlgorithm::shortDescription() const
{
return QgsProcessingUtils::formatHelpMapAsHtml( mHelpContent, this );
return mHelpContent.value( QStringLiteral( "SHORT_DESCRIPTION" ) ).toString();
}

QgsProcessingAlgorithm::Flags QgsProcessingModelAlgorithm::flags() const
@@ -51,7 +51,7 @@ class CORE_EXPORT QgsProcessingModelAlgorithm : public QgsProcessingAlgorithm
QIcon icon() const override;
QString svgIconPath() const override;
QString shortHelpString() const override;
QString helpUrl() const override;
QString shortDescription() const override;
Flags flags() const override;

bool canExecute( QString *errorMessage SIP_OUT = nullptr ) const override;
@@ -595,23 +595,33 @@ QString QgsProcessingUtils::formatHelpMapAsHtml( const QVariantMap &map, const Q

QString s = QObject::tr( "<html><body><h2>Algorithm description</h2>\n" );
s += QStringLiteral( "<p>" ) + getText( QStringLiteral( "ALG_DESC" ) ) + QStringLiteral( "</p>\n" );
s += QObject::tr( "<h2>Input parameters</h2>\n" );

QString inputs;
Q_FOREACH ( const QgsProcessingParameterDefinition *def, algorithm->parameterDefinitions() )
{
s += QStringLiteral( "<h3>" ) + def->description() + QStringLiteral( "</h3>\n" );
s += QStringLiteral( "<p>" ) + getText( def->name() ) + QStringLiteral( "</p>\n" );
inputs += QStringLiteral( "<h3>" ) + def->description() + QStringLiteral( "</h3>\n" );
inputs += QStringLiteral( "<p>" ) + getText( def->name() ) + QStringLiteral( "</p>\n" );
}
s += QObject::tr( "<h2>Outputs</h2>\n" );
if ( !inputs.isEmpty() )
s += QObject::tr( "<h2>Input parameters</h2>\n" ) + inputs;

QString outputs;
Q_FOREACH ( const QgsProcessingOutputDefinition *def, algorithm->outputDefinitions() )
{
s += QStringLiteral( "<h3>" ) + def->description() + QStringLiteral( "</h3>\n" );
s += QStringLiteral( "<p>" ) + getText( def->name() ) + QStringLiteral( "</p>\n" );
outputs += QStringLiteral( "<h3>" ) + def->description() + QStringLiteral( "</h3>\n" );
outputs += QStringLiteral( "<p>" ) + getText( def->name() ) + QStringLiteral( "</p>\n" );
}
if ( !outputs.isEmpty() )
s += QObject::tr( "<h2>Outputs</h2>\n" ) + outputs;

s += QLatin1String( "<br>" );
s += QObject::tr( "<p align=\"right\">Algorithm author: %1</p>" ).arg( getText( QStringLiteral( "ALG_CREATOR" ) ) );
s += QObject::tr( "<p align=\"right\">Help author: %1</p>" ).arg( getText( QStringLiteral( "ALG_HELP_CREATOR" ) ) );
s += QObject::tr( "<p align=\"right\">Algorithm version: %1</p>" ).arg( getText( QStringLiteral( "ALG_VERSION" ) ) );
if ( !map.value( QStringLiteral( "ALG_CREATOR" ) ).toString().isEmpty() )
s += QObject::tr( "<p align=\"right\">Algorithm author: %1</p>" ).arg( getText( QStringLiteral( "ALG_CREATOR" ) ) );
if ( !map.value( QStringLiteral( "ALG_HELP_CREATOR" ) ).toString().isEmpty() )
s += QObject::tr( "<p align=\"right\">Help author: %1</p>" ).arg( getText( QStringLiteral( "ALG_HELP_CREATOR" ) ) );
if ( !map.value( QStringLiteral( "ALG_VERSION" ) ).toString().isEmpty() )
s += QObject::tr( "<p align=\"right\">Algorithm version: %1</p>" ).arg( getText( QStringLiteral( "ALG_VERSION" ) ) );

s += QStringLiteral( "</body></html>" );
return s;
}

0 comments on commit e2082a0

Please sign in to comment.
You can’t perform that action at this time.