blob: ed8331d4042c5e2aa5048c3db0487ae4768cfb4e (
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
|
#include "Sport.h"
#include <set>
#include <QJsonObject>
#include <QJsonArray>
#include <QJsonValueRef>
#include <QString>
/**
* @brief Sport::getCategories Reads all possible categories (also called units).
* @return A set of all category names.
*/
set<QString> Sport::getCategories() {
set<QString> categoryNames;
for (const QJsonValueRef& unit : this->discipline["units"].toArray()) {
categoryNames.insert(unit.toObject()["eventUnitName"].toString());
}
return categoryNames;
}
/**
* @brief Sport::getCompetitorsByCategory Searches for all competitors, who took part in the given category.
* @param category The category to search in.
* @return An QJsonArray with all competitors as QJsonValueRef, which can be casted to QJsonObject.
*/
QJsonArray Sport::getCompetitorsByCategory(QString category) {
QJsonArray competitors;
for (const QJsonValueRef& unitRef : this->discipline["units"].toArray()) {
QJsonObject unit = unitRef.toObject();
// search all units with the same category
if (QString::compare(unit["eventUnitName"].toString(), category, Qt::CaseSensitive) == 0) {
// add all competitors from one unit
for (const QJsonValueRef& comp : unit["competitors"].toArray()) {
competitors.push_back(comp.toObject());
}
}
}
return competitors;
}
|