Skip to content

Commit

Permalink
also use 1-dimensional table in modeler dialog (follow up 4b35498)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy authored and nyalldawson committed Jun 13, 2018
1 parent 262cee6 commit dcff720
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
34 changes: 16 additions & 18 deletions python/plugins/processing/gui/matrixmodelerwidget.py
Expand Up @@ -103,26 +103,28 @@ def changeHeader(self, index):
self.tblView.model().setHeaderData(index, Qt.Horizontal, txt)

def value(self):
cols = self.tblView.model().columnCount()
rows = self.tblView.model().rowCount()

items = []
model = self.tblView.model()
for i in range(model.rowCount()):
row = []
for j in range(model.columnCount()):
item = model.item(i, j)
row.append(item.text())
items.append(row)
for row in range(rows):
for col in range(cols):
items.append(str(self.tblView.model().item(row, col).text()))

return items

def setValue(self, table):
cols = len(table[0])
rows = len(table)
def setValue(self, headers, table):
model = self.tblView.model()
model.setHorizontalHeaderLabels(headers)

cols = len(headers)
rows = len(table) // cols
model = QStandardItemModel(rows, cols)

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 headers(self):
Expand All @@ -133,10 +135,6 @@ def headers(self):

return headers

def setHeaders(self, headers):
model = self.tblView.model()
model.setHorizontalHeaderLabels(headers)

def fixedRows(self):
return self.chkFixedRows.isChecked()

Expand Down
Expand Up @@ -294,8 +294,7 @@ def setupUi(self):
isinstance(self.param, QgsProcessingParameterMatrix):
self.widget = MatrixModelerWidget(self)
if self.param is not None:
self.widget.setValue(self.param.defaultValue())
self.widget.setHeaders(self.param.headers())
self.widget.setValue(self.param.headers(), self.param.defaultValue())
self.widget.setFixedRows(self.param.hasFixedNumberRows())
self.verticalLayout.addWidget(self.widget)

Expand Down

0 comments on commit dcff720

Please sign in to comment.