summaryrefslogtreecommitdiff
path: root/src/model/MedalWinner.h
blob: 99ca1a32dcd0455d7d850e59a788d79be7d541f4 (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
40
41
42
43
44
45
46
47
48
49
50
51

#ifndef ITAT_CHALLANGE_OLYMPICS_MEDALWINNER_H
#define ITAT_CHALLANGE_OLYMPICS_MEDALWINNER_H

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

#include <QAbstractListModel>

class MedalWinner : public Competitor {
    Q_OBJECT

    Q_PROPERTY(int gold READ gold)
    Q_PROPERTY(int silver READ silver)
    Q_PROPERTY(int bronze READ bronze)

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;
    }

    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 gold; }
    int getSilver() { return silver; }
    int getBronze() { return bronze; }

    static bool compare(MedalWinner lComp, MedalWinner rComp);

private:
    int gold, silver, bronze;

};


#endif //ITAT_CHALLANGE_OLYMPICS_MEDALWINNER_H