mirror of
https://codeberg.org/vyn/mirai.git
synced 2025-07-05 03:03:20 +00:00
57 lines
1.4 KiB
C++
57 lines
1.4 KiB
C++
|
/*
|
||
|
* 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;
|
||
|
}
|
||
|
}
|