feat(SportFilter): search/filter events from TextField
This commit is contained in:
parent
f87bc73c3f
commit
4c5cd95b85
|
@ -27,6 +27,8 @@ qt_add_qml_module(itat_challange_olympics
|
||||||
src/model/CompetitorWithResults.h
|
src/model/CompetitorWithResults.h
|
||||||
src/model/EventInfo.cpp
|
src/model/EventInfo.cpp
|
||||||
src/model/EventInfo.h
|
src/model/EventInfo.h
|
||||||
|
src/model/FilterModel.cpp
|
||||||
|
src/model/FilterModel.h
|
||||||
src/model/MedalWinner.cpp
|
src/model/MedalWinner.cpp
|
||||||
src/model/MedalWinner.h
|
src/model/MedalWinner.h
|
||||||
src/model/Sport.cpp
|
src/model/Sport.cpp
|
||||||
|
|
|
@ -26,10 +26,10 @@ Page {
|
||||||
|
|
||||||
|
|
||||||
ComboBox {
|
ComboBox {
|
||||||
width: 200
|
width: 300
|
||||||
height: 50
|
height: 50
|
||||||
|
|
||||||
displayText: "Disziplin: " + currentText
|
displayText: "Discipline: " + currentText
|
||||||
model: myListModel
|
model: myListModel
|
||||||
textRole: "text"
|
textRole: "text"
|
||||||
|
|
||||||
|
@ -236,22 +236,11 @@ Page {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ComboBox {
|
TextField {
|
||||||
width: 200
|
|
||||||
height: 50
|
height: 50
|
||||||
|
|
||||||
displayText: "Sort by: " + currentText
|
|
||||||
model: ["hu", "hi"]
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
ComboBox {
|
|
||||||
width: 200
|
width: 200
|
||||||
height: 50
|
placeholderText: "Search"
|
||||||
|
onTextChanged: filter.setFilterFixedString(text)
|
||||||
displayText: "Filter: " + currentText
|
|
||||||
model: ["hu", "hi"]
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -262,7 +251,7 @@ Page {
|
||||||
height: parent.height
|
height: parent.height
|
||||||
width: parent.width
|
width: parent.width
|
||||||
spacing: 20
|
spacing: 20
|
||||||
model: sports
|
model: filter
|
||||||
delegate: ItemDelegate {
|
delegate: ItemDelegate {
|
||||||
required property string eventName
|
required property string eventName
|
||||||
required property list<string> competitors
|
required property list<string> competitors
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
// #include <iostream>
|
// #include <iostream>
|
||||||
#include "../model/Sport.h"
|
#include "../model/Sport.h"
|
||||||
|
#include "../model/FilterModel.h"
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
@ -31,7 +32,10 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
SportModel model;
|
SportModel model;
|
||||||
model.request("ARC");
|
model.request("ARC");
|
||||||
|
FilterModel filter;
|
||||||
|
filter.setSourceModel(&model);
|
||||||
objectContext->setContextProperty("sports", &model);
|
objectContext->setContextProperty("sports", &model);
|
||||||
|
objectContext->setContextProperty("filter", &filter);
|
||||||
|
|
||||||
QQmlComponent component(&engine, "qrc:/qt/qml/itat/res/gui/application.qml");
|
QQmlComponent component(&engine, "qrc:/qt/qml/itat/res/gui/application.qml");
|
||||||
QObject *object = component.create(objectContext);
|
QObject *object = component.create(objectContext);
|
||||||
|
|
8
src/model/FilterModel.cpp
Normal file
8
src/model/FilterModel.cpp
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
#include "FilterModel.h"
|
||||||
|
#include "Sport.h"
|
||||||
|
|
||||||
|
FilterModel::FilterModel(QObject *parent)
|
||||||
|
: QSortFilterProxyModel(parent) {
|
||||||
|
setFilterRole(SportModel::Role::EventName);
|
||||||
|
}
|
||||||
|
|
14
src/model/FilterModel.h
Normal file
14
src/model/FilterModel.h
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
#include <QSortFilterProxyModel>
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
class FilterModel : public QSortFilterProxyModel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
FilterModel(QObject *parent = nullptr);
|
||||||
|
|
||||||
|
private:
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in a new issue