make tables sortable
This commit is contained in:
@@ -2,6 +2,7 @@ from datetime import datetime
|
||||
|
||||
from PySide6.QtCore import QAbstractTableModel, QModelIndex
|
||||
from PySide6.QtGui import Qt
|
||||
from kontor_schema import ColumnEntry
|
||||
|
||||
from .model_config import KontorModelConfig
|
||||
|
||||
@@ -42,8 +43,9 @@ class KontorTableModel(QAbstractTableModel):
|
||||
return len(self._data)
|
||||
|
||||
def headerData(self, col, orientation, role=Qt.ItemDataRole.DisplayRole):
|
||||
# self.log.info(f"{self._config.header[col]}")
|
||||
if orientation == Qt.Orientation.Horizontal and role == Qt.ItemDataRole.DisplayRole:
|
||||
return self._config.header[col]['label']
|
||||
return self._config.header[col][ColumnEntry.COLUMN_LABEL]
|
||||
if orientation == Qt.Orientation.Vertical and role == Qt.ItemDataRole.DisplayRole:
|
||||
return str(col+1)
|
||||
|
||||
@@ -52,27 +54,32 @@ class KontorTableModel(QAbstractTableModel):
|
||||
return None
|
||||
value = self._data[index.row()][index.column()]
|
||||
# print('{}:: {}:: {}: {}'.format(index, role, value, type(value)))
|
||||
row = index.row()
|
||||
column = index.column()
|
||||
column_type = self._config.header[column][ColumnEntry.COLUMN_TYPE]
|
||||
# self.log.info(f"{row}-{column}: {column_type}")
|
||||
if role == Qt.ItemDataRole.DisplayRole or role == Qt.ItemDataRole.EditRole:
|
||||
if column_type == "BOOLEAN":
|
||||
if isinstance(value, bytes):
|
||||
if value == b'\x01':
|
||||
return self._config.main_window.tick
|
||||
else:
|
||||
return self._config.main_window.cross
|
||||
if isinstance(value, int):
|
||||
# print('{}:: {}: {}'.format(index, value, type(value)))
|
||||
if value == 1:
|
||||
return self._config.main_window.tick
|
||||
else:
|
||||
return self._config.main_window.cross
|
||||
if isinstance(value, bool):
|
||||
if value:
|
||||
return self._config.main_window.tick
|
||||
else:
|
||||
return self._config.main_window.cross
|
||||
if isinstance(value, datetime):
|
||||
return value.strftime("%Y-%m-%d %M:%M:%S")
|
||||
if isinstance(value, str):
|
||||
return value
|
||||
if isinstance(value, bytes):
|
||||
if value == b'\x01':
|
||||
return self._config.main_window.tick
|
||||
else:
|
||||
return self._config.main_window.cross
|
||||
if isinstance(value, int):
|
||||
# print('{}:: {}: {}'.format(index, value, type(value)))
|
||||
if value == 1:
|
||||
return self._config.main_window.tick
|
||||
else:
|
||||
return self._config.main_window.cross
|
||||
if isinstance(value, bool):
|
||||
if value:
|
||||
return self._config.main_window.tick
|
||||
else:
|
||||
return self._config.main_window.cross
|
||||
return str(value)
|
||||
if role == Qt.ItemDataRole.DecorationRole:
|
||||
if isinstance(value, bytes):
|
||||
|
||||
Reference in New Issue
Block a user