diff options
author | Steru <jerrydream111@gmail.com> | 2024-08-12 22:09:50 +0200 |
---|---|---|
committer | Steru <jerrydream111@gmail.com> | 2024-08-12 22:09:50 +0200 |
commit | 94fb05a764c1d0d1f275f29ecd21686d835f9768 (patch) | |
tree | 283d60ee309ca35132c3cd64b55d018cc2cbfc87 /src/model/MedalWinner.h | |
parent | c539242efa11538e5e3f91bf3ff2f0de1c526bed (diff) |
Created Model for competitors.
Diffstat (limited to 'src/model/MedalWinner.h')
-rw-r--r-- | src/model/MedalWinner.h | 35 |
1 files changed, 35 insertions, 0 deletions
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 <QMap> +#include <QJsonObject> +#include <stdexcept> + +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<QString, QString> wonMedals; + +}; + + +#endif //ITAT_CHALLANGE_OLYMPICS_MEDALWINNER_H |