Skip to content

Commit

Permalink
[processing] Fix modeler help/description generation, allow setting
Browse files Browse the repository at this point in the history
of model short description text

Fixes #18767
  • Loading branch information
nyalldawson committed Sep 25, 2018
1 parent aa55de8 commit e2082a0
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 16 deletions.
Expand Up @@ -45,7 +45,7 @@ Constructor for QgsProcessingModelAlgorithm.

virtual QString shortHelpString() const;

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

virtual Flags flags() const;

Expand Down
3 changes: 3 additions & 0 deletions python/plugins/processing/gui/HelpEditionDialog.py
Expand Up @@ -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)
Expand Down Expand Up @@ -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():
Expand Down
11 changes: 6 additions & 5 deletions src/core/processing/models/qgsprocessingmodelalgorithm.cpp
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/core/processing/models/qgsprocessingmodelalgorithm.h
Expand Up @@ -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;
Expand Down
28 changes: 19 additions & 9 deletions src/core/processing/qgsprocessingutils.cpp
Expand Up @@ -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;
}
Expand Down

0 comments on commit e2082a0

Please sign in to comment.