summaryrefslogtreecommitdiff
path: root/src/model/MedalWinner.h
blob: 45d1ee8e39aba3b89b7e8722de859b9a5b5ae64c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39

#pragma once

#include "Competitor.h"
#include <QMap>
#include <QJsonObject>
#include <stdexcept>

#include <QAbstractListModel>

class MedalWinner : public Competitor {

     Q_OBJECT

     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();
        setMedals(medals);
    }

    bool setMedals(const QJsonObject &medals);
    int getGold() { return m_gold; }
    int getSilver() { return m_silver; }
    int getBronze() { return m_bronze; }

    static bool compare(MedalWinner lComp, MedalWinner rComp);

private:
    int m_gold, m_silver, m_bronze;

};