summaryrefslogtreecommitdiff
path: root/src/model/MedalWinner.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/model/MedalWinner.cpp')
-rw-r--r--src/model/MedalWinner.cpp25
1 files changed, 21 insertions, 4 deletions
diff --git a/src/model/MedalWinner.cpp b/src/model/MedalWinner.cpp
index bdf6ee3..56cfb22 100644
--- a/src/model/MedalWinner.cpp
+++ b/src/model/MedalWinner.cpp
@@ -11,12 +11,12 @@ bool MedalWinner::setMedals(const QJsonObject &medals) {
if (!medals.contains("ME_GOLD")
|| !medals.contains("ME_SILVER")
|| !medals.contains("ME_BRONZE")) {
- throw invalid_argument("Medal object of competitor is incomplete.");
+ return false;
}
- this->m_gold = medals["ME_GOLD"].toInt();
- this->m_silver = medals["ME_SILVER"].toInt();
- this->m_bronze = medals["ME_BRONZE"].toInt();
+ setGold(medals["ME_GOLD"].toInt());
+ setSilver(medals["ME_SILVER"].toInt());
+ setBronze(medals["ME_BRONZE"].toInt());
return true;
}
@@ -38,3 +38,20 @@ bool MedalWinner::compare(MedalWinner lComp, MedalWinner rComp) {
// compare medal differences
return gold < 0 || (gold == 0 && (silver < 0 || (silver == 0 && bronze < 0)));
}
+
+bool MedalWinner::setMedalWinner(const QJsonObject &competitor) {
+ setCompetitor(competitor);
+
+ if (!competitor.contains("medals")) return false;
+ QJsonObject medals = competitor["medals"].toObject();
+ setMedals(medals);
+ return true;
+}
+
+void MedalWinner::setMedalWinner(const MedalWinner &competitor) {
+ setCompetitor(competitor);
+
+ setGold(competitor.m_gold);
+ setSilver(competitor.m_silver);
+ setBronze(competitor.m_bronze);
+}