Skip to content

Commit e2082a0

Browse files
committed
[processing] Fix modeler help/description generation, allow setting
of model short description text Fixes #18767
1 parent aa55de8 commit e2082a0

File tree

5 files changed

+30
-16
lines changed

5 files changed

+30
-16
lines changed

python/core/auto_generated/processing/models/qgsprocessingmodelalgorithm.sip.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Constructor for QgsProcessingModelAlgorithm.
4545

4646
virtual QString shortHelpString() const;
4747

48-
virtual QString helpUrl() const;
48+
virtual QString shortDescription() const;
4949

5050
virtual Flags flags() const;
5151

python/plugins/processing/gui/HelpEditionDialog.py

+3
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class HelpEditionDialog(BASE, WIDGET):
5252
ALG_CREATOR = 'ALG_CREATOR'
5353
ALG_HELP_CREATOR = 'ALG_HELP_CREATOR'
5454
ALG_VERSION = 'ALG_VERSION'
55+
SHORT_DESCRIPTION = 'SHORT_DESCRIPTION'
5556

5657
def __init__(self, alg):
5758
super(HelpEditionDialog, self).__init__(None)
@@ -103,6 +104,8 @@ def getHtml(self):
103104
def fillTree(self):
104105
item = TreeDescriptionItem(self.tr('Algorithm description'), self.ALG_DESC)
105106
self.tree.addTopLevelItem(item)
107+
item = TreeDescriptionItem(self.tr('Short description'), self.SHORT_DESCRIPTION)
108+
self.tree.addTopLevelItem(item)
106109
parametersItem = TreeDescriptionItem(self.tr('Input parameters'), None)
107110
self.tree.addTopLevelItem(parametersItem)
108111
for param in self.alg.parameterDefinitions():

src/core/processing/models/qgsprocessingmodelalgorithm.cpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,15 @@ QString QgsProcessingModelAlgorithm::svgIconPath() const
7070

7171
QString QgsProcessingModelAlgorithm::shortHelpString() const
7272
{
73-
if ( mHelpContent.contains( QStringLiteral( "ALG_DESC" ) ) )
74-
return mHelpContent.value( QStringLiteral( "ALG_DESC" ) ).toString();
75-
return QString();
73+
if ( mHelpContent.empty() )
74+
return QString();
75+
76+
return QgsProcessingUtils::formatHelpMapAsHtml( mHelpContent, this );
7677
}
7778

78-
QString QgsProcessingModelAlgorithm::helpUrl() const
79+
QString QgsProcessingModelAlgorithm::shortDescription() const
7980
{
80-
return QgsProcessingUtils::formatHelpMapAsHtml( mHelpContent, this );
81+
return mHelpContent.value( QStringLiteral( "SHORT_DESCRIPTION" ) ).toString();
8182
}
8283

8384
QgsProcessingAlgorithm::Flags QgsProcessingModelAlgorithm::flags() const

src/core/processing/models/qgsprocessingmodelalgorithm.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class CORE_EXPORT QgsProcessingModelAlgorithm : public QgsProcessingAlgorithm
5151
QIcon icon() const override;
5252
QString svgIconPath() const override;
5353
QString shortHelpString() const override;
54-
QString helpUrl() const override;
54+
QString shortDescription() const override;
5555
Flags flags() const override;
5656

5757
bool canExecute( QString *errorMessage SIP_OUT = nullptr ) const override;

src/core/processing/qgsprocessingutils.cpp

+19-9
Original file line numberDiff line numberDiff line change
@@ -595,23 +595,33 @@ QString QgsProcessingUtils::formatHelpMapAsHtml( const QVariantMap &map, const Q
595595

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

599+
QString inputs;
600600
Q_FOREACH ( const QgsProcessingParameterDefinition *def, algorithm->parameterDefinitions() )
601601
{
602-
s += QStringLiteral( "<h3>" ) + def->description() + QStringLiteral( "</h3>\n" );
603-
s += QStringLiteral( "<p>" ) + getText( def->name() ) + QStringLiteral( "</p>\n" );
602+
inputs += QStringLiteral( "<h3>" ) + def->description() + QStringLiteral( "</h3>\n" );
603+
inputs += QStringLiteral( "<p>" ) + getText( def->name() ) + QStringLiteral( "</p>\n" );
604604
}
605-
s += QObject::tr( "<h2>Outputs</h2>\n" );
605+
if ( !inputs.isEmpty() )
606+
s += QObject::tr( "<h2>Input parameters</h2>\n" ) + inputs;
607+
608+
QString outputs;
606609
Q_FOREACH ( const QgsProcessingOutputDefinition *def, algorithm->outputDefinitions() )
607610
{
608-
s += QStringLiteral( "<h3>" ) + def->description() + QStringLiteral( "</h3>\n" );
609-
s += QStringLiteral( "<p>" ) + getText( def->name() ) + QStringLiteral( "</p>\n" );
611+
outputs += QStringLiteral( "<h3>" ) + def->description() + QStringLiteral( "</h3>\n" );
612+
outputs += QStringLiteral( "<p>" ) + getText( def->name() ) + QStringLiteral( "</p>\n" );
610613
}
614+
if ( !outputs.isEmpty() )
615+
s += QObject::tr( "<h2>Outputs</h2>\n" ) + outputs;
616+
611617
s += QLatin1String( "<br>" );
612-
s += QObject::tr( "<p align=\"right\">Algorithm author: %1</p>" ).arg( getText( QStringLiteral( "ALG_CREATOR" ) ) );
613-
s += QObject::tr( "<p align=\"right\">Help author: %1</p>" ).arg( getText( QStringLiteral( "ALG_HELP_CREATOR" ) ) );
614-
s += QObject::tr( "<p align=\"right\">Algorithm version: %1</p>" ).arg( getText( QStringLiteral( "ALG_VERSION" ) ) );
618+
if ( !map.value( QStringLiteral( "ALG_CREATOR" ) ).toString().isEmpty() )
619+
s += QObject::tr( "<p align=\"right\">Algorithm author: %1</p>" ).arg( getText( QStringLiteral( "ALG_CREATOR" ) ) );
620+
if ( !map.value( QStringLiteral( "ALG_HELP_CREATOR" ) ).toString().isEmpty() )
621+
s += QObject::tr( "<p align=\"right\">Help author: %1</p>" ).arg( getText( QStringLiteral( "ALG_HELP_CREATOR" ) ) );
622+
if ( !map.value( QStringLiteral( "ALG_VERSION" ) ).toString().isEmpty() )
623+
s += QObject::tr( "<p align=\"right\">Algorithm version: %1</p>" ).arg( getText( QStringLiteral( "ALG_VERSION" ) ) );
624+
615625
s += QStringLiteral( "</body></html>" );
616626
return s;
617627
}

0 commit comments

Comments
 (0)