From a86ece9c9af9ac77ec2013459bba47f2b8f216fc Mon Sep 17 00:00:00 2001 From: Aurelie Delhaie Date: Sun, 8 Jan 2023 20:43:24 +0100 Subject: [PATCH] Expected for color, add filter model --- TaskBoard.pro | 8 +- src/frames/mainwindow.cpp | 29 +++++-- src/models/board.cpp | 13 ++- src/models/board.h | 2 + src/models/filter.cpp | 161 ++++++++++++++++++++++++++++++++++++++ src/models/filter.h | 33 ++++++++ src/models/priority.cpp | 9 ++- src/models/status.cpp | 9 ++- src/models/task.cpp | 12 +++ src/models/task.h | 2 + 10 files changed, 261 insertions(+), 17 deletions(-) create mode 100644 src/models/filter.cpp create mode 100644 src/models/filter.h diff --git a/TaskBoard.pro b/TaskBoard.pro index 5c719c4..0958cf9 100644 --- a/TaskBoard.pro +++ b/TaskBoard.pro @@ -1,11 +1,11 @@ QT += core gui -greaterThan(QT_MAJOR_VERSION, 4): QT += widgets +greaterThan(QT_MAJOR_VERSION, 5): QT += widgets CONFIG += c++17 -win32:VERSION = 0.1.1.0 # major.minor.patch.build -else:VERSION = 0.1.1 # major.minor.patch +win32:VERSION = 0.2.0.0 # major.minor.patch.build +else:VERSION = 0.2.0 # major.minor.patch DEFINES += APP_VERSION=\"\\\"$${VERSION}\\\"\" DEFINES += APP_NAME=\"\\\"TaskBoard\\\"\" @@ -74,6 +74,7 @@ SOURCES += \ src/frames/mainwindow.cpp \ src/frames/namedialog.cpp \ src/frames/prefdialog.cpp \ + src/models/filter.cpp \ src/models/priority.cpp \ src/models/status.cpp \ src/models/task.cpp \ @@ -86,6 +87,7 @@ HEADERS += \ src/frames/mainwindow.h \ src/frames/namedialog.h \ src/frames/prefdialog.h \ + src/models/filter.h \ src/models/priority.h \ src/models/status.h \ src/models/task.h \ diff --git a/src/frames/mainwindow.cpp b/src/frames/mainwindow.cpp index 5a3de9c..77efbb5 100644 --- a/src/frames/mainwindow.cpp +++ b/src/frames/mainwindow.cpp @@ -265,19 +265,19 @@ void MainWindow::init() QVector MainWindow::defaultPriorities() { QVector res; - res.append(Priority(QUuid::createUuid().toString(QUuid::WithoutBraces), "None", QColor("#d9d9d9"))); - res.append(Priority(QUuid::createUuid().toString(QUuid::WithoutBraces), "Low", QColor("#309db0"))); - res.append(Priority(QUuid::createUuid().toString(QUuid::WithoutBraces), "Medium", QColor("#b08e30"))); - res.append(Priority(QUuid::createUuid().toString(QUuid::WithoutBraces), "High", QColor("#b04330"))); + res.append(Priority(QUuid::createUuid().toString(QUuid::WithoutBraces), "None", QColor(217, 217, 217))); + res.append(Priority(QUuid::createUuid().toString(QUuid::WithoutBraces), "Low", QColor(48, 157, 176))); + res.append(Priority(QUuid::createUuid().toString(QUuid::WithoutBraces), "Medium", QColor(176, 142, 48))); + res.append(Priority(QUuid::createUuid().toString(QUuid::WithoutBraces), "High", QColor(176, 67, 48))); return res; } QVector MainWindow::defaultStatus() { QVector res; - res.append(Status(QUuid::createUuid().toString(QUuid::WithoutBraces), "To Do", QColor("#8f8f8f"))); - res.append(Status(QUuid::createUuid().toString(QUuid::WithoutBraces), "Working on", QColor("#5f30b0"))); - res.append(Status(QUuid::createUuid().toString(QUuid::WithoutBraces), "Completed", QColor("#30b049"))); + res.append(Status(QUuid::createUuid().toString(QUuid::WithoutBraces), "To Do", QColor(143, 143, 143))); + res.append(Status(QUuid::createUuid().toString(QUuid::WithoutBraces), "Working on", QColor(95, 48, 176))); + res.append(Status(QUuid::createUuid().toString(QUuid::WithoutBraces), "Completed", QColor(48, 176, 73))); return res; } @@ -362,6 +362,21 @@ void MainWindow::updateTaskRow(QTreeWidgetItem *item, Task t) item->setToolTip(0, t.getDescription()); item->setText(3, t.getExpectedFor().toString()); + if (t.getExpectedFor() < QDate::currentDate()) + { + QBrush fgColor = item->foreground(3); + fgColor.setColor(QColor(176, 67, 48)); + fgColor.setStyle(Qt::BrushStyle::SolidPattern); + item->setForeground(3, fgColor); + } + else if (t.getExpectedFor() == QDate::currentDate()) + { + QBrush fgColor = item->foreground(3); + fgColor.setColor(QColor(176, 142, 48)); + fgColor.setStyle(Qt::BrushStyle::SolidPattern); + item->setForeground(3, fgColor); + } + if (!t.getStatusUUID().isEmpty()) { item->setText(1, getStatusLabel(t.getStatusUUID())); diff --git a/src/models/board.cpp b/src/models/board.cpp index c852872..6db71a0 100644 --- a/src/models/board.cpp +++ b/src/models/board.cpp @@ -2,18 +2,24 @@ #define NAME_KEY "name" #define TASKS_KEY "tasks" +#define UUID_KEY "uuid" #include #include +#include Board::Board(QString name) { + QUuid uuid = QUuid::createUuid(); + this->uuid = uuid.toString(QUuid::WithoutBraces); this->name = name; } Board::Board(QJsonObject obj) { - this->name = obj[NAME_KEY].toString(); + QUuid uuid = QUuid::createUuid(); + this->uuid = obj[UUID_KEY].toString(uuid.toString(QUuid::WithoutBraces)); + this->name = obj[NAME_KEY].toString("!Missing name!"); QJsonArray jsonTasks = obj[TASKS_KEY].toArray(); for (QJsonValue value : jsonTasks) { Task *t = new Task(value.toObject()); @@ -30,6 +36,11 @@ Board::~Board() } } +const QString Board::getUuid() +{ + return uuid; +} + const QString Board::getName() { return name; diff --git a/src/models/board.h b/src/models/board.h index 25e08f7..4089e81 100644 --- a/src/models/board.h +++ b/src/models/board.h @@ -14,6 +14,7 @@ public: Board(QJsonObject); ~Board(); + const QString getUuid(); const QString getName(); void setName(const QString name); void add(Task); @@ -25,6 +26,7 @@ public: private: QVector tasks; + QString uuid; QString name; }; diff --git a/src/models/filter.cpp b/src/models/filter.cpp new file mode 100644 index 0000000..6542c1c --- /dev/null +++ b/src/models/filter.cpp @@ -0,0 +1,161 @@ +#include "filter.h" + +#define NAME_KEY "name" +#define DATE_KEY "date" +#define BOARDS_KEY "boards" +#define STATUS_KEY "status" +#define PRIORITY_KEY "priority" + +filter::filter(QString name, uint8 expectedForComparator, QVector boards, QVector status, QVector priorities) +{ + this->name = name; + this->expectedForComparator = expectedForComparator; + this->boards = boards; + this->status = status; + this->priorities = priorities; +} + +filter::filter(QJsonObject obj) +{ + this->name = obj[NAME_KEY].toString("!Missing name!"); + this->expectedForComparator = obj[DATE_KEY].toInt(); + QJsonArray b = obj[BOARDS_KEY].toArray(); + QJsonArray s = obj[STATUS_KEY].toArray(); + QJsonArray p = obj[PRIORITY_KEY].toArray(); + foreach (QJsonValue value, b) + { + if (value.isString()) + { + boards.append(value.toString()); + } + } + foreach (QJsonValue value, s) + { + if (value.isString()) + { + status.append(value.toString()); + } + } + foreach (QJsonValue value, p) + { + if (value.isString()) + { + priorities.append(value.toString()); + } + } +} + +QVector filter::get(QVector allBoards) +{ + QDate now = QDate::currentDate(); + QVector selectedBoards; + if (this->boards.count() > 0) + { + for (Board *b : allBoards) + { + foreach (QString boardUuid, this->boards) + { + if (b->getUuid() == boardUuid) + { + selectedBoards.append(b); + } + } + } + } + else + { + selectedBoards = allBoards; + } + + bool fstatus, fpriority, fdate; + QVector result; + for (Board *b : selectedBoards) + { + for (Task *t : b->getTasks()) + { + fstatus = filterStatus(t); + fpriority = filterPriority(t); + fdate = filterDate(t, now); + if (fstatus && fpriority && fdate) + { + result.append(t); + } + } + } + return result; +} + +bool filter::filterStatus(Task *t) +{ + if (status.count() == 0) + { + return true; + } + bool result = false; + foreach (QString s, status) + { + if (t->getStatusUUID() == s) + { + result = true; + } + } + return result; +} + +bool filter::filterPriority(Task *t) +{ + if (priorities.count() == 0) + { + return true; + } + bool result = false; + foreach (QString p, priorities) + { + if (t->getPriorityUUID() == p) + { + result = true; + } + } + return result; +} + +bool filter::filterDate(Task *t, QDate now) +{ + switch (expectedForComparator) { + case 0: + return true; + case 1: + return t->getExpectedFor() < now; + case 2: + return t->getExpectedFor() == now; + case 3: + return t->getExpectedFor() > now; + } + return false; +} + +const QJsonObject filter::toJson() +{ + QJsonObject obj; + obj[name] = name; + obj[DATE_KEY] = expectedForComparator; + QJsonArray b; + foreach (QString uuid, boards) + { + b.append(uuid); + } + QJsonArray s; + foreach (QString uuid, status) + { + s.append(uuid); + } + QJsonArray p; + foreach (QString uuid, priorities) + { + p.append(uuid); + } + obj[BOARDS_KEY] = b; + obj[STATUS_KEY] = s; + obj[PRIORITY_KEY] = p; + return obj; +} diff --git a/src/models/filter.h b/src/models/filter.h new file mode 100644 index 0000000..df3929c --- /dev/null +++ b/src/models/filter.h @@ -0,0 +1,33 @@ +#ifndef FILTER_H +#define FILTER_H + +#include +#include +#include + +#include "task.h" +#include "board.h" + +class filter +{ +private: + QString name; + // 0 none, 1 lower, 2 equal, 3 upper + uint8_t expectedForComparator; + // if empty => all + QVector boards; + QVector status; + QVector priorities; +public: + filter(QString name, uint8 expectedForComparator,QVector boards,QVector status,QVector priorities); + filter(QJsonObject obj); + + QVector get(QVector); + + bool filterStatus(Task *t); + bool filterPriority(Task *t); + bool filterDate(Task *t, QDate now); + const QJsonObject toJson(); +}; + +#endif // FILTER_H diff --git a/src/models/priority.cpp b/src/models/priority.cpp index 24da0ea..907dd0b 100644 --- a/src/models/priority.cpp +++ b/src/models/priority.cpp @@ -4,6 +4,8 @@ #define NAME_KEY "name" #define COLOR_KEY "color" +#include + Priority::Priority(QString uuid, QString name, QColor color) { this->uuid = uuid; @@ -13,9 +15,10 @@ Priority::Priority(QString uuid, QString name, QColor color) Priority::Priority(QJsonObject obj) { - this->uuid = obj[UUID_KEY].toString(); - this->name = obj[NAME_KEY].toString(); - this->color = QColor(obj[COLOR_KEY].toString()); + QUuid uuid = QUuid::createUuid(); + this->uuid = obj[UUID_KEY].toString(uuid.toString(QUuid::WithoutBraces)); + this->name = obj[NAME_KEY].toString("!Missing name!"); + this->color = QColor(obj[COLOR_KEY].toString("#ffffff")); } const QString Priority::getName() diff --git a/src/models/status.cpp b/src/models/status.cpp index 13ec325..8ea7f0e 100644 --- a/src/models/status.cpp +++ b/src/models/status.cpp @@ -4,6 +4,8 @@ #define NAME_KEY "name" #define COLOR_KEY "color" +#include + Status::Status(QString uuid, QString name, QColor color) { this->uuid = uuid; @@ -13,9 +15,10 @@ Status::Status(QString uuid, QString name, QColor color) Status::Status(QJsonObject obj) { - this->uuid = obj[UUID_KEY].toString(); - this->name = obj[NAME_KEY].toString(); - this->color = QColor(obj[COLOR_KEY].toString()); + QUuid uuid = QUuid::createUuid(); + this->uuid = obj[UUID_KEY].toString(uuid.toString(QUuid::WithoutBraces)); + this->name = obj[NAME_KEY].toString("!Missing name!"); + this->color = QColor(obj[COLOR_KEY].toString("#ffffff")); } const QString Status::getName() diff --git a/src/models/task.cpp b/src/models/task.cpp index eb36cae..5ed5dae 100644 --- a/src/models/task.cpp +++ b/src/models/task.cpp @@ -5,9 +5,14 @@ #define EXPECTEDFOR_KEY "expected_for" #define PRIORITY_KEY "priority" #define STATUS_KEY "status" +#define UUID_KEY "uuid" + +#include Task::Task(QString title, QString description, QDate expectedFor, QString priorityUUID, QString statusUUID) { + QUuid uuid = QUuid::createUuid(); + this->uuid = uuid.toString(QUuid::WithoutBraces); this->title = title; this->description = description; this->expectedFor = expectedFor; @@ -17,6 +22,8 @@ Task::Task(QString title, QString description, QDate expectedFor, QString priori Task::Task(QJsonObject obj) { + QUuid uuid = QUuid::createUuid(); + this->uuid = obj[UUID_KEY].toString(uuid.toString(QUuid::WithoutBraces)); this->title = obj[TITLE_KEY].toString(); this->description = obj[DESCRIPTION_KEY].toString(); this->expectedFor = QDate::fromString(obj[EXPECTEDFOR_KEY].toString(), Qt::DateFormat::ISODate); @@ -24,6 +31,11 @@ Task::Task(QJsonObject obj) this->statusUUID = obj[STATUS_KEY].toString(); } +const QString Task::getUuid() +{ + return this->uuid; +} + const QString Task::getTitle() { return this->title; diff --git a/src/models/task.h b/src/models/task.h index c07cc84..bb13c27 100644 --- a/src/models/task.h +++ b/src/models/task.h @@ -11,6 +11,7 @@ public: Task(QString title, QString description, QDate expectedFor, QString priorityUUID, QString statusUUID); Task(QJsonObject); + const QString getUuid(); const QString getTitle(); const QString getDescription(); const QDate getExpectedFor(); @@ -21,6 +22,7 @@ public: void update(Task); private: + QString uuid; QString title; QString description; QDate expectedFor;