3131
3232import os
3333
34+ from qgis .core import (QgsProcessingParameterDefinition ,
35+ QgsProcessingParameterExtent ,
36+ QgsProcessingParameterPoint ,
37+ QgsProcessingParameterVectorLayer )
3438from qgis .PyQt import uic
3539from qgis .PyQt .QtCore import QCoreApplication
3640from qgis .PyQt .QtWidgets import (QWidget , QHBoxLayout , QToolButton ,
3741 QLabel , QCheckBox )
3842from qgis .PyQt .QtGui import QIcon
3943
4044from processing .gui .OutputSelectionPanel import OutputSelectionPanel
45+ from processing .gui .wrappers import WidgetWrapperFactory
4146from processing .core .parameters import ParameterVector , ParameterExtent , ParameterPoint
4247from processing .core .outputs import OutputRaster
4348from 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