mirror of
https://codeberg.org/vyn/mirai.git
synced 2025-07-03 18:23:19 +00:00
Refactor TasksView, Mirai instance doesn't depend on it anymore
This commit is contained in:
parent
d1a4858504
commit
841c87752f
7 changed files with 39 additions and 57 deletions
|
@ -7,6 +7,7 @@
|
|||
#include "Backend.h"
|
||||
#include "TaskItem.h"
|
||||
#include "core/TaskItem.h"
|
||||
#include "core/TasksView.h"
|
||||
#include "core/TodoMd.h"
|
||||
#include <iostream>
|
||||
#include <ostream>
|
||||
|
@ -15,7 +16,7 @@
|
|||
#include <qlogging.h>
|
||||
#include <qvariant.h>
|
||||
|
||||
Backend::Backend()
|
||||
Backend::Backend() : view(&mirai)
|
||||
{
|
||||
std::cout << "Backend created" << std::endl;
|
||||
QDir().mkdir(QDir::homePath() + "/.config/mirai");
|
||||
|
@ -51,8 +52,7 @@ Backend::Backend()
|
|||
jsonTagsConfig.toObject()[jsonTagConfigKey].toObject()["color"].toString();
|
||||
}
|
||||
}
|
||||
|
||||
view = mirai.getTasks();
|
||||
view.update();
|
||||
rebuildQMLTasksList();
|
||||
}
|
||||
|
||||
|
@ -60,6 +60,7 @@ void Backend::addTodo(QString newTodo, QString date)
|
|||
{
|
||||
mirai.addTask(newTodo.toStdString(), date.toStdString());
|
||||
mirai.save();
|
||||
view.update();
|
||||
rebuildQMLTasksList();
|
||||
emit tasksChanged();
|
||||
}
|
||||
|
@ -75,42 +76,42 @@ void Backend::addTodoFromRawFormat(QString filePath, QString text, QString date)
|
|||
mirai::TodoMdFormat::StringToTask(text.toStdString(), date.toStdString())
|
||||
);
|
||||
mirai.save();
|
||||
view.lock()->update();
|
||||
view.update();
|
||||
rebuildQMLTasksList();
|
||||
emit tasksChanged();
|
||||
}
|
||||
|
||||
void Backend::addTagFilter(QString tag)
|
||||
{
|
||||
view.lock()->addTagFilter(tag.toStdString());
|
||||
view.addTagFilter(tag.toStdString());
|
||||
rebuildQMLTasksList();
|
||||
emit tasksChanged();
|
||||
}
|
||||
|
||||
void Backend::removeTagFilter(QString tag)
|
||||
{
|
||||
view.lock()->removeTagFilter(tag.toStdString());
|
||||
view.removeTagFilter(tag.toStdString());
|
||||
rebuildQMLTasksList();
|
||||
emit tasksChanged();
|
||||
}
|
||||
|
||||
void Backend::addFileFilter(QString fileName)
|
||||
{
|
||||
view.lock()->addFileFilter(fileName.toStdString());
|
||||
view.addFileFilter(fileName.toStdString());
|
||||
rebuildQMLTasksList();
|
||||
emit tasksChanged();
|
||||
}
|
||||
|
||||
void Backend::removeFileFilter(QString fileName)
|
||||
{
|
||||
view.lock()->removeFileFilter(fileName.toStdString());
|
||||
view.removeFileFilter(fileName.toStdString());
|
||||
rebuildQMLTasksList();
|
||||
emit tasksChanged();
|
||||
}
|
||||
|
||||
void Backend::removeFilters()
|
||||
{
|
||||
view.lock()->removeFilters();
|
||||
view.removeFilters();
|
||||
rebuildQMLTasksList();
|
||||
emit tasksChanged();
|
||||
}
|
||||
|
@ -122,7 +123,7 @@ void Backend::updateTodoFromRawFormat(int todoIndex, QString text, QString date)
|
|||
*(taskItem.taskItem) =
|
||||
mirai::TodoMdFormat::StringToTask(text.toStdString(), date.toStdString());
|
||||
mirai.save();
|
||||
view.lock()->update();
|
||||
view.update();
|
||||
rebuildQMLTasksList();
|
||||
emit tasksChanged();
|
||||
}
|
||||
|
@ -138,7 +139,7 @@ void Backend::updateTodo(int todoIndex, QString state, QString text, QString dat
|
|||
taskItem.taskItem->setText(text.toStdString());
|
||||
taskItem.taskItem->setDate(date.toStdString());
|
||||
mirai.save();
|
||||
view.lock()->update();
|
||||
view.update();
|
||||
rebuildQMLTasksList();
|
||||
emit tasksChanged();
|
||||
}
|
||||
|
@ -148,6 +149,7 @@ void Backend::removeTodo(int todoIndex)
|
|||
QMLTaskItem &taskItem = QMLTasks[todoIndex];
|
||||
mirai.removeTask(taskItem.taskItem);
|
||||
mirai.save();
|
||||
view.update();
|
||||
rebuildQMLTasksList();
|
||||
emit tasksChanged();
|
||||
}
|
||||
|
@ -173,8 +175,8 @@ void Backend::rebuildQMLTasksList()
|
|||
std::tm tm = *std::localtime(&t);
|
||||
std::stringstream currentDate;
|
||||
currentDate << std::put_time(&tm, "%Y-%m-%d");
|
||||
for (int i = 0; i < view.lock()->count(); ++i) {
|
||||
mirai::TaskItem &task = (*view.lock())[i];
|
||||
for (int i = 0; i < view.count(); ++i) {
|
||||
mirai::TaskItem &task = view[i];
|
||||
if (shouldHideCompletedTasks_ && task.getState() == mirai::DONE && task.hasDate() &&
|
||||
task.getDate() < currentDate.str()) {
|
||||
continue;
|
||||
|
@ -199,12 +201,12 @@ void Backend::rebuildQMLTasksList()
|
|||
}
|
||||
|
||||
QMLActiveTagsFilter.clear();
|
||||
for (auto &activeTagFilter : view.lock()->getActiveTagsFilter()) {
|
||||
for (auto &activeTagFilter : view.getActiveTagsFilter()) {
|
||||
QMLActiveTagsFilter.push_back(QString::fromStdString(activeTagFilter));
|
||||
}
|
||||
|
||||
QMLActiveFilesFilter.clear();
|
||||
for (auto &activeFileFilter : view.lock()->getActiveFilesFilter()) {
|
||||
for (auto &activeFileFilter : view.getActiveFilesFilter()) {
|
||||
QMLActiveFilesFilter.push_back(QString::fromStdString(activeFileFilter));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue