Implement saving to file

This commit is contained in:
Aurélie Delhaie
2022-12-18 20:13:51 +01:00
parent a348705c39
commit 94c7ff87c4
13 changed files with 260 additions and 28 deletions

View File

@@ -1,10 +1,25 @@
#include "board.h"
#define NAME_KEY "name"
#define TASKS_KEY "tasks"
#include <QJsonArray>
#include <QJsonValue>
Board::Board(QString name)
{
this->name = name;
}
Board::Board(QJsonObject obj)
{
this->name = obj[NAME_KEY].toString();
foreach (QJsonValue value, obj[TASKS_KEY].toArray()) {
Task *t = new Task(value.toObject());
this->tasks.append(t);
}
}
Board::~Board()
{
for (uint16_t i = 0; i < tasks.count(); i++)
@@ -38,3 +53,15 @@ 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[TASKS_KEY] = array;
return obj;
}