2020-11-03 15:56:43 +01:00
|
|
|
#include "headers/brcompetition.h"
|
|
|
|
#include "headers/brleague.h"
|
2020-11-04 13:55:37 +01:00
|
|
|
#include "headers/brprovider.h"
|
2020-10-31 15:16:06 +01:00
|
|
|
|
2020-11-04 13:55:37 +01:00
|
|
|
BRCompetition::BRCompetition(BRProvider* provider, BRWidget::BRFederation federation, int id, BRCompetitionData initialData) : BRWidget(provider, federation, id) {
|
|
|
|
this->currentCategory = nullptr;
|
2020-11-03 15:56:43 +01:00
|
|
|
this->setData(initialData);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BRCompetition::setLeague(BRLeague* league) {
|
|
|
|
if(league == nullptr)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this->league = league;
|
|
|
|
emit this->metadataChanged();
|
2020-10-31 15:16:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QString BRCompetition::getName() {
|
|
|
|
return this->name;
|
|
|
|
}
|
|
|
|
|
2020-11-03 15:56:43 +01:00
|
|
|
BRCompetition::BRDiscipline BRCompetition::getDiscipline() {
|
|
|
|
return this->discipline;
|
|
|
|
}
|
|
|
|
|
|
|
|
QDate BRCompetition::getStartDate() {
|
|
|
|
return this->startDate;
|
|
|
|
}
|
|
|
|
|
|
|
|
QDate BRCompetition::getEndDate() {
|
|
|
|
return this->endDate;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString BRCompetition::getDateSpan() {
|
|
|
|
if(this->startDate == this->endDate)
|
|
|
|
return this->startDate.toString("d MMMM yyyy");
|
|
|
|
else
|
|
|
|
return this->startDate.toString("d MMMM yyyy") + " - " + this->endDate.toString("d MMMM yyyy");
|
|
|
|
}
|
|
|
|
|
|
|
|
BRLeague* BRCompetition::getLeague() {
|
|
|
|
return this->league;
|
|
|
|
}
|
|
|
|
|
|
|
|
QUrl BRCompetition::getEventWebsiteUrl() {
|
|
|
|
return this->eventWebsiteUrl;
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<QUrl> BRCompetition::getInfosheetUrls() {
|
|
|
|
return this->infosheetUrls;
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<QObject*> BRCompetition::getCategoriesQML() {
|
|
|
|
return this->listToQmlList(this->categories);
|
|
|
|
}
|
|
|
|
|
2020-11-04 17:25:28 +01:00
|
|
|
QList<BRCategory*> BRCompetition::getCategories() {
|
|
|
|
return this->categories;
|
|
|
|
}
|
2020-11-04 13:55:37 +01:00
|
|
|
|
|
|
|
BRCategory* BRCompetition::getCurrentCategory() const {
|
|
|
|
return this->currentCategory;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BRCompetition::setCurrentCategory(BRCategory* category) {
|
|
|
|
if(!this->categories.contains(category))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// try to find the same round in the new category
|
|
|
|
if(this->currentCategory != nullptr && this->currentCategory->getCurrentRound() != nullptr) {
|
|
|
|
QString currentRoundName = this->currentCategory->getCurrentRound()->getName();
|
|
|
|
|
|
|
|
// search round name in new category
|
|
|
|
for(BRRound* round : category->getRounds())
|
|
|
|
if(round->getName() == currentRoundName)
|
|
|
|
category->setCurrentRound(round);
|
|
|
|
}
|
|
|
|
|
|
|
|
this->currentCategory = category;
|
|
|
|
emit this->currentCategoryChanged();
|
|
|
|
}
|
|
|
|
|
2020-11-04 17:25:28 +01:00
|
|
|
QList<QObject*> BRCompetition::getResultsQML() {
|
|
|
|
if(this->currentCategory == nullptr || this->currentCategory->getCurrentRound() == nullptr)
|
|
|
|
return {};
|
|
|
|
|
|
|
|
return this->currentCategory->getCurrentRound()->getResultsQML();
|
|
|
|
}
|
|
|
|
|
2020-10-31 15:16:06 +01:00
|
|
|
BRWidget::BRWidgetStatusCode BRCompetition::load() {
|
2020-11-04 13:55:37 +01:00
|
|
|
BRCompetitionData newData {
|
|
|
|
this,
|
|
|
|
this->name,
|
|
|
|
this->discipline,
|
|
|
|
this->startDate,
|
|
|
|
this->endDate,
|
|
|
|
this->eventWebsiteUrl,
|
|
|
|
this->infosheetUrls,
|
|
|
|
|
2020-11-04 17:25:28 +01:00
|
|
|
this->currentCategory,
|
2020-11-04 13:55:37 +01:00
|
|
|
this->categories
|
|
|
|
};
|
|
|
|
|
|
|
|
BRWidget::BRWidgetStatusCode statusCode = this->getProvider()->getWidgetData(&newData);
|
|
|
|
|
|
|
|
if(statusCode != BRWidget::Success)
|
|
|
|
return statusCode;
|
|
|
|
|
|
|
|
this->setData(newData);
|
2020-10-31 15:16:06 +01:00
|
|
|
|
2020-11-04 13:55:37 +01:00
|
|
|
return BRWidget::Success;
|
2020-10-31 15:16:06 +01:00
|
|
|
}
|
2020-11-03 15:56:43 +01:00
|
|
|
|
|
|
|
void BRCompetition::setData(BRCompetition::BRCompetitionData data) {
|
|
|
|
this->name = data.name;
|
|
|
|
this->discipline = data.discipline;
|
|
|
|
this->startDate = data.startDate;
|
|
|
|
this->endDate = data.endDate;
|
|
|
|
this->eventWebsiteUrl = data.eventWebsiteUrl;
|
|
|
|
this->infosheetUrls = data.infosheetUrls;
|
|
|
|
emit this->metadataChanged();
|
|
|
|
|
2020-11-04 17:25:28 +01:00
|
|
|
if(this->currentCategory != data.currentCategory) {
|
|
|
|
this->currentCategory = data.currentCategory;
|
|
|
|
emit this->currentCategoryChanged();
|
|
|
|
}
|
|
|
|
|
2020-11-03 15:56:43 +01:00
|
|
|
if(this->categories != data.categories) {
|
|
|
|
this->categories.clear();
|
|
|
|
this->categories = data.categories;
|
2020-11-04 17:25:28 +01:00
|
|
|
for(BRCategory* category : this->categories) {
|
2020-11-04 13:55:37 +01:00
|
|
|
category->competition = this;
|
2020-11-04 17:25:28 +01:00
|
|
|
connect(category, &BRCategory::resultsChanged, this, &BRCompetition::resultsChanged);
|
|
|
|
}
|
2020-11-03 15:56:43 +01:00
|
|
|
emit this->categoriesChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool BRCompetition::lessThan(BRCompetition* competition1, BRCompetition* competition2) {
|
|
|
|
return competition1->startDate < competition2->startDate;
|
|
|
|
}
|