diff options
author | Steru <jerrydream111@gmail.com> | 2024-08-15 19:21:02 +0200 |
---|---|---|
committer | Steru <jerrydream111@gmail.com> | 2024-08-16 15:48:53 +0200 |
commit | 5f4431e19c0b6c50c7f24ce040bcbcdd40b7a13c (patch) | |
tree | a769254e53716ca2c0a1fde64b2842bc3a6bac13 /src/model/MedalWinner.h | |
parent | 3d19fd72716561a0322ba0acc5c94aac9f161e9d (diff) |
Added Q Object macros.
Diffstat (limited to 'src/model/MedalWinner.h')
-rw-r--r-- | src/model/MedalWinner.h | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/src/model/MedalWinner.h b/src/model/MedalWinner.h index e771185..99ca1a3 100644 --- a/src/model/MedalWinner.h +++ b/src/model/MedalWinner.h @@ -7,27 +7,43 @@ #include <QJsonObject> #include <stdexcept> +#include <QAbstractListModel> + class MedalWinner : public Competitor { + Q_OBJECT + + Q_PROPERTY(int gold READ gold) + Q_PROPERTY(int silver READ silver) + Q_PROPERTY(int bronze READ bronze) public: + MedalWinner() : Competitor() { + this->gold = 0; + this->silver = 0; + this->bronze = 0; + } + MedalWinner(const MedalWinner &medalWinner) : Competitor(medalWinner) { - this->wonMedals = { - {QString("ME_GOLD"), medalWinner.wonMedals.value("ME_GOLD")}, - {QString("ME_SILVER"), medalWinner.wonMedals.value("ME_SILVER")}, - {QString("ME_BRONZE"), medalWinner.wonMedals.value("ME_BRONZE")} - }; + this->gold = medalWinner.gold; + this->silver = medalWinner.silver; + this->bronze = medalWinner.bronze; } MedalWinner(const QJsonObject &competitor) : Competitor(competitor) { - if (competitor.contains("medals")) throw invalid_argument("Competitor has no medals."); + if (!competitor.contains("medals")) throw invalid_argument("Competitor has no medals."); QJsonObject medals = competitor["medals"].toObject(); setMedals(medals); } bool setMedals(const QJsonObject &medals); + int getGold() { return gold; } + int getSilver() { return silver; } + int getBronze() { return bronze; } + + static bool compare(MedalWinner lComp, MedalWinner rComp); private: - QMap<QString, QString> wonMedals; + int gold, silver, bronze; }; |