Skip to content

Commit

Permalink
[processing] Correctly set default value for matrix parameters
Browse files Browse the repository at this point in the history
Fixes #18871
  • Loading branch information
nyalldawson committed May 1, 2018
1 parent b63733e commit c68262d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
2 changes: 1 addition & 1 deletion python/plugins/processing/gui/FixedTableDialog.py
Expand Up @@ -81,7 +81,7 @@ def populateTable(self, table):
# Populate table
for i in range(rows):
for j in range(cols):
item = QStandardItem(table[i][j])
item = QStandardItem(str(table[i][j]))
model.setItem(i, j, item)
self.tblView.setModel(model)

Expand Down
13 changes: 9 additions & 4 deletions python/plugins/processing/gui/FixedTablePanel.py
Expand Up @@ -56,11 +56,16 @@ def __init__(self, param, parent=None):

self.btnSelect.clicked.connect(self.showFixedTableDialog)

def updateSummaryText(self):
self.leText.setText(self.tr('Fixed table {0}x{1}').format(
len(self.table), len(self.param.headers())))

def setValue(self, value):
self.table = value
self.updateSummaryText()

def showFixedTableDialog(self):
dlg = FixedTableDialog(self.param, self.table)
dlg.exec_()
if dlg.rettable is not None:
self.table = dlg.rettable

self.leText.setText(self.tr('Fixed table {0}x{1}').format(
len(self.table), len(self.param.headers())))
self.setValue(dlg.rettable)
2 changes: 1 addition & 1 deletion python/plugins/processing/gui/wrappers.py
Expand Up @@ -559,7 +559,7 @@ def createWidget(self):
return FixedTablePanel(self.param)

def setValue(self, value):
pass
self.widget.setValue(value)

def value(self):
if self.dialogType == DIALOG_MODELER:
Expand Down
20 changes: 20 additions & 0 deletions python/plugins/processing/tests/GuiTest.py
Expand Up @@ -28,6 +28,7 @@
from qgis.testing import start_app, unittest
from qgis.core import (QgsApplication,
QgsCoordinateReferenceSystem,
QgsProcessingParameterMatrix,
QgsVectorLayer)
from qgis.analysis import QgsNativeAlgorithms

Expand Down Expand Up @@ -158,6 +159,25 @@ def testDistance(self):

widget.deleteLater()

def testMatrix(self):
self.checkConstructWrapper(QgsProcessingParameterMatrix('test'), FixedTableWidgetWrapper)

alg = QgsApplication.processingRegistry().algorithmById('native:centroids')
dlg = AlgorithmDialog(alg)
param = QgsProcessingParameterMatrix('test', 'test', 2, True, ['x', 'y'], [['a', 'b'], ['c', 'd']])
wrapper = FixedTableWidgetWrapper(param, dlg)
widget = wrapper.createWidget()

# check that default value is initially set
self.assertEqual(wrapper.value(), [['a', 'b'], ['c', 'd']])

# test widget
widget.show()
wrapper.setValue([[1, 2], [3, 4]])
self.assertEqual(wrapper.value(), [[1, 2], [3, 4]])

widget.deleteLater()

def testNumber(self):
self.checkConstructWrapper(QgsProcessingParameterNumber('test'), NumberWidgetWrapper)

Expand Down

0 comments on commit c68262d

Please sign in to comment.