diff --git a/gui/CustomerTables.qml b/gui/CustomerTables.qml index d1653bb..27d6064 100644 --- a/gui/CustomerTables.qml +++ b/gui/CustomerTables.qml @@ -7,7 +7,7 @@ import Qt.labs.qmlmodels Item { - + property var availableFilters: ["Name", "Adresse", "PLZ", "Ort"] SearchBar { id:searchBar @@ -57,119 +57,48 @@ Item { text: qsTr("Erledigt") } + } - TableView { + HorizontalHeaderView + { + id: horizontalHeader + Layout.fillWidth: true + + syncView: testTable + + } + TableView + { id: testTable Layout.fillHeight: true Layout.fillWidth: true - columnSpacing: 10 + + columnSpacing: 1 rowSpacing: 2 - model: TableModel { - TableModelColumn { display: "checked" } - TableModelColumn { display: "amount" } - TableModelColumn { display: "fruitType" } - TableModelColumn { display: "fruitName" } - TableModelColumn { display: "fruitPrice" } + model: dbm + delegate:Item + { + implicitWidth: 200 + implicitHeight: 25 - - rows: [ - { - checked: "checked", - amount: "amount", - fruitType: "Fruittype", - fruitName: "fruitName", - fruitPrice: "Price" - }, - { - checked: true, - amount: 2, - fruitType: "Fruittype", - fruitName: "blabla", - fruitPrice: 1.50 - }, - - { - - checked: true, - amount: 1, - fruitType: "Apple", - fruitName: "Granny Smith", - fruitPrice: 1.50 - }, - { - checked: "true", - amount: 4, - fruitType: "Orange", - fruitName: "Navel", - fruitPrice: 2.50 - }, - { - checked: "false", - amount: 1, - fruitType: "Banana", - fruitName: "Cavendish", - fruitPrice: 3.50 - } - ] + Text + { + Layout.fillWidth: true + text: model.display } + MouseArea + { + anchors.fill: parent + onClicked: dbm.onRowClicked(row) + } + } - delegate: DelegateChooser { - DelegateChoice { - column: 0 - delegate: Text { + } - text: model.display - //selectByMouse: true - //implicitWidth: 140 - //onVisibleChanged: model.display = "checked" - } - } - DelegateChoice { - column: 1 - delegate: Text { - - text: model.display - //selectByMouse: true - //implicitWidth: 140 - //onVisibleChanged: model.display = "amount" - //onLinkHovered: model.display = checked - } - } - DelegateChoice { - column: 2 - delegate: Text { - - text: model.display - //selectByMouse: true - //implicitWidth: 140 - //model.display : "fruitType" - } - } - DelegateChoice { - column: 3 - delegate: Text { - - text: model.display - //selectByMouse: true - //implicitWidth: 140 - //onVisibleChanged: model.display = "fruitName" - } - } - DelegateChoice { - column: 4 - delegate: Text { - - text: model.display - //selectByMouse: true - //implicitWidth: 140 - //onVisibleChanged: model.display = "fruitPrice" - } - } - } } Item { Layout.fillHeight: true @@ -179,3 +108,4 @@ Item { } + diff --git a/gui/SearchBar.qml b/gui/SearchBar.qml index 2eddb5e..b4e8c76 100644 --- a/gui/SearchBar.qml +++ b/gui/SearchBar.qml @@ -1,5 +1,6 @@ import QtQuick import QtQuick.Controls +import QtQuick.Layouts Item @@ -15,10 +16,6 @@ Item width: 300 - - - - Button { icon.source: "../images/search.svg" @@ -31,13 +28,57 @@ Item } Button { + id: filterBtn icon.source: "../images/filter.svg" icon.color: "olive" anchors.left: searchField.right height: searchField.height flat: true + onClicked: filterPopup.open() + + + } + Popup + { + id: filterPopup + x: filterBtn.x + filterBtn.width + y: filterBtn.y + width: 100 + height: 150 + modal: true + focus: true + closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutsideParent + contentItem: Item + { + + ColumnLayout + { + anchors.fill: parent + //id: filterContent + + Repeater + { + model: availableFilters + CheckBox + { + text: model.modelData + onClicked: + { + setFilter(text, checkState) + } + } + + } + } + } + } + function setFilter(filter,activated) + { + console.log(filter) + console.log(activated) } + } diff --git a/lib/DataBase.py b/lib/DataBase.py new file mode 100644 index 0000000..1063482 --- /dev/null +++ b/lib/DataBase.py @@ -0,0 +1,44 @@ +# This Python file uses the following encoding: utf-8 +import sys +import os +import sqlite3 +from PySide6.QtCore import QAbstractTableModel, QModelIndex, Qt, Slot + + + + +class DataBase(QAbstractTableModel): + + def __init__(self, con): + super().__init__() + self.con = con + self.__data = self.__getData() + + def __getData(self): + cursor = self.con.cursor() + cursor.execute("SELECT * FROM test") + return cursor.fetchall() + + def rowCount(self, parent= QModelIndex()): + return len (self.__data) + + def columnCount(self, parent= QModelIndex()): + return 3 + + def data(self, index, role= Qt.DisplayRole): + if role == Qt.DisplayRole: + row, col = index.row(), index.column() + return self.__data[row][col] + return None + + def headerData(self, section, orientation, role= Qt.DisplayRole): + header= ["ID", "Kundenname", "Ort"] + if orientation == Qt.Horizontal and role ==Qt.DisplayRole: + return header[section] + return super().headerData(section, orientation, role) + #return None + + @Slot(int) + def onRowClicked(self, row): + print(row) + diff --git a/main.py b/main.py index 96982fb..be59c81 100644 --- a/main.py +++ b/main.py @@ -4,7 +4,8 @@ from pathlib import Path from PySide6.QtGui import QGuiApplication from PySide6.QtQml import QQmlApplicationEngine from lib.ConfigLoader import ConfigLoader - +from lib.DataBase import DataBase +import sqlite3 # [pyqcrm] # program-name="" @@ -17,7 +18,18 @@ from lib.ConfigLoader import ConfigLoader # password="" # name="" # type="" - +def testConnection(): + connection= sqlite3.connect(":memory:") + cur= connection.cursor() + cur.execute("CREATE TABLE test(id INTEGER primary key, Kundenname TEXT, Ort TEXT)") + cur.execute(""" + INSERT INTO test VALUES + (1, 'Gruva', 'Dusseldorf'), + (2, 'Teroteroterotero', 'Krefeld'), + (3, 'Blabla','Paris') + """) + connection.commit() + return connection @@ -32,10 +44,13 @@ if __name__ == "__main__": config = ConfigLoader() + con = testConnection() + dbm = DataBase(con) if not config.getConfig(): bad_config = True + engine.rootContext().setContextProperty("dbm", dbm) engine.rootContext().setContextProperty("bad_config", bad_config) # print(f"Fehler: {i}") engine.rootContext().setContextProperty("config", config) engine.load(qml_file) diff --git a/pyqcrm.pyproject b/pyqcrm.pyproject index dda5c63..fe53c64 100644 --- a/pyqcrm.pyproject +++ b/pyqcrm.pyproject @@ -11,6 +11,7 @@ "gui/TopBar.qml", "gui/CustomerTables.qml", "gui/SearchBar.qml", - "gui/test.qml" + "gui/test.qml", + "lib/DataBase.py" ] }