app/sources/brleague.cpp

105 lines
2.4 KiB
C++
Raw Normal View History

#include "headers/brleague.h"
#include "headers/brprovider.h"
BRLeague::BRLeague(BRProvider* provider, BRWidget::BRFederation federation, int id, BRLeagueData initialData) : BRWidget(provider, federation, id)
{
this->competitions = {};
connect(this, &BRLeague::stateChanged, this, &BRLeague::enabledChanged);
this->setState(Configured);
this->setData(initialData);
}
QString BRLeague::getName() {
return this->name;
}
QColor BRLeague::getColor() {
return this->color;
}
bool BRLeague::getEnabled() {
return this->enabled && this->state == Loaded;
}
void BRLeague::setEnabled(bool enabled) {
if(this->enabled == enabled)
return;
this->enabled = enabled;
emit this->enabledChanged();
}
QList<BRCompetition*> BRLeague::getCompetitions() {
return this->competitions;
}
QList<QObject*> BRLeague::getCompetitionsQML() {
return this->listToQmlList(this->competitions);
}
QList<QObject*> BRLeague::getCupsQML() {
return this->listToQmlList(this->cups);
}
void BRLeague::setData(BRLeagueData data) {
this->name = data.name;
this->color = data.color;
emit this->metadataChanged();
if(this->competitions != data.competitions) {
this->competitions.clear();
this->competitions = data.competitions;
for(BRCompetition* competition : this->competitions) {
competition->setLeague(this);
connect(competition, &BRCompetition::pinnedChanged, this, &BRLeague::competitionsChanged);
}
emit this->competitionsChanged();
}
if(this->cups != data.cups) {
this->cups.clear();
this->cups = data.cups;
emit this->cupsChanged();
}
if(this->competitions.length() > 0 || this->cups.length() > 0)
this->setState(Loaded);
else
this->setState(Configured);
if(data.enabled != this->enabled) {
this->enabled = data.enabled;
emit this->enabledChanged();
}
}
BRWidget::BRWidgetStatusCode BRLeague::load() {
if(this->getProvider() == nullptr)
return BRWidget::NoProviderError;
this->setState(Loading);
BRLeagueData newData {
this,
this->name,
this->color,
this->enabled,
this->competitions,
this->cups
};
BRWidget::BRWidgetStatusCode statusCode = this->getProvider()->getWidgetData(&newData);
if(statusCode != BRWidget::Success)
return statusCode;
this->setData(newData);
return statusCode;
}