add column header info

This commit is contained in:
Thomas Peetz
2025-01-07 01:48:03 +01:00
parent 78632e0e12
commit 1a7da0ab9f
9 changed files with 289 additions and 225 deletions
+6 -5
View File
@@ -19,7 +19,7 @@ class KontorTableModel(QAbstractTableModel):
cursor = self._config.db_conn.cursor()
cursor.execute(self._config.get_statement())
rows = cursor.fetchall()
print(len(rows))
# print(len(rows))
if len(rows) > 0:
self.beginResetModel()
for row in rows:
@@ -39,7 +39,7 @@ class KontorTableModel(QAbstractTableModel):
def headerData(self, col, orientation, role=Qt.ItemDataRole.DisplayRole):
if orientation == Qt.Orientation.Horizontal and role == Qt.ItemDataRole.DisplayRole:
return self._config.header[col]
return self._config.header[col]['column']
if orientation == Qt.Orientation.Vertical and role == Qt.ItemDataRole.DisplayRole:
return str(col+1)
@@ -48,6 +48,7 @@ class KontorTableModel(QAbstractTableModel):
return None
value = self._data[index.row()][index.column()]
if role == Qt.ItemDataRole.DisplayRole:
# print('{}: {}'.format(value, type(value)))
if isinstance(value, datetime):
return value.strftime("%Y-%m-%d %M:%M:%S")
if isinstance(value, str):
@@ -57,7 +58,7 @@ class KontorTableModel(QAbstractTableModel):
return self._main_window.tick
else:
return self._main_window.cross
return value
return str(value)
if role == Qt.ItemDataRole.DecorationRole:
if isinstance(value, bytes):
# print('{}: {}'.format(value, type(value)))
@@ -69,8 +70,8 @@ class KontorTableModel(QAbstractTableModel):
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())}")
return len(self._config.get_header())
# print(f"Header count: {len(self._config.get_header())}")
return len(self._config.header)
def setData(self, index, value, role=Qt.ItemDataRole.EditRole):
if role == Qt.ItemDataRole.EditRole: