Implement saving to file
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user