Implement saving to file
This commit is contained in:
@@ -1,8 +1,15 @@
|
|||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "ui_mainwindow.h"
|
#include "ui_mainwindow.h"
|
||||||
|
|
||||||
|
#define PRIORITIES_KEY "priorities"
|
||||||
|
#define STATUS_KEY "status"
|
||||||
|
#define BOARDS_KEY "boards"
|
||||||
|
|
||||||
#include <QUuid>
|
#include <QUuid>
|
||||||
#include <QColor>
|
#include <QColor>
|
||||||
|
#include <QJsonArray>
|
||||||
|
#include <QJsonObject>
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
#include "prefdialog.h"
|
#include "prefdialog.h"
|
||||||
#include "aboutdialog.h"
|
#include "aboutdialog.h"
|
||||||
@@ -15,6 +22,7 @@ MainWindow::MainWindow(QWidget *parent)
|
|||||||
, ui(new Ui::MainWindow)
|
, ui(new Ui::MainWindow)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
init();
|
||||||
this->selectedBoardIndex = -1;
|
this->selectedBoardIndex = -1;
|
||||||
connect(ui->actionPreferences, &QAction::triggered, this, &MainWindow::openPreferences);
|
connect(ui->actionPreferences, &QAction::triggered, this, &MainWindow::openPreferences);
|
||||||
connect(ui->actionAbout, &QAction::triggered, this, &MainWindow::openAbout);
|
connect(ui->actionAbout, &QAction::triggered, this, &MainWindow::openAbout);
|
||||||
@@ -22,8 +30,6 @@ MainWindow::MainWindow(QWidget *parent)
|
|||||||
connect(ui->listWidget, &QListWidget::currentRowChanged, this, &MainWindow::onBoardSelected);
|
connect(ui->listWidget, &QListWidget::currentRowChanged, this, &MainWindow::onBoardSelected);
|
||||||
connect(ui->actionNew_task, &QAction::triggered, this, &MainWindow::onNewTaskClick);
|
connect(ui->actionNew_task, &QAction::triggered, this, &MainWindow::onNewTaskClick);
|
||||||
connect(ui->treeWidget, &QTreeWidget::itemDoubleClicked, this, &MainWindow::onEditTask);
|
connect(ui->treeWidget, &QTreeWidget::itemDoubleClicked, this, &MainWindow::onEditTask);
|
||||||
this->priorities = defaultPriorities();
|
|
||||||
this->status = defaultStatus();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
@@ -43,6 +49,7 @@ void MainWindow::openPreferences()
|
|||||||
{
|
{
|
||||||
this->priorities = dialog.getPriorities();
|
this->priorities = dialog.getPriorities();
|
||||||
this->status = dialog.getStatus();
|
this->status = dialog.getStatus();
|
||||||
|
save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,6 +69,7 @@ void MainWindow::onNewBoardClick()
|
|||||||
boards.append(b);
|
boards.append(b);
|
||||||
QListWidgetItem *item = new QListWidgetItem(name);
|
QListWidgetItem *item = new QListWidgetItem(name);
|
||||||
ui->listWidget->addItem(item);
|
ui->listWidget->addItem(item);
|
||||||
|
save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,6 +106,7 @@ void MainWindow::onNewTaskClick()
|
|||||||
item->setForeground(2, fgColor);
|
item->setForeground(2, fgColor);
|
||||||
|
|
||||||
ui->treeWidget->addTopLevelItem(item);
|
ui->treeWidget->addTopLevelItem(item);
|
||||||
|
save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -153,11 +162,38 @@ void MainWindow::onEditTask(QTreeWidgetItem *item)
|
|||||||
fgColor.setColor(Tools::getForegroundColor(bgColor.color()));
|
fgColor.setColor(Tools::getForegroundColor(bgColor.color()));
|
||||||
item->setBackground(2, bgColor);
|
item->setBackground(2, bgColor);
|
||||||
item->setForeground(2, fgColor);
|
item->setForeground(2, fgColor);
|
||||||
|
save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::init()
|
||||||
|
{
|
||||||
|
if (Tools::isSaveFileExist())
|
||||||
|
{
|
||||||
|
QJsonDocument doc;
|
||||||
|
if (Tools::readSaveFile(doc))
|
||||||
|
{
|
||||||
|
QJsonObject save = doc.object();
|
||||||
|
for (QJsonValue value : save[PRIORITIES_KEY].toArray()) {
|
||||||
|
priorities.append(Priority(value.toObject()));
|
||||||
|
}
|
||||||
|
for (QJsonValue value : save[STATUS_KEY].toArray()) {
|
||||||
|
status.append(Status(value.toObject()));
|
||||||
|
}
|
||||||
|
for (QJsonValue value : save[BOARDS_KEY].toArray()) {
|
||||||
|
boards.append(new Board(value.toObject()));
|
||||||
|
}
|
||||||
|
redrawBoardList();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this->priorities = defaultPriorities();
|
||||||
|
this->status = defaultStatus();
|
||||||
|
save();
|
||||||
|
}
|
||||||
|
|
||||||
QVector<Priority> MainWindow::defaultPriorities()
|
QVector<Priority> MainWindow::defaultPriorities()
|
||||||
{
|
{
|
||||||
QVector<Priority> res;
|
QVector<Priority> res;
|
||||||
@@ -228,10 +264,34 @@ const QColor MainWindow::getStatusColor(QString uuid, QColor defaultColor)
|
|||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const QJsonDocument MainWindow::getJsonSave()
|
||||||
|
{
|
||||||
|
QJsonDocument doc;
|
||||||
|
QJsonObject obj;
|
||||||
|
QJsonArray jsonPriorities;
|
||||||
|
foreach (Priority p, this->priorities) {
|
||||||
|
jsonPriorities.append(p.toJson());
|
||||||
|
}
|
||||||
|
QJsonArray jsonStatus;
|
||||||
|
foreach (Status s, this->status) {
|
||||||
|
jsonStatus.append(s.toJson());
|
||||||
|
}
|
||||||
|
QJsonArray jsonBoards;
|
||||||
|
foreach (Board *b, this->boards) {
|
||||||
|
jsonBoards.append(b->toJson());
|
||||||
|
}
|
||||||
|
obj[PRIORITIES_KEY] = jsonPriorities;
|
||||||
|
obj[STATUS_KEY] = jsonStatus;
|
||||||
|
obj[BOARDS_KEY] = jsonBoards;
|
||||||
|
doc.setObject(obj);
|
||||||
|
return doc;
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::redrawBoardList()
|
void MainWindow::redrawBoardList()
|
||||||
{
|
{
|
||||||
QListWidget *l = ui->listWidget;
|
QListWidget *l = ui->listWidget;
|
||||||
for (uint16_t i = 0; i < l->count(); i++)
|
uint16_t itemCount = l->count();
|
||||||
|
for (int16_t i = itemCount; i >= 0; i--)
|
||||||
{
|
{
|
||||||
delete l->takeItem(i);
|
delete l->takeItem(i);
|
||||||
}
|
}
|
||||||
@@ -245,7 +305,8 @@ void MainWindow::redrawBoardList()
|
|||||||
void MainWindow::redrawTaskTree()
|
void MainWindow::redrawTaskTree()
|
||||||
{
|
{
|
||||||
QTreeWidget *l = ui->treeWidget;
|
QTreeWidget *l = ui->treeWidget;
|
||||||
for (uint16_t i = 0; i < l->topLevelItemCount(); i++)
|
uint16_t itemCount = l->topLevelItemCount();
|
||||||
|
for (int16_t i = itemCount; i >= 0; i--)
|
||||||
{
|
{
|
||||||
delete l->takeTopLevelItem(i);
|
delete l->takeTopLevelItem(i);
|
||||||
}
|
}
|
||||||
@@ -282,3 +343,12 @@ void MainWindow::redrawTaskTree()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::save()
|
||||||
|
{
|
||||||
|
QJsonDocument doc = getJsonSave();
|
||||||
|
if (!Tools::writeSaveToFile(doc))
|
||||||
|
{
|
||||||
|
QMessageBox::critical(this, "Failed to save", "Failed to write the save to the file", QMessageBox::StandardButton::Ok);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
#include <QTreeWidgetItem>
|
#include <QTreeWidgetItem>
|
||||||
#include <QBrush>
|
#include <QBrush>
|
||||||
|
#include <QJsonDocument>
|
||||||
|
|
||||||
#include "../models/priority.h"
|
#include "../models/priority.h"
|
||||||
#include "../models/status.h"
|
#include "../models/status.h"
|
||||||
@@ -32,6 +33,8 @@ private slots:
|
|||||||
private:
|
private:
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
|
|
||||||
|
void init();
|
||||||
|
|
||||||
int16_t selectedBoardIndex;
|
int16_t selectedBoardIndex;
|
||||||
QVector<Priority> priorities;
|
QVector<Priority> priorities;
|
||||||
QVector<Status> status;
|
QVector<Status> status;
|
||||||
@@ -46,7 +49,10 @@ private:
|
|||||||
const QColor getPriorityColor(QString uuid, QColor defaultColor);
|
const QColor getPriorityColor(QString uuid, QColor defaultColor);
|
||||||
const QColor getStatusColor(QString uuid, QColor defaultColor);
|
const QColor getStatusColor(QString uuid, QColor defaultColor);
|
||||||
|
|
||||||
|
const QJsonDocument getJsonSave();
|
||||||
|
|
||||||
void redrawBoardList();
|
void redrawBoardList();
|
||||||
void redrawTaskTree();
|
void redrawTaskTree();
|
||||||
|
void save();
|
||||||
};
|
};
|
||||||
#endif // MAINWINDOW_H
|
#endif // MAINWINDOW_H
|
||||||
|
|||||||
@@ -47,10 +47,10 @@ PrefDialog::~PrefDialog()
|
|||||||
|
|
||||||
QVector<Priority> PrefDialog::getPriorities()
|
QVector<Priority> PrefDialog::getPriorities()
|
||||||
{
|
{
|
||||||
int count = ui->priorityListWidget->count();
|
uint16_t count = ui->priorityListWidget->count();
|
||||||
QVector<Priority> res;
|
QVector<Priority> res;
|
||||||
|
|
||||||
for (int i = 0; i < count; i++)
|
for (uint16_t i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
QListWidgetItem *item = ui->priorityListWidget->item(i);
|
QListWidgetItem *item = ui->priorityListWidget->item(i);
|
||||||
Priority p(priorityUUIDRef[i], item->text(), item->background().color());
|
Priority p(priorityUUIDRef[i], item->text(), item->background().color());
|
||||||
@@ -62,10 +62,10 @@ QVector<Priority> PrefDialog::getPriorities()
|
|||||||
|
|
||||||
QVector<Status> PrefDialog::getStatus()
|
QVector<Status> PrefDialog::getStatus()
|
||||||
{
|
{
|
||||||
int count = ui->statusListWidget->count();
|
uint16_t count = ui->statusListWidget->count();
|
||||||
QVector<Status> res;
|
QVector<Status> res;
|
||||||
|
|
||||||
for (int i = 0; i < count; i++)
|
for (uint16_t i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
QListWidgetItem *item = ui->statusListWidget->item(i);
|
QListWidgetItem *item = ui->statusListWidget->item(i);
|
||||||
Status s(statusUUIDRef[i], item->text(), item->background().color());
|
Status s(statusUUIDRef[i], item->text(), item->background().color());
|
||||||
|
|||||||
@@ -1,10 +1,25 @@
|
|||||||
#include "board.h"
|
#include "board.h"
|
||||||
|
|
||||||
|
#define NAME_KEY "name"
|
||||||
|
#define TASKS_KEY "tasks"
|
||||||
|
|
||||||
|
#include <QJsonArray>
|
||||||
|
#include <QJsonValue>
|
||||||
|
|
||||||
Board::Board(QString name)
|
Board::Board(QString name)
|
||||||
{
|
{
|
||||||
this->name = 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()
|
Board::~Board()
|
||||||
{
|
{
|
||||||
for (uint16_t i = 0; i < tasks.count(); i++)
|
for (uint16_t i = 0; i < tasks.count(); i++)
|
||||||
@@ -38,3 +53,15 @@ const QVector<Task *> Board::getTasks()
|
|||||||
return tasks;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include <QJsonObject>
|
||||||
|
|
||||||
#include "task.h"
|
#include "task.h"
|
||||||
|
|
||||||
@@ -10,6 +11,7 @@ class Board
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Board(QString name);
|
Board(QString name);
|
||||||
|
Board(QJsonObject);
|
||||||
~Board();
|
~Board();
|
||||||
|
|
||||||
const QString getName();
|
const QString getName();
|
||||||
@@ -17,6 +19,8 @@ public:
|
|||||||
Task *taskAt(uint16_t);
|
Task *taskAt(uint16_t);
|
||||||
const QVector<Task*> getTasks();
|
const QVector<Task*> getTasks();
|
||||||
|
|
||||||
|
const QJsonObject toJson();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QVector<Task*> tasks;
|
QVector<Task*> tasks;
|
||||||
QString name;
|
QString name;
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
#include "priority.h"
|
#include "priority.h"
|
||||||
|
|
||||||
|
#define UUID_KEY "uuid"
|
||||||
|
#define NAME_KEY "name"
|
||||||
|
#define COLOR_KEY "color"
|
||||||
|
|
||||||
Priority::Priority(QString uuid, QString name, QColor color)
|
Priority::Priority(QString uuid, QString name, QColor color)
|
||||||
{
|
{
|
||||||
this->uuid = uuid;
|
this->uuid = uuid;
|
||||||
@@ -7,6 +11,13 @@ Priority::Priority(QString uuid, QString name, QColor color)
|
|||||||
this->color = color;
|
this->color = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Priority::Priority(QJsonObject obj)
|
||||||
|
{
|
||||||
|
this->uuid = obj[UUID_KEY].toString();
|
||||||
|
this->name = obj[NAME_KEY].toString();
|
||||||
|
this->color = QColor::fromString(obj[COLOR_KEY].toString());
|
||||||
|
}
|
||||||
|
|
||||||
const QString Priority::getName()
|
const QString Priority::getName()
|
||||||
{
|
{
|
||||||
return this->name;
|
return this->name;
|
||||||
@@ -21,3 +32,12 @@ const QColor Priority::getColor()
|
|||||||
{
|
{
|
||||||
return this->color;
|
return this->color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const QJsonObject Priority::toJson()
|
||||||
|
{
|
||||||
|
QJsonObject obj;
|
||||||
|
obj[UUID_KEY] = this->uuid;
|
||||||
|
obj[NAME_KEY] = this->name;
|
||||||
|
obj[COLOR_KEY] = this->color.name(QColor::HexRgb);
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,15 +3,18 @@
|
|||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QColor>
|
#include <QColor>
|
||||||
|
#include <QJsonObject>
|
||||||
|
|
||||||
class Priority
|
class Priority
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Priority(QString uuid, QString name, QColor color);
|
Priority(QString uuid, QString name, QColor color);
|
||||||
|
Priority(QJsonObject);
|
||||||
|
|
||||||
const QString getName();
|
const QString getName();
|
||||||
const QString getUUID();
|
const QString getUUID();
|
||||||
const QColor getColor();
|
const QColor getColor();
|
||||||
|
const QJsonObject toJson();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString uuid;
|
QString uuid;
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
#include "status.h"
|
#include "status.h"
|
||||||
|
|
||||||
|
#define UUID_KEY "uuid"
|
||||||
|
#define NAME_KEY "name"
|
||||||
|
#define COLOR_KEY "color"
|
||||||
|
|
||||||
Status::Status(QString uuid, QString name, QColor color)
|
Status::Status(QString uuid, QString name, QColor color)
|
||||||
{
|
{
|
||||||
this->uuid = uuid;
|
this->uuid = uuid;
|
||||||
@@ -7,6 +11,13 @@ Status::Status(QString uuid, QString name, QColor color)
|
|||||||
this->color = color;
|
this->color = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Status::Status(QJsonObject obj)
|
||||||
|
{
|
||||||
|
this->uuid = obj[UUID_KEY].toString();
|
||||||
|
this->name = obj[NAME_KEY].toString();
|
||||||
|
this->color = QColor::fromString(obj[COLOR_KEY].toString());
|
||||||
|
}
|
||||||
|
|
||||||
const QString Status::getName()
|
const QString Status::getName()
|
||||||
{
|
{
|
||||||
return this->name;
|
return this->name;
|
||||||
@@ -21,3 +32,12 @@ const QColor Status::getColor()
|
|||||||
{
|
{
|
||||||
return this->color;
|
return this->color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const QJsonObject Status::toJson()
|
||||||
|
{
|
||||||
|
QJsonObject obj;
|
||||||
|
obj[UUID_KEY] = this->uuid;
|
||||||
|
obj[NAME_KEY] = this->name;
|
||||||
|
obj[COLOR_KEY] = this->color.name(QColor::HexRgb);
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,15 +3,18 @@
|
|||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QColor>
|
#include <QColor>
|
||||||
|
#include <QJsonObject>
|
||||||
|
|
||||||
class Status
|
class Status
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Status(QString uuid, QString name, QColor color);
|
Status(QString uuid, QString name, QColor color);
|
||||||
|
Status(QJsonObject);
|
||||||
|
|
||||||
const QString getName();
|
const QString getName();
|
||||||
const QString getUUID();
|
const QString getUUID();
|
||||||
const QColor getColor();
|
const QColor getColor();
|
||||||
|
const QJsonObject toJson();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString uuid;
|
QString uuid;
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
#include "task.h"
|
#include "task.h"
|
||||||
|
|
||||||
|
#define TITLE_KEY "title"
|
||||||
|
#define DESCRIPTION_KEY "description"
|
||||||
|
#define EXPECTEDFOR_KEY "expected_for"
|
||||||
|
#define PRIORITY_KEY "priority"
|
||||||
|
#define STATUS_KEY "status"
|
||||||
|
|
||||||
Task::Task(QString title, QString description, QDate expectedFor, QString priorityUUID, QString statusUUID)
|
Task::Task(QString title, QString description, QDate expectedFor, QString priorityUUID, QString statusUUID)
|
||||||
{
|
{
|
||||||
this->title = title;
|
this->title = title;
|
||||||
@@ -9,6 +15,15 @@ Task::Task(QString title, QString description, QDate expectedFor, QString priori
|
|||||||
this->statusUUID = statusUUID;
|
this->statusUUID = statusUUID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Task::Task(QJsonObject obj)
|
||||||
|
{
|
||||||
|
this->title = obj[TITLE_KEY].toString();
|
||||||
|
this->description = obj[DESCRIPTION_KEY].toString();
|
||||||
|
this->expectedFor = QDate::fromString(obj[EXPECTEDFOR_KEY].toString(), Qt::DateFormat::ISODate);
|
||||||
|
this->priorityUUID = obj[PRIORITY_KEY].toString();
|
||||||
|
this->statusUUID = obj[STATUS_KEY].toString();
|
||||||
|
}
|
||||||
|
|
||||||
const QString Task::getTitle()
|
const QString Task::getTitle()
|
||||||
{
|
{
|
||||||
return this->title;
|
return this->title;
|
||||||
@@ -34,6 +49,17 @@ const QString Task::getStatusUUID()
|
|||||||
return this->statusUUID;
|
return this->statusUUID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const QJsonObject Task::toJson()
|
||||||
|
{
|
||||||
|
QJsonObject obj;
|
||||||
|
obj[TITLE_KEY] = this->title;
|
||||||
|
obj[DESCRIPTION_KEY] = this->description;
|
||||||
|
obj[EXPECTEDFOR_KEY] = this->expectedFor.toString(Qt::DateFormat::ISODate);
|
||||||
|
obj[PRIORITY_KEY] = this->priorityUUID;
|
||||||
|
obj[STATUS_KEY] = this->statusUUID;
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
void Task::update(Task t)
|
void Task::update(Task t)
|
||||||
{
|
{
|
||||||
this->title = t.title;
|
this->title = t.title;
|
||||||
|
|||||||
@@ -3,17 +3,20 @@
|
|||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QDate>
|
#include <QDate>
|
||||||
|
#include <QJsonObject>
|
||||||
|
|
||||||
class Task
|
class Task
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Task(QString title, QString description, QDate expectedFor, QString priorityUUID, QString statusUUID);
|
Task(QString title, QString description, QDate expectedFor, QString priorityUUID, QString statusUUID);
|
||||||
|
Task(QJsonObject);
|
||||||
|
|
||||||
const QString getTitle();
|
const QString getTitle();
|
||||||
const QString getDescription();
|
const QString getDescription();
|
||||||
const QDate getExpectedFor();
|
const QDate getExpectedFor();
|
||||||
const QString getPriorityUUID();
|
const QString getPriorityUUID();
|
||||||
const QString getStatusUUID();
|
const QString getStatusUUID();
|
||||||
|
const QJsonObject toJson();
|
||||||
|
|
||||||
void update(Task);
|
void update(Task);
|
||||||
|
|
||||||
|
|||||||
@@ -3,13 +3,17 @@
|
|||||||
#define BRIGHTNESS_THRESHOLD 170
|
#define BRIGHTNESS_THRESHOLD 170
|
||||||
#define WHITECOLOR 240
|
#define WHITECOLOR 240
|
||||||
#define BLACKCOLOR 15
|
#define BLACKCOLOR 15
|
||||||
|
#define FILENAME "data.json"
|
||||||
|
|
||||||
|
#include <QStandardPaths>
|
||||||
|
#include <QDir>
|
||||||
|
|
||||||
Tools::Tools()
|
Tools::Tools()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QColor Tools::getRandomColor()
|
const QColor Tools::getRandomColor()
|
||||||
{
|
{
|
||||||
srand(time(0));
|
srand(time(0));
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
@@ -24,24 +28,12 @@ QColor Tools::getRandomColor()
|
|||||||
return QColor(r, g, b);
|
return QColor(r, g, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
QColor Tools::getForegroundColor(QColor background)
|
const QColor Tools::getForegroundColor(QColor background)
|
||||||
{
|
{
|
||||||
uint8_t avg = background.red();
|
uint8_t avg = (background.red() + background.green() + background.blue()) / 3;
|
||||||
avg += background.green();
|
uint8_t avg2 = (background.red() + background.green()) / 2;
|
||||||
avg += background.blue();
|
uint8_t avg3 = (background.red() + background.blue()) / 2;
|
||||||
avg = avg / 3;
|
uint8_t avg4 = (background.green() + background.blue()) / 2;
|
||||||
|
|
||||||
uint8_t avg2 = background.red();
|
|
||||||
avg2 += background.green();
|
|
||||||
avg2 = avg2 / 2;
|
|
||||||
|
|
||||||
uint8_t avg3 = background.red();
|
|
||||||
avg3 += background.blue();
|
|
||||||
avg3 = avg3 / 2;
|
|
||||||
|
|
||||||
uint8_t avg4 = background.green();
|
|
||||||
avg4 += background.blue();
|
|
||||||
avg4 = avg4 / 2;
|
|
||||||
|
|
||||||
if (avg < BRIGHTNESS_THRESHOLD && avg2 < BRIGHTNESS_THRESHOLD && avg3 < BRIGHTNESS_THRESHOLD && avg4 < BRIGHTNESS_THRESHOLD)
|
if (avg < BRIGHTNESS_THRESHOLD && avg2 < BRIGHTNESS_THRESHOLD && avg3 < BRIGHTNESS_THRESHOLD && avg4 < BRIGHTNESS_THRESHOLD)
|
||||||
{
|
{
|
||||||
@@ -52,3 +44,54 @@ QColor Tools::getForegroundColor(QColor background)
|
|||||||
return QColor(BLACKCOLOR, BLACKCOLOR, BLACKCOLOR);
|
return QColor(BLACKCOLOR, BLACKCOLOR, BLACKCOLOR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const QString Tools::getSaveFilePath() {
|
||||||
|
QString path = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
|
||||||
|
if (!QDir(path).exists())
|
||||||
|
{
|
||||||
|
QDir().mkpath(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
path += "/data/";
|
||||||
|
if (!QDir(path).exists())
|
||||||
|
{
|
||||||
|
QDir().mkpath(path);
|
||||||
|
}
|
||||||
|
path += FILENAME;
|
||||||
|
return QDir::cleanPath(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Tools::isSaveFileExist()
|
||||||
|
{
|
||||||
|
return QFile::exists(Tools::getSaveFilePath());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Tools::writeSaveToFile(QJsonDocument doc)
|
||||||
|
{
|
||||||
|
bool success = false;
|
||||||
|
QFile *f = new QFile(getSaveFilePath());
|
||||||
|
if (f->open(QIODevice::WriteOnly))
|
||||||
|
{
|
||||||
|
f->write(doc.toJson());
|
||||||
|
f->close();
|
||||||
|
success = true;
|
||||||
|
}
|
||||||
|
delete f;
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Tools::readSaveFile(QJsonDocument &doc) {
|
||||||
|
QFile* file = new QFile(getSaveFilePath());
|
||||||
|
if (!file->open(QIODevice::ReadOnly))
|
||||||
|
{
|
||||||
|
file->close();
|
||||||
|
delete file;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
QString json = QString(file->readAll());
|
||||||
|
file->close();
|
||||||
|
delete file;
|
||||||
|
|
||||||
|
doc = QJsonDocument::fromJson(json.toUtf8());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|||||||
11
src/tools.h
11
src/tools.h
@@ -2,14 +2,21 @@
|
|||||||
#define TOOLS_H
|
#define TOOLS_H
|
||||||
|
|
||||||
#include <QColor>
|
#include <QColor>
|
||||||
|
#include <QJsonDocument>
|
||||||
|
|
||||||
class Tools
|
class Tools
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Tools();
|
Tools();
|
||||||
|
|
||||||
static QColor getRandomColor();
|
static const QColor getRandomColor();
|
||||||
static QColor getForegroundColor(QColor background);
|
static const QColor getForegroundColor(QColor background);
|
||||||
|
static bool isSaveFileExist();
|
||||||
|
static bool writeSaveToFile(QJsonDocument doc);
|
||||||
|
static bool readSaveFile(QJsonDocument &doc);
|
||||||
|
|
||||||
|
private:
|
||||||
|
static const QString getSaveFilePath();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user