From b869b8983656b12f9dee59439acfb6b3db647b72 Mon Sep 17 00:00:00 2001 From: Steru Date: Thu, 15 Aug 2024 23:27:54 +0200 Subject: Made Competitor a QObject and tidied up some code. --- src/model/MedalWinner.h | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) (limited to 'src/model/MedalWinner.h') diff --git a/src/model/MedalWinner.h b/src/model/MedalWinner.h index 7f17449..45d1ee8 100644 --- a/src/model/MedalWinner.h +++ b/src/model/MedalWinner.h @@ -9,25 +9,17 @@ #include class MedalWinner : public Competitor { - Q_OBJECT - Q_PROPERTY(int gold READ gold NOTIFY nGold) - Q_PROPERTY(int silver READ silver NOTIFY nSilver) - Q_PROPERTY(int bronze READ bronze NOTIFY nBronze) + Q_OBJECT -public: - MedalWinner() : Competitor() { - this->gold = 0; - this->silver = 0; - this->bronze = 0; - } - - MedalWinner(const MedalWinner &medalWinner) : Competitor(medalWinner) { - this->gold = medalWinner.gold; - this->silver = medalWinner.silver; - this->bronze = medalWinner.bronze; - } + Q_PROPERTY(int gold READ m_gold NOTIFY nGold) + Q_PROPERTY(int silver READ m_silver NOTIFY nSilver) + Q_PROPERTY(int bronze READ m_bronze NOTIFY nBronze) +public: + MedalWinner() : Competitor(), m_gold(0), m_silver(0), m_bronze(0) {} + MedalWinner(const MedalWinner &medalWinner) : Competitor(medalWinner), + m_gold(medalWinner.m_gold), m_silver(medalWinner.m_silver), m_bronze(medalWinner.m_bronze) {} MedalWinner(const QJsonObject &competitor) : Competitor(competitor) { if (!competitor.contains("medals")) throw invalid_argument("Competitor has no medals."); QJsonObject medals = competitor["medals"].toObject(); @@ -35,13 +27,13 @@ public: } bool setMedals(const QJsonObject &medals); - int getGold() { return gold; } - int getSilver() { return silver; } - int getBronze() { return bronze; } + int getGold() { return m_gold; } + int getSilver() { return m_silver; } + int getBronze() { return m_bronze; } static bool compare(MedalWinner lComp, MedalWinner rComp); private: - int gold, silver, bronze; + int m_gold, m_silver, m_bronze; }; -- cgit v1.2.3