mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
[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()
This commit is contained in:
parent
1e5fe12d8c
commit
3408e02c46
@ -74,7 +74,6 @@ class ParametersPanel(BASE, WIDGET):
|
||||
self.alg = alg
|
||||
self.wrappers = {}
|
||||
self.outputWidgets = {}
|
||||
self.labels = {}
|
||||
self.checkBoxes = {}
|
||||
self.dependentItems = {}
|
||||
self.iterateButtons = {}
|
||||
@ -108,14 +107,6 @@ class ParametersPanel(BASE, WIDGET):
|
||||
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 @@ class ParametersPanel(BASE, WIDGET):
|
||||
|
||||
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.core import (
|
||||
from qgis.PyQt.QtWidgets import (
|
||||
QCheckBox,
|
||||
QComboBox,
|
||||
QLabel,
|
||||
QDialog,
|
||||
QFileDialog,
|
||||
QHBoxLayout,
|
||||
@ -150,6 +151,7 @@ class WidgetWrapper(QObject):
|
||||
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 @@ class WidgetWrapper(QObject):
|
||||
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 @@ class BasicWidgetWrapper(WidgetWrapper):
|
||||
|
||||
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 @@ class ModelerParametersDialog(QDialog):
|
||||
super(ModelerParametersDialog, self).closeEvent(event)
|
||||
|
||||
def setupUi(self):
|
||||
self.labels = {}
|
||||
self.widgets = {}
|
||||
self.checkBoxes = {}
|
||||
self.showAdvanced = False
|
||||
self.wrappers = {}
|
||||
@ -136,15 +134,6 @@ class ModelerParametersDialog(QDialog):
|
||||
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 @@ class ModelerParametersDialog(QDialog):
|
||||
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 @@ class ModelerParametersDialog(QDialog):
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user