mirai/src/core/TasksView.cpp

57 lines
1.4 KiB
C++
Raw Normal View History

2024-04-10 16:53:18 +02:00
/*
* Mirai. Copyright (C) 2024 Vyn
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
*/
#include "TasksView.h"
namespace mirai {
TasksView::TasksView(std::shared_ptr<std::vector<TasksFile>> files) : files(files) {
update();
}
TaskItem& TasksView::operator[](int index) {
return *(tasksToShow.at(index));
}
int TasksView::count() const { return tasksToShow.size(); }
void TasksView::update() {
tasksToShow.clear();
for (auto& file : *files) {
for (auto& task : file.getTasks()) {
if (tagsFilter.size() != 0
&& std::find_if(tagsFilter.begin(), tagsFilter.end(), [&](const std::string& tag) {
return task->getText().find(tag) != std::string::npos;
}) == tagsFilter.end())
continue;
tasksToShow.push_back(task.get());
}
}
}
void TasksView::addTagFilter(const std::string& tag) {
tagsFilter.push_back(tag);
update();
}
void TasksView::removeTagFilter(const std::string& tag) {
tagsFilter.erase(std::remove_if(tagsFilter.begin(), tagsFilter.end(), [&] (const auto& tagInFilter){
return tag == tagInFilter;
}));
update();
}
void TasksView::removeFilters() {
tagsFilter.clear();
update();
}
const std::vector<std::string>& TasksView::getActiveTagsFilter() {
return tagsFilter;
}
}