app/sources/brcalendar.cpp

71 lines
1.8 KiB
C++
Raw Normal View History

2020-10-31 15:16:06 +01:00
#include "../headers/brcalendar.h"
#include "headers/brprovider.h"
BRCalendar::BRCalendar(BRProvider* provider, BRFederation federation) : BRWidget(provider, federation)
2020-10-31 15:16:06 +01:00
{
this->currentSeason = nullptr;
this->seasons = {};
connect(this, &BRCalendar::currentSeasonChanged, this, &BRCalendar::titleChanged);
connect(this, &BRCalendar::seasonsChanged, this, &BRCalendar::titleChanged);
2020-10-31 15:16:06 +01:00
}
QString BRCalendar::getTitle() {
QString title = QStringList({"IFSC", "DAV", "SAC"})[this->getFederation()] + " " + tr("calendar");
2020-10-31 15:16:06 +01:00
if(this->currentSeason != nullptr)
title += " " + this->currentSeason->getName();
2020-10-31 15:16:06 +01:00
return title;
2020-10-31 15:16:06 +01:00
}
QList<QObject*> BRCalendar::getSeasonsQML() {
return this->listToQmlList(this->seasons);
2020-10-31 15:16:06 +01:00
}
BRSeason* BRCalendar::getCurrentSeason() {
return this->currentSeason;
}
2020-10-31 15:16:06 +01:00
void BRCalendar::setCurrentSeason(BRSeason* season) {
if(!this->seasons.contains(season))
return;
this->currentSeason = season;
this->currentSeason->load();
emit this->currentSeasonChanged();
2020-10-31 15:16:06 +01:00
}
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();
}
2020-10-31 15:16:06 +01:00
return statusCode;
2020-10-31 15:16:06 +01:00
}