Skip to content
Snippets Groups Projects

#105 Autentiseringstavle viser elementnr for autentisering

Merged Anders H. Rebner requested to merge autentiseringstavle-testelement-linje into master
Files
6
@@ -48,35 +48,48 @@ class CodeTableBase(ModuleBase, QTableWidget, metaclass=Meta):
# Resize table when headline changes
self.cellChanged.connect(
lambda: resize_table(
self,
resize_rows=False,
resize_columns=False,
has_headline=True,
self, rows=False, columns=False, has_headline=True,
)
)
# If parameters are None, generate new table
if size is None and data is None:
self.generate_table()
self.resizeColumnsToContents()
self.insert_headline(self.headline)
self.resizeRowsToContents()
self.insert_headline(self.start_headline)
# Resize height of rows and set size of window
resize_table(self, resize_columns=False, has_headline=True)
resize_table(
self, columns=False, rows=False, has_headline=True,
)
else:
self.setColumnCount(len(data[1]))
self.setRowCount(len(data) - 1) # - 1 to skip headline
self.code_length = data["code_length"]
self.space_interval = data["space_interval"]
self.space_amount = data["space_amount"]
self.code_character_type = data["code_character_type"]
cells = data["cells"]
self.setColumnCount(len(cells[1]))
self.setRowCount(len(cells) - 1) # - 1 to skip headline
# Set cell-items
for i in range(self.rowCount()):
for j in range(self.columnCount()):
item = QTableWidgetItem(data[i + 1][j]) # +1 skip headline
item.setTextAlignment(Qt.AlignCenter)
item = QTableWidgetItem(
cells[i + 1][j]
) # +1 skip headline
if j == 2 and self.type == AUTHENTICATIONBOARD_MODULE:
item.setTextAlignment(Qt.AlignLeft | Qt.AlignVCenter)
else:
item.setTextAlignment(Qt.AlignCenter)
self.setItem(i, j, item)
self.resizeColumnsToContents()
self.insert_headline(data[0])
self.resizeRowsToContents()
self.insert_headline(cells[0])
resize_table(self, resize_columns=False, has_headline=True)
resize_table(
self, columns=False, rows=False, has_headline=True,
)
self.setFixedWidth(size["width"])
self.setFixedHeight(size["height"])
@@ -112,13 +125,13 @@ class CodeTableBase(ModuleBase, QTableWidget, metaclass=Meta):
Parameters
----------
text : string, optional
The headline text, self.headline is used if None,
The headline text, self.start_headline is used if None,
by default None.
"""
headline = self.headline if text is None else text
headline = self.start_headline if text is None else text
item_headline = QTableWidgetItem(headline)
item_headline.setTextAlignment(Qt.AlignHCenter)
item_headline.setTextAlignment(Qt.AlignCenter)
item_headline.setFont(HEADLINE_FONT)
self.insertRow(0)
@@ -200,16 +213,26 @@ class CodeTableBase(ModuleBase, QTableWidget, metaclass=Meta):
List[0] contains headline,
list[x][y] represents value of row x, column y.
"""
data = []
cells = []
item_headline = self.item(0, 0)
if item_headline is not None:
data.append(item_headline.text())
cells.append(item_headline.text())
else:
cells.append("")
for i in range(1, self.rowCount()):
row = []
for j in range(self.columnCount()):
row.append(self.item(i, j).text())
data.append(row)
cells.append(row)
data = {
"cells": cells,
"code_length": self.code_length,
"space_interval": self.space_interval,
"space_amount": self.space_amount,
"code_character_type": self.code_character_type,
}
return data
Loading