From eb61690873e234ea28a3f437fb7211c773a449fe Mon Sep 17 00:00:00 2001 From: Orangerot Date: Fri, 16 Aug 2024 07:06:05 +0200 Subject: feat(EventInfo): display EventInfo with List of Competitors --- src/model/Sport.cpp | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'src/model/Sport.cpp') diff --git a/src/model/Sport.cpp b/src/model/Sport.cpp index 38173ce..8c4902b 100644 --- a/src/model/Sport.cpp +++ b/src/model/Sport.cpp @@ -1,4 +1,5 @@ #include "Sport.h" +#include "Competitor.h" // categories #include @@ -34,12 +35,15 @@ int SportModel::rowCount(const QModelIndex &parent) const { QVariant SportModel::data(const QModelIndex &index, int role) const { if (index.isValid() && index.row() >= 0 && index.row() < m_sportList.size()) { - QString sportName = m_sportList[index.row()]; + EventInfo *event = m_sportList[index.row()]; - return sportName; - // switch ((Role) role) { - // case SportName: - // } + switch ((Role) role) { + case EventName: + return event->eventName(); + + case Competitors: + return event->competitors(); + } } return {}; @@ -48,7 +52,8 @@ QVariant SportModel::data(const QModelIndex &index, int role) const { QHash SportModel::roleNames() const { QHash names; - names[SportName] = "sportName"; + names[EventName] = "eventName"; + names[Competitors] = "competitors"; return names; } @@ -77,8 +82,18 @@ void SportModel::parseData() { QJsonArray sports = jsonDocument["units"].toArray(); for (const auto &sport : sports) { QJsonObject entry = sport.toObject(); + + EventInfo *event = new EventInfo(this); + event->setEventName(entry["eventUnitName"].toString()); + + QList competitors; + for (const auto &competitor : entry["competitors"].toArray()) { + competitors << competitor.toObject()["name"].toString(); + } + event->setCompetitors(competitors); + qDebug() << entry["eventUnitName"].toString(); - m_sportList << entry["eventUnitName"].toString(); + m_sportList << event; } endResetModel(); } -- cgit v1.2.3