Skip to content

Commit 9997ab6

Browse files
committed
Partially port wrappers to QgsProcessingParameterDefinition
And create a new WidgetWrapperFactory for creating a suitable wrapper corresponding to a parameter
1 parent 77ab933 commit 9997ab6

File tree

8 files changed

+340
-178
lines changed

8 files changed

+340
-178
lines changed

python/core/processing/qgsprocessingoutputs.sip

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ class QgsProcessingOutputDefinition
2525

2626
%TypeHeaderCode
2727
#include "qgsprocessingoutputs.h"
28+
%End
29+
30+
%ConvertToSubClassCode
31+
if ( sipCpp->type() == "outputVector" )
32+
sipType = sipType_QgsProcessingOutputVectorLayer;
2833
%End
2934
public:
3035

python/core/processing/qgsprocessingparameters.sip

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,45 @@ class QgsProcessingParameterDefinition
2626

2727
%TypeHeaderCode
2828
#include "qgsprocessingparameters.h"
29+
%End
30+
31+
%ConvertToSubClassCode
32+
if ( sipCpp->type() == "boolean" )
33+
sipType = sipType_QgsProcessingParameterBoolean;
34+
else if ( sipCpp->type() == "crs" )
35+
sipType = sipType_QgsProcessingParameterCrs;
36+
else if ( sipCpp->type() == "layer" )
37+
sipType = sipType_QgsProcessingParameterMapLayer;
38+
else if ( sipCpp->type() == "extent" )
39+
sipType = sipType_QgsProcessingParameterExtent;
40+
else if ( sipCpp->type() == "point" )
41+
sipType = sipType_QgsProcessingParameterPoint;
42+
else if ( sipCpp->type() == "file" )
43+
sipType = sipType_QgsProcessingParameterFile;
44+
else if ( sipCpp->type() == "matrix" )
45+
sipType = sipType_QgsProcessingParameterMatrix;
46+
else if ( sipCpp->type() == "multilayer" )
47+
sipType = sipType_QgsProcessingParameterMultipleLayers;
48+
else if ( sipCpp->type() == "number" )
49+
sipType = sipType_QgsProcessingParameterNumber;
50+
else if ( sipCpp->type() == "range" )
51+
sipType = sipType_QgsProcessingParameterRange;
52+
else if ( sipCpp->type() == "raster" )
53+
sipType = sipType_QgsProcessingParameterRasterLayer;
54+
else if ( sipCpp->type() == "enum" )
55+
sipType = sipType_QgsProcessingParameterEnum;
56+
else if ( sipCpp->type() == "string" )
57+
sipType = sipType_QgsProcessingParameterString;
58+
else if ( sipCpp->type() == "expression" )
59+
sipType = sipType_QgsProcessingParameterExpression;
60+
else if ( sipCpp->type() == "table" )
61+
sipType = sipType_QgsProcessingParameterTable;
62+
else if ( sipCpp->type() == "field" )
63+
sipType = sipType_QgsProcessingParameterTableField;
64+
else if ( sipCpp->type() == "vector" )
65+
sipType = sipType_QgsProcessingParameterVectorLayer;
66+
else if ( sipCpp->type() == "vectorOut" )
67+
sipType = sipType_QgsProcessingParameterOutputVectorLayer;
2968
%End
3069
public:
3170

python/plugins/processing/core/GeoAlgorithm.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,6 @@ def getCustomModelerParametersDialog(self, modelAlg, algName=None):
8989
"""
9090
return None
9191

92-
def getParameterDescriptions(self):
93-
"""Returns a dict with param names as keys and detailed
94-
descriptions of each param as value. These descriptions are
95-
used as tool tips in the parameters dialog.
96-
97-
If a description does not exist, the parameter's
98-
human-readable name is used.
99-
"""
100-
descs = {}
101-
return descs
102-
10392
def checkParameterValuesBeforeExecuting(self):
10493
"""If there is any check to do before launching the execution
10594
of the algorithm, it should be done here.

python/plugins/processing/gui/ParametersPanel.py

Lines changed: 71 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,18 @@
3131

3232
import os
3333

34+
from qgis.core import (QgsProcessingParameterDefinition,
35+
QgsProcessingParameterExtent,
36+
QgsProcessingParameterPoint,
37+
QgsProcessingParameterVectorLayer)
3438
from qgis.PyQt import uic
3539
from qgis.PyQt.QtCore import QCoreApplication
3640
from qgis.PyQt.QtWidgets import (QWidget, QHBoxLayout, QToolButton,
3741
QLabel, QCheckBox)
3842
from qgis.PyQt.QtGui import QIcon
3943

4044
from processing.gui.OutputSelectionPanel import OutputSelectionPanel
45+
from processing.gui.wrappers import WidgetWrapperFactory
4146
from processing.core.parameters import ParameterVector, ParameterExtent, ParameterPoint
4247
from processing.core.outputs import OutputRaster
4348
from processing.core.outputs import OutputTable
@@ -78,83 +83,80 @@ def layerRegistryChanged(self, layers):
7883

7984
def initWidgets(self):
8085
# If there are advanced parameters — show corresponding groupbox
81-
for param in self.alg.parameters:
82-
if param.isAdvanced:
86+
for param in self.alg.parameterDefinitions():
87+
if param.flags() & QgsProcessingParameterDefinition.FlagAdvanced:
8388
self.grpAdvanced.show()
8489
break
8590
# Create widgets and put them in layouts
86-
for param in self.alg.parameters:
87-
if param.hidden:
91+
for param in self.alg.parameterDefinitions():
92+
if param.flags() & QgsProcessingParameterDefinition.FlagHidden:
8893
continue
8994

90-
desc = param.description
91-
if isinstance(param, ParameterExtent):
92-
desc += self.tr(' (xmin, xmax, ymin, ymax)')
93-
if isinstance(param, ParameterPoint):
94-
desc += self.tr(' (x, y)')
95-
if param.optional:
96-
desc += self.tr(' [optional]')
97-
98-
wrapper = self.getWidgetWrapperFromParameter(param)
99-
self.wrappers[param.name] = wrapper
100-
widget = wrapper.widget
101-
102-
if widget is not None:
103-
if isinstance(param, ParameterVector):
104-
layout = QHBoxLayout()
105-
layout.setSpacing(2)
106-
layout.setMargin(0)
107-
layout.addWidget(widget)
108-
button = QToolButton()
109-
icon = QIcon(os.path.join(pluginPath, 'images', 'iterate.png'))
110-
button.setIcon(icon)
111-
button.setToolTip(self.tr('Iterate over this layer'))
112-
button.setCheckable(True)
113-
layout.addWidget(button)
114-
self.iterateButtons[param.name] = button
115-
button.toggled.connect(self.buttonToggled)
116-
widget = QWidget()
117-
widget.setLayout(layout)
118-
119-
tooltips = self.alg.getParameterDescriptions()
120-
widget.setToolTip(tooltips.get(param.name, param.description))
121-
122-
if type(widget) is QCheckBox:
123-
# checkbox widget - so description is embedded in widget rather than a separate
124-
# label
125-
widget.setText(desc)
126-
else:
127-
label = QLabel(desc)
128-
# label.setToolTip(tooltip)
129-
self.labels[param.name] = label
130-
131-
if param.isAdvanced:
132-
self.layoutAdvanced.addWidget(label)
95+
if param.isDestination():
96+
label = QLabel(param.description())
97+
widget = OutputSelectionPanel(param, self.alg)
98+
self.layoutMain.insertWidget(self.layoutMain.count() - 1, label)
99+
self.layoutMain.insertWidget(self.layoutMain.count() - 1, widget)
100+
if isinstance(param, (OutputRaster, QgsProcessingParameterOutputVectorLayer, OutputTable)):
101+
check = QCheckBox()
102+
check.setText(self.tr('Open output file after running algorithm'))
103+
check.setChecked(True)
104+
self.layoutMain.insertWidget(self.layoutMain.count() - 1, check)
105+
self.checkBoxes[param.name()] = check
106+
self.outputWidgets[param.name()] = widget
107+
else:
108+
desc = param.description()
109+
if isinstance(param, QgsProcessingParameterExtent):
110+
desc += self.tr(' (xmin, xmax, ymin, ymax)')
111+
if isinstance(param, QgsProcessingParameterPoint):
112+
desc += self.tr(' (x, y)')
113+
if param.flags() & QgsProcessingParameterDefinition.FlagOptional:
114+
desc += self.tr(' [optional]')
115+
116+
wrapper = WidgetWrapperFactory.create_wrapper(param, self.parent)
117+
self.wrappers[param.name()] = wrapper
118+
widget = wrapper.widget
119+
120+
if widget is not None:
121+
if isinstance(param, QgsProcessingParameterVectorLayer):
122+
layout = QHBoxLayout()
123+
layout.setSpacing(2)
124+
layout.setMargin(0)
125+
layout.addWidget(widget)
126+
button = QToolButton()
127+
icon = QIcon(os.path.join(pluginPath, 'images', 'iterate.png'))
128+
button.setIcon(icon)
129+
button.setToolTip(self.tr('Iterate over this layer'))
130+
button.setCheckable(True)
131+
layout.addWidget(button)
132+
self.iterateButtons[param.name()] = button
133+
button.toggled.connect(self.buttonToggled)
134+
widget = QWidget()
135+
widget.setLayout(layout)
136+
137+
widget.setToolTip(param.description())
138+
139+
if type(widget) is QCheckBox:
140+
# checkbox widget - so description is embedded in widget rather than a separate
141+
# label
142+
widget.setText(desc)
143+
else:
144+
label = QLabel(desc)
145+
# label.setToolTip(tooltip)
146+
self.labels[param.name()] = label
147+
148+
if param.flags() & QgsProcessingParameterDefinition.FlagAdvanced:
149+
self.layoutAdvanced.addWidget(label)
150+
else:
151+
self.layoutMain.insertWidget(
152+
self.layoutMain.count() - 2, label)
153+
154+
if param.flags() & QgsProcessingParameterDefinition.FlagAdvanced:
155+
self.layoutAdvanced.addWidget(widget)
133156
else:
134157
self.layoutMain.insertWidget(
135-
self.layoutMain.count() - 2, label)
136-
137-
if param.isAdvanced:
138-
self.layoutAdvanced.addWidget(widget)
139-
else:
140-
self.layoutMain.insertWidget(
141-
self.layoutMain.count() - 2, widget)
158+
self.layoutMain.count() - 2, widget)
142159

143-
for output in self.alg.outputs:
144-
if output.hidden:
145-
continue
146-
147-
label = QLabel(output.description)
148-
widget = OutputSelectionPanel(output, self.alg)
149-
self.layoutMain.insertWidget(self.layoutMain.count() - 1, label)
150-
self.layoutMain.insertWidget(self.layoutMain.count() - 1, widget)
151-
if isinstance(output, (OutputRaster, OutputVector, OutputTable)):
152-
check = QCheckBox()
153-
check.setText(self.tr('Open output file after running algorithm'))
154-
check.setChecked(True)
155-
self.layoutMain.insertWidget(self.layoutMain.count() - 1, check)
156-
self.checkBoxes[output.name] = check
157-
self.outputWidgets[output.name] = widget
158160
for wrapper in list(self.wrappers.values()):
159161
wrapper.postInitialize(list(self.wrappers.values()))
160162

@@ -164,6 +166,3 @@ def buttonToggled(self, value):
164166
for button in list(self.iterateButtons.values()):
165167
if button is not sender:
166168
button.setChecked(False)
167-
168-
def getWidgetWrapperFromParameter(self, param):
169-
return param.wrapper(self.parent)

0 commit comments

Comments
 (0)