app/sources/brseason.cpp
Dorian Zedler 9b762ea246
many new implementations:
- Results are now starting to work on VL
2020-11-04 13:55:37 +01:00

91 lines
2.3 KiB
C++

#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)
{
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<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) {
allCompetitions.append(league->getCompetitions());
}
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::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;
}