Skip to content

Commit

Permalink
[processing] create and manage label in WidgetWrapper
Browse files Browse the repository at this point in the history
ModelerParametersDialog and ParametersPanel have to keep list of
wrappers only. widget and label( if needed) are created through
WidgetWrapper.createLabel()
  • Loading branch information
Rashad Kanavath authored and nyalldawson committed Apr 2, 2018
1 parent 1e5fe12 commit 3408e02
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 39 deletions.
33 changes: 12 additions & 21 deletions python/plugins/processing/gui/ParametersPanel.py
Expand Up @@ -74,7 +74,6 @@ def __init__(self, parent, alg):
self.alg = alg
self.wrappers = {}
self.outputWidgets = {}
self.labels = {}
self.checkBoxes = {}
self.dependentItems = {}
self.iterateButtons = {}
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down
23 changes: 23 additions & 0 deletions python/plugins/processing/gui/wrappers.py
Expand Up @@ -77,6 +77,7 @@
from qgis.PyQt.QtWidgets import (
QCheckBox,
QComboBox,
QLabel,
QDialog,
QFileDialog,
QHBoxLayout,
Expand Down Expand Up @@ -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())

Expand All @@ -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

Expand Down Expand Up @@ -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()
Expand Down
22 changes: 4 additions & 18 deletions python/plugins/processing/modeler/ModelerParametersDialog.py
Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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
Expand All @@ -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():
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3408e02

Please sign in to comment.