app/sources/competition/brcategory.cpp
Dorian Zedler 85c8760bed
- moved some stuff
- results work now (still basic)
2020-11-15 14:48:12 +01:00

110 lines
2.9 KiB
C++

#include "brcategory.h"
#include "brprovider.h"
#include "brcompetition.h"
BRCategory::BRCategory(BRProvider* provider, BRWidget::BRFederation federation, int id, BRCategoryData initialData) : BRWidget(provider, federation, id)
{
this->currentRound = nullptr;
this->discipline = UnknownDiscipline;
this->generalResult = nullptr;
connect(this, &BRCategory::generalResultChanged, this, &BRCategory::resultsChanged);
connect(this, &BRCategory::roundsChanged, this, &BRCategory::resultsChanged);
this->setData(initialData);
}
BRCompetition* BRCategory::getCompetition() const {
return this->competition;
}
QString BRCategory::getName() {
return this->name;
}
BRCategory::BRDiscipline BRCategory::getDiscipline() {
return this->discipline;
}
BRCategory::BRCategoryStatus BRCategory::getStatus() {
return this->status;
}
BRRound* BRCategory::getCurrentRound() const {
return this->currentRound;
}
void BRCategory::setCurrentRound(BRRound* round) {
if(!this->rounds.contains(round) && this->generalResult != round)
return;
this->currentRound = round;
emit this->currentRoundChanged();
}
BRRound* BRCategory::getGeneralResult() {
return this->generalResult;
}
QList<BRRound*> BRCategory::getRounds(bool includeGeneralResult) const {
QList<BRRound*> rounds;
if(includeGeneralResult && this->generalResult != nullptr)
rounds.append(this->generalResult);
rounds.append(this->rounds);
return rounds;
}
QList<QObject*> BRCategory::getRoundsQML() {
return this->listToQmlList(this->getRounds(true));
}
BRCategory::BRCategoryData BRCategory::getData() {
BRCategory::BRCategoryData data {
this,
this->name,
this->discipline,
this->status,
this->currentRound,
this->generalResult,
this->rounds
};
return data;
}
void BRCategory::setData(BRCategoryData data) {
this->name = data.name;
this->discipline = data.discipline;
this->status = data.status;
emit this->metadataChanged();
if(this->currentRound != data.currentRound) {
this->currentRound = data.currentRound;
emit this->currentRoundChanged();
}
if(this->generalResult != data.generalResult) {
this->generalResult = data.generalResult;
this->generalResult->category = this;
connect(this->generalResult, &BRRound::resultsChanged, this, &BRCategory::generalResultChanged);
emit this->generalResultChanged();
}
if(this->rounds != data.rounds) {
this->rounds.clear();
this->rounds = data.rounds;
for(BRRound* round : this->rounds) {
round->category = this;
connect(round, &BRRound::resultsChanged, this, &BRCategory::resultsChanged);
}
emit this->roundsChanged();
}
}
BRWidget::BRWidgetStatusCode BRCategory::load() {
return BRWidget::OpeationNotSupportedError;
}