/* * 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" #include "cpp-utils/vector.h" #include #include namespace mirai { TasksView::TasksView(std::shared_ptr> 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()) { std::function f = [&](const std::string& tag) { return task->hasTag(tag); }; if (tagsFilter.size() > 0 && !vectorUtils::containsAll(tagsFilter, task->getTags())) 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& TasksView::getActiveTagsFilter() { return tagsFilter; } }