Skip to content

Commit 5edcc64

Browse files
committed
[processing] Allow algorithms to return a translated short description
This is used in the algorithm's tooltip in the toolbox, and is intended for single sentence description of the algorithm, e.g. "Converts 2D features to 3D by sampling a DEM raster." Convert grass algorithms to use short description for the descriptive parts of their names, to cleanup the toolbox and make it more uniform.
1 parent 698fad6 commit 5edcc64

File tree

6 files changed

+45
-10
lines changed

6 files changed

+45
-10
lines changed

python/core/auto_generated/processing/qgsprocessingalgorithm.sip.in

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,20 @@ provider's ID and the algorithms unique name (e.g. "qgis:mergelayers" ).
106106
Returns the translated algorithm name, which should be used for any user-visible display
107107
of the algorithm name.
108108

109+
Algorithm display names should be short, e.g. ideally no more than 3 or 4 words.
110+
The name should use sentence case (e.g. "Raster layer statistics", not "Raster Layer Statistics").
111+
109112
.. seealso:: :py:func:`name`
113+
114+
.. seealso:: :py:func:`shortDescription`
115+
%End
116+
117+
virtual QString shortDescription() const;
118+
%Docstring
119+
Returns an optional translated short description of the algorithm. This should be
120+
at most a single sentence, e.g. "Converts 2D features to 3D by sampling a DEM raster."
121+
122+
.. versionadded:: 3.2
110123
%End
111124

112125
virtual QStringList tags() const;

python/plugins/processing/algs/grass7/Grass7Algorithm.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ def __init__(self, descriptionfile):
102102
super().__init__()
103103
self._name = ''
104104
self._display_name = ''
105+
self._short_description = ''
105106
self._group = ''
106107
self._groupId = ''
107108
self.groupIdRegex = re.compile('^[^\s\(]+')
@@ -142,6 +143,9 @@ def name(self):
142143
def displayName(self):
143144
return self._display_name
144145

146+
def shortDescription(self):
147+
return self._short_description
148+
145149
def group(self):
146150
return self._group
147151

@@ -191,13 +195,12 @@ def defineCharacteristicsFromFile(self):
191195
self.grass7Name = line
192196
# Second line if the algorithm name in Processing
193197
line = lines.readline().strip('\n').strip()
194-
self._name = line
195-
self._display_name = QCoreApplication.translate("GrassAlgorithm", line)
196-
if " - " not in self._name:
197-
self._name = self.grass7Name + " - " + self._name
198-
self._display_name = self.grass7Name + " - " + self._display_name
199-
200-
self._name = self._name[:self._name.find(' ')].lower()
198+
self._short_description = line
199+
if " - " not in line:
200+
self._name = self.grass7Name
201+
else:
202+
self._name = line[:line.find(' ')].lower()
203+
self._display_name = self._name
201204
# Read the grass group
202205
line = lines.readline().strip('\n').strip()
203206
self._group = QCoreApplication.translate("GrassAlgorithm", line)

python/plugins/processing/gui/ProcessingToolbox.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,8 +508,9 @@ def __init__(self, alg):
508508
self.setData(0, ProcessingToolbox.TYPE_ROLE, ProcessingToolbox.ALG_ITEM)
509509

510510
def formatAlgorithmTooltip(self, alg):
511-
return '<p><b>{}</b></p><p>{}</p>'.format(
511+
return '<p><b>{}</b></p>{}<p>{}</p>'.format(
512512
alg.displayName(),
513+
'<p>{}</p>'.format(alg.shortDescription()) if alg.shortDescription() else '',
513514
QCoreApplication.translate('Toolbox', 'Algorithm ID: ‘{}’').format('<i>{}</i>'.format(alg.id()))
514515
)
515516

python/plugins/processing/modeler/ModelerDialog.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -779,9 +779,10 @@ def __init__(self, alg):
779779
self.setData(0, ModelerDialog.TYPE_ROLE, ModelerDialog.ALG_ITEM)
780780

781781
def formatAlgorithmTooltip(self, alg):
782-
return '<p><b>{}</b></p><p>{}</p>'.format(
782+
return '<p><b>{}</b></p>{}<p>{}</p>'.format(
783783
alg.displayName(),
784-
QCoreApplication.translate('TreeAlgorithmItem', 'Algorithm ID: ‘{}’').format('<i>{}</i>'.format(alg.id()))
784+
'<p>{}</p>'.format(alg.shortDescription()) if alg.shortDescription() else '',
785+
QCoreApplication.translate('Toolbox', 'Algorithm ID: ‘{}’').format('<i>{}</i>'.format(alg.id()))
785786
)
786787

787788

src/core/processing/qgsprocessingalgorithm.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ QString QgsProcessingAlgorithm::id() const
4949
return name();
5050
}
5151

52+
QString QgsProcessingAlgorithm::shortDescription() const
53+
{
54+
return QString();
55+
}
56+
5257
QString QgsProcessingAlgorithm::shortHelpString() const
5358
{
5459
return QString();

src/core/processing/qgsprocessingalgorithm.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,22 @@ class CORE_EXPORT QgsProcessingAlgorithm
146146
/**
147147
* Returns the translated algorithm name, which should be used for any user-visible display
148148
* of the algorithm name.
149+
*
150+
* Algorithm display names should be short, e.g. ideally no more than 3 or 4 words.
151+
* The name should use sentence case (e.g. "Raster layer statistics", not "Raster Layer Statistics").
152+
*
149153
* \see name()
154+
* \see shortDescription()
150155
*/
151156
virtual QString displayName() const = 0;
152157

158+
/**
159+
* Returns an optional translated short description of the algorithm. This should be
160+
* at most a single sentence, e.g. "Converts 2D features to 3D by sampling a DEM raster."
161+
* \since QGIS 3.2
162+
*/
163+
virtual QString shortDescription() const;
164+
153165
/**
154166
* Returns a list of tags which relate to the algorithm, and are used to assist users in searching
155167
* for suitable algorithms. These tags should be localised.

0 commit comments

Comments
 (0)