mirror of
https://codeberg.org/vyn/mirai.git
synced 2025-07-02 01:13:19 +00:00
59 lines
1.4 KiB
C++
59 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"
|
|
#include "cpp-utils/vector.h"
|
|
#include <algorithm>
|
|
#include <string>
|
|
|
|
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()) {
|
|
std::function<bool(const std::string&)> 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<std::string>& TasksView::getActiveTagsFilter() {
|
|
return tagsFilter;
|
|
}
|
|
}
|