feat(EventInfo): display EventInfo with List of Competitors
This commit is contained in:
parent
c09350b7c9
commit
eb61690873
|
@ -10,10 +10,6 @@ set(CMAKE_AUTOMOC ON)
|
|||
set(CMAKE_AUTOUIC ON)
|
||||
qt_add_executable(itat_challange_olympics src/main/main.cpp
|
||||
application.qrc
|
||||
src/api/OlympicsAPI.cpp
|
||||
src/api/OlympicsAPI.h
|
||||
src/model/Sport.cpp
|
||||
src/model/Sport.h
|
||||
)
|
||||
|
||||
|
||||
|
@ -24,6 +20,18 @@ qt_add_qml_module(itat_challange_olympics
|
|||
res/gui/EventInfoPage.qml
|
||||
res/gui/EventsPage.qml
|
||||
|
||||
SOURCES
|
||||
src/model/Competitor.cpp
|
||||
src/model/Competitor.h
|
||||
src/model/CompetitorWithResults.cpp
|
||||
src/model/CompetitorWithResults.h
|
||||
src/model/EventInfo.cpp
|
||||
src/model/EventInfo.h
|
||||
src/model/MedalWinner.cpp
|
||||
src/model/MedalWinner.h
|
||||
src/model/Sport.cpp
|
||||
src/model/Sport.h
|
||||
|
||||
RESOURCES
|
||||
res/pictograms/ARC_small.svg
|
||||
res/pictograms/ATH_small.svg
|
||||
|
|
|
@ -4,7 +4,8 @@ import QtQuick.Controls
|
|||
|
||||
Page {
|
||||
id: root
|
||||
property string event_id
|
||||
property string eventName
|
||||
property list<string> competitors
|
||||
|
||||
header: ToolBar {
|
||||
ToolButton {
|
||||
|
@ -18,7 +19,29 @@ Page {
|
|||
id: pageTitle
|
||||
font.pixelSize: 20
|
||||
anchors.centerIn: parent
|
||||
text: qsTr("Event Info")
|
||||
text: eventName
|
||||
}
|
||||
}
|
||||
|
||||
ListView {
|
||||
id: listView
|
||||
anchors.fill: parent
|
||||
topMargin: 48
|
||||
leftMargin: 48
|
||||
bottomMargin: 48
|
||||
rightMargin: 48
|
||||
spacing: 20
|
||||
model: competitors
|
||||
delegate: ItemDelegate {
|
||||
text: modelData
|
||||
width: listView.width - listView.leftMargin - listView.rightMargin
|
||||
height: avatar.implicitHeight + 32
|
||||
leftPadding: avatar.implicitWidth + 32
|
||||
|
||||
Image {
|
||||
id: avatar
|
||||
// source: "images/" + modelData.replace(" ", "_") + ".png"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -21,12 +21,13 @@ Page {
|
|||
spacing: 20
|
||||
model: sports
|
||||
delegate: ItemDelegate {
|
||||
required property string sportName
|
||||
text: sportName
|
||||
required property string eventName
|
||||
required property list<string> competitors
|
||||
text: eventName
|
||||
width: listView.width - listView.leftMargin - listView.rightMargin
|
||||
height: avatar.implicitHeight + 32
|
||||
leftPadding: avatar.implicitWidth + 32
|
||||
onClicked: root.StackView.view.push("EventInfoPage.qml", { event_id: 1 })
|
||||
onClicked: root.StackView.view.push("EventInfoPage.qml", { eventName, competitors })
|
||||
|
||||
Image {
|
||||
id: avatar
|
||||
|
|
22
src/model/EventInfo.cpp
Normal file
22
src/model/EventInfo.cpp
Normal file
|
@ -0,0 +1,22 @@
|
|||
#include <QObject>
|
||||
#include "EventInfo.h"
|
||||
|
||||
EventInfo::EventInfo(QObject *parent) : QObject(parent) {
|
||||
}
|
||||
|
||||
QString EventInfo::eventName() const {
|
||||
return m_eventName;
|
||||
}
|
||||
|
||||
void EventInfo::setEventName(const QString &newEventName) {
|
||||
m_eventName = newEventName;
|
||||
}
|
||||
|
||||
QList<QString> EventInfo::competitors() const {
|
||||
return m_competitors;
|
||||
}
|
||||
|
||||
void EventInfo::setCompetitors(const QList<QString> &newCompetitors) {
|
||||
m_competitors = newCompetitors;
|
||||
}
|
||||
|
28
src/model/EventInfo.h
Normal file
28
src/model/EventInfo.h
Normal file
|
@ -0,0 +1,28 @@
|
|||
#ifndef ITAT_CHALLANGE_OLYMPICS_EVENT_H
|
||||
#define ITAT_CHALLANGE_OLYMPICS_EVENT_H
|
||||
|
||||
#include <QObject>
|
||||
#include <qqml.h>
|
||||
|
||||
class EventInfo : QObject {
|
||||
Q_OBJECT
|
||||
// QML_ELEMENT
|
||||
|
||||
Q_PROPERTY(QString eventName READ eventName WRITE setEventName);
|
||||
Q_PROPERTY(QList<QString> competitors READ competitors WRITE setCompetitors);
|
||||
|
||||
public:
|
||||
explicit EventInfo(QObject *parent = nullptr);
|
||||
|
||||
QString eventName() const;
|
||||
void setEventName(const QString &newEventName);
|
||||
|
||||
QList<QString> competitors() const;
|
||||
void setCompetitors(const QList<QString> &newCompetitors);
|
||||
|
||||
private:
|
||||
QString m_eventName;
|
||||
QList<QString> m_competitors;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -1,4 +1,5 @@
|
|||
#include "Sport.h"
|
||||
#include "Competitor.h"
|
||||
|
||||
// categories
|
||||
#include <QNetworkReply>
|
||||
|
@ -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<int, QByteArray> SportModel::roleNames() const {
|
||||
QHash<int, QByteArray> 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<QString> 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();
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include <QJsonObject>
|
||||
#include <QJsonDocument>
|
||||
#include <QString>
|
||||
#include "EventInfo.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
@ -16,7 +17,8 @@ class SportModel : public QAbstractListModel {
|
|||
|
||||
public:
|
||||
enum Role {
|
||||
SportName = Qt::UserRole + 1
|
||||
EventName = Qt::UserRole + 1,
|
||||
Competitors
|
||||
};
|
||||
|
||||
explicit SportModel(QObject *parent = nullptr);
|
||||
|
@ -29,7 +31,7 @@ class SportModel : public QAbstractListModel {
|
|||
void parseData();
|
||||
|
||||
private:
|
||||
QList<QString> m_sportList;
|
||||
QList<EventInfo*> m_sportList;
|
||||
QNetworkAccessManager m_networkManager;
|
||||
QNetworkReply *m_reply = nullptr;
|
||||
};
|
||||
|
@ -111,4 +113,4 @@ private:
|
|||
};
|
||||
|
||||
|
||||
#endif //ITAT_CHALLANGE_OLYMPICS_SPORT_H
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue