Refactor GUI to use Multi Document Interface

This commit is contained in:
Thomas Peetz
2025-01-21 20:12:50 +01:00
parent 4e884fdbe5
commit e8660faa06
5 changed files with 122 additions and 68 deletions
+23 -19
View File
@@ -13,8 +13,13 @@ class KontorTableModel(QAbstractTableModel):
self._main_window = model_config.main_window
self._config = model_config
self._data = []
self.log = model_config.log
def __str__(self):
return f"KontorTableModel({self._config})"
def refresh(self):
# self.log.info("refresh")
data = self._config.get_data()
count = 0
# print(data)
@@ -27,9 +32,10 @@ class KontorTableModel(QAbstractTableModel):
# print(data)
# print(self._data)
self.layoutChanged.emit()
self._main_window.statusBar.showMessage(f"{count} Einträge geladen", 3000)
self._main_window.update_status(f"{count} Einträge geladen")
def rowCount(self, parent=QModelIndex()):
# self.log.info("rowCount %s: %d", self, len(self._data))
# The length of the outer list.
if self._data is None:
return 0
@@ -53,53 +59,51 @@ class KontorTableModel(QAbstractTableModel):
return value
if isinstance(value, bytes):
if value == b'\x01':
return self._main_window.tick
return self._config.main_window.tick
else:
return self._main_window.cross
return self._config.main_window.cross
if isinstance(value, int):
# print('{}:: {}: {}'.format(index, value, type(value)))
if value == 1:
return self._main_window.tick
return self._config.main_window.tick
else:
return self._main_window.cross
return self._config.main_window.cross
if isinstance(value, bool):
if value:
return self._main_window.tick
return self._config.main_window.tick
else:
return self._main_window.cross
return self._config.main_window.cross
return str(value)
if role == Qt.ItemDataRole.DecorationRole:
if isinstance(value, bytes):
if value == b'\x01':
return self._main_window.tick
return self._config.main_window.tick
else:
return self._main_window.cross
return self._config.main_window.cross
if isinstance(value, int):
if value == 1:
return self._main_window.tick
return self._config.main_window.tick
else:
return self._main_window.cross
return self._config.main_window.cross
if isinstance(value, bool):
if value:
return self._main_window.tick
return self._config.main_window.tick
else:
return self._main_window.cross
return self._config.main_window.cross
def columnCount(self, index=QModelIndex()):
# The following takes the first sub-list, and returns
# the length (only works if all rows are an equal length)
# print(f"Header count: {len(self._config.get_header())}")
# self.log.info("rowCount %s: %d", self, len(self._config.header))
return len(self._config.header)
def setData(self, index, value, role: int) -> bool:
print(index, role)
# print(index, role)
if role == Qt.ItemDataRole.EditRole:
self._data[index.row()][index.column()] = value
print(self._data[index.row()][index.column()])
# print(self._data[index.row()][index.column()])
self.dataChanged.emit(index, index)
return True
if role == Qt.ItemDataRole.CheckStateRole:
print("role == Qt.ItemDataRole.CheckStateRole")
# print("role == Qt.ItemDataRole.CheckStateRole")
checked = value == Qt.CheckState.Checked
self._data[index.row()][index.column()] = checked
return False