154 lines
2.9 KiB
C++
154 lines
2.9 KiB
C++
#include "board.h"
|
|
|
|
#define NAME_KEY "name"
|
|
#define TASKS_KEY "tasks"
|
|
#define UUID_KEY "uuid"
|
|
#define DESCRIPTION_KEY "description"
|
|
#define AUTOSTATUS_KEY "auto_status"
|
|
#define STATUS_KEY "status"
|
|
|
|
#include <QJsonArray>
|
|
#include <QJsonValue>
|
|
#include <QUuid>
|
|
|
|
#include "../services/taskstateservice.h"
|
|
|
|
Board::Board(QString name, QString description)
|
|
{
|
|
QUuid uuid = QUuid::createUuid();
|
|
this->uuid = uuid.toString(QUuid::WithoutBraces);
|
|
this->name = name;
|
|
this->description = description;
|
|
}
|
|
|
|
Board::Board(QJsonObject obj)
|
|
{
|
|
QUuid uuid = QUuid::createUuid();
|
|
this->uuid = obj[UUID_KEY].toString(uuid.toString(QUuid::WithoutBraces));
|
|
this->name = obj[NAME_KEY].toString("!Missing name!");
|
|
this->description = obj[DESCRIPTION_KEY].toString("");
|
|
this->autoStatus = obj[AUTOSTATUS_KEY].toBool(true);
|
|
this->statusUUID = obj[STATUS_KEY].toString();
|
|
QJsonArray jsonTasks = obj[TASKS_KEY].toArray();
|
|
foreach (QJsonValue value, jsonTasks) {
|
|
Task *t = new Task(value.toObject());
|
|
this->tasks.append(t);
|
|
}
|
|
}
|
|
|
|
Board::~Board()
|
|
{
|
|
for (uint16_t i = 0; i < tasks.count(); i++)
|
|
{
|
|
Task *t = tasks.takeAt(i);
|
|
delete t;
|
|
}
|
|
}
|
|
|
|
const QString Board::getUuid()
|
|
{
|
|
return uuid;
|
|
}
|
|
|
|
const QString Board::getName()
|
|
{
|
|
return name;
|
|
}
|
|
|
|
const QString Board::getDescription()
|
|
{
|
|
return description;
|
|
}
|
|
|
|
const QString Board::getStatus()
|
|
{
|
|
if (autoStatus)
|
|
{
|
|
TaskStateService *tss = TaskStateService::getInstance();
|
|
int16_t h = -1;
|
|
QString suuid = "";
|
|
for (Task *t : tasks)
|
|
{
|
|
int16_t w = tss->getStatusWeight(t->getStatusUUID());
|
|
if (w > -1 && h < w)
|
|
{
|
|
h = w;
|
|
suuid = t->getStatusUUID();
|
|
}
|
|
}
|
|
return suuid;
|
|
}
|
|
return statusUUID;
|
|
}
|
|
|
|
bool Board::isAutoStatus()
|
|
{
|
|
return autoStatus;
|
|
}
|
|
|
|
void Board::setName(const QString name)
|
|
{
|
|
this->name = name;
|
|
}
|
|
|
|
void Board::setDescription(const QString description)
|
|
{
|
|
this->description = description;
|
|
}
|
|
|
|
void Board::setDirtyStatus(Status s)
|
|
{
|
|
this->autoStatus = false;
|
|
this->statusUUID = s.getUUID();
|
|
}
|
|
|
|
void Board::removeDirtyStatus()
|
|
{
|
|
this->autoStatus = true;
|
|
this->statusUUID = "";
|
|
}
|
|
|
|
void Board::add(Task t)
|
|
{
|
|
tasks.append(new Task(t));
|
|
}
|
|
|
|
void Board::remove(uint16_t index)
|
|
{
|
|
if (index < tasks.count())
|
|
{
|
|
tasks.removeAt(index);
|
|
}
|
|
}
|
|
|
|
Task *Board::taskAt(uint16_t i)
|
|
{
|
|
if (i < tasks.count())
|
|
{
|
|
return tasks[i];
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
const QVector<Task *> Board::getTasks()
|
|
{
|
|
return tasks;
|
|
}
|
|
|
|
const QJsonObject Board::toJson()
|
|
{
|
|
QJsonArray array;
|
|
foreach (Task *t, this->tasks) {
|
|
array.append(t->toJson());
|
|
}
|
|
QJsonObject obj;
|
|
obj[NAME_KEY] = this->name;
|
|
obj[UUID_KEY] = this->uuid;
|
|
obj[STATUS_KEY] = this->statusUUID;
|
|
obj[AUTOSTATUS_KEY] = this->autoStatus;
|
|
obj[TASKS_KEY] = array;
|
|
obj[DESCRIPTION_KEY] = description;
|
|
return obj;
|
|
}
|
|
|