Skip to content

Commit 2a1a715

Browse files
committedApr 7, 2017
Move algorithm id (previously commandLineName) to QgsProcessingAlgorithm
1 parent 950ed68 commit 2a1a715

22 files changed

+66
-70
lines changed
 

‎python/core/processing/qgsprocessingalgorithm.sip

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ class QgsProcessingAlgorithm
5151
\see tags()
5252
%End
5353

54+
QString id() const;
55+
%Docstring
56+
Returns the unique ID for the algorithm, which is a combination of the algorithm
57+
provider's ID and the algorithms unique name (e.g. "qgis:mergelayers" ).
58+
\see name()
59+
\see provider()
60+
%End
61+
5462
virtual QString displayName() const = 0;
5563
%Docstring
5664
Returns the translated algorithm name, which should be used for any user-visible display

‎python/plugins/processing/algs/gdal/GridAverage.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,14 @@ class GridAverage(GdalAlgorithm):
5757
TYPE = ['Byte', 'Int16', 'UInt16', 'UInt32', 'Int32', 'Float32', 'Float64']
5858

5959
def name(self):
60-
return 'gridmovingaverage'
60+
return 'gridaverage'
6161

6262
def displayName(self):
6363
return self.tr('Grid (Moving average)')
6464

6565
def icon(self):
6666
return QIcon(os.path.join(pluginPath, 'images', 'gdaltools', 'grid.png'))
6767

68-
def commandLineName(self):
69-
return "gdal:gridaverage"
70-
7168
def group(self):
7269
return self.tr('Raster analysis')
7370

‎python/plugins/processing/algs/gdal/GridDataMetrics.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,6 @@ def displayName(self):
7070
def icon(self):
7171
return QIcon(os.path.join(pluginPath, 'images', 'gdaltools', 'grid.png'))
7272

73-
def commandLineName(self):
74-
return "gdal:griddatametrics"
75-
7673
def group(self):
7774
return self.tr('Raster analysis')
7875

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def __init__(self, descriptionfile):
9090
self.uniqueSuffix = str(uuid.uuid4()).replace('-', '')
9191

9292
# Use the ext mechanism
93-
name = self.commandLineName().replace('.', '_')[len('grass7:'):]
93+
name = self.name().replace('.', '_')
9494
try:
9595
self.module = importlib.import_module('processing.algs.grass7.ext.' + name)
9696
except ImportError:
@@ -574,9 +574,6 @@ def exportRasterLayer(self, layer):
574574
def getTempFilename(self):
575575
return system.getTempFilename()
576576

577-
def commandLineName(self):
578-
return 'grass7:' + self.name()
579-
580577
def checkBeforeOpeningParametersDialog(self):
581578
return Grass7Utils.checkGrass7IsInstalled()
582579

‎python/plugins/processing/algs/saga/SagaAlgorithm.py

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,6 @@ def defineCharacteristicsFromFile(self):
108108
else:
109109
self.cmdname = self._name
110110
self._display_name = QCoreApplication.translate("SAGAAlgorithm", str(self._name))
111-
# _commandLineName is the name used in processing to call the algorithm
112-
# Most of the time will be equal to the cmdname, but in same cases, several processing algorithms
113-
# call the same SAGA one
114-
self._commandLineName = self.createCommandLineName(self._name)
115111
self._name = decoratedAlgorithmName(self._name)
116112
self._display_name = QCoreApplication.translate("SAGAAlgorithm", str(self._name))
117113

@@ -289,7 +285,7 @@ def processAlgorithm(self, feedback):
289285
f.write(self.crs.toWkt())
290286

291287
def preProcessInputs(self):
292-
name = self.commandLineName().replace('.', '_')[len('saga:'):]
288+
name = self.name().replace('.', '_')
293289
try:
294290
module = importlib.import_module('processing.algs.saga.ext.' + name)
295291
except ImportError:
@@ -299,9 +295,8 @@ def preProcessInputs(self):
299295
func(self)
300296

301297
def editCommands(self, commands):
302-
name = self.commandLineName()[len('saga:'):]
303298
try:
304-
module = importlib.import_module('processing.algs.saga.ext.' + name)
299+
module = importlib.import_module('processing.algs.saga.ext.' + self.name())
305300
except ImportError:
306301
return commands
307302
if hasattr(module, 'editCommands'):
@@ -373,11 +368,3 @@ def checkParameterValuesBeforeExecuting(self):
373368
extent2 = (layer.extent(), layer.height(), layer.width())
374369
if extent != extent2:
375370
return self.tr("Input layers do not have the same grid extent.")
376-
377-
def createCommandLineName(self, name):
378-
validChars = \
379-
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789:'
380-
return 'saga:' + ''.join(c for c in name if c in validChars).lower()
381-
382-
def commandLineName(self):
383-
return self._commandLineName

‎python/plugins/processing/core/GeoAlgorithm.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def help(self):
9393
return False, None
9494

9595
def shortHelp(self):
96-
text = shortHelp.get(self.commandLineName(), None)
96+
text = shortHelp.get(self.id(), None)
9797
if text is not None:
9898
text = self._formatHelp(text)
9999
return text
@@ -461,9 +461,6 @@ def __str__(self):
461461
s += '\n'
462462
return s
463463

464-
def commandLineName(self):
465-
return self.provider().id().lower() + ':' + self.name()
466-
467464
def removeOutputFromName(self, name):
468465
for out in self.outputs:
469466
if out.name == name:
@@ -499,7 +496,7 @@ def getAsCommand(self):
499496
console.
500497
"""
501498

502-
s = 'processing.run("' + self.commandLineName() + '",'
499+
s = 'processing.run("' + self.id() + '",'
503500
for param in self.parameters:
504501
s += param.getValueAsCommandLineParameter() + ','
505502
for out in self.outputs:

‎python/plugins/processing/core/alglist.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ def reloadProvider(self, provider_id):
4747
for p in QgsApplication.processingRegistry().providers():
4848
if p.id() == provider_id:
4949
p.refreshAlgorithms()
50-
self.algs[p.id()] = {a.commandLineName(): a for a in p.algorithms()}
50+
self.algs[p.id()] = {a.id(): a for a in p.algorithms()}
5151
self.providerUpdated.emit(p.id())
5252
break
5353

5454
def addProvider(self, provider):
5555
if QgsApplication.processingRegistry().addProvider(provider):
56-
self.algs[provider.id()] = {a.commandLineName(): a for a in provider.algorithms()}
56+
self.algs[provider.id()] = {a.id(): a for a in provider.algorithms()}
5757

5858
def getAlgorithm(self, name):
5959
for provider in list(self.algs.values()):

‎python/plugins/processing/gui/ConfigDialog.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,9 @@ def fillTreeUsingProviders(self):
236236
algItem.setIcon(icon)
237237
algItem.setEditable(False)
238238
try:
239-
settingMenu = ProcessingConfig.settings["MENU_" + alg.commandLineName()]
240-
settingButton = ProcessingConfig.settings["BUTTON_" + alg.commandLineName()]
241-
settingIcon = ProcessingConfig.settings["ICON_" + alg.commandLineName()]
239+
settingMenu = ProcessingConfig.settings["MENU_" + alg.id()]
240+
settingButton = ProcessingConfig.settings["BUTTON_" + alg.id()]
241+
settingIcon = ProcessingConfig.settings["ICON_" + alg.id()]
242242
except:
243243
continue
244244
self.items[settingMenu] = SettingItem(settingMenu)
@@ -269,8 +269,8 @@ def resetMenusToDefaults(self):
269269
providers = Processing.providers
270270
for provider in providers:
271271
for alg in provider.algorithms():
272-
d = defaultMenuEntries.get(alg.commandLineName(), "")
273-
setting = ProcessingConfig.settings["MENU_" + alg.commandLineName()]
272+
d = defaultMenuEntries.get(alg.id(), "")
273+
setting = ProcessingConfig.settings["MENU_" + alg.id()]
274274
item = self.items[setting]
275275
item.setData(d, Qt.EditRole)
276276
self.saveMenus = True

‎python/plugins/processing/gui/EditRenderingStylesDialog.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def setTableContent(self):
7575
self.tblStyles.setItem(i, 0, item)
7676
item = RenderingStyleFilePanel()
7777
style = \
78-
RenderingStyles.getStyle(self.alg.commandLineName(),
78+
RenderingStyles.getStyle(self.alg.id(),
7979
output.name)
8080
if style:
8181
item.setText(str(style))
@@ -88,7 +88,7 @@ def accept(self):
8888
styles = {}
8989
for key in list(self.valueItems.keys()):
9090
styles[key] = str(self.valueItems[key].getValue())
91-
RenderingStyles.addAlgStylesAndSave(self.alg.commandLineName(), styles)
91+
RenderingStyles.addAlgStylesAndSave(self.alg.id(), styles)
9292

9393
QDialog.accept(self)
9494

‎python/plugins/processing/gui/Postprocessing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def handleAlgorithmResults(alg, feedback=None, showResults=True):
7070
else:
7171
name = out.description
7272
dataobjects.load(out.value, name, alg.crs,
73-
RenderingStyles.getStyle(alg.commandLineName(),
73+
RenderingStyles.getStyle(alg.id(),
7474
out.name))
7575
except Exception:
7676
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR,

‎python/plugins/processing/gui/ProcessingToolbox.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def _filterItem(self, item, text):
141141
# hide if every part of text is not contained somewhere in either the item text or item user role
142142
item_text = [item.text(0).lower(), item.data(0, Qt.UserRole).lower()]
143143
if isinstance(item, TreeAlgorithmItem):
144-
item_text.append(item.alg.commandLineName())
144+
item_text.append(item.alg.id())
145145
item_text.extend(item.data(0, Qt.UserRole + 1))
146146

147147
hide = bool(text) and not all(
@@ -227,14 +227,14 @@ def showPopupMenu(self, point):
227227
def editRenderingStyles(self):
228228
item = self.algorithmTree.currentItem()
229229
if isinstance(item, TreeAlgorithmItem):
230-
alg = Processing.getAlgorithm(item.alg.commandLineName())
230+
alg = Processing.getAlgorithm(item.alg.id())
231231
dlg = EditRenderingStylesDialog(alg)
232232
dlg.exec_()
233233

234234
def executeAlgorithmAsBatchProcess(self):
235235
item = self.algorithmTree.currentItem()
236236
if isinstance(item, TreeAlgorithmItem):
237-
alg = Processing.getAlgorithm(item.alg.commandLineName())
237+
alg = Processing.getAlgorithm(item.alg.id())
238238
alg = alg.getCopy()
239239
dlg = BatchAlgorithmDialog(alg)
240240
dlg.show()
@@ -243,7 +243,7 @@ def executeAlgorithmAsBatchProcess(self):
243243
def executeAlgorithm(self):
244244
item = self.algorithmTree.currentItem()
245245
if isinstance(item, TreeAlgorithmItem):
246-
alg = Processing.getAlgorithm(item.alg.commandLineName())
246+
alg = Processing.getAlgorithm(item.alg.id())
247247
message = alg.checkBeforeOpeningParametersDialog()
248248
if message:
249249
dlg = MessageDialog()

‎python/plugins/processing/gui/menus.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,14 @@
114114
def initializeMenus():
115115
for provider in QgsApplication.processingRegistry().providers():
116116
for alg in provider.algorithms():
117-
d = defaultMenuEntries.get(alg.commandLineName(), "")
118-
setting = Setting(menusSettingsGroup, "MENU_" + alg.commandLineName(),
117+
d = defaultMenuEntries.get(alg.id(), "")
118+
setting = Setting(menusSettingsGroup, "MENU_" + alg.id(),
119119
"Menu path", d)
120120
ProcessingConfig.addSetting(setting)
121-
setting = Setting(menusSettingsGroup, "BUTTON_" + alg.commandLineName(),
121+
setting = Setting(menusSettingsGroup, "BUTTON_" + alg.id(),
122122
"Add button", False)
123123
ProcessingConfig.addSetting(setting)
124-
setting = Setting(menusSettingsGroup, "ICON_" + alg.commandLineName(),
124+
setting = Setting(menusSettingsGroup, "ICON_" + alg.id(),
125125
"Icon", "", valuetype=Setting.FILE)
126126
ProcessingConfig.addSetting(setting)
127127

@@ -137,9 +137,9 @@ def updateMenus():
137137
def createMenus():
138138
for provider in list(algList.algs.values()):
139139
for alg in list(provider.values()):
140-
menuPath = ProcessingConfig.getSetting("MENU_" + alg.commandLineName())
141-
addButton = ProcessingConfig.getSetting("BUTTON_" + alg.commandLineName())
142-
icon = ProcessingConfig.getSetting("ICON_" + alg.commandLineName())
140+
menuPath = ProcessingConfig.getSetting("MENU_" + alg.id())
141+
addButton = ProcessingConfig.getSetting("BUTTON_" + alg.id())
142+
icon = ProcessingConfig.getSetting("ICON_" + alg.id())
143143
if icon and os.path.exists(icon):
144144
icon = QIcon(icon)
145145
else:
@@ -152,7 +152,7 @@ def createMenus():
152152
def removeMenus():
153153
for provider in list(algList.algs.values()):
154154
for alg in list(provider.values()):
155-
menuPath = ProcessingConfig.getSetting("MENU_" + alg.commandLineName())
155+
menuPath = ProcessingConfig.getSetting("MENU_" + alg.id())
156156
if menuPath:
157157
paths = menuPath.split("/")
158158
removeAlgorithmEntry(alg, paths[0], paths[-1])
@@ -161,7 +161,7 @@ def removeMenus():
161161
def addAlgorithmEntry(alg, menuName, submenuName, actionText=None, icon=None, addButton=False):
162162
action = QAction(icon or alg.icon(), actionText or alg.displayName(), iface.mainWindow())
163163
action.triggered.connect(lambda: _executeAlgorithm(alg))
164-
action.setObjectName("mProcessingUserMenu_%s" % alg.commandLineName())
164+
action.setObjectName("mProcessingUserMenu_%s" % alg.id())
165165

166166
if menuName:
167167
menu = getMenu(menuName, iface.mainWindow().menuBar())

‎python/plugins/processing/modeler/ModelerAlgorithm.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -541,12 +541,6 @@ def getAsCommand(self):
541541
else:
542542
return None
543543

544-
def commandLineName(self):
545-
if self.descriptionFile is None:
546-
return ''
547-
else:
548-
return 'modeler:' + os.path.basename(self.descriptionFile)[:-6].lower()
549-
550544
def checkBeforeOpeningParametersDialog(self):
551545
for alg in list(self.algs.values()):
552546
algInstance = algList.getAlgorithm(alg.consoleName)

‎python/plugins/processing/modeler/ModelerDialog.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ def _mimeDataAlgorithm(items):
186186
item = items[0]
187187
if isinstance(item, TreeAlgorithmItem):
188188
mimeData = QMimeData()
189-
mimeData.setText(item.alg.commandLineName())
189+
mimeData.setText(item.alg.id())
190190
return mimeData
191191

192192
self.algorithmTree.mimeData = _mimeDataAlgorithm
@@ -549,7 +549,7 @@ def fillInputsTree(self):
549549
def addAlgorithm(self):
550550
item = self.algorithmTree.currentItem()
551551
if isinstance(item, TreeAlgorithmItem):
552-
alg = algList.getAlgorithm(item.alg.commandLineName())
552+
alg = algList.getAlgorithm(item.alg.id())
553553
self._addAlgorithm(alg.getCopy())
554554

555555
def _addAlgorithm(self, alg, pos=None):
@@ -611,7 +611,7 @@ def fillAlgorithmTreeUsingProviders(self):
611611
for alg in algs:
612612
if alg.flags() & QgsProcessingAlgorithm.FlagHideFromModeler:
613613
continue
614-
if alg.commandLineName() == self.alg.commandLineName():
614+
if alg.id() == self.alg.id():
615615
continue
616616

617617
item_text = [alg.displayName().lower()]

‎python/plugins/processing/modeler/ModelerParametersDialog.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ def setPreviousValues(self):
321321
self.dependenciesPanel.setSelectedItems(selected)
322322

323323
def createAlgorithm(self):
324-
alg = Algorithm(self._alg.commandLineName())
324+
alg = Algorithm(self._alg.id())
325325
alg.setName(self.model)
326326
alg.description = self.descriptionBox.text()
327327
params = self._alg.parameters

‎python/plugins/processing/preconfigured/PreconfiguredAlgorithm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def getCopy(self):
6363
return newone
6464

6565
def defineCharacteristics(self):
66-
self.name = self.description["name"]
66+
self._name = self.description["name"]
6767
self._group = self.description["group"]
6868

6969
def execute(self, feedback):

‎python/plugins/processing/preconfigured/PreconfiguredUtils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ def algAsDict(alg):
3535
outputs = {}
3636
for out in alg.outputs:
3737
outputs[out.name] = out.value
38-
return {"parameters": params, "outputs": outputs, "algname": alg.commandLineName()}
38+
return {"parameters": params, "outputs": outputs, "algname": alg.id()}

‎python/plugins/processing/tools/general.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def algorithmsList(text=None):
5151
sortedlist = sorted(list(provider.values()), key=lambda alg: alg.name())
5252
for alg in sortedlist:
5353
if text is None or text.lower() in alg.name().lower():
54-
lst.append(alg.commandLineName())
54+
lst.append(alg.id())
5555
return lst
5656

5757

@@ -66,7 +66,7 @@ def printAlgorithms(text=None):
6666
sortedlist = sorted(list(provider.values()), key=lambda alg: alg.name())
6767
for alg in sortedlist:
6868
if text is None or text.lower() in alg.name().lower():
69-
s += '{}--->{}\n'.format(alg.name().ljust(50, '-'), alg.commandLineName())
69+
s += '{}--->{}\n'.format(alg.name().ljust(50, '-'), alg.id())
7070
print(s)
7171

7272

‎python/plugins/processing/tools/help.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def baseHelpForAlgorithm(alg, folder):
3838
groupName = alg.group().lower()
3939
groupName = groupName.replace('[', '').replace(']', '').replace(' - ', '_')
4040
groupName = groupName.replace(' ', '_')
41-
cmdLineName = alg.commandLineName()
41+
cmdLineName = alg.id()
4242
algName = cmdLineName[cmdLineName.find(':') + 1:].lower()
4343
validChars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_'
4444
safeGroupName = ''.join(c for c in groupName if c in validChars)
@@ -89,7 +89,7 @@ def baseHelpForAlgorithm(alg, folder):
8989
f.write('Console usage\n')
9090
f.write('-------------\n')
9191
f.write('\n::\n\n')
92-
cmd = " processing.run('{}', ".format(alg.commandLineName())
92+
cmd = " processing.run('{}', ".format(alg.id())
9393
for p in alg.parameters:
9494
cmd += '{}, '.format(p.name.lower().strip())
9595

‎src/core/processing/qgsprocessingalgorithm.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@
1717

1818
#include "qgsprocessingalgorithm.h"
1919
#include "qgsapplication.h"
20+
#include "qgsprocessingprovider.h"
21+
22+
QString QgsProcessingAlgorithm::id() const
23+
{
24+
if ( mProvider )
25+
return QString( "%1:%2" ).arg( mProvider->id(), name() );
26+
else
27+
return name();
28+
}
2029

2130
QIcon QgsProcessingAlgorithm::icon() const
2231
{

‎src/core/processing/qgsprocessingalgorithm.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ class CORE_EXPORT QgsProcessingAlgorithm
6868
*/
6969
virtual QString name() const = 0;
7070

71+
/**
72+
* Returns the unique ID for the algorithm, which is a combination of the algorithm
73+
* provider's ID and the algorithms unique name (e.g. "qgis:mergelayers" ).
74+
* \see name()
75+
* \see provider()
76+
*/
77+
QString id() const;
78+
7179
/**
7280
* Returns the translated algorithm name, which should be used for any user-visible display
7381
* of the algorithm name.

‎tests/src/core/testqgsprocessing.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,10 @@ void TestQgsProcessing::algorithm()
347347
{
348348
DummyAlgorithm alg( "test" );
349349
DummyProvider *p = new DummyProvider( "p1" );
350+
QCOMPARE( alg.id(), QString( "test" ) );
350351
alg.setProvider( p );
351352
QCOMPARE( alg.provider(), p );
353+
QCOMPARE( alg.id(), QString( "p1:test" ) );
352354

353355
QVERIFY( p->algorithms().isEmpty() );
354356

0 commit comments

Comments
 (0)
Please sign in to comment.