From 3d19fd72716561a0322ba0acc5c94aac9f161e9d Mon Sep 17 00:00:00 2001 From: Orangerot Date: Fri, 16 Aug 2024 15:40:37 +0200 Subject: feat(Sport): select Discipline --- src/model/Sport.cpp | 20 +++++++++++++++----- src/model/Sport.h | 10 +++++++++- 2 files changed, 24 insertions(+), 6 deletions(-) (limited to 'src/model') diff --git a/src/model/Sport.cpp b/src/model/Sport.cpp index 8c4902b..a21e21d 100644 --- a/src/model/Sport.cpp +++ b/src/model/Sport.cpp @@ -22,7 +22,7 @@ #include namespace { - const QString &k_requestUrl = "https://sph-s-api.olympics.com/summer/schedules/api/ENG/schedule/discipline/ARC"; + const QString &k_requestUrl = "https://sph-s-api.olympics.com/summer/schedules/api/ENG/schedule/discipline/"; } SportModel::SportModel(QObject *parent) : QAbstractListModel(parent) { @@ -58,8 +58,18 @@ QHash SportModel::roleNames() const { return names; } -void SportModel::request() { - m_reply = m_networkManager.get(QNetworkRequest( k_requestUrl )); +QString SportModel::discipline() const { + return m_discipline; +} + +void SportModel::setDiscipline(const QString &discipline) { + m_discipline = discipline; +} + + +void SportModel::request(QString discipline) { + m_discipline = discipline; + m_reply = m_networkManager.get(QNetworkRequest( k_requestUrl + m_discipline)); qDebug() << m_reply; connect(m_reply, &QNetworkReply::finished, this, &SportModel::parseData); } @@ -68,8 +78,8 @@ void SportModel::parseData() { if (m_reply->error() == QNetworkReply::NoError) { beginResetModel(); - // qDeleteAll(m_sportList); - // m_sportList.clear(); + qDeleteAll(m_sportList); + m_sportList.clear(); diff --git a/src/model/Sport.h b/src/model/Sport.h index be74a51..01798fb 100644 --- a/src/model/Sport.h +++ b/src/model/Sport.h @@ -3,6 +3,7 @@ #include #include +#include #include #include @@ -15,6 +16,8 @@ using namespace std; class SportModel : public QAbstractListModel { Q_OBJECT + Q_PROPERTY(QString discipline READ discipline WRITE setDiscipline); + public: enum Role { EventName = Qt::UserRole + 1, @@ -26,12 +29,17 @@ class SportModel : public QAbstractListModel { virtual int rowCount(const QModelIndex &parent) const override; virtual QVariant data(const QModelIndex &index, int role) const override; virtual QHash roleNames() const override; + + + QString discipline() const; + void setDiscipline(const QString &discipline); public slots: - void request(); + void request(QString discipline); void parseData(); private: QList m_sportList; + QString m_discipline; QNetworkAccessManager m_networkManager; QNetworkReply *m_reply = nullptr; }; -- cgit v1.2.3