Skip to content
Permalink
Browse files

[processing] Correctly set default value for matrix parameters

Fixes #18871

(cherry-picked from c68262d)
  • Loading branch information
nyalldawson committed May 3, 2018
1 parent 3a77ba7 commit 0c6a59ec6a9d5d1c4bfe5465bdc7456bfad8d826
@@ -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)

@@ -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)
@@ -532,7 +532,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:
@@ -26,7 +26,10 @@
__revision__ = '$Format:%H$'

from qgis.testing import start_app, unittest
from qgis.core import QgsApplication
from qgis.core import (QgsApplication,
QgsCoordinateReferenceSystem,
QgsProcessingParameterMatrix,
QgsVectorLayer)
from qgis.analysis import QgsNativeAlgorithms

from processing.gui.AlgorithmDialog import AlgorithmDialog
@@ -115,12 +118,34 @@ def testField(self):
def testSource(self):
self.checkConstructWrapper(QgsProcessingParameterFeatureSource('test'), FeatureSourceWidgetWrapper)

def testSource(self):
self.checkConstructWrapper(QgsProcessingParameterBand('test'), BandWidgetWrapper)

def testMapLayer(self):
self.checkConstructWrapper(QgsProcessingParameterMapLayer('test'), MapLayerWidgetWrapper)

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)

def testBand(self):
self.checkConstructWrapper(QgsProcessingParameterBand('test'), BandWidgetWrapper)


if __name__ == '__main__':
unittest.main()

0 comments on commit 0c6a59e

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