mirai/lib/mirai-core/TaskItem.h

82 lines
1.3 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
*/
#ifndef MIRAI_TASKITEM_H
#define MIRAI_TASKITEM_H
#include "using.h"
2024-04-14 14:11:41 +02:00
#include <functional>
2024-04-10 16:53:18 +02:00
#include <string>
2024-04-13 11:52:42 +02:00
namespace mirai
{
2024-08-16 21:35:12 +02:00
class BaseResource;
class Day;
2024-04-13 11:52:42 +02:00
enum TaskItemState { TODO, DONE };
2024-04-14 14:11:41 +02:00
struct TaskItemData {
std::string text;
TaskItemState state;
Tags tags;
};
class TaskItem
{
2024-04-13 11:52:42 +02:00
public:
2024-08-16 21:35:12 +02:00
TaskItem(BaseResource *source, Day *day, const TaskItemData data);
2024-04-14 14:11:41 +02:00
TaskItem &operator=(const TaskItemData &newData)
{
data = newData;
onChange();
return *this;
};
2024-04-13 11:52:42 +02:00
void markAsDone();
void markAsUndone();
void setDate(const std::string &date);
void setText(const std::string &text);
const std::string &getLine() const;
const std::string &getText() const;
const TaskItemState &getState() const;
const Tags &getTags() const;
bool hasTag(const std::string &tag) const;
2024-08-16 21:35:12 +02:00
int id() const
{
return id_;
}
BaseResource *source()
{
return source_;
}
Day *day()
{
return day_;
}
2024-04-13 11:52:42 +02:00
2024-04-14 14:11:41 +02:00
private:
void onChange();
2024-08-16 21:35:12 +02:00
static int nextId;
int id_ = nextId++;
2024-04-14 14:11:41 +02:00
TaskItemData data;
2024-08-16 21:35:12 +02:00
BaseResource *source_;
Day *day_;
2024-04-13 11:52:42 +02:00
};
2024-08-16 21:35:12 +02:00
2024-04-13 11:52:42 +02:00
} // namespace mirai
2024-04-10 16:53:18 +02:00
#endif