diff options
author | Steru <jerrydream111@gmail.com> | 2024-08-16 16:58:31 +0200 |
---|---|---|
committer | Orangerot <purple@orangerot.dev> | 2024-08-26 11:19:38 +0200 |
commit | cd69d722717c5ae40360f7cec22e191aa735b675 (patch) | |
tree | 1fa6b75f3c187aef8b82d0bad53d24805bda9d7c /src/model/SportModel.h | |
parent | fe6a2c883d29613640c5504244ad13af4c1f5fed (diff) |
Integrated Sport class into SportModel class.
Diffstat (limited to 'src/model/SportModel.h')
-rw-r--r-- | src/model/SportModel.h | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/src/model/SportModel.h b/src/model/SportModel.h new file mode 100644 index 0000000..5ad289c --- /dev/null +++ b/src/model/SportModel.h @@ -0,0 +1,88 @@ +#pragma once + +#include "MedalWinner.h" +#include "CompetitorWithResults.h" +#include <QAbstractListModel> +#include <QNetworkAccessManager> +#include <qcontainerfwd.h> +#include <set> + +#include <QJsonObject> +#include <QJsonDocument> +#include <QString> +#include <QList> +#include "EventInfo.h" + +using namespace std; + +class SportModel : public QAbstractListModel +{ + Q_OBJECT + + Q_PROPERTY(QString discipline READ discipline WRITE setDiscipline NOTIFY disciplineChanged); + +public: + enum Role + { + EventName = Qt::UserRole + 1, + Competitors + }; + + explicit SportModel(QObject *parent = nullptr); + + void setDiscipline(QJsonObject discipline) + { + this->o_discipline = QJsonObject(discipline); + } + + virtual int rowCount(const QModelIndex &parent) const override; + virtual QVariant data(const QModelIndex &index, int role) const override; + virtual QHash<int, QByteArray> roleNames() const override; + + set<QString> getCategories(); + QList<CompetitorWithResults*> getCompetitorsByCategory(QString category); // TODO ref instead of obj + QList<MedalWinner*> getCompetitorsWithMedal(); // TODO ref instead of obj + + // filter to change the current competitor list + void lastName(QList<Competitor*> &competitors); // TODO ref instead of obj + void filterByName(QList<Competitor*> &competitors, QString name); // TODO ref instead of obj + void filterByCountry(QList<Competitor*> &competitors, QString nocShort); // TODO ref instead of obj + + // sort functions to change the order of the current competitor list + void sortByName(QList<Competitor*> &competitors); // TODO ref instead of obj + void sortByCountry(QList<Competitor*> &competitors); // TODO ref instead of obj + void sortByResult(QList<CompetitorWithResults*> &competitors); // TODO ref instead of obj + void sortByMedals(QList<MedalWinner*> &competitors); // TODO ref instead of obj + void reverseOrder(QList<Competitor*> &competitors); // TODO ref instead of obj + + // statistic function + void addRelativeToFirst(QList<CompetitorWithResults*> &competitors); // TODO ref instead of obj + + QString discipline() const; + void setDiscipline(const QString &discipline); + +public slots: + void request(QString discipline); + void parseData(); + +signals: + void disciplineChanged(); + +private: + QList<EventInfo *> m_sportList; + QString m_discipline; + QNetworkAccessManager m_networkManager; + QNetworkReply *m_reply = nullptr; + + // data from api + QJsonObject o_discipline; + bool validateDiscipline(); + + void filterCompetitors(QList<Competitor*> &competitors, QString filter); // TODO ref instead of obj + + QJsonObject createCompetitorWithMedals(QJsonObject medalComp); + + // function for statistic calculation + float calcRelativeStat(QString ref, QString val); + +}; |