From 94fb05a764c1d0d1f275f29ecd21686d835f9768 Mon Sep 17 00:00:00 2001 From: Steru Date: Mon, 12 Aug 2024 22:09:50 +0200 Subject: Created Model for competitors. --- src/model/MedalWinner.h | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/model/MedalWinner.h (limited to 'src/model/MedalWinner.h') diff --git a/src/model/MedalWinner.h b/src/model/MedalWinner.h new file mode 100644 index 0000000..e771185 --- /dev/null +++ b/src/model/MedalWinner.h @@ -0,0 +1,35 @@ + +#ifndef ITAT_CHALLANGE_OLYMPICS_MEDALWINNER_H +#define ITAT_CHALLANGE_OLYMPICS_MEDALWINNER_H + +#include "Competitor.h" +#include +#include +#include + +class MedalWinner : public Competitor { + +public: + 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")} + }; + } + + MedalWinner(const QJsonObject &competitor) : Competitor(competitor) { + if (competitor.contains("medals")) throw invalid_argument("Competitor has no medals."); + QJsonObject medals = competitor["medals"].toObject(); + setMedals(medals); + } + + bool setMedals(const QJsonObject &medals); + +private: + QMap wonMedals; + +}; + + +#endif //ITAT_CHALLANGE_OLYMPICS_MEDALWINNER_H -- cgit v1.2.3