From 4c5cd95b85c42b669691dd12d635a72ad6f99645 Mon Sep 17 00:00:00 2001 From: Orangerot Date: Fri, 16 Aug 2024 18:03:26 +0200 Subject: feat(SportFilter): search/filter events from TextField --- CMakeLists.txt | 2 ++ res/gui/EventsPage.qml | 23 ++++++----------------- src/main/main.cpp | 4 ++++ src/model/FilterModel.cpp | 8 ++++++++ src/model/FilterModel.h | 14 ++++++++++++++ 5 files changed, 34 insertions(+), 17 deletions(-) create mode 100644 src/model/FilterModel.cpp create mode 100644 src/model/FilterModel.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 359afe1..0f05bb1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,6 +27,8 @@ qt_add_qml_module(itat_challange_olympics src/model/CompetitorWithResults.h src/model/EventInfo.cpp src/model/EventInfo.h + src/model/FilterModel.cpp + src/model/FilterModel.h src/model/MedalWinner.cpp src/model/MedalWinner.h src/model/Sport.cpp diff --git a/res/gui/EventsPage.qml b/res/gui/EventsPage.qml index ad36d15..33df246 100644 --- a/res/gui/EventsPage.qml +++ b/res/gui/EventsPage.qml @@ -26,10 +26,10 @@ Page { ComboBox { - width: 200 + width: 300 height: 50 - displayText: "Disziplin: " + currentText + displayText: "Discipline: " + currentText model: myListModel textRole: "text" @@ -236,22 +236,11 @@ Page { } } } - ComboBox { - width: 200 + TextField { height: 50 - - displayText: "Sort by: " + currentText - model: ["hu", "hi"] - - } - - ComboBox { width: 200 - height: 50 - - displayText: "Filter: " + currentText - model: ["hu", "hi"] - + placeholderText: "Search" + onTextChanged: filter.setFilterFixedString(text) } } @@ -262,7 +251,7 @@ Page { height: parent.height width: parent.width spacing: 20 - model: sports + model: filter delegate: ItemDelegate { required property string eventName required property list competitors diff --git a/src/main/main.cpp b/src/main/main.cpp index 7f4e9f7..27a4800 100644 --- a/src/main/main.cpp +++ b/src/main/main.cpp @@ -21,6 +21,7 @@ #include // #include #include "../model/Sport.h" +#include "../model/FilterModel.h" int main(int argc, char *argv[]) { @@ -31,7 +32,10 @@ int main(int argc, char *argv[]) SportModel model; model.request("ARC"); + FilterModel filter; + filter.setSourceModel(&model); objectContext->setContextProperty("sports", &model); + objectContext->setContextProperty("filter", &filter); QQmlComponent component(&engine, "qrc:/qt/qml/itat/res/gui/application.qml"); QObject *object = component.create(objectContext); diff --git a/src/model/FilterModel.cpp b/src/model/FilterModel.cpp new file mode 100644 index 0000000..7fe07d6 --- /dev/null +++ b/src/model/FilterModel.cpp @@ -0,0 +1,8 @@ +#include "FilterModel.h" +#include "Sport.h" + +FilterModel::FilterModel(QObject *parent) + : QSortFilterProxyModel(parent) { + setFilterRole(SportModel::Role::EventName); + } + diff --git a/src/model/FilterModel.h b/src/model/FilterModel.h new file mode 100644 index 0000000..0bd1fbb --- /dev/null +++ b/src/model/FilterModel.h @@ -0,0 +1,14 @@ +#include + +#pragma once + +class FilterModel : public QSortFilterProxyModel +{ + Q_OBJECT + +public: + FilterModel(QObject *parent = nullptr); + +private: +}; + -- cgit v1.2.3