#include "headers/brseason.h" #include "headers/brprovider.h" using namespace std; BRSeason::BRSeason(BRProvider* provider, BRWidget::BRFederation federation, int id, BRSeasonData initialData) : BRWidget(provider, federation), id(id) { connect(this, &BRSeason::leaguesChanged, this, &BRSeason::competitionsChanged); connect(this, &BRSeason::leaguesChanged, this, &BRSeason::cupsChanged); this->setData(initialData); } int BRSeason::getYear() const { return this->year; } QString BRSeason::getName() { return this->name; } QList BRSeason::getLeaguesQML() { return this->listToQmlList(this->leagues); } QList BRSeason::getLeagues() const { return this->leagues; } QList BRSeason::getCompetitionsQML() { QList allCompetitions; for(BRLeague* league : this->leagues) { allCompetitions.append(league->getCompetitions()); } std::sort(allCompetitions.begin(), allCompetitions.end(), BRCompetition::lessThan); qDebug() << "competitions: " << allCompetitions; return this->listToQmlList(allCompetitions); } QList BRSeason::getCupsQML() { QList allCups; for(BRLeague* league : this->leagues) { allCups.append(league->getCupsQML()); } return this->listToQmlList(allCups); } void BRSeason::setData(BRSeasonData data) { this->year = data.year; this->name = data.name; this->multiLeagueSupport = data.nativeMultiLeagueSupport; emit this->metadataChanged(); if(this->leagues != data.leagues) { this->leagues.clear(); this->leagues = data.leagues; emit this->leaguesChanged(); for(BRLeague* league : this->leagues) { connect(league, &BRLeague::competitionsChanged, this, &BRSeason::competitionsChanged); connect(league, &BRLeague::cupsChanged, this, &BRSeason::cupsChanged); } } } BRWidget::BRWidgetStatusCode BRSeason::load() { if(this->getProvider() == nullptr) return BRWidget::NoProviderError; // reload all comp data using our providers BRSeasonData newData { this, this->year, this->name, this->multiLeagueSupport, this->leagues }; BRWidget::BRWidgetStatusCode statusCode = this->getProvider()->getWidgetData(&newData); if(statusCode != BRWidget::Success) return statusCode; this->setData(newData); return statusCode; }