summaryrefslogtreecommitdiff
path: root/src/model/CompetitorWithResults.h
blob: 2203064439537d76a29e0b9c924ca49338a09457 (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

#pragma once

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

class CompetitorWithResults : public Competitor {

     Q_OBJECT

     Q_PROPERTY(QString mark READ mark NOTIFY nMark)
     Q_PROPERTY(QString medalType READ medalType NOTIFY nMedalType)
     Q_PROPERTY(QString statistic READ statistic NOTIFY nStatistic)

public:
    CompetitorWithResults() : Competitor(), m_mark(""), m_medalType("") {}
    CompetitorWithResults(const CompetitorWithResults &competitor) : Competitor(competitor),
            m_mark(competitor.m_mark), m_medalType(competitor.m_medalType) {}

    CompetitorWithResults(const QJsonObject &competitor) : Competitor(competitor) {
        if (!competitor.contains("results")) throw invalid_argument("Competitor does not contain results.");
        QJsonObject results = competitor["results"].toObject();
        setResults(results);
    }

    bool setResults(const QJsonObject &results);
    void setStatistic(QString stat) { this->m_statistic = stat; }

    QString getMark() { return this->m_mark; }
    QString getMedalType() { return this->m_medalType; }
    QString getStatistic() { return this->m_statistic; }

    static bool compare(CompetitorWithResults lComp, CompetitorWithResults rComp);

private:
    QString m_mark;
    QString m_medalType;
    QString m_statistic;

};