mirai/src/core/TaskItem.cpp

91 lines
1.4 KiB
C++
Raw Normal View History

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-04-14 14:11:41 +02:00
#include "TasksFile.h"
#include "core/utils.h"
#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-04-14 14:11:41 +02:00
TaskItem::TaskItem(TasksFile *parent, TaskItemData data) : parent(parent), data(data)
{
}
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::setDate(const std::string &date)
{
2024-04-14 14:11:41 +02:00
this->data.date = date;
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-13 11:52:42 +02:00
const std::string &TaskItem::getDate() const
{
2024-04-14 14:11:41 +02:00
return data.date;
2024-04-13 11:52:42 +02:00
}
const std::string &TaskItem::getStartTime() const
{
2024-04-14 14:11:41 +02:00
return data.startTime;
2024-04-13 11:52:42 +02:00
}
const std::string &TaskItem::getEndTime() const
{
2024-04-14 14:11:41 +02:00
return data.endTime;
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::hasDate() const
{
2024-04-14 14:11:41 +02:00
return isDate(data.date);
2024-04-13 11:52:42 +02:00
}
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()
{
if (parent) {
parent->setDirty(true);
}
}
2024-04-13 11:52:42 +02:00
} // namespace mirai