diff --git a/src/domain/task.h b/src/domain/task.h --- a/src/domain/task.h +++ b/src/domain/task.h @@ -38,12 +38,21 @@ Q_PROPERTY(bool done READ isDone WRITE setDone NOTIFY doneChanged) Q_PROPERTY(QDateTime startDate READ startDate WRITE setStartDate NOTIFY startDateChanged) Q_PROPERTY(QDateTime dueDate READ dueDate WRITE setDueDate NOTIFY dueDateChanged) + Q_PROPERTY(Domain::Task::Recurrence recurrence READ recurrence WRITE setRecurrence NOTIFY recurrenceChanged) Q_PROPERTY(Domain::Task::Delegate delegate READ delegate WRITE setDelegate NOTIFY delegateChanged) Q_PROPERTY(Domain::Task::Attachments attachements READ attachments WRITE setAttachments NOTIFY attachmentsChanged) public: typedef QSharedPointer Ptr; typedef QList List; + enum Recurrence { + NoRecurrence = 0, + RecursDaily, + RecursWeekly, + RecursMonthly // for now only monthly on the same day (say 11th day of the month) + }; + Q_ENUM(Recurrence) + class Attachment { public: @@ -117,6 +126,7 @@ QDateTime startDate() const; QDateTime dueDate() const; QDateTime doneDate() const; + Recurrence recurrence() const; Attachments attachments() const; Delegate delegate() const; @@ -126,6 +136,7 @@ void setDoneDate(const QDateTime &doneDate); void setStartDate(const QDateTime &startDate); void setDueDate(const QDateTime &dueDate); + void setRecurrence(Domain::Task::Recurrence recurrence); void setAttachments(const Domain::Task::Attachments &attachments); void setDelegate(const Domain::Task::Delegate &delegate); @@ -135,6 +146,7 @@ void doneDateChanged(const QDateTime &doneDate); void startDateChanged(const QDateTime &startDate); void dueDateChanged(const QDateTime &dueDate); + void recurrenceChanged(Domain::Task::Recurrence recurrence); void attachmentsChanged(const Domain::Task::Attachments &attachments); void delegateChanged(const Domain::Task::Delegate &delegate); @@ -144,6 +156,7 @@ QDateTime m_startDate; QDateTime m_dueDate; QDateTime m_doneDate; + Recurrence m_recurrence; Attachments m_attachments; Delegate m_delegate; }; diff --git a/src/domain/task.cpp b/src/domain/task.cpp --- a/src/domain/task.cpp +++ b/src/domain/task.cpp @@ -31,7 +31,8 @@ Task::Task(QObject *parent) : Artifact(parent), m_running(false), - m_done(false) + m_done(false), + m_recurrence(NoRecurrence) { } @@ -96,6 +97,11 @@ return m_doneDate; } +Task::Recurrence Task::recurrence() const +{ + return m_recurrence; +} + Task::Attachments Task::attachments() const { return m_attachments; @@ -123,6 +129,15 @@ emit dueDateChanged(dueDate); } +void Task::setRecurrence(Task::Recurrence recurrence) +{ + if (m_recurrence == recurrence) + return; + + m_recurrence = recurrence; + emit recurrenceChanged(recurrence); +} + void Task::setAttachments(const Task::Attachments &attachments) { if (m_attachments == attachments) diff --git a/tests/units/domain/tasktest.cpp b/tests/units/domain/tasktest.cpp --- a/tests/units/domain/tasktest.cpp +++ b/tests/units/domain/tasktest.cpp @@ -36,6 +36,7 @@ explicit TaskTest(QObject *parent = Q_NULLPTR) : QObject(parent) { + qRegisterMetaType(); qRegisterMetaType(); qRegisterMetaType(); } @@ -50,6 +51,7 @@ QCOMPARE(t.startDate(), QDateTime()); QCOMPARE(t.dueDate(), QDateTime()); QCOMPARE(t.doneDate(), QDateTime()); + QCOMPARE(t.recurrence(), Domain::Task::NoRecurrence); QVERIFY(t.attachments().isEmpty()); QVERIFY(!t.delegate().isValid()); } @@ -210,6 +212,24 @@ QCOMPARE(spy.count(), 0); } + void shouldNotifyRecurrenceChanges() + { + Task t; + QSignalSpy spy(&t, &Task::recurrenceChanged); + t.setRecurrence(Task::RecursWeekly); + QCOMPARE(spy.count(), 1); + QCOMPARE(spy.first().first().value(), Task::RecursWeekly); + } + + void shouldNotNotifyIdenticalRecurrenceChanges() + { + Task t; + t.setRecurrence(Task::RecursWeekly); + QSignalSpy spy(&t, &Task::recurrenceChanged); + t.setRecurrence(Task::RecursWeekly); + QCOMPARE(spy.count(), 0); + } + void shouldNotifyAttachmentsChanges() { Task::Attachments attachments;