2024-04-13 11:52:42 +02:00
|
|
|
/*
|
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 "TaskItem.h"
|
2024-05-09 14:39:10 +02:00
|
|
|
#include "BaseResource.h"
|
2024-08-16 21:35:12 +02:00
|
|
|
#include "utils.h"
|
2024-04-14 14:11:41 +02:00
|
|
|
#include <iostream>
|
2024-04-10 16:53:18 +02:00
|
|
|
|
2024-04-13 11:52:42 +02:00
|
|
|
namespace mirai
|
|
|
|
{
|
2024-04-10 16:53:18 +02:00
|
|
|
|
2024-08-16 21:35:12 +02:00
|
|
|
int TaskItem::nextId = 0;
|
|
|
|
|
|
|
|
TaskItem::TaskItem(BaseResource *source, Day *day, TaskItemData data)
|
|
|
|
: source_(source), day_(day), data(data)
|
2024-04-14 14:11:41 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2024-04-13 11:52:42 +02:00
|
|
|
void TaskItem::markAsDone()
|
|
|
|
{
|
2024-04-14 14:11:41 +02:00
|
|
|
data.state = DONE;
|
|
|
|
onChange();
|
2024-04-13 11:52:42 +02:00
|
|
|
}
|
2024-04-10 16:53:18 +02:00
|
|
|
|
2024-04-13 11:52:42 +02:00
|
|
|
void TaskItem::markAsUndone()
|
|
|
|
{
|
2024-04-14 14:11:41 +02:00
|
|
|
data.state = TODO;
|
|
|
|
onChange();
|
2024-04-13 11:52:42 +02:00
|
|
|
}
|
2024-04-10 16:53:18 +02:00
|
|
|
|
2024-04-13 11:52:42 +02:00
|
|
|
void TaskItem::setText(const std::string &text)
|
|
|
|
{
|
2024-04-14 14:11:41 +02:00
|
|
|
this->data.text = text;
|
|
|
|
onChange();
|
2024-04-13 11:52:42 +02:00
|
|
|
}
|
2024-04-10 16:53:18 +02:00
|
|
|
|
2024-04-13 11:52:42 +02:00
|
|
|
const std::string &TaskItem::getText() const
|
|
|
|
{
|
2024-04-14 14:11:41 +02:00
|
|
|
return data.text;
|
2024-04-13 11:52:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const TaskItemState &TaskItem::getState() const
|
|
|
|
{
|
2024-04-14 14:11:41 +02:00
|
|
|
return data.state;
|
2024-04-13 11:52:42 +02:00
|
|
|
}
|
2024-04-11 11:42:13 +02:00
|
|
|
|
2024-04-13 11:52:42 +02:00
|
|
|
const Tags &TaskItem::getTags() const
|
|
|
|
{
|
2024-04-14 14:11:41 +02:00
|
|
|
return data.tags;
|
2024-04-13 11:52:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool TaskItem::hasTag(const std::string &tag) const
|
|
|
|
{
|
2024-04-14 14:11:41 +02:00
|
|
|
return vectorUtils::contains(data.tags, tag);
|
2024-04-10 16:53:18 +02:00
|
|
|
}
|
2024-04-14 14:11:41 +02:00
|
|
|
|
|
|
|
void TaskItem::onChange()
|
|
|
|
{
|
2024-08-16 21:35:12 +02:00
|
|
|
source()->setDirty(true);
|
2024-04-14 14:11:41 +02:00
|
|
|
}
|
|
|
|
|
2024-04-13 11:52:42 +02:00
|
|
|
} // namespace mirai
|