diff --git a/src/domain/CMakeLists.txt b/src/domain/CMakeLists.txt --- a/src/domain/CMakeLists.txt +++ b/src/domain/CMakeLists.txt @@ -1,5 +1,4 @@ set(domain_SRCS - artifact.cpp context.cpp contextqueries.cpp contextrepository.cpp diff --git a/src/domain/artifact.h b/src/domain/artifact.h deleted file mode 100644 --- a/src/domain/artifact.h +++ /dev/null @@ -1,68 +0,0 @@ -/* This file is part of Zanshin - - Copyright 2014 Kevin Ottens - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of - the License or (at your option) version 3 or any later version - accepted by the membership of KDE e.V. (or its successor approved - by the membership of KDE e.V.), which shall act as a proxy - defined in Section 14 of version 3 of the license. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - USA. -*/ - - -#ifndef DOMAIN_ARTIFACT_H -#define DOMAIN_ARTIFACT_H - -#include -#include -#include - -namespace Domain { - -class Artifact : public QObject -{ - Q_OBJECT - Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged) - Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged) - -public: - typedef QSharedPointer Ptr; - typedef QList List; - - explicit Artifact(QObject *parent = Q_NULLPTR); - virtual ~Artifact(); - - QString text() const; - QString title() const; - -public slots: - void setText(const QString &text); - void setTitle(const QString &title); - -signals: - void textChanged(const QString &text); - void titleChanged(const QString &title); - -private: - QString m_text; - QString m_title; -}; - -} - -Q_DECLARE_METATYPE(Domain::Artifact::Ptr) -Q_DECLARE_METATYPE(Domain::Artifact::List) - -#endif // DOMAIN_ARTIFACT_H diff --git a/src/domain/artifact.cpp b/src/domain/artifact.cpp deleted file mode 100644 --- a/src/domain/artifact.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/* This file is part of Zanshin - - Copyright 2014 Kevin Ottens - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of - the License or (at your option) version 3 or any later version - accepted by the membership of KDE e.V. (or its successor approved - by the membership of KDE e.V.), which shall act as a proxy - defined in Section 14 of version 3 of the license. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - USA. -*/ - - -#include "artifact.h" - -using namespace Domain; - -Artifact::Artifact(QObject *parent) - : QObject(parent) -{ -} - -Artifact::~Artifact() -{ -} - -QString Artifact::text() const -{ - return m_text; -} - -void Artifact::setText(const QString &text) -{ - if (m_text == text) - return; - - m_text = text; - emit textChanged(text); -} - -QString Artifact::title() const -{ - return m_title; -} - -void Artifact::setTitle(const QString &title) -{ - if (m_title == title) - return; - - m_title = title; - emit titleChanged(title); -} - diff --git a/src/domain/task.h b/src/domain/task.h --- a/src/domain/task.h +++ b/src/domain/task.h @@ -25,15 +25,19 @@ #ifndef DOMAIN_TASK_H #define DOMAIN_TASK_H -#include "artifact.h" #include +#include +#include +#include #include namespace Domain { -class Task : public Artifact +class Task : public QObject { Q_OBJECT + Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged) + Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged) Q_PROPERTY(bool running READ isRunning WRITE setRunning NOTIFY runningChanged) Q_PROPERTY(bool done READ isDone WRITE setDone NOTIFY doneChanged) Q_PROPERTY(QDate startDate READ startDate WRITE setStartDate NOTIFY startDateChanged) @@ -95,6 +99,8 @@ explicit Task(QObject *parent = Q_NULLPTR); virtual ~Task(); + QString text() const; + QString title() const; bool isRunning() const; bool isDone() const; QDate startDate() const; @@ -104,6 +110,8 @@ Attachments attachments() const; public slots: + void setText(const QString &text); + void setTitle(const QString &title); void setRunning(bool running); void setDone(bool done); void setDoneDate(const QDate &doneDate); @@ -113,6 +121,8 @@ void setAttachments(const Domain::Task::Attachments &attachments); signals: + void textChanged(const QString &text); + void titleChanged(const QString &title); void runningChanged(bool isRunning); void doneChanged(bool isDone); void doneDateChanged(const QDate &doneDate); @@ -122,6 +132,8 @@ void attachmentsChanged(const Domain::Task::Attachments &attachments); private: + QString m_text; + QString m_title; bool m_running; bool m_done; QDate m_startDate; diff --git a/src/domain/task.cpp b/src/domain/task.cpp --- a/src/domain/task.cpp +++ b/src/domain/task.cpp @@ -29,7 +29,7 @@ using namespace Domain; Task::Task(QObject *parent) - : Artifact(parent), + : QObject(parent), m_running(false), m_done(false), m_recurrence(NoRecurrence) @@ -40,6 +40,16 @@ { } +QString Task::text() const +{ + return m_text; +} + +QString Task::title() const +{ + return m_title; +} + bool Task::isRunning() const { return m_running; @@ -107,6 +117,24 @@ return m_attachments; } +void Task::setText(const QString &text) +{ + if (m_text == text) + return; + + m_text = text; + emit textChanged(text); +} + +void Task::setTitle(const QString &title) +{ + if (m_title == title) + return; + + m_title = title; + emit titleChanged(title); +} + void Task::setRunning(bool running) { if (m_running == running) diff --git a/tests/units/domain/CMakeLists.txt b/tests/units/domain/CMakeLists.txt --- a/tests/units/domain/CMakeLists.txt +++ b/tests/units/domain/CMakeLists.txt @@ -1,5 +1,4 @@ zanshin_auto_tests( - artifacttest contexttest datasourcetest livequerytest diff --git a/tests/units/domain/artifacttest.cpp b/tests/units/domain/artifacttest.cpp deleted file mode 100644 --- a/tests/units/domain/artifacttest.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/* This file is part of Zanshin - - Copyright 2014 Kevin Ottens - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of - the License or (at your option) version 3 or any later version - accepted by the membership of KDE e.V. (or its successor approved - by the membership of KDE e.V.), which shall act as a proxy - defined in Section 14 of version 3 of the license. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - USA. -*/ - -#include - -#include "domain/artifact.h" - -using namespace Domain; - -class ArtifactTest : public QObject -{ - Q_OBJECT -private slots: - void shouldHaveEmptyPropertiesByDefault() - { - Artifact a; - QCOMPARE(a.text(), QString()); - QCOMPARE(a.title(), QString()); - } - - void shouldNotifyTextChanges() - { - Artifact a; - QSignalSpy spy(&a, &Artifact::textChanged); - a.setText(QStringLiteral("foo")); - QCOMPARE(spy.count(), 1); - QCOMPARE(spy.first().first().toString(), QStringLiteral("foo")); - } - - void shouldNotNotifyIdenticalTextChanges() - { - Artifact a; - a.setText(QStringLiteral("foo")); - QSignalSpy spy(&a, &Artifact::textChanged); - a.setText(QStringLiteral("foo")); - QCOMPARE(spy.count(), 0); - } - - void shouldNotifyTitleChanges() - { - Artifact a; - QSignalSpy spy(&a, &Artifact::titleChanged); - a.setTitle(QStringLiteral("foo")); - QCOMPARE(spy.count(), 1); - QCOMPARE(spy.first().first().toString(), QStringLiteral("foo")); - } - - void shouldNotNotifyIdenticalTitleChanges() - { - Artifact a; - a.setTitle(QStringLiteral("foo")); - QSignalSpy spy(&a, &Artifact::titleChanged); - a.setTitle(QStringLiteral("foo")); - QCOMPARE(spy.count(), 0); - } -}; - -ZANSHIN_TEST_MAIN(ArtifactTest) - -#include "artifacttest.moc" 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 @@ -54,6 +54,42 @@ QVERIFY(t.attachments().isEmpty()); } + void shouldNotifyTextChanges() + { + Task t; + QSignalSpy spy(&t, &Task::textChanged); + t.setText(QStringLiteral("foo")); + QCOMPARE(spy.count(), 1); + QCOMPARE(spy.first().first().toString(), QStringLiteral("foo")); + } + + void shouldNotNotifyIdenticalTextChanges() + { + Task t; + t.setText(QStringLiteral("foo")); + QSignalSpy spy(&t, &Task::textChanged); + t.setText(QStringLiteral("foo")); + QCOMPARE(spy.count(), 0); + } + + void shouldNotifyTitleChanges() + { + Task t; + QSignalSpy spy(&t, &Task::titleChanged); + t.setTitle(QStringLiteral("foo")); + QCOMPARE(spy.count(), 1); + QCOMPARE(spy.first().first().toString(), QStringLiteral("foo")); + } + + void shouldNotNotifyIdenticalTitleChanges() + { + Task t; + t.setTitle(QStringLiteral("foo")); + QSignalSpy spy(&t, &Task::titleChanged); + t.setTitle(QStringLiteral("foo")); + QCOMPARE(spy.count(), 0); + } + void shouldHaveValueBasedAttachment() { Task::Attachment a;