Skip to content
Permalink
Browse files

[processing] create and manage label in WidgetWrapper

ModelerParametersDialog and ParametersPanel have to keep list of
wrappers only. widget and label( if needed) are created through
WidgetWrapper.createLabel()
  • Loading branch information
rkanavath authored and nyalldawson committed Apr 2, 2018
1 parent 1e5fe12 commit 3408e02c468d963c80106596f6449b0ba860c2c2
@@ -74,7 +74,6 @@ def __init__(self, parent, alg):
self.alg = alg
self.wrappers = {}
self.outputWidgets = {}
self.labels = {}
self.checkBoxes = {}
self.dependentItems = {}
self.iterateButtons = {}
@@ -108,14 +107,6 @@ def initWidgets(self):
if param.isDestination():
continue
else:
desc = param.description()
if isinstance(param, QgsProcessingParameterExtent):
desc += self.tr(' (xmin, xmax, ymin, ymax)')
if isinstance(param, QgsProcessingParameterPoint):
desc += self.tr(' (x, y)')
if param.flags() & QgsProcessingParameterDefinition.FlagOptional:
desc += self.tr(' [optional]')

wrapper = WidgetWrapperFactory.create_wrapper(param, self.parent)
self.wrappers[param.name()] = wrapper
widget = wrapper.widget
@@ -141,21 +132,21 @@ def initWidgets(self):

widget.setToolTip(param.toolTip())

if isinstance(widget, QCheckBox):
# checkbox widget - so description is embedded in widget rather than a separate
# label
widget.setText(desc)
else:
label = QLabel(desc)
# label.setToolTip(tooltip)
self.labels[param.name()] = label

if wrapper.label is not None:
if param.flags() & QgsProcessingParameterDefinition.FlagAdvanced:
self.layoutAdvanced.addWidget(label)
self.layoutAdvanced.addWidget(wrapper.label)
else:
self.layoutMain.insertWidget(
self.layoutMain.count() - 2, label)

self.layoutMain.count() - 2, wrapper.label)
else:
desc = param.description()
if isinstance(param, QgsProcessingParameterExtent):
desc += self.tr(' (xmin, xmax, ymin, ymax)')
if isinstance(param, QgsProcessingParameterPoint):
desc += self.tr(' (x, y)')
if param.flags() & QgsProcessingParameterDefinition.FlagOptional:
desc += self.tr(' [optional]')
widget.setText(desc)
if param.flags() & QgsProcessingParameterDefinition.FlagAdvanced:
self.layoutAdvanced.addWidget(widget)
else:
@@ -77,6 +77,7 @@
from qgis.PyQt.QtWidgets import (
QCheckBox,
QComboBox,
QLabel,
QDialog,
QFileDialog,
QHBoxLayout,
@@ -150,6 +151,7 @@ def __init__(self, param, dialog, row=0, col=0, **kwargs):
self.col = col
self.dialogType = dialogTypes.get(dialog.__class__.__name__, DIALOG_STANDARD)
self.widget = self.createWidget(**kwargs)
self.label = self.createLabel()
if param.defaultValue() is not None:
self.setValue(param.defaultValue())

@@ -172,6 +174,21 @@ def comboValue(self, validator=None, combobox=None):
def createWidget(self, **kwargs):
pass

def createLabel(self):
if self.dialogType == DIALOG_BATCH:
return None
desc = self.param.description()
if isinstance(self.param, QgsProcessingParameterExtent):
desc += self.tr(' (xmin, xmax, ymin, ymax)')
if isinstance(self.param, QgsProcessingParameterPoint):
desc += self.tr(' (x, y)')
if self.param.flags() & QgsProcessingParameterDefinition.FlagOptional:
desc += self.tr(' [optional]')

label = QLabel(desc)
label.setToolTip(self.param.name())
return label

def setValue(self, value):
pass

@@ -240,6 +257,12 @@ def value(self):

class BooleanWidgetWrapper(WidgetWrapper):

def createLabel(self):
if self.dialogType == DIALOG_STANDARD:
return None
else:
return super().createLabel()

def createWidget(self):
if self.dialogType == DIALOG_STANDARD:
return QCheckBox()
@@ -87,8 +87,6 @@ def closeEvent(self, event):
super(ModelerParametersDialog, self).closeEvent(event)

def setupUi(self):
self.labels = {}
self.widgets = {}
self.checkBoxes = {}
self.showAdvanced = False
self.wrappers = {}
@@ -136,15 +134,6 @@ def setupUi(self):
for param in self._alg.parameterDefinitions():
if param.isDestination() or param.flags() & QgsProcessingParameterDefinition.FlagHidden:
continue
desc = param.description()
if isinstance(param, QgsProcessingParameterExtent):
desc += self.tr('(xmin, xmax, ymin, ymax)')
if isinstance(param, QgsProcessingParameterPoint):
desc += self.tr('(x, y)')
if param.flags() & QgsProcessingParameterDefinition.FlagOptional:
desc += self.tr(' [optional]')
label = QLabel(desc)
self.labels[param.name()] = label

wrapper = WidgetWrapperFactory.create_wrapper(param, self)
self.wrappers[param.name()] = wrapper
@@ -153,14 +142,11 @@ def setupUi(self):
if widget is not None:
self.valueItems[param.name()] = widget
tooltip = param.description()
label.setToolTip(tooltip)
widget.setToolTip(tooltip)
if param.flags() & QgsProcessingParameterDefinition.FlagAdvanced:
label.setVisible(self.showAdvanced)
wrapper.label.setVisible(self.showAdvanced)
widget.setVisible(self.showAdvanced)
self.widgets[param.name()] = widget

self.verticalLayout.addWidget(label)
self.verticalLayout.addWidget(wrapper.label)
self.verticalLayout.addWidget(widget)

for dest in self._alg.destinationParameterDefinitions():
@@ -230,8 +216,8 @@ def showAdvancedParametersClicked(self):
self.advancedButton.setText(self.tr('Show advanced parameters'))
for param in self._alg.parameterDefinitions():
if param.flags() & QgsProcessingParameterDefinition.FlagAdvanced:
self.labels[param.name()].setVisible(self.showAdvanced)
self.widgets[param.name()].setVisible(self.showAdvanced)
self.wrappers[param.name()].widget.setVisible(self.showAdvanced)
self.wrappers[param.name()].label.setVisible(self.showAdvanced)

def getAvailableValuesOfType(self, paramType, outTypes=[], dataTypes=[]):
# upgrade paramType to list

0 comments on commit 3408e02

Please sign in to comment.
You can’t perform that action at this time.