Fixed first start configuration load and add city model in add customer

This commit is contained in:
2024-12-07 16:43:55 +01:00
parent 82cbfb8daf
commit 4dfe986111
5 changed files with 56 additions and 16 deletions

View File

@@ -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

View File

@@ -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):
@@ -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):

View File

@@ -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

8
lib/PyqcrmDataRoles.py Normal file
View File

@@ -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

34
main.py
View File

@@ -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)