app/sources/brseason.cpp

99 lines
2.7 KiB
C++
Raw Permalink Normal View History

#include "brseason.h"
#include "brprovider.h"
using namespace std;
BRSeason::BRSeason(BRProvider* provider, BRWidget::BRFederation federation, int id, BRSeasonData initialData) : BRWidget(provider, federation, id)
{
connect(this, &BRSeason::leaguesChanged, this, &BRSeason::competitionsChanged);
connect(this, &BRSeason::leaguesChanged, this, &BRSeason::cupsChanged);
this->leagues = {};
this->setData(initialData);
}
int BRSeason::getYear() const {
return this->year;
}
QString BRSeason::getName() {
return this->name;
}
QList<QObject*> BRSeason::getLeaguesQML() {
return this->listToQmlList(this->leagues);
}
QList<BRLeague*> BRSeason::getLeagues() const {
return this->leagues;
}
QList<QObject*> BRSeason::getCompetitionsQML() {
QList<BRCompetition*> allCompetitions;
for(BRLeague* league : this->leagues) {
if(league->getEnabled())
allCompetitions.append(league->getCompetitions());
else
for(BRCompetition* competition : league->getCompetitions())
if(competition->getPinned())
allCompetitions.append(competition);
}
std::sort(allCompetitions.begin(), allCompetitions.end(), BRCompetition::lessThan);
return this->listToQmlList(allCompetitions);
}
QList<QObject*> BRSeason::getCupsQML() {
QList<QObject*> 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::enabledChanged, 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;
}