diff options
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; }; |