Commit b0c87c81 authored by Nicolas Fella's avatar Nicolas Fella Committed by Dimitris Kardarakos

Rework todocontroller

parent 9dc3cc99
Pipeline #6203 passed with stage
in 5 minutes and 4 seconds
......@@ -207,9 +207,9 @@ Kirigami.Page {
onTriggered: {
if(summary.text) {
console.log("Saving task");
var controller = todoController.createObject(parent, { calendar: root.calendar });
controller.vtodo = { "uid": root.uid, "summary":root.summary, "startDate": root.startdt , "startHour": root.startHour + (root.startPm ? 12 : 0), "startMinute": root.startMinute, "allDay": root.allDay, "description": root.description,"location": root.location, "completed": root.completed};
controller.addEdit();
var controller = todoController.createObject(parent, {});
var vtodo = { "uid": root.uid, "summary":root.summary, "startDate": root.startdt , "startHour": root.startHour + (root.startPm ? 12 : 0), "startMinute": root.startMinute, "allDay": root.allDay, "description": root.description,"location": root.location, "completed": root.completed};
controller.addEdit(root.calendar, vtodo);
taskeditcompleted();
}
else {
......
......@@ -91,9 +91,9 @@ Kirigami.Page {
icon.name: "delete"
onTriggered: {
var controller = todoController.createObject(parent, { calendar: root.calendar });
controller.vtodo = { "uid" : model.uid };
controller.remove();
var controller = todoController.createObject(parent, {});
var vtodo = { "uid" : model.uid };
controller.remove(root.calendar, vtodo);
tasksUpdated();
}
},
......
......@@ -26,45 +26,19 @@ TodoController::TodoController(QObject* parent) : QObject(parent) {}
TodoController::~TodoController() = default;
QObject * TodoController::calendar() const
{
return m_calendar;
}
void TodoController::setCalendar(QObject *const calendarPtr)
{
if(m_calendar != calendarPtr)
{
m_calendar = calendarPtr;
emit calendarChanged();
}
}
QVariantMap TodoController::vtodo() const
{
return m_todo;
}
void TodoController::setVtodo(const QVariantMap& todo)
{
m_todo = todo;
emit vtodoChanged();
}
void TodoController::addEdit()
void TodoController::addEdit(LocalCalendar *calendar, const QVariantMap& todo)
{
qDebug() << "Adding/updating todo";
auto localCalendar = qobject_cast<LocalCalendar*>(m_calendar);
MemoryCalendar::Ptr memoryCalendar = localCalendar->memorycalendar();
MemoryCalendar::Ptr memoryCalendar = calendar->memorycalendar();
Todo::Ptr vtodo;
QDateTime now = QDateTime::currentDateTime();
QString uid = m_todo["uid"].value<QString>();
QString summary = m_todo["summary"].value<QString>();
QDate startDate = m_todo["startDate"].value<QDate>();
int startHour = m_todo["startHour"].value<int>();
int startMinute = m_todo["startMinute"].value<int>();
bool allDayFlg= m_todo["allDay"].value<bool>();
QString uid = todo["uid"].value<QString>();
QString summary = todo["summary"].value<QString>();
QDate startDate = todo["startDate"].value<QDate>();
int startHour = todo["startHour"].value<int>();
int startMinute = todo["startMinute"].value<int>();
bool allDayFlg= todo["allDay"].value<bool>();
if(uid == "")
{
......@@ -86,35 +60,28 @@ void TodoController::addEdit()
}
vtodo->setDtStart(startDateTime);
vtodo->setDescription(m_todo["description"].value<QString>());
vtodo->setDescription(todo["description"].value<QString>());
vtodo->setSummary(summary);
vtodo->setAllDay(allDayFlg);
vtodo->setLocation(m_todo["location"].value<QString>());
vtodo->setCompleted(m_todo["completed"].value<bool>());
vtodo->setLocation(todo["location"].value<QString>());
vtodo->setCompleted(todo["completed"].value<bool>());
memoryCalendar->addTodo(vtodo);
bool merged = localCalendar->save();
bool merged = calendar->save();
qDebug() << "Todo added/updated: " << merged;
emit vtodoChanged();
emit vtodosUpdated();
}
void TodoController::remove()
void TodoController::remove(LocalCalendar *calendar, const QVariantMap& todo)
{
qDebug() << "Deleting todo";
auto localCalendar = qobject_cast<LocalCalendar*>(m_calendar);
MemoryCalendar::Ptr memoryCalendar = localCalendar->memorycalendar();
QString uid = m_todo["uid"].value<QString>();
MemoryCalendar::Ptr memoryCalendar = calendar->memorycalendar();
QString uid = todo["uid"].value<QString>();
Todo::Ptr vtodo = memoryCalendar->todo(uid);
memoryCalendar->deleteTodo(vtodo);
bool removed = localCalendar->save();
bool removed = calendar->save();
qDebug() << "Todo deleted: " << removed;
emit vtodoChanged();
emit vtodosUpdated();
}
......@@ -21,34 +21,19 @@
#include <QObject>
#include <QVariantMap>
class LocalCalendar;
class TodoController : public QObject
{
Q_OBJECT
Q_PROPERTY(QObject* calendar READ calendar WRITE setCalendar NOTIFY calendarChanged);
Q_PROPERTY(QVariantMap vtodo READ vtodo WRITE setVtodo NOTIFY vtodoChanged);
public:
explicit TodoController(QObject* parent = nullptr);
~TodoController() override;
QObject* calendar() const;
void setCalendar(QObject* const calendarPtr );
QVariantMap vtodo() const;
void setVtodo(const QVariantMap& todo);
Q_INVOKABLE void remove();
Q_INVOKABLE void addEdit();
Q_SIGNALS:
void calendarChanged();
void vtodoChanged();
void vtodosUpdated();
Q_INVOKABLE void remove(LocalCalendar *calendar, const QVariantMap& todo);
Q_INVOKABLE void addEdit(LocalCalendar *calendar, const QVariantMap& todo);
private:
QObject* m_calendar;
QVariantMap m_todo;
};
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment