#pragma once #include "MedalWinner.h" #include "CompetitorWithResults.h" #include #include #include #include #include #include #include #include #include "EventInfo.h" using namespace std; class SportModel : public QAbstractListModel { Q_OBJECT Q_PROPERTY(QString discipline READ discipline WRITE setDiscipline); 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 roleNames() const override; set getCategories(); QList getCompetitorsByCategory(QString category); // TODO ref instead of obj QList getCompetitorsWithMedal(); // TODO ref instead of obj // filter to change the current competitor list void lastName(QList &competitors); // TODO ref instead of obj void filterByName(QList &competitors, QString name); // TODO ref instead of obj void filterByCountry(QList &competitors, QString nocShort); // TODO ref instead of obj // sort functions to change the order of the current competitor list void sortByName(QList &competitors); // TODO ref instead of obj void sortByCountry(QList &competitors); // TODO ref instead of obj void sortByResult(QList &competitors); // TODO ref instead of obj void sortByMedals(QList &competitors); // TODO ref instead of obj void reverseOrder(QList &competitors); // TODO ref instead of obj // statistic function void addRelativeToFirst(QList &competitors); // TODO ref instead of obj QString discipline() const; void setDiscipline(const QString &discipline); public slots: void request(QString discipline); void parseData(); private: QList m_sportList; QString m_discipline; QNetworkAccessManager m_networkManager; QNetworkReply *m_reply = nullptr; // data from api QJsonObject o_discipline; bool validateDiscipline(); void filterCompetitors(QList &competitors, QString filter); // TODO ref instead of obj QJsonObject createCompetitorWithMedals(QJsonObject medalComp); // function for statistic calculation float calcRelativeStat(QString ref, QString val); };