Skip to content

Commit 4b35498

Browse files
committedJun 4, 2018
[processing] Matrix parameter values are always 1-dimensional
Fix gui wrapper returns 2-dimensional parameters, which don't match with the expectations of QgsProcessingParameterMatrix
1 parent f85a3d6 commit 4b35498

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed
 

‎python/plugins/processing/gui/FixedTableDialog.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,13 @@
4343
class FixedTableDialog(BASE, WIDGET):
4444

4545
def __init__(self, param, table):
46-
super(FixedTableDialog, self).__init__(None)
46+
"""
47+
Constructor for FixedTableDialog
48+
:param param: linked processing parameter
49+
:param table: initial table contents - squashed to 1-dimensional!
50+
"""
51+
super().__init__(None)
52+
4753
self.setupUi(self)
4854

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

7783
def populateTable(self, table):
7884
cols = len(self.param.headers())
79-
rows = len(table)
85+
rows = len(table) // cols
8086
model = QStandardItemModel(rows, cols)
8187

8288
# Set headers
8389
model.setHorizontalHeaderLabels(self.param.headers())
8490

8591
# Populate table
86-
for i in range(rows):
87-
for j in range(cols):
88-
item = QStandardItem(str(table[i][j]))
89-
model.setItem(i, j, item)
92+
for row in range(rows):
93+
for col in range(cols):
94+
item = QStandardItem(str(table[row * cols + col]))
95+
model.setItem(row, col, item)
9096
self.tblView.setModel(model)
9197

9298
def accept(self):
9399
cols = self.tblView.model().columnCount()
94100
rows = self.tblView.model().rowCount()
101+
# Table MUST BE 1-dimensional to match core QgsProcessingParameterMatrix expectations
95102
self.rettable = []
96-
for i in range(rows):
97-
self.rettable.append(list())
98-
for j in range(cols):
99-
self.rettable[i].append(str(self.tblView.model().item(i, j).text()))
103+
for row in range(rows):
104+
for col in range(cols):
105+
self.rettable.append(str(self.tblView.model().item(row, col).text()))
100106
QDialog.accept(self)
101107

102108
def reject(self):

‎python/plugins/processing/gui/FixedTablePanel.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,12 @@ def __init__(self, param, parent=None):
4949
self.leText.setEnabled(False)
5050

5151
self.param = param
52+
53+
# NOTE - table IS squashed to 1-dimensional!
5254
self.table = []
53-
for i in range(param.numberRows()):
54-
self.table.append(list())
55-
for j in range(len(param.headers())):
56-
self.table[i].append('0')
55+
for row in range(param.numberRows()):
56+
for col in range(len(param.headers())):
57+
self.table.append('0')
5758

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

6364
def updateSummaryText(self):
6465
self.leText.setText(self.tr('Fixed table {0}x{1}').format(
65-
len(self.table), len(self.param.headers())))
66+
len(self.table) // len(self.param.headers()), len(self.param.headers())))
6667

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

0 commit comments

Comments
 (0)
Please sign in to comment.