70 lines
1.8 KiB
C++
70 lines
1.8 KiB
C++
#include "../headers/brcalendar.h"
|
|
#include "headers/brprovider.h"
|
|
|
|
BRCalendar::BRCalendar(BRProvider* provider, BRFederation federation) : BRWidget(provider, federation, -1)
|
|
{
|
|
this->currentSeason = nullptr;
|
|
this->seasons = {};
|
|
|
|
connect(this, &BRCalendar::currentSeasonChanged, this, &BRCalendar::titleChanged);
|
|
connect(this, &BRCalendar::seasonsChanged, this, &BRCalendar::titleChanged);
|
|
}
|
|
|
|
QString BRCalendar::getTitle() {
|
|
QString title = QStringList({"IFSC", "DAV", "SAC"})[this->getFederation()] + " " + tr("calendar");
|
|
|
|
if(this->currentSeason != nullptr)
|
|
title += " " + this->currentSeason->getName();
|
|
|
|
return title;
|
|
}
|
|
|
|
QList<QObject*> BRCalendar::getSeasonsQML() {
|
|
return this->listToQmlList(this->seasons);
|
|
}
|
|
|
|
|
|
BRSeason* BRCalendar::getCurrentSeason() {
|
|
return this->currentSeason;
|
|
}
|
|
|
|
void BRCalendar::setCurrentSeason(BRSeason* season) {
|
|
if(!this->seasons.contains(season))
|
|
return;
|
|
|
|
this->currentSeason = season;
|
|
this->currentSeason->load();
|
|
emit this->currentSeasonChanged();
|
|
}
|
|
|
|
BRWidget::BRWidgetStatusCode BRCalendar::load() {
|
|
if(this->getProvider() == nullptr)
|
|
return BRWidget::NoProviderError;
|
|
|
|
// reload all comp data using our providers
|
|
|
|
BRCalendarData newData {
|
|
this,
|
|
this->currentSeason,
|
|
this->seasons
|
|
};
|
|
|
|
BRWidget::BRWidgetStatusCode statusCode = this->getProvider()->getWidgetData(&newData);
|
|
|
|
if(statusCode != BRWidget::Success)
|
|
return statusCode;
|
|
|
|
if(this->seasons != newData.seasons) {
|
|
this->seasons.clear();
|
|
this->seasons = newData.seasons;
|
|
emit this->seasonsChanged();
|
|
}
|
|
|
|
if(this->currentSeason != newData.currentSeason) {
|
|
this->currentSeason = newData.currentSeason;
|
|
emit this->currentSeasonChanged();
|
|
}
|
|
|
|
|
|
return statusCode;
|
|
}
|