Fixing ObjectAddOnContactPerson.qml conflict
This commit is contained in:
87
lib/DB/ObjectModel.py
Normal file
87
lib/DB/ObjectModel.py
Normal file
@@ -0,0 +1,87 @@
|
||||
from PySide6.QtCore import QAbstractTableModel, QModelIndex, Qt, Slot, Signal
|
||||
from .ObjectDAO import ObjectDAO
|
||||
from ..PyqcrmFlags import PyqcrmFlags, PyqcrmAppliEmpyFlags
|
||||
from ..ConfigLoader import ConfigLoader
|
||||
import re
|
||||
import json
|
||||
|
||||
class ObjectModel(QAbstractTableModel):
|
||||
objectAdded = Signal(bool)
|
||||
|
||||
__data = None
|
||||
__object_dao = None
|
||||
__visible_index = None
|
||||
__visible_columns = None
|
||||
__col_name = ""
|
||||
__employee_dao = None
|
||||
__col_skip = 2
|
||||
__everyone = True
|
||||
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.__object_dao = ObjectDAO()
|
||||
self.__object_dao.newObjectAdded.connect(self.__refreshView)
|
||||
self.__conf = ConfigLoader().getConfig()
|
||||
self.__key = self.__conf['pyqcrm']['ENCRYPTION_KEY']
|
||||
self.__object_dao.newObjectAdded.connect(self.objectAdded)
|
||||
self.__getData()
|
||||
|
||||
@Slot(dict, list, bool)
|
||||
def addObject(self, new_object, new_objcontact = None, new_contact = False):
|
||||
print(new_object)
|
||||
|
||||
print(new_objcontact)
|
||||
|
||||
self.__object_dao.addObject(new_object, new_objcontact, self.__key)
|
||||
|
||||
# @Slot(str)
|
||||
# def viewCriterion(self, criterion, processed = False, fired = False):
|
||||
# self.__getData(criterion, processed, fired)
|
||||
|
||||
@Slot()
|
||||
def __refreshView(self):
|
||||
self.__getData()
|
||||
|
||||
def __getData(self, criterion = "Alle"):
|
||||
self.beginResetModel()
|
||||
rows, self.__visible_columns = self.__object_dao.getObjects(criterion, self.__key)
|
||||
self.__data = rows
|
||||
self.endResetModel()
|
||||
|
||||
def rowCount(self, parent= QModelIndex()):
|
||||
return len (self.__data)
|
||||
|
||||
def columnCount(self, parent= QModelIndex()):
|
||||
return len(self.__visible_columns) - self.__col_skip
|
||||
|
||||
@Slot(str)
|
||||
def viewCriterion(self, criterion):
|
||||
self.__getData(criterion)
|
||||
|
||||
def data(self, index, role= Qt.DisplayRole):
|
||||
if role == Qt.DisplayRole:
|
||||
row = self.__data[index.row()]
|
||||
applicant_col = index.column() + self.__col_skip
|
||||
tr = row[applicant_col] #if type(row[index.column() + 2]) is str else str(row[index.column() + 2], "utf-8")
|
||||
#print(f"Data: {tr}")
|
||||
# return row[index.column() + 2]
|
||||
return tr
|
||||
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 + self.__col_skip]
|
||||
return self.__col_name
|
||||
return super().headerData(section, orientation, role)
|
||||
|
||||
@Slot(int)
|
||||
def onRowClicked(self, row):
|
||||
#print(self.__data)
|
||||
print(f"Selected table row: {row}, corresponding DB ID: {self.__data[row][0]}")
|
||||
#if not self.__employee_dict['employee'] or self.__data[row][0] != self.__employee_dict['employee']['id']:
|
||||
#self.__employee = self.__employee_dao.getEmployee(self.__data[row][0], self.__key)
|
||||
#print(self.__business)
|
||||
#self.__getEmployeeInfo()
|
||||
# self.__getContactInfo()
|
||||
# print(self.__business_dict)
|
||||
Reference in New Issue
Block a user