summaryrefslogtreecommitdiff
path: root/src/model/Sport.h
diff options
context:
space:
mode:
authorSteru <jerrydream111@gmail.com>2024-08-15 20:41:08 +0200
committerOrangerot <purple@orangerot.dev>2024-08-26 11:19:38 +0200
commitdf2cd325395886868e64c4d96ba7a959ef7d204e (patch)
tree0917ed288870d4fcba4e8876682aafc4837058d9 /src/model/Sport.h
parent87e9d4aa8b64e4a8262115f678febb241f2ac3d0 (diff)
Reworked Sport class to work with QObjects instead of JSON objects.
Diffstat (limited to 'src/model/Sport.h')
-rw-r--r--src/model/Sport.h179
1 files changed, 91 insertions, 88 deletions
diff --git a/src/model/Sport.h b/src/model/Sport.h
index 6a68570..2ca83a3 100644
--- a/src/model/Sport.h
+++ b/src/model/Sport.h
@@ -1,6 +1,8 @@
#ifndef ITAT_CHALLANGE_OLYMPICS_SPORT_H
#define ITAT_CHALLANGE_OLYMPICS_SPORT_H
+#include "MedalWinner.h"
+#include "CompetitorWithResults.h"
#include <QAbstractListModel>
#include <QNetworkAccessManager>
#include <qcontainerfwd.h>
@@ -9,33 +11,35 @@
#include <QJsonObject>
#include <QJsonDocument>
#include <QString>
+#include <QList>
#include "EventInfo.h"
using namespace std;
-class SportModel : public QAbstractListModel {
+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);
+public:
+ enum Role
+ {
+ EventName = Qt::UserRole + 1,
+ Competitors
+ };
- 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;
+ explicit SportModel(QObject *parent = nullptr);
+ 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;
- QString discipline() const;
- void setDiscipline(const QString &discipline);
- public slots:
- void request(QString discipline);
- void parseData();
+ QString discipline() const;
+ void setDiscipline(const QString &discipline);
+public slots:
+ void request(QString discipline);
+ void parseData();
signals:
void disciplineChanged();
@@ -47,81 +51,80 @@ class SportModel : public QAbstractListModel {
QNetworkReply *m_reply = nullptr;
};
-class Sport {
+class Sport
+{
public:
-
- Sport(QJsonObject discipline) {
- this->discipline = discipline;
- }
-
- set<QString> getCategories();
- QJsonArray getCompetitorsByCategory(QString category);
- QJsonArray getCompetitorsWithMedal();
-
- // filter to change the current competitor array
- void lastName(QJsonArray &competitors);
- void filterByName(QJsonArray &competitors, QString name);
- void filterByCountry(QJsonArray &competitors, QString nocShort);
-
- // sort functions to change the order of the current competitor array
- void sortByName(QJsonArray &competitors);
- void sortByCountry(QJsonArray &competitors);
- void sortByResult(QJsonArray &competitors);
- void reverseOrder(QJsonArray &competitors);
-
- // statistic function(s)
- void addRelativeToFirst(QJsonArray &competitors);
-
- void setDiscipline(QJsonObject discipline) {
- this->discipline = QJsonObject(discipline);
- }
+ Sport(QJsonObject discipline)
+ {
+ this->discipline = discipline;
+ }
+
+ set<QString> getCategories();
+ QList<CompetitorWithResults> getCompetitorsByCategory(QString category);
+ QList<MedalWinner> getCompetitorsWithMedal();
+
+ // filter to change the current competitor array
+ void lastName(QList<Competitor> &competitors);
+ void filterByName(QList<Competitor> &competitors, QString name);
+ void filterByCountry(QList<Competitor> &competitors, QString nocShort);
+
+ // sort functions to change the order of the current competitor array
+ void sortByName(QList<Competitor> &competitors);
+ void sortByCountry(QList<Competitor> &competitors);
+ void sortByResult(QList<CompetitorWithResults> &competitors);
+ void sortByMedals(QList<MedalWinner> &competitors);
+ void reverseOrder(QList<Competitor> &competitors);
+
+ // statistic function(s)
+ void addRelativeToFirst(QList<CompetitorWithResults> &competitors);
+
+ void setDiscipline(QJsonObject discipline)
+ {
+ this->discipline = QJsonObject(discipline);
+ }
private:
-
- /*
- * Analysis of provided competitor objects:
- *
- * Attributes:
- * - code
- * - noc (national olympics comittee)
- * - name (sometimes the country name? mostly the competitors name)
- * - order
- * [- results] (only if the results are out!)
- *
- *
- * Analysis of provided result objects:
- *
- * Attributes:
- * - position
- * - mark
- * - medalType
- * - irk
- * [- winnerLoserTie] (only if provided in the discipline?)
- *
- * Analysis of where to find the medal winners:
- *
- * Search for ... in category name.
- * - "Bronze"
- * - "Gold"
- * - "Final"
- *
- * ! ATTENTION !
- * When searching for "Final" there might be "Final A", "Final B", etc.
- * The results will only be in ONE of these categories!
- * -> which is good... cause then we can count occurences.
- */
- QJsonObject discipline;
-
- void filterCompetitors(QJsonArray &competitors, QString attribute, QString filter);
- void sortCompetitors(QJsonArray &competitors, function<bool (const QJsonValue &left, const QJsonValue &right)> compare);
-
- bool validateDiscipline();
- QJsonObject createCompetitorWithMedals(QJsonObject medalComp);
-
- float calcRelativeStat(QString ref, QString val);
-
+ /*
+ * Analysis of provided competitor objects:
+ *
+ * Attributes:
+ * - code
+ * - noc (national olympics comittee)
+ * - name (sometimes the country name? mostly the competitors name)
+ * - order
+ * [- results] (only if the results are out!)
+ *
+ *
+ * Analysis of provided result objects:
+ *
+ * Attributes:
+ * - position
+ * - mark
+ * - medalType
+ * - irk
+ * [- winnerLoserTie] (only if provided in the discipline?)
+ *
+ * Analysis of where to find the medal winners:
+ *
+ * Search for ... in category name.
+ * - "Bronze"
+ * - "Gold"
+ * - "Final"
+ *
+ * ! ATTENTION !
+ * When searching for "Final" there might be "Final A", "Final B", etc.
+ * The results will only be in ONE of these categories!
+ * -> which is good... cause then we can count occurences.
+ */
+ QJsonObject discipline;
+
+ void filterCompetitors(QList<Competitor> &competitors, QString filter);
+
+ bool validateDiscipline();
+ QJsonObject createCompetitorWithMedals(QJsonObject medalComp);
+
+ float calcRelativeStat(QString ref, QString val);
};
-
-#endif
+#endif