diff --git a/Gui/AddCustomer.qml b/Gui/AddCustomer.qml index 5845615..80bb485 100644 --- a/Gui/AddCustomer.qml +++ b/Gui/AddCustomer.qml @@ -95,6 +95,7 @@ ColumnLayout popup.height: 300 popup.y: postcode.y + 5 - (postcode.height * 2) currentIndex: -1 + onCurrentIndexChanged: city.currentIndex = postcode.currentIndex } Label @@ -110,7 +111,12 @@ ColumnLayout editable: true onEditTextChanged: isEmptyField() onCurrentTextChanged: isEmptyField() - model: ["", "MarcosDorf", "OschkarsLand"] + model: am + textRole: "city" + popup.height: 300 + popup.y: postcode.y + 5 - (postcode.height * 2) + currentIndex: -1 + onCurrentIndexChanged: postcode.currentIndex = city.currentIndex } Label diff --git a/lib/ConfigLoader.py b/lib/ConfigLoader.py index 8705c9c..1f0e165 100644 --- a/lib/ConfigLoader.py +++ b/lib/ConfigLoader.py @@ -9,7 +9,7 @@ from urllib.parse import urlparse from .DB.DbManager import DbManager import os from Crypto.Random import get_random_bytes -from base64 import b64encode, b64decode +from base64 import b64encode from .DB.UserManager import UserManager from .PyqcrmFlags import PyqcrmFlags @@ -24,6 +24,7 @@ class ConfigLoader(QObject): dbConnectionError = Signal(str, bool) adminUserError = Signal(str, bool) usernameNotAvailable = Signal() + configurationReady = Signal() def __init__(self): super().__init__() @@ -64,6 +65,9 @@ class ConfigLoader(QObject): self.__config = toml.loads(app_config) self.__saveConfig() conf = self.__checkAdminUser() + if conf: + self.configurationReady.emit() + def __configLoad(self): @@ -95,7 +99,7 @@ class ConfigLoader(QObject): return True else: self.dbConnectionError.emit("Connection fehlgeschlagen", False) - return False + return False def __checkAdminUser(self): con = DbManager().getConnection() @@ -105,9 +109,10 @@ class ConfigLoader(QObject): if not result: #if not result[0][0] == 1: self.adminUserError.emit("Kein Admin vorhanden", False) + return False else: self.adminUserError.emit("Admin vorhanden", True) - + return True @Slot(str) def setEncyrptKey(self, key): diff --git a/lib/DB/AddressModel.py b/lib/DB/AddressModel.py index bb8f870..4478b89 100644 --- a/lib/DB/AddressModel.py +++ b/lib/DB/AddressModel.py @@ -1,6 +1,6 @@ from PySide6.QtCore import QAbstractListModel, Qt, Slot, QModelIndex from .AddressDAO import AddressDAO - +from ..PyqcrmDataRoles import PyqcrmDataRoles class AddressModel(QAbstractListModel): @@ -16,8 +16,17 @@ class AddressModel(QAbstractListModel): if role == Qt.DisplayRole: data= self.__address_data[row][2] return data + elif role == PyqcrmDataRoles.CITY_ROLE: + data= self.__address_data[row][3] + return data return None + def roleNames(self): + return { + Qt.DisplayRole: b"display", + PyqcrmDataRoles.CITY_ROLE: b"city", + } + def setData(self): pass diff --git a/lib/PyqcrmDataRoles.py b/lib/PyqcrmDataRoles.py new file mode 100644 index 0000000..a1d63c3 --- /dev/null +++ b/lib/PyqcrmDataRoles.py @@ -0,0 +1,8 @@ +# This Python file uses the following encoding: utf-8 + +from PySide6.QtCore import Qt +from enum import IntEnum + +class PyqcrmDataRoles(IntEnum): + CITY_ROLE = Qt.UserRole + 1 + diff --git a/main.py b/main.py index 3b69b08..1083e86 100644 --- a/main.py +++ b/main.py @@ -26,6 +26,26 @@ from lib.DB.AddressModel import AddressModel # name="" # type="" +am = None +bm = None +user = None + +def initializeProgram(): + global am, bad_config, bm, user + dbconf = config.getConfig()['database'] + DbManager(dbconf) + bad_config = False + bm = BusinessModel() + user = UserManager() + am = AddressModel() + + publishContext() + +def publishContext(): + global engine + engine.rootContext().setContextProperty("loggedin_user", user) + engine.rootContext().setContextProperty("bm", bm) + engine.rootContext().setContextProperty("am", am) if __name__ == "__main__": #QResource.registerResource("rc_qml.py") @@ -50,21 +70,13 @@ if __name__ == "__main__": if not config.getConfig(): bad_config = True - bm = False + config.configurationReady.connect(initializeProgram) + else: - dbconf = config.getConfig()['database'] - DbManager(dbconf) - bm = BusinessModel() - user = UserManager() - am = AddressModel() + initializeProgram() - #print(con is con2) - - engine.rootContext().setContextProperty("bm", bm) - engine.rootContext().setContextProperty("am", am) engine.rootContext().setContextProperty("bad_config", bad_config) # print(f"Fehler: {i}") engine.rootContext().setContextProperty("config", config) - engine.rootContext().setContextProperty("loggedin_user", user) engine.load(qml_file)