Skip to content
Permalink
Browse files

[processing] Matrix parameter values are always 1-dimensional

Fix gui wrapper returns 2-dimensional parameters, which don't
match with the expectations of QgsProcessingParameterMatrix
  • Loading branch information
nyalldawson committed Jun 4, 2018
1 parent f85a3d6 commit 4b354984e8f5d9ad904d5250f7db452f1f9af780
Showing with 22 additions and 15 deletions.
  1. +16 −10 python/plugins/processing/gui/FixedTableDialog.py
  2. +6 −5 python/plugins/processing/gui/FixedTablePanel.py
@@ -43,7 +43,13 @@
class FixedTableDialog(BASE, WIDGET):

def __init__(self, param, table):
super(FixedTableDialog, self).__init__(None)
"""
Constructor for FixedTableDialog
:param param: linked processing parameter
:param table: initial table contents - squashed to 1-dimensional!
"""
super().__init__(None)

self.setupUi(self)

self.tblView.setSelectionBehavior(QAbstractItemView.SelectRows)
@@ -76,27 +82,27 @@ def __init__(self, param, table):

def populateTable(self, table):
cols = len(self.param.headers())
rows = len(table)
rows = len(table) // cols
model = QStandardItemModel(rows, cols)

# Set headers
model.setHorizontalHeaderLabels(self.param.headers())

# Populate table
for i in range(rows):
for j in range(cols):
item = QStandardItem(str(table[i][j]))
model.setItem(i, j, item)
for row in range(rows):
for col in range(cols):
item = QStandardItem(str(table[row * cols + col]))
model.setItem(row, col, item)
self.tblView.setModel(model)

def accept(self):
cols = self.tblView.model().columnCount()
rows = self.tblView.model().rowCount()
# Table MUST BE 1-dimensional to match core QgsProcessingParameterMatrix expectations
self.rettable = []
for i in range(rows):
self.rettable.append(list())
for j in range(cols):
self.rettable[i].append(str(self.tblView.model().item(i, j).text()))
for row in range(rows):
for col in range(cols):
self.rettable.append(str(self.tblView.model().item(row, col).text()))
QDialog.accept(self)

def reject(self):
@@ -49,11 +49,12 @@ def __init__(self, param, parent=None):
self.leText.setEnabled(False)

self.param = param

# NOTE - table IS squashed to 1-dimensional!
self.table = []
for i in range(param.numberRows()):
self.table.append(list())
for j in range(len(param.headers())):
self.table[i].append('0')
for row in range(param.numberRows()):
for col in range(len(param.headers())):
self.table.append('0')

self.leText.setText(
self.tr('Fixed table {0}x{1}').format(param.numberRows(), len(param.headers())))
@@ -62,7 +63,7 @@ def __init__(self, param, parent=None):

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

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

0 comments on commit 4b35498

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