# This Python file uses the following encoding: utf-8 from PySide6.QtCore import QAbstractTableModel, QModelIndex, Qt, Slot CUSTOMER_COLUMN_NAMES = \ { "userid": "Identification", "username": "Benutzername", "password": "Passwort", "enabled": "Aktiv", "roleid": "Rolle", "gecos": "Information" } class BusinessModel(QAbstractTableModel): def __init__(self, con, cols): super().__init__() self.__con = con self.__visible_columns = cols self.__data = self.__getData() def __getData(self): cursor = self.__con.cursor() cursor.execute("SELECT * FROM users") self.__all_cols = [desc[0] for desc in cursor.description] rows = cursor.fetchall() return rows def rowCount(self, parent= QModelIndex()): return len (self.__data) def columnCount(self, parent= QModelIndex()): return len(self.__visible_columns) def data(self, index, role= Qt.DisplayRole): if role == Qt.DisplayRole: # row = index.row() row = self.__data[index.row()] col_name = self.__visible_columns[index.column()] col_index = self.__all_cols.index(col_name) return row[col_index] return None def headerData(self, section, orientation, role= Qt.DisplayRole): #header= ["ID", "Benutzername", "Passwort", "Information", "Rolle", "Aktiv"] if orientation == Qt.Horizontal and role ==Qt.DisplayRole: #return header[section] col_name = self.__visible_columns[section] return CUSTOMER_COLUMN_NAMES.get(col_name, col_name) return super().headerData(section, orientation, role) #return None @Slot(int) def onRowClicked(self, row): print(row)