# This Python file uses the following encoding: utf-8 from PySide6.QtCore import QAbstractTableModel, QModelIndex, Qt, Slot, Signal from .BusinessDAO import BusinessDAO from ..PyqcrmFlags import PyqcrmFlags from ..ConfigLoader import ConfigLoader # USERS TABLE # CUSTOMER_COLUMN_NAMES = \ # { # "userid": "Identification", # "username": "Benutzername", # "password": "Passwort", # "enabled": "Aktiv", # "roleid": "Rolle", # "gecos": "Information" # } # # CUSTOMER_COLUMN_INDEX = \ # { # "userid": 0, # "username": 1, # "password": 2, # "enabled": 3, # "roleid": 4, # "gecos": 5 # } ####################################### # COLS = \ # { # "businessid": "Kundennummer", # "company": "Firma", # "street": "Straße", # "postcodeid": "PLZ", # "phone": "Telefon", # "mobilephone": "Mobil", # "email": "E-Mail", # "homepage": "Homepage", # "director": "Geschäftsführer", # "contactpersonid": "Ansprechpartner", # "info": "Info", # "btid": "Typ", # } # COLS_INDEX = \ # { # "businessid": 0, # "company": 1, # "street": 2, # "postcodeid": 3, # "phone": 4, # "mobilephone": 5, # "email": 6, # "homepage": 7, # "director": 8, # "contactpersonid": 9, # "info": 10, # "btid": 11, # } class BusinessModel(QAbstractTableModel): __visible_index = {} __col_name = "" __business_dao = None def __init__(self): super().__init__() # <<<<<<< HEAD self.__business_dao = BusinessDAO() self.__business_dao.newBusinessAdded.connect(self.__refreshView) self.__conf = ConfigLoader().getConfig() self.__key = self.__conf['pyqcrm']['ENCRYPTION_KEY'] # ======= # self.__key = ConfigLoader().getKey() # >>>>>>> e28c68f (AddCustomer, AddContact finished) self.__getData() def __getData(self, criterion = "Alle"): self.beginResetModel() rows, self.__visible_columns = self.__business_dao.getBusiness(self.__key, criterion) self.__data = rows self.endResetModel() def rowCount(self, parent= QModelIndex()): return len (self.__data) def columnCount(self, parent= QModelIndex()): #return len(self.__visible_columns) - 1 return len(self.__visible_columns) def data(self, index, role= Qt.DisplayRole): if role == Qt.DisplayRole: row = self.__data[index.row()] #return row[index.column() + 1] return row[index.column()] return None def headerData(self, section, orientation, role= Qt.DisplayRole): if orientation == Qt.Horizontal and role ==Qt.DisplayRole: #self.__col_name = self.__visible_columns[section + 1] self.__col_name = self.__visible_columns[section] return self.__col_name return super().headerData(section, orientation, role) ########################NOT READY################################# # @Slot(dict) # def setVisibleColumns(self, cols): # self.__visible_columns.clear() # self.__visible_index.clear() # for col, val in cols.items(): # self.__visible_index[val] = COLS_INDEX[cols[col]] # self.__visible_columns.append(cols[col]) # # self.headerDataChanged.emit() # # self.dataChanged.emit() # self.layoutChanged.emit() ################################################################# @Slot(int) def onRowClicked(self, row): print(f"Selected table row: {row}, corresponding DB ID: {self.__data[row][0]}") @Slot(str) def viewCriterion(self, criterion): self.__getData(criterion) @Slot(dict, int) def addBusiness(self, business, contact_id): BusinessDAO().addBusiness(self.__key, business, contact_id) @Slot() def __refreshView(self): self.__getData() @Slot(dict) def setContact(self, contact): pass def updateTable(self): pass