summaryrefslogtreecommitdiff
path: root/src/model/MedalWinner.cpp
diff options
context:
space:
mode:
authorSteru <jerrydream111@gmail.com>2024-08-16 15:39:05 +0200
committerSteru <jerrydream111@gmail.com>2024-08-16 15:59:22 +0200
commit3918de89ce74bea2f18f814edc9accad4af9d818 (patch)
treeb86013c6be31e0f2caec6e00dd9cc82cfa194ad1 /src/model/MedalWinner.cpp
parent66d5d8685f7dcd45b2e9581315c101e69646cd6f (diff)
Fixed constructors.
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);
+}