add todos
This commit is contained in:
@@ -10,8 +10,10 @@ public:
|
||||
~TodoEntry() override;
|
||||
|
||||
int get_id() const { return id; }
|
||||
std::string get_text() const { return text; }
|
||||
private:
|
||||
int id;
|
||||
std::string text;
|
||||
sigc::signal<void(int)> signal_dismissed;
|
||||
|
||||
void on_dismiss_clicked();
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "components/todoEntry.hpp"
|
||||
#include "services/todoAdapter.hpp"
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class TodoService {
|
||||
public:
|
||||
@@ -12,11 +13,15 @@ class TodoService {
|
||||
std::map<int, TodoEntry *> getTodos();
|
||||
void init();
|
||||
void removeTodo(int id);
|
||||
TodoEntry *addTodo(std::string text, bool emitSignal = true);
|
||||
TodoEntry *addTodo(std::string text, bool emitSignal = true, bool persist = true);
|
||||
void updateTodo(int id, std::string text);
|
||||
|
||||
private:
|
||||
void load();
|
||||
|
||||
int nextId = 1;
|
||||
std::map<int, TodoEntry *> todos;
|
||||
sigc::signal<void()> refreshSignal;
|
||||
|
||||
std::unique_ptr<ITodoAdapter> adapter;
|
||||
};
|
||||
21
include/services/todoAdapter.hpp
Normal file
21
include/services/todoAdapter.hpp
Normal file
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
struct TodoRecord {
|
||||
int id;
|
||||
std::string text;
|
||||
};
|
||||
|
||||
class ITodoAdapter {
|
||||
public:
|
||||
virtual ~ITodoAdapter() = default;
|
||||
|
||||
virtual bool init() = 0;
|
||||
virtual std::vector<TodoRecord> listTodos() = 0;
|
||||
|
||||
virtual int addTodo(const std::string &text) = 0;
|
||||
virtual bool removeTodo(int id) = 0;
|
||||
virtual bool updateTodo(int id, const std::string &text) = 0;
|
||||
};
|
||||
Reference in New Issue
Block a user