From e2ca009d35308b33869731220aaba0b17ea7c04a Mon Sep 17 00:00:00 2001 From: jopejoe1 Date: Thu, 11 Jul 2024 21:54:27 +0200 Subject: [PATCH 1/3] native: make table nice --- native/AddData.qml | 2 +- native/MainPage.qml | 88 +++++++++++++++++++++++---------------------- 2 files changed, 47 insertions(+), 43 deletions(-) diff --git a/native/AddData.qml b/native/AddData.qml index 1e55c6d..ffe9b2c 100644 --- a/native/AddData.qml +++ b/native/AddData.qml @@ -96,7 +96,7 @@ Window { name: nameT.text, key: keyT.text, amount: parseInt(amountT.text), - group_id: "f7604976-1e3c-49b7-841b-6a4025257c70", + group_id: "ff664d29-68c9-45c2-a6bc-8f378876c90d", }); xhr.send(data); diff --git a/native/MainPage.qml b/native/MainPage.qml index 5844bba..5c23359 100644 --- a/native/MainPage.qml +++ b/native/MainPage.qml @@ -4,6 +4,8 @@ import QtQuick.Layouts 2.15 import QtQuick.Controls 2.15 Rectangle { + visible: true + SystemPalette { id: activeColors; colorGroup: SystemPalette.Active } SystemPalette { id: inactiveColors; colorGroup: SystemPalette.Inactive } SystemPalette { id: disabledColors; colorGroup: SystemPalette.Disabled } @@ -26,44 +28,37 @@ Rectangle { height: 50 color: getColors().midlight - TextField { - anchors { - verticalCenter: s1.verticalCenter - rightMargin: 5 - right: loginB.left + RowLayout { + anchors.fill: parent + spacing: 10 + anchors.margins: 5 + + TextField { + placeholderText: qsTr("Search") + Layout.alignment: Qt.AlignVCenter + Layout.fillWidth: true } - placeholderText: qsTr("Search") - } - - Button { - id: loginB - anchors { - verticalCenter: s1.verticalCenter - rightMargin: 10 - right: s1.right + Button { + text: qsTr("Add License") + Layout.alignment: Qt.AlignVCenter + onClicked: { + // Create and show a new window + var newWindow = newWindowComponent.createObject(null, { authToken: authToken }); + if (newWindow !== null) { + newWindow.show(); + } else { + console.log("Failed to create new window"); + } + } } - text: qsTr("Logout") - onClicked: { - logout(); - } - } - - Button { - text: qsTr("Add License") - anchors { - verticalCenter: s1.verticalCenter - rightMargin: 10 - right: loginB.left - } - onClicked: { - // Create and show a new window - var newWindow = newWindowComponent.createObject(null, { authToken: authToken }); - if (newWindow !== null) { - newWindow.show(); - } else { - console.log("Failed to create new window"); + Button { + id: loginB + text: qsTr("Logout") + Layout.alignment: Qt.AlignVCenter + onClicked: { + logout(); } } } @@ -84,46 +79,55 @@ Rectangle { } ListView { - anchors { - topMargin: 5 - fill: s2 - } + id: listView + anchors.fill: parent clip: true boundsBehavior: Flickable.StopAtBounds - model: apiDataModel - delegate: Item { - width: parent.width + delegate: Rectangle { + width: listView.width height: 50 + color: getColors().button - Row { + RowLayout { + anchors.fill: parent spacing: 10 Text { text: model.name color: getColors().text + Layout.alignment: Qt.AlignVCenter } Text { text: model.key color: getColors().text + Layout.alignment: Qt.AlignVCenter } + Text { text: model.amount color: getColors().text + Layout.alignment: Qt.AlignVCenter } + Text { text: model.start color: getColors().text + Layout.alignment: Qt.AlignVCenter } + Text { text: model.end color: getColors().text + Layout.alignment: Qt.AlignVCenter } + Text { text: model.group color: getColors().text + Layout.alignment: Qt.AlignVCenter } } } From 8a6ba829c0adb807e75747a826a45846cd03550d Mon Sep 17 00:00:00 2001 From: jopejoe1 Date: Thu, 11 Jul 2024 22:02:36 +0200 Subject: [PATCH 2/3] native: add table header --- native/MainPage.qml | 84 ++++++++++++++++++++++----------------------- 1 file changed, 41 insertions(+), 43 deletions(-) diff --git a/native/MainPage.qml b/native/MainPage.qml index 5c23359..13edf46 100644 --- a/native/MainPage.qml +++ b/native/MainPage.qml @@ -74,63 +74,61 @@ Rectangle { } color: getColors().window - ListModel { - id: apiDataModel - } - - ListView { - id: listView + ColumnLayout { anchors.fill: parent - clip: true - boundsBehavior: Flickable.StopAtBounds - model: apiDataModel + spacing: 0 - delegate: Rectangle { - width: listView.width - height: 50 - color: getColors().button + Rectangle { + id: header + color: getColors().midlight + height: 40 + Layout.fillWidth: true RowLayout { anchors.fill: parent spacing: 10 + anchors.margins: 5 - Text { - text: model.name - color: getColors().text - Layout.alignment: Qt.AlignVCenter - } + Text { text: qsTr("Name"); color: getColors().text; Layout.fillWidth: true } + Text { text: qsTr("Key"); color: getColors().text; Layout.fillWidth: true } + Text { text: qsTr("Amount"); color: getColors().text; Layout.fillWidth: true } + Text { text: qsTr("Start"); color: getColors().text; Layout.fillWidth: true } + Text { text: qsTr("End"); color: getColors().text; Layout.fillWidth: true } + Text { text: qsTr("Group"); color: getColors().text; Layout.fillWidth: true } + } + } - Text { - text: model.key - color: getColors().text - Layout.alignment: Qt.AlignVCenter - } + ListView { + id: listView + Layout.fillWidth: true + Layout.fillHeight: true + clip: true + boundsBehavior: Flickable.StopAtBounds + model: apiDataModel - Text { - text: model.amount - color: getColors().text - Layout.alignment: Qt.AlignVCenter - } + delegate: Rectangle { + width: listView.width + height: 50 + color: getColors().button - Text { - text: model.start - color: getColors().text - Layout.alignment: Qt.AlignVCenter - } + RowLayout { + anchors.fill: parent + spacing: 10 + anchors.margins: 5 - Text { - text: model.end - color: getColors().text - Layout.alignment: Qt.AlignVCenter - } - - Text { - text: model.group - color: getColors().text - Layout.alignment: Qt.AlignVCenter + Text { text: model.name; color: getColors().text; Layout.fillWidth: true } + Text { text: model.key; color: getColors().text; Layout.fillWidth: true } + Text { text: model.amount; color: getColors().text; Layout.fillWidth: true } + Text { text: model.start; color: getColors().text; Layout.fillWidth: true } + Text { text: model.end; color: getColors().text; Layout.fillWidth: true } + Text { text: model.group; color: getColors().text; Layout.fillWidth: true } } } } + + ListModel { + id: apiDataModel + } } } From 4306f561a6d972ecd2f138f4a61aadfc23b0d3bd Mon Sep 17 00:00:00 2001 From: jopejoe1 Date: Thu, 11 Jul 2024 22:06:53 +0200 Subject: [PATCH 3/3] native: add search support --- native/MainPage.qml | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/native/MainPage.qml b/native/MainPage.qml index 13edf46..09f918d 100644 --- a/native/MainPage.qml +++ b/native/MainPage.qml @@ -15,6 +15,7 @@ Rectangle { } property string authToken: "" + property string searchText: "" // Property to hold the search text signal logout() @@ -34,9 +35,14 @@ Rectangle { anchors.margins: 5 TextField { + id: searchField placeholderText: qsTr("Search") Layout.alignment: Qt.AlignVCenter Layout.fillWidth: true + onTextChanged: { + searchText = text + filterModel() // Filter model based on search text + } } Button { @@ -104,7 +110,7 @@ Rectangle { Layout.fillHeight: true clip: true boundsBehavior: Flickable.StopAtBounds - model: apiDataModel + model: filteredApiDataModel // Use the filtered model delegate: Rectangle { width: listView.width @@ -129,6 +135,10 @@ Rectangle { ListModel { id: apiDataModel } + + ListModel { + id: filteredApiDataModel + } } } @@ -162,6 +172,7 @@ Rectangle { }); } } + filterModel() // Filter the model after loading data } else { console.log("Error: " + xhr.status); } @@ -169,4 +180,19 @@ Rectangle { } xhr.send(); } + + function filterModel() { + filteredApiDataModel.clear() + for (var i = 0; i < apiDataModel.count; ++i) { + var item = apiDataModel.get(i) + if (item.name.toLowerCase().indexOf(searchText.toLowerCase()) !== -1 || + item.key.toLowerCase().indexOf(searchText.toLowerCase()) !== -1 || + item.amount.toLowerCase().indexOf(searchText.toLowerCase()) !== -1 || + item.start.toLowerCase().indexOf(searchText.toLowerCase()) !== -1 || + item.end.toLowerCase().indexOf(searchText.toLowerCase()) !== -1 || + item.group.toLowerCase().indexOf(searchText.toLowerCase()) !== -1) { + filteredApiDataModel.append(item) + } + } + } }