diff --git a/python/plugins/processing/gui/FixedTableDialog.py b/python/plugins/processing/gui/FixedTableDialog.py index 5d481f24f48..1b1f9e3efe5 100644 --- a/python/plugins/processing/gui/FixedTableDialog.py +++ b/python/plugins/processing/gui/FixedTableDialog.py @@ -81,7 +81,7 @@ class FixedTableDialog(BASE, WIDGET): # 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) diff --git a/python/plugins/processing/gui/FixedTablePanel.py b/python/plugins/processing/gui/FixedTablePanel.py index b5597da2725..52a8225512f 100644 --- a/python/plugins/processing/gui/FixedTablePanel.py +++ b/python/plugins/processing/gui/FixedTablePanel.py @@ -56,11 +56,16 @@ class FixedTablePanel(BASE, WIDGET): 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) diff --git a/python/plugins/processing/gui/wrappers.py b/python/plugins/processing/gui/wrappers.py index 0e3193bc267..6b66e823d10 100755 --- a/python/plugins/processing/gui/wrappers.py +++ b/python/plugins/processing/gui/wrappers.py @@ -559,7 +559,7 @@ class FixedTableWidgetWrapper(WidgetWrapper): return FixedTablePanel(self.param) def setValue(self, value): - pass + self.widget.setValue(value) def value(self): if self.dialogType == DIALOG_MODELER: diff --git a/python/plugins/processing/tests/GuiTest.py b/python/plugins/processing/tests/GuiTest.py index 61de8d33096..e6231636d8e 100644 --- a/python/plugins/processing/tests/GuiTest.py +++ b/python/plugins/processing/tests/GuiTest.py @@ -28,6 +28,7 @@ __revision__ = '$Format:%H$' from qgis.testing import start_app, unittest from qgis.core import (QgsApplication, QgsCoordinateReferenceSystem, + QgsProcessingParameterMatrix, QgsVectorLayer) from qgis.analysis import QgsNativeAlgorithms @@ -158,6 +159,25 @@ class WrappersTest(unittest.TestCase): 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)