diff --git a/src/presentation/CMakeLists.txt b/src/presentation/CMakeLists.txt --- a/src/presentation/CMakeLists.txt +++ b/src/presentation/CMakeLists.txt @@ -1,6 +1,6 @@ set(presentation_SRCS applicationmodel.cpp - artifacteditormodel.cpp + editormodel.cpp artifactfilterproxymodel.cpp availablepagesmodelinterface.cpp availablepagessortfilterproxymodel.cpp diff --git a/src/presentation/applicationmodel.cpp b/src/presentation/applicationmodel.cpp --- a/src/presentation/applicationmodel.cpp +++ b/src/presentation/applicationmodel.cpp @@ -24,9 +24,9 @@ #include "applicationmodel.h" -#include "presentation/artifacteditormodel.h" #include "presentation/availablepagesmodelinterface.h" #include "presentation/availablesourcesmodel.h" +#include "presentation/editormodel.h" #include "presentation/errorhandler.h" #include "presentation/pagemodel.h" @@ -75,7 +75,7 @@ QObject *ApplicationModel::editor() { if (!m_editor) { - auto model = Utils::DependencyManager::globalInstance().create(); + auto model = Utils::DependencyManager::globalInstance().create(); model->setErrorHandler(errorHandler()); m_editor = model; } @@ -114,7 +114,7 @@ if (m_availablePages) m_availablePages.staticCast()->setErrorHandler(errorHandler); if (m_editor) - m_editor.staticCast()->setErrorHandler(errorHandler); + m_editor.staticCast()->setErrorHandler(errorHandler); if (m_currentPage) m_currentPage.staticCast()->setErrorHandler(errorHandler); } diff --git a/src/presentation/artifacteditormodel.h b/src/presentation/editormodel.h rename from src/presentation/artifacteditormodel.h rename to src/presentation/editormodel.h --- a/src/presentation/artifacteditormodel.h +++ b/src/presentation/editormodel.h @@ -22,8 +22,8 @@ */ -#ifndef PRESENTATION_ARTIFACTEDITORMODEL_H -#define PRESENTATION_ARTIFACTEDITORMODEL_H +#ifndef PRESENTATION_EDITORMODEL_H +#define PRESENTATION_EDITORMODEL_H #include #include @@ -41,34 +41,31 @@ class AttachmentModel; -class ArtifactEditorModel : public QObject, public ErrorHandlingModelBase +class EditorModel : public QObject, public ErrorHandlingModelBase { Q_OBJECT - Q_PROPERTY(Domain::Artifact::Ptr artifact READ artifact WRITE setArtifact NOTIFY artifactChanged) + Q_PROPERTY(Domain::Task::Ptr task READ task WRITE setTask NOTIFY taskChanged) Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged) Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged) Q_PROPERTY(bool done READ isDone WRITE setDone NOTIFY doneChanged) Q_PROPERTY(QDate startDate READ startDate WRITE setStartDate NOTIFY startDateChanged) Q_PROPERTY(QDate dueDate READ dueDate WRITE setDueDate NOTIFY dueDateChanged) Q_PROPERTY(Domain::Task::Recurrence recurrence READ recurrence WRITE setRecurrence NOTIFY recurrenceChanged) Q_PROPERTY(QAbstractItemModel* attachmentModel READ attachmentModel CONSTANT) - Q_PROPERTY(bool hasTaskProperties READ hasTaskProperties NOTIFY hasTaskPropertiesChanged) Q_PROPERTY(bool editingInProgress READ editingInProgress WRITE setEditingInProgress) public: - typedef std::function SaveFunction; + typedef std::function SaveFunction; - explicit ArtifactEditorModel(QObject *parent = Q_NULLPTR); - ~ArtifactEditorModel(); + explicit EditorModel(QObject *parent = Q_NULLPTR); + ~EditorModel(); - Domain::Artifact::Ptr artifact() const; - void setArtifact(const Domain::Artifact::Ptr &artifact); + Domain::Task::Ptr task() const; + void setTask(const Domain::Task::Ptr &task); bool hasSaveFunction() const; void setSaveFunction(const SaveFunction &function); - bool hasTaskProperties() const; - QString text() const; QString title() const; bool isDone() const; @@ -97,8 +94,7 @@ void setEditingInProgress(bool editingInProgress); signals: - void artifactChanged(const Domain::Artifact::Ptr &artifact); - void hasTaskPropertiesChanged(bool hasTaskProperties); + void taskChanged(const Domain::Task::Ptr &task); void textChanged(const QString &text); void titleChanged(const QString &title); void doneChanged(bool done); @@ -126,7 +122,7 @@ void applyNewDueDate(const QDate &due); void applyNewRecurrence(Domain::Task::Recurrence recurrence); - Domain::Artifact::Ptr m_artifact; + Domain::Task::Ptr m_task; SaveFunction m_saveFunction; QString m_text; @@ -144,4 +140,4 @@ } -#endif // PRESENTATION_ARTIFACTEDITORMODEL_H +#endif // PRESENTATION_EDITORMODEL_H diff --git a/src/presentation/artifacteditormodel.cpp b/src/presentation/editormodel.cpp rename from src/presentation/artifacteditormodel.cpp rename to src/presentation/editormodel.cpp --- a/src/presentation/artifacteditormodel.cpp +++ b/src/presentation/editormodel.cpp @@ -22,7 +22,7 @@ */ -#include "artifacteditormodel.h" +#include "editormodel.h" #include #include @@ -107,7 +107,7 @@ static int s_autoSaveDelay = 500; -ArtifactEditorModel::ArtifactEditorModel(QObject *parent) +EditorModel::EditorModel(QObject *parent) : QObject(parent), m_done(false), m_recurrence(Domain::Task::NoRecurrence), @@ -117,21 +117,22 @@ m_editingInProgress(false) { m_saveTimer->setSingleShot(true); - connect(m_saveTimer, &QTimer::timeout, this, &ArtifactEditorModel::save); + connect(m_saveTimer, &QTimer::timeout, this, &EditorModel::save); } -ArtifactEditorModel::~ArtifactEditorModel() +EditorModel::~EditorModel() { save(); } -Domain::Artifact::Ptr ArtifactEditorModel::artifact() const + +Domain::Task::Ptr EditorModel::task() const { - return m_artifact; + return m_task; } -void ArtifactEditorModel::setArtifact(const Domain::Artifact::Ptr &artifact) +void EditorModel::setTask(const Domain::Task::Ptr &task) { - if (m_artifact == artifact) + if (m_task == task) return; save(); @@ -144,158 +145,149 @@ m_recurrence = Domain::Task::NoRecurrence; m_attachmentModel->setTask(Domain::Task::Ptr()); - if (m_artifact) - disconnect(m_artifact.data(), Q_NULLPTR, this, Q_NULLPTR); - - m_artifact = artifact; - - if (m_artifact) { - m_text = m_artifact->text(); - m_title = m_artifact->title(); - - connect(m_artifact.data(), &Domain::Artifact::textChanged, this, &ArtifactEditorModel::onTextChanged); - connect(m_artifact.data(), &Domain::Artifact::titleChanged, this, &ArtifactEditorModel::onTitleChanged); + if (m_task) + disconnect(m_task.data(), Q_NULLPTR, this, Q_NULLPTR); + + m_task = task; + + if (m_task) { + m_text = m_task->text(); + m_title = m_task->title(); + m_done = m_task->isDone(); + m_start = m_task->startDate(); + m_due = m_task->dueDate(); + m_recurrence = m_task->recurrence(); + m_attachmentModel->setTask(m_task); + + connect(m_task.data(), &Domain::Artifact::textChanged, this, &EditorModel::onTextChanged); + connect(m_task.data(), &Domain::Artifact::titleChanged, this, &EditorModel::onTitleChanged); + connect(m_task.data(), &Domain::Task::doneChanged, this, &EditorModel::onDoneChanged); + connect(m_task.data(), &Domain::Task::startDateChanged, this, &EditorModel::onStartDateChanged); + connect(m_task.data(), &Domain::Task::dueDateChanged, this, &EditorModel::onDueDateChanged); + connect(m_task.data(), &Domain::Task::recurrenceChanged, this, &EditorModel::onRecurrenceChanged); } - if (auto task = artifact.objectCast()) { - m_done = task->isDone(); - m_start = task->startDate(); - m_due = task->dueDate(); - m_recurrence = task->recurrence(); - m_attachmentModel->setTask(task); - - connect(task.data(), &Domain::Task::doneChanged, this, &ArtifactEditorModel::onDoneChanged); - connect(task.data(), &Domain::Task::startDateChanged, this, &ArtifactEditorModel::onStartDateChanged); - connect(task.data(), &Domain::Task::dueDateChanged, this, &ArtifactEditorModel::onDueDateChanged); - connect(task.data(), &Domain::Task::recurrenceChanged, this, &ArtifactEditorModel::onRecurrenceChanged); - } emit textChanged(m_text); emit titleChanged(m_title); emit doneChanged(m_done); emit startDateChanged(m_start); emit dueDateChanged(m_due); emit recurrenceChanged(m_recurrence); - emit hasTaskPropertiesChanged(hasTaskProperties()); - emit artifactChanged(m_artifact); + emit taskChanged(m_task); } -bool ArtifactEditorModel::hasSaveFunction() const +bool EditorModel::hasSaveFunction() const { return bool(m_saveFunction); } -void ArtifactEditorModel::setSaveFunction(const SaveFunction &function) +void EditorModel::setSaveFunction(const SaveFunction &function) { m_saveFunction = function; } -bool ArtifactEditorModel::hasTaskProperties() const -{ - return m_artifact.objectCast(); -} - -QString ArtifactEditorModel::text() const +QString EditorModel::text() const { return m_text; } -QString ArtifactEditorModel::title() const +QString EditorModel::title() const { return m_title; } -bool ArtifactEditorModel::isDone() const +bool EditorModel::isDone() const { return m_done; } -QDate ArtifactEditorModel::startDate() const +QDate EditorModel::startDate() const { return m_start; } -QDate ArtifactEditorModel::dueDate() const +QDate EditorModel::dueDate() const { return m_due; } -Domain::Task::Recurrence ArtifactEditorModel::recurrence() const +Domain::Task::Recurrence EditorModel::recurrence() const { return m_recurrence; } -QAbstractItemModel *ArtifactEditorModel::attachmentModel() const +QAbstractItemModel *EditorModel::attachmentModel() const { return m_attachmentModel; } -int ArtifactEditorModel::autoSaveDelay() +int EditorModel::autoSaveDelay() { return s_autoSaveDelay; } -void ArtifactEditorModel::setAutoSaveDelay(int delay) +void EditorModel::setAutoSaveDelay(int delay) { s_autoSaveDelay = delay; } -bool ArtifactEditorModel::editingInProgress() const +bool EditorModel::editingInProgress() const { return m_editingInProgress; } -void ArtifactEditorModel::setText(const QString &text) +void EditorModel::setText(const QString &text) { if (m_text == text) return; applyNewText(text); setSaveNeeded(true); } -void ArtifactEditorModel::setTitle(const QString &title) +void EditorModel::setTitle(const QString &title) { if (m_title == title) return; applyNewTitle(title); setSaveNeeded(true); } -void ArtifactEditorModel::setDone(bool done) +void EditorModel::setDone(bool done) { if (m_done == done) return; applyNewDone(done); setSaveNeeded(true); } -void ArtifactEditorModel::setStartDate(const QDate &start) +void EditorModel::setStartDate(const QDate &start) { if (m_start == start) return; applyNewStartDate(start); setSaveNeeded(true); } -void ArtifactEditorModel::setDueDate(const QDate &due) +void EditorModel::setDueDate(const QDate &due) { if (m_due == due) return; applyNewDueDate(due); setSaveNeeded(true); } -void ArtifactEditorModel::setRecurrence(Domain::Task::Recurrence recurrence) +void EditorModel::setRecurrence(Domain::Task::Recurrence recurrence) { if (m_recurrence == recurrence) return; applyNewRecurrence(recurrence); setSaveNeeded(true); } -void ArtifactEditorModel::addAttachment(const QString &fileName) +void EditorModel::addAttachment(const QString &fileName) { - auto task = m_artifact.objectCast(); + auto task = m_task.objectCast(); if (!task) return; @@ -326,9 +318,9 @@ setSaveNeeded(true); } -void ArtifactEditorModel::removeAttachment(const QModelIndex &index) +void EditorModel::removeAttachment(const QModelIndex &index) { - auto task = m_artifact.objectCast(); + auto task = m_task.objectCast(); if (!task) return; @@ -339,9 +331,9 @@ setSaveNeeded(true); } -void ArtifactEditorModel::openAttachment(const QModelIndex &index) +void EditorModel::openAttachment(const QModelIndex &index) { - auto task = m_artifact.objectCast(); + auto task = m_task.objectCast(); Q_ASSERT(task); auto attachment = task->attachments().at(index.row()); @@ -358,71 +350,71 @@ QDesktopServices::openUrl(uri); } -void ArtifactEditorModel::setEditingInProgress(bool editing) +void EditorModel::setEditingInProgress(bool editing) { m_editingInProgress = editing; } -void ArtifactEditorModel::onTextChanged(const QString &text) +void EditorModel::onTextChanged(const QString &text) { if (!m_editingInProgress) applyNewText(text); } -void ArtifactEditorModel::onTitleChanged(const QString &title) +void EditorModel::onTitleChanged(const QString &title) { if (!m_editingInProgress) applyNewTitle(title); } -void ArtifactEditorModel::onDoneChanged(bool done) +void EditorModel::onDoneChanged(bool done) { if (!m_editingInProgress) applyNewDone(done); } -void ArtifactEditorModel::onStartDateChanged(const QDate &start) +void EditorModel::onStartDateChanged(const QDate &start) { if (!m_editingInProgress) applyNewStartDate(start); } -void ArtifactEditorModel::onDueDateChanged(const QDate &due) +void EditorModel::onDueDateChanged(const QDate &due) { if (!m_editingInProgress) applyNewDueDate(due); } -void ArtifactEditorModel::onRecurrenceChanged(Domain::Task::Recurrence recurrence) +void EditorModel::onRecurrenceChanged(Domain::Task::Recurrence recurrence) { if (!m_editingInProgress) applyNewRecurrence(recurrence); } -void ArtifactEditorModel::save() +void EditorModel::save() { if (!isSaveNeeded()) return; - Q_ASSERT(m_artifact); + Q_ASSERT(m_task); - const auto currentTitle = m_artifact->title(); - m_artifact->setTitle(m_title); - m_artifact->setText(m_text); + const auto currentTitle = m_task->title(); + m_task->setTitle(m_title); + m_task->setText(m_text); - if (auto task = m_artifact.objectCast()) { + if (auto task = m_task.objectCast()) { task->setDone(m_done); task->setStartDate(m_start); task->setDueDate(m_due); task->setRecurrence(m_recurrence); } - const auto job = m_saveFunction(m_artifact); + const auto job = m_saveFunction(m_task); installHandler(job, i18n("Cannot modify task %1", currentTitle)); setSaveNeeded(false); } -void ArtifactEditorModel::setSaveNeeded(bool needed) +void EditorModel::setSaveNeeded(bool needed) { if (needed) m_saveTimer->start(autoSaveDelay()); @@ -432,45 +424,45 @@ m_saveNeeded = needed; } -bool ArtifactEditorModel::isSaveNeeded() const +bool EditorModel::isSaveNeeded() const { return m_saveNeeded; } -void ArtifactEditorModel::applyNewText(const QString &text) +void EditorModel::applyNewText(const QString &text) { m_text = text; emit textChanged(m_text); } -void ArtifactEditorModel::applyNewTitle(const QString &title) +void EditorModel::applyNewTitle(const QString &title) { m_title = title; emit titleChanged(m_title); } -void ArtifactEditorModel::applyNewDone(bool done) +void EditorModel::applyNewDone(bool done) { m_done = done; emit doneChanged(m_done); } -void ArtifactEditorModel::applyNewStartDate(const QDate &start) +void EditorModel::applyNewStartDate(const QDate &start) { m_start = start; emit startDateChanged(m_start); } -void ArtifactEditorModel::applyNewDueDate(const QDate &due) +void EditorModel::applyNewDueDate(const QDate &due) { m_due = due; emit dueDateChanged(m_due); } -void ArtifactEditorModel::applyNewRecurrence(Domain::Task::Recurrence recurrence) +void EditorModel::applyNewRecurrence(Domain::Task::Recurrence recurrence) { m_recurrence = recurrence; emit recurrenceChanged(m_recurrence); } -#include "artifacteditormodel.moc" +#include "editormodel.moc" diff --git a/src/widgets/applicationcomponents.h b/src/widgets/applicationcomponents.h --- a/src/widgets/applicationcomponents.h +++ b/src/widgets/applicationcomponents.h @@ -86,7 +86,7 @@ private slots: void onCurrentPageChanged(QObject *page); - void onCurrentArtifactChanged(const Domain::Artifact::Ptr &artifact); + void onCurrentTaskChanged(const Domain::Artifact::Ptr &artifact); void onMoveItemsRequested(); private: diff --git a/src/widgets/applicationcomponents.cpp b/src/widgets/applicationcomponents.cpp --- a/src/widgets/applicationcomponents.cpp +++ b/src/widgets/applicationcomponents.cpp @@ -136,7 +136,7 @@ self->m_pageView = pageView; self->m_errorHandler->setPageView(pageView); - connect(self->m_pageView, &PageView::currentArtifactChanged, self, &ApplicationComponents::onCurrentArtifactChanged); + connect(self->m_pageView, &PageView::currentTaskChanged, self, &ApplicationComponents::onCurrentTaskChanged); } return m_pageView; @@ -231,7 +231,7 @@ editorModel->setProperty("artifact", QVariant::fromValue(Domain::Artifact::Ptr())); } -void ApplicationComponents::onCurrentArtifactChanged(const Domain::Artifact::Ptr &artifact) +void ApplicationComponents::onCurrentTaskChanged(const Domain::Artifact::Ptr &artifact) { if (!m_model) return; diff --git a/src/widgets/editorview.h b/src/widgets/editorview.h --- a/src/widgets/editorview.h +++ b/src/widgets/editorview.h @@ -77,8 +77,7 @@ bool eventFilter(QObject *watched, QEvent *event) Q_DECL_OVERRIDE; private slots: - void onArtifactChanged(); - void onHasTaskPropertiesChanged(); + void onTaskChanged(); void onTextOrTitleChanged(); void onStartDateChanged(); void onDueDateChanged(); diff --git a/src/widgets/editorview.cpp b/src/widgets/editorview.cpp --- a/src/widgets/editorview.cpp +++ b/src/widgets/editorview.cpp @@ -60,13 +60,6 @@ ui->recurrenceCombo->addItem(i18n("Weekly"), QVariant::fromValue(Domain::Task::RecursWeekly)); ui->recurrenceCombo->addItem(i18n("Monthly"), QVariant::fromValue(Domain::Task::RecursMonthly)); - // Make sure our minimum width is always the one with - // the task group visible - ui->layout->activate(); - setMinimumWidth(minimumSizeHint().width()); - - ui->taskGroup->setVisible(false); - ui->textEdit->installEventFilter(this); ui->startDateEdit->installEventFilter(this); ui->dueDateEdit->installEventFilter(this); @@ -130,19 +123,16 @@ connect(ui->attachmentList->selectionModel(), &QItemSelectionModel::selectionChanged, this, &EditorView::onAttachmentSelectionChanged); - onArtifactChanged(); + onTaskChanged(); onTextOrTitleChanged(); - onHasTaskPropertiesChanged(); onStartDateChanged(); onDueDateChanged(); onDoneChanged(); onRecurrenceChanged(); onAttachmentSelectionChanged(); - connect(m_model, SIGNAL(artifactChanged(Domain::Artifact::Ptr)), - this, SLOT(onArtifactChanged())); - connect(m_model, SIGNAL(hasTaskPropertiesChanged(bool)), - this, SLOT(onHasTaskPropertiesChanged())); + connect(m_model, SIGNAL(taskChanged(Domain::Task::Ptr)), + this, SLOT(onTaskChanged())); connect(m_model, SIGNAL(titleChanged(QString)), this, SLOT(onTextOrTitleChanged())); connect(m_model, SIGNAL(textChanged(QString)), this, SLOT(onTextOrTitleChanged())); connect(m_model, SIGNAL(startDateChanged(QDate)), this, SLOT(onStartDateChanged())); @@ -183,15 +173,10 @@ return false; } -void EditorView::onArtifactChanged() -{ - auto artifact = m_model->property("artifact").value(); - setEnabled(artifact); -} - -void EditorView::onHasTaskPropertiesChanged() +void EditorView::onTaskChanged() { - ui->taskGroup->setVisible(m_model->property("hasTaskProperties").toBool()); + auto task = m_model->property("task").value(); + setEnabled(task); } void EditorView::onTextOrTitleChanged() diff --git a/src/widgets/pageview.h b/src/widgets/pageview.h --- a/src/widgets/pageview.h +++ b/src/widgets/pageview.h @@ -72,7 +72,7 @@ void displayErrorMessage(const QString &message); signals: - void currentArtifactChanged(const Domain::Artifact::Ptr &artifact); + void currentTaskChanged(const Domain::Artifact::Ptr &artifact); private slots: void onReturnPressed(); diff --git a/src/widgets/pageview.cpp b/src/widgets/pageview.cpp --- a/src/widgets/pageview.cpp +++ b/src/widgets/pageview.cpp @@ -453,7 +453,7 @@ if (!artifact) return; - emit currentArtifactChanged(artifact); + emit currentTaskChanged(artifact); } bool PageView::eventFilter(QObject *object, QEvent *event) diff --git a/src/zanshin/app/dependencies.cpp b/src/zanshin/app/dependencies.cpp --- a/src/zanshin/app/dependencies.cpp +++ b/src/zanshin/app/dependencies.cpp @@ -38,9 +38,9 @@ #include "akonadi/akonadiserializer.h" #include "akonadi/akonadistorage.h" -#include "presentation/artifacteditormodel.h" #include "presentation/availablesourcesmodel.h" #include "presentation/availabletaskpagesmodel.h" +#include "presentation/editormodel.h" #include "presentation/runningtaskmodel.h" #include "utils/dependencymanager.h" @@ -99,8 +99,8 @@ Akonadi::TaskRepository(Akonadi::StorageInterface*, Akonadi::SerializerInterface*)>(); - deps.add([] (Utils::DependencyManager *deps) { - auto model = new Presentation::ArtifactEditorModel; + deps.add([] (Utils::DependencyManager *deps) { + auto model = new Presentation::EditorModel; auto repository = deps->create(); model->setSaveFunction([repository] (const Domain::Artifact::Ptr &artifact) { auto task = artifact.objectCast(); diff --git a/tests/units/presentation/CMakeLists.txt b/tests/units/presentation/CMakeLists.txt --- a/tests/units/presentation/CMakeLists.txt +++ b/tests/units/presentation/CMakeLists.txt @@ -1,6 +1,6 @@ zanshin_auto_tests( applicationmodeltest - artifacteditormodeltest + editormodeltest artifactfilterproxymodeltest availablepagessortfilterproxymodeltest availablesourcesmodeltest diff --git a/tests/units/presentation/applicationmodeltest.cpp b/tests/units/presentation/applicationmodeltest.cpp --- a/tests/units/presentation/applicationmodeltest.cpp +++ b/tests/units/presentation/applicationmodeltest.cpp @@ -28,9 +28,9 @@ #include "utils/mockobject.h" #include "presentation/applicationmodel.h" -#include "presentation/artifacteditormodel.h" #include "presentation/availablepagesmodelinterface.h" #include "presentation/availablesourcesmodel.h" +#include "presentation/editormodel.h" #include "presentation/pagemodel.h" #include "presentation/errorhandler.h" @@ -95,9 +95,9 @@ { Utils::DependencyManager::globalInstance().add(); - Utils::DependencyManager::globalInstance().add( + Utils::DependencyManager::globalInstance().add( [] (Utils::DependencyManager *) { - return new Presentation::ArtifactEditorModel; + return new Presentation::EditorModel; }); Utils::DependencyManager::globalInstance().add( [] (Utils::DependencyManager *) { @@ -185,16 +185,16 @@ QVERIFY(!page); } - void shouldProvideArtifactEditorModel() + void shouldProvideEditorModel() { // GIVEN Presentation::ApplicationModel app; // WHEN QObject *page = app.editor(); // THEN - QVERIFY(qobject_cast(page)); + QVERIFY(qobject_cast(page)); } void shouldSetErrorHandlerToAllModels() @@ -212,7 +212,7 @@ // THEN auto availableSource = static_cast(app.availableSources()); auto availablePages = static_cast(app.availablePages()); - auto editor = static_cast(app.editor()); + auto editor = static_cast(app.editor()); auto page = static_cast(app.currentPage()); QCOMPARE(availableSource->errorHandler(), &errorHandler); QCOMPARE(availablePages->errorHandler(), &errorHandler); diff --git a/tests/units/presentation/artifacteditormodeltest.cpp b/tests/units/presentation/editormodeltest.cpp rename from tests/units/presentation/artifacteditormodeltest.cpp rename to tests/units/presentation/editormodeltest.cpp --- a/tests/units/presentation/artifacteditormodeltest.cpp +++ b/tests/units/presentation/editormodeltest.cpp @@ -32,7 +32,7 @@ #include "domain/task.h" -#include "presentation/artifacteditormodel.h" +#include "presentation/editormodel.h" #include "presentation/errorhandler.h" using namespace mockitopp; @@ -48,29 +48,28 @@ QString m_message; }; -class ArtifactEditorModelTest : public QObject +class EditorModelTest : public QObject { Q_OBJECT public: - explicit ArtifactEditorModelTest(QObject *parent = Q_NULLPTR) + explicit EditorModelTest(QObject *parent = Q_NULLPTR) : QObject(parent) { qRegisterMetaType(); - Presentation::ArtifactEditorModel::setAutoSaveDelay(50); + Presentation::EditorModel::setAutoSaveDelay(50); } private slots: void shouldHaveEmptyDefaultState() { // GIVEN - Presentation::ArtifactEditorModel model; + Presentation::EditorModel model; // WHEN // Nothing // THEN - QVERIFY(model.artifact().isNull()); - QVERIFY(!model.hasTaskProperties()); + QVERIFY(model.task().isNull()); QVERIFY(model.text().isEmpty()); QVERIFY(model.title().isEmpty()); QVERIFY(!model.isDone()); @@ -86,13 +85,13 @@ void shouldHaveTaskProperties() { // GIVEN - Presentation::ArtifactEditorModel model; - QSignalSpy textSpy(&model, &Presentation::ArtifactEditorModel::textChanged); - QSignalSpy titleSpy(&model, &Presentation::ArtifactEditorModel::titleChanged); - QSignalSpy doneSpy(&model, &Presentation::ArtifactEditorModel::doneChanged); - QSignalSpy startSpy(&model, &Presentation::ArtifactEditorModel::startDateChanged); - QSignalSpy dueSpy(&model, &Presentation::ArtifactEditorModel::dueDateChanged); - QSignalSpy recurrenceSpy(&model, &Presentation::ArtifactEditorModel::recurrenceChanged); + Presentation::EditorModel model; + QSignalSpy textSpy(&model, &Presentation::EditorModel::textChanged); + QSignalSpy titleSpy(&model, &Presentation::EditorModel::titleChanged); + QSignalSpy doneSpy(&model, &Presentation::EditorModel::doneChanged); + QSignalSpy startSpy(&model, &Presentation::EditorModel::startDateChanged); + QSignalSpy dueSpy(&model, &Presentation::EditorModel::dueDateChanged); + QSignalSpy recurrenceSpy(&model, &Presentation::EditorModel::recurrenceChanged); QSignalSpy attachmentSpy(model.attachmentModel(), &QAbstractItemModel::modelReset); Domain::Task::Attachments attachments; @@ -121,7 +120,7 @@ task->setAttachments(attachments); // WHEN - model.setArtifact(task); + model.setTask(task); // To make sure we don't signal too much model.setText(task->text()); model.setTitle(task->title()); @@ -131,8 +130,6 @@ model.setRecurrence(task->recurrence()); // THEN - QVERIFY(model.hasTaskProperties()); - QCOMPARE(textSpy.size(), 1); QCOMPARE(textSpy.takeFirst().at(0).toString(), task->text()); QCOMPARE(model.property("text").toString(), task->text()); @@ -166,114 +163,114 @@ QCOMPARE(am->data(am->index(1, 0), Qt::DecorationRole).value(), QIcon::fromTheme("text-html")); } - void shouldReactToArtifactPropertyChanges_data() + void shouldReactToTaskPropertyChanges_data() { - QTest::addColumn("artifact"); + QTest::addColumn("task"); QTest::addColumn("propertyName"); QTest::addColumn("propertyValue"); QTest::addColumn("signal"); - QTest::newRow("task text") << Domain::Artifact::Ptr(Domain::Task::Ptr::create()) + QTest::newRow("task text") << Domain::Task::Ptr(Domain::Task::Ptr::create()) << QByteArray("text") << QVariant("new text") << QByteArray(SIGNAL(textChanged(QString))); - QTest::newRow("task title") << Domain::Artifact::Ptr(Domain::Task::Ptr::create()) + QTest::newRow("task title") << Domain::Task::Ptr(Domain::Task::Ptr::create()) << QByteArray("title") << QVariant("new title") << QByteArray(SIGNAL(titleChanged(QString))); - QTest::newRow("task done") << Domain::Artifact::Ptr(Domain::Task::Ptr::create()) + QTest::newRow("task done") << Domain::Task::Ptr(Domain::Task::Ptr::create()) << QByteArray("done") << QVariant(true) << QByteArray(SIGNAL(doneChanged(bool))); - QTest::newRow("task start") << Domain::Artifact::Ptr(Domain::Task::Ptr::create()) + QTest::newRow("task start") << Domain::Task::Ptr(Domain::Task::Ptr::create()) << QByteArray("startDate") << QVariant(QDate::currentDate()) << QByteArray(SIGNAL(startDateChanged(QDate))); - QTest::newRow("task due") << Domain::Artifact::Ptr(Domain::Task::Ptr::create()) + QTest::newRow("task due") << Domain::Task::Ptr(Domain::Task::Ptr::create()) << QByteArray("dueDate") << QVariant(QDate::currentDate().addDays(2)) << QByteArray(SIGNAL(dueDateChanged(QDate))); - QTest::newRow("task recurrence") << Domain::Artifact::Ptr(Domain::Task::Ptr::create()) + QTest::newRow("task recurrence") << Domain::Task::Ptr(Domain::Task::Ptr::create()) << QByteArray("recurrence") << QVariant::fromValue(Domain::Task::RecursDaily) << QByteArray(SIGNAL(recurrenceChanged(Domain::Task::Recurrence))); } - void shouldReactToArtifactPropertyChanges() + void shouldReactToTaskPropertyChanges() { // GIVEN - QFETCH(Domain::Artifact::Ptr, artifact); + QFETCH(Domain::Task::Ptr, task); QFETCH(QByteArray, propertyName); QFETCH(QVariant, propertyValue); QFETCH(QByteArray, signal); - Presentation::ArtifactEditorModel model; - model.setArtifact(artifact); + Presentation::EditorModel model; + model.setTask(task); QSignalSpy spy(&model, signal.constData()); // WHEN - artifact->setProperty(propertyName, propertyValue); + task->setProperty(propertyName, propertyValue); // THEN QCOMPARE(spy.size(), 1); QCOMPARE(spy.takeFirst().at(0), propertyValue); QCOMPARE(model.property(propertyName), propertyValue); } - void shouldNotReactToArtifactPropertyChangesWhenEditing_data() + void shouldNotReactToTaskPropertyChangesWhenEditing_data() { - shouldReactToArtifactPropertyChanges_data(); + shouldReactToTaskPropertyChanges_data(); } - void shouldNotReactToArtifactPropertyChangesWhenEditing() + void shouldNotReactToTaskPropertyChangesWhenEditing() { // GIVEN - QFETCH(Domain::Artifact::Ptr, artifact); + QFETCH(Domain::Task::Ptr, task); QFETCH(QByteArray, propertyName); QFETCH(QVariant, propertyValue); QFETCH(QByteArray, signal); - Presentation::ArtifactEditorModel model; - model.setArtifact(artifact); + Presentation::EditorModel model; + model.setTask(task); QSignalSpy spy(&model, signal.constData()); // WHEN - const auto oldPropertyValue = artifact->property(propertyName); + const auto oldPropertyValue = task->property(propertyName); model.setEditingInProgress(true); - artifact->setProperty(propertyName, propertyValue); + task->setProperty(propertyName, propertyValue); // THEN QVERIFY(spy.isEmpty()); QCOMPARE(model.property(propertyName), oldPropertyValue); } - void shouldApplyChangesBackToArtifactAfterADelay_data() + void shouldApplyChangesBackToTaskAfterADelay_data() { - shouldReactToArtifactPropertyChanges_data(); + shouldReactToTaskPropertyChanges_data(); } - void shouldApplyChangesBackToArtifactAfterADelay() + void shouldApplyChangesBackToTaskAfterADelay() { // GIVEN - QFETCH(Domain::Artifact::Ptr, artifact); + QFETCH(Domain::Task::Ptr, task); QFETCH(QByteArray, propertyName); QFETCH(QVariant, propertyValue); QFETCH(QByteArray, signal); - auto savedArtifact = Domain::Artifact::Ptr(); - auto save = [this, &savedArtifact] (const Domain::Artifact::Ptr &artifact) { - savedArtifact = artifact; + auto savedTask = Domain::Task::Ptr(); + auto save = [this, &savedTask] (const Domain::Task::Ptr &task) { + savedTask = task; return new FakeJob(this); }; - Presentation::ArtifactEditorModel model; + Presentation::EditorModel model; model.setSaveFunction(save); - model.setArtifact(artifact); + model.setTask(task); QSignalSpy spy(&model, signal.constData()); // WHEN @@ -283,40 +280,40 @@ QCOMPARE(spy.size(), 1); QCOMPARE(spy.takeFirst().at(0), propertyValue); QCOMPARE(model.property(propertyName), propertyValue); - QVERIFY(artifact->property(propertyName) != propertyValue); - QVERIFY(!savedArtifact); + QVERIFY(task->property(propertyName) != propertyValue); + QVERIFY(!savedTask); // WHEN (apply after delay) QTest::qWait(model.autoSaveDelay() + 50); // THEN - QCOMPARE(savedArtifact, artifact); - QCOMPARE(artifact->property(propertyName), propertyValue); + QCOMPARE(savedTask, task); + QCOMPARE(task->property(propertyName), propertyValue); } - void shouldApplyChangesImmediatelyIfANewArtifactIsSet_data() + void shouldApplyChangesImmediatelyIfANewTaskIsSet_data() { - shouldReactToArtifactPropertyChanges_data(); + shouldReactToTaskPropertyChanges_data(); } - void shouldApplyChangesImmediatelyIfANewArtifactIsSet() + void shouldApplyChangesImmediatelyIfANewTaskIsSet() { // GIVEN - QFETCH(Domain::Artifact::Ptr, artifact); + QFETCH(Domain::Task::Ptr, task); QFETCH(QByteArray, propertyName); QFETCH(QVariant, propertyValue); QFETCH(QByteArray, signal); - auto savedArtifact = Domain::Artifact::Ptr(); - auto save = [this, &savedArtifact] (const Domain::Artifact::Ptr &artifact) { - savedArtifact = artifact; + auto savedTask = Domain::Task::Ptr(); + auto save = [this, &savedTask] (const Domain::Task::Ptr &task) { + savedTask = task; return new FakeJob(this); }; - Presentation::ArtifactEditorModel model; + Presentation::EditorModel model; model.setSaveFunction(save); QVERIFY(model.hasSaveFunction()); - model.setArtifact(artifact); + model.setTask(task); QSignalSpy spy(&model, signal.constData()); // WHEN @@ -326,48 +323,48 @@ QCOMPARE(spy.size(), 1); QCOMPARE(spy.takeFirst().at(0), propertyValue); QCOMPARE(model.property(propertyName), propertyValue); - QVERIFY(artifact->property(propertyName) != propertyValue); - QVERIFY(!savedArtifact); + QVERIFY(task->property(propertyName) != propertyValue); + QVERIFY(!savedTask); // WHEN (apply immediately) - model.setArtifact(Domain::Task::Ptr::create()); + model.setTask(Domain::Task::Ptr::create()); // THEN - QCOMPARE(savedArtifact, artifact); - QCOMPARE(artifact->property(propertyName), propertyValue); - savedArtifact.clear(); + QCOMPARE(savedTask, task); + QCOMPARE(task->property(propertyName), propertyValue); + savedTask.clear(); // WHEN (nothing else happens after a delay) QTest::qWait(model.autoSaveDelay() + 50); // THEN - QVERIFY(!savedArtifact); - QCOMPARE(artifact->property(propertyName), propertyValue); + QVERIFY(!savedTask); + QCOMPARE(task->property(propertyName), propertyValue); } void shouldApplyChangesImmediatelyIfDeleted_data() { - shouldReactToArtifactPropertyChanges_data(); + shouldReactToTaskPropertyChanges_data(); } void shouldApplyChangesImmediatelyIfDeleted() { // GIVEN - QFETCH(Domain::Artifact::Ptr, artifact); + QFETCH(Domain::Task::Ptr, task); QFETCH(QByteArray, propertyName); QFETCH(QVariant, propertyValue); QFETCH(QByteArray, signal); - auto savedArtifact = Domain::Artifact::Ptr(); - auto save = [this, &savedArtifact] (const Domain::Artifact::Ptr &artifact) { - savedArtifact = artifact; + auto savedTask = Domain::Task::Ptr(); + auto save = [this, &savedTask] (const Domain::Task::Ptr &task) { + savedTask = task; return new FakeJob(this); }; - auto model = new Presentation::ArtifactEditorModel; + auto model = new Presentation::EditorModel; model->setSaveFunction(save); QVERIFY(model->hasSaveFunction()); - model->setArtifact(artifact); + model->setTask(task); QSignalSpy spy(model, signal.constData()); // WHEN @@ -377,37 +374,37 @@ QCOMPARE(spy.size(), 1); QCOMPARE(spy.takeFirst().at(0), propertyValue); QCOMPARE(model->property(propertyName), propertyValue); - QVERIFY(artifact->property(propertyName) != propertyValue); - QVERIFY(!savedArtifact); + QVERIFY(task->property(propertyName) != propertyValue); + QVERIFY(!savedTask); // WHEN (apply immediately) delete model; // THEN - QCOMPARE(savedArtifact, artifact); - QCOMPARE(artifact->property(propertyName), propertyValue); + QCOMPARE(savedTask, task); + QCOMPARE(task->property(propertyName), propertyValue); } void shouldGetAnErrorMessageWhenSaveFailed() { // GIVEN auto task = Domain::Task::Ptr::create(); task->setTitle(QStringLiteral("Task 1")); - auto savedArtifact = Domain::Artifact::Ptr(); - auto save = [this, &savedArtifact] (const Domain::Artifact::Ptr &artifact) { - savedArtifact = artifact; + auto savedTask = Domain::Task::Ptr(); + auto save = [this, &savedTask] (const Domain::Task::Ptr &task) { + savedTask = task; auto job = new FakeJob(this); job->setExpectedError(KJob::KilledJobError, QStringLiteral("Foo")); return job; }; - auto model = new Presentation::ArtifactEditorModel; + auto model = new Presentation::EditorModel; model->setSaveFunction(save); QVERIFY(model->hasSaveFunction()); FakeErrorHandler errorHandler; model->setErrorHandler(&errorHandler); - model->setArtifact(task); + model->setTask(task); // WHEN model->setProperty("title", "Foo"); @@ -418,55 +415,55 @@ QCOMPARE(errorHandler.m_message, QStringLiteral("Cannot modify task Task 1: Foo")); } - void shouldDisconnectFromPreviousArtifact_data() + void shouldDisconnectFromPreviousTask_data() { - shouldReactToArtifactPropertyChanges_data(); + shouldReactToTaskPropertyChanges_data(); } - void shouldDisconnectFromPreviousArtifact() + void shouldDisconnectFromPreviousTask() { // GIVEN - QFETCH(Domain::Artifact::Ptr, artifact); + QFETCH(Domain::Task::Ptr, task); QFETCH(QByteArray, propertyName); QFETCH(QVariant, propertyValue); QFETCH(QByteArray, signal); - Presentation::ArtifactEditorModel model; - model.setArtifact(artifact); + Presentation::EditorModel model; + model.setTask(task); QSignalSpy spy(&model, signal.constData()); - Domain::Artifact::Ptr newArtifact = Domain::Task::Ptr::create(); + Domain::Task::Ptr newTask = Domain::Task::Ptr::create(); // WHEN - model.setArtifact(newArtifact); - // modifying the *old* artifact should have no effect. - artifact->setProperty(propertyName, propertyValue); + model.setTask(newTask); + // modifying the *old* task should have no effect. + task->setProperty(propertyName, propertyValue); // THEN - QCOMPARE(spy.size(), 1); // emitted by setArtifact - QVERIFY(model.property(propertyName) != artifact->property(propertyName)); + QCOMPARE(spy.size(), 1); // emitted by setTask + QVERIFY(model.property(propertyName) != task->property(propertyName)); } void shouldAddAttachments() { // GIVEN - QTemporaryFile temporaryFile(QDir::tempPath() + "/artifacteditormodeltest_XXXXXX.txt"); + QTemporaryFile temporaryFile(QDir::tempPath() + "/taskeditormodeltest_XXXXXX.txt"); temporaryFile.open(); temporaryFile.write("foo bar"); temporaryFile.close(); auto fileName = temporaryFile.fileName().mid(QDir::tempPath().size() + 1); auto task = Domain::Task::Ptr::create(); - auto savedArtifact = Domain::Artifact::Ptr(); - auto save = [this, &savedArtifact] (const Domain::Artifact::Ptr &artifact) { - savedArtifact = artifact; + auto savedTask = Domain::Task::Ptr(); + auto save = [this, &savedTask] (const Domain::Task::Ptr &task) { + savedTask = task; return new FakeJob(this); }; - Presentation::ArtifactEditorModel model; + Presentation::EditorModel model; model.setSaveFunction(save); - model.setArtifact(task); + model.setTask(task); QSignalSpy spy(model.attachmentModel(), &QAbstractItemModel::modelReset); @@ -476,13 +473,13 @@ // THEN QCOMPARE(spy.size(), 1); QCOMPARE(model.attachmentModel()->rowCount(), 1); - QVERIFY(!savedArtifact); + QVERIFY(!savedTask); // WHEN (nothing else happens after a delay) QTest::qWait(model.autoSaveDelay() + 50); // THEN - QCOMPARE(savedArtifact.objectCast(), task); + QCOMPARE(savedTask.objectCast(), task); QCOMPARE(task->attachments().size(), 1); QCOMPARE(task->attachments().first().label(), fileName); QCOMPARE(task->attachments().first().mimeType(), QStringLiteral("text/plain")); @@ -497,15 +494,15 @@ task->setAttachments(Domain::Task::Attachments() << Domain::Task::Attachment("foo") << Domain::Task::Attachment("bar")); - auto savedArtifact = Domain::Artifact::Ptr(); - auto save = [this, &savedArtifact] (const Domain::Artifact::Ptr &artifact) { - savedArtifact = artifact; + auto savedTask = Domain::Task::Ptr(); + auto save = [this, &savedTask] (const Domain::Task::Ptr &task) { + savedTask = task; return new FakeJob(this); }; - Presentation::ArtifactEditorModel model; + Presentation::EditorModel model; model.setSaveFunction(save); - model.setArtifact(task); + model.setTask(task); QSignalSpy spy(model.attachmentModel(), &QAbstractItemModel::modelReset); @@ -515,18 +512,18 @@ // THEN QCOMPARE(spy.size(), 1); QCOMPARE(model.attachmentModel()->rowCount(), 1); - QVERIFY(!savedArtifact); + QVERIFY(!savedTask); // WHEN (nothing else happens after a delay) QTest::qWait(model.autoSaveDelay() + 50); // THEN - QCOMPARE(savedArtifact.objectCast(), task); + QCOMPARE(savedTask.objectCast(), task); QCOMPARE(task->attachments().size(), 1); QCOMPARE(task->attachments().first().data(), QByteArrayLiteral("bar")); } }; -ZANSHIN_TEST_MAIN(ArtifactEditorModelTest) +ZANSHIN_TEST_MAIN(EditorModelTest) -#include "artifacteditormodeltest.moc" +#include "editormodeltest.moc" diff --git a/tests/units/widgets/applicationcomponentstest.cpp b/tests/units/widgets/applicationcomponentstest.cpp --- a/tests/units/widgets/applicationcomponentstest.cpp +++ b/tests/units/widgets/applicationcomponentstest.cpp @@ -227,8 +227,6 @@ emit startDateChanged(value.toDate()); else if (name == "dueDate") emit dueDateChanged(value.toDate()); - else if (name == "hasTaskProperties") - emit hasTaskPropertiesChanged(value.toBool()); else qFatal("Unsupported property %s", name.constData()); } @@ -241,7 +239,6 @@ void setDueDate(const QDate &due) { setPropertyAndSignal("dueDate", due); } signals: - void hasTaskPropertiesChanged(bool hasTaskProperties); void textChanged(const QString &text); void titleChanged(const QString &title); void doneChanged(bool done); diff --git a/tests/units/widgets/editorviewtest.cpp b/tests/units/widgets/editorviewtest.cpp --- a/tests/units/widgets/editorviewtest.cpp +++ b/tests/units/widgets/editorviewtest.cpp @@ -56,8 +56,8 @@ return; setProperty(name, value); - if (name == "artifact") - emit artifactChanged(value.value()); + if (name == "task") + emit taskChanged(value.value()); else if (name == "text") emit textChanged(value.toString()); else if (name == "title") @@ -70,21 +70,19 @@ emit dueDateChanged(value.toDate()); else if (name == "recurrence") emit recurrenceChanged(value.value()); - else if (name == "hasTaskProperties") - emit hasTaskPropertiesChanged(value.toBool()); else qFatal("Unsupported property %s", name.constData()); } public slots: - void setArtifact(const Domain::Artifact::Ptr &artifact) { setPropertyAndSignal("artifact", QVariant::fromValue(artifact)); } + void setTask(const Domain::Task::Ptr &task) { setPropertyAndSignal("task", QVariant::fromValue(task)); } void setTitle(const QString &title) { setPropertyAndSignal("title", title); } void setText(const QString &text) { setPropertyAndSignal("text", text); } void setDone(bool done) { setPropertyAndSignal("done", done); } void setStartDate(const QDate &start) { setPropertyAndSignal("startDate", start); } void setDueDate(const QDate &due) { setPropertyAndSignal("dueDate", due); } void setRecurrence(Domain::Task::Recurrence recurrence) { setPropertyAndSignal("recurrence", QVariant::fromValue(recurrence)); } - void makeTaskAvailable() { setArtifact(Domain::Artifact::Ptr(new Domain::Task)); } + void makeTaskAvailable() { setTask(Domain::Task::Ptr(new Domain::Task)); } void addAttachment(const QString &fileName) { @@ -99,8 +97,7 @@ } signals: - void artifactChanged(const Domain::Artifact::Ptr &artifact); - void hasTaskPropertiesChanged(bool hasTaskProperties); + void taskChanged(const Domain::Task::Ptr &task); void textChanged(const QString &text); void titleChanged(const QString &title); void doneChanged(bool done); @@ -135,31 +132,31 @@ auto startDateEdit = editor.findChild(QStringLiteral("startDateEdit")); QVERIFY(startDateEdit); - QVERIFY(!startDateEdit->isVisibleTo(&editor)); + QVERIFY(startDateEdit->isVisibleTo(&editor)); auto dueDateEdit = editor.findChild(QStringLiteral("dueDateEdit")); QVERIFY(dueDateEdit); - QVERIFY(!dueDateEdit->isVisibleTo(&editor)); + QVERIFY(dueDateEdit->isVisibleTo(&editor)); auto recurrenceCombo = editor.findChild(QStringLiteral("recurrenceCombo")); QVERIFY(recurrenceCombo); - QVERIFY(!recurrenceCombo->isVisibleTo(&editor)); + QVERIFY(recurrenceCombo->isVisibleTo(&editor)); auto doneButton = editor.findChild(QStringLiteral("doneButton")); QVERIFY(doneButton); - QVERIFY(!doneButton->isVisibleTo(&editor)); + QVERIFY(doneButton->isVisibleTo(&editor)); auto attachmentList = editor.findChild(QStringLiteral("attachmentList")); QVERIFY(attachmentList); - QVERIFY(!attachmentList->isVisibleTo(&editor)); + QVERIFY(attachmentList->isVisibleTo(&editor)); auto addAttachmentButton = editor.findChild(QStringLiteral("addAttachmentButton")); QVERIFY(addAttachmentButton); - QVERIFY(!addAttachmentButton->isVisibleTo(&editor)); + QVERIFY(addAttachmentButton->isVisibleTo(&editor)); auto removeAttachmentButton = editor.findChild(QStringLiteral("removeAttachmentButton")); QVERIFY(removeAttachmentButton); - QVERIFY(!removeAttachmentButton->isVisibleTo(&editor)); + QVERIFY(removeAttachmentButton->isVisibleTo(&editor)); } void shouldNotCrashForNullModel() @@ -169,7 +166,6 @@ EditorModelStub model; model.setTitle(QStringLiteral("Foo")); model.setText(QStringLiteral("Bar")); - model.setPropertyAndSignal("hasTaskProperties", true); editor.setModel(&model); auto textEdit = editor.findChild(QStringLiteral("textEdit")); @@ -213,48 +209,7 @@ QVERIFY(!removeAttachmentButton->isVisibleTo(&editor)); } - void shouldShowTaskPropertiesEditorsOnlyForTasks() - { - // GIVEN - Widgets::EditorView editor; - EditorModelStub model; - model.setPropertyAndSignal("hasTaskProperties", true); - - auto startDateEdit = editor.findChild(QStringLiteral("startDateEdit")); - QVERIFY(!startDateEdit->isVisibleTo(&editor)); - - auto dueDateEdit = editor.findChild(QStringLiteral("dueDateEdit")); - QVERIFY(!dueDateEdit->isVisibleTo(&editor)); - - auto recurrenceCombo = editor.findChild(QStringLiteral("recurrenceCombo")); - QVERIFY(recurrenceCombo); - - auto doneButton = editor.findChild(QStringLiteral("doneButton")); - QVERIFY(!doneButton->isVisibleTo(&editor)); - - auto attachmentList = editor.findChild(QStringLiteral("attachmentList")); - QVERIFY(attachmentList); - - auto addAttachmentButton = editor.findChild(QStringLiteral("addAttachmentButton")); - QVERIFY(addAttachmentButton); - - auto removeAttachmentButton = editor.findChild(QStringLiteral("removeAttachmentButton")); - QVERIFY(removeAttachmentButton); - - // WHEN - editor.setModel(&model); - - // THEN - QVERIFY(startDateEdit->isVisibleTo(&editor)); - QVERIFY(dueDateEdit->isVisibleTo(&editor)); - QVERIFY(recurrenceCombo->isVisibleTo(&editor)); - QVERIFY(doneButton->isVisibleTo(&editor)); - QVERIFY(attachmentList->isVisibleTo(&editor)); - QVERIFY(addAttachmentButton->isVisibleTo(&editor)); - QVERIFY(removeAttachmentButton->isVisibleTo(&editor)); - } - - void shouldBeEnabledOnlyWhenAnArtifactIsAvailable() + void shouldBeEnabledOnlyWhenAnTaskIsAvailable() { // GIVEN Widgets::EditorView editor; @@ -268,64 +223,37 @@ // WHEN // like model.makeTaskAvailable() does: - Domain::Artifact::Ptr artifact(new Domain::Task); - model.setPropertyAndSignal("artifact", QVariant::fromValue(artifact)); + Domain::Task::Ptr task(new Domain::Task); + model.setPropertyAndSignal("task", QVariant::fromValue(task)); // THEN QVERIFY(editor.isEnabled()); // WHEN - model.setPropertyAndSignal("artifact", QVariant::fromValue(Domain::Artifact::Ptr())); + model.setPropertyAndSignal("task", QVariant::fromValue(Domain::Task::Ptr())); // THEN QVERIFY(!editor.isEnabled()); // GIVEN EditorModelStub model2; - model2.setPropertyAndSignal("artifact", QVariant::fromValue(artifact)); + model2.setPropertyAndSignal("task", QVariant::fromValue(task)); // WHEN editor.setModel(&model2); // THEN QVERIFY(editor.isEnabled()); } - void shouldReactToHasTaskPropertiesChanged() - { - // GIVEN - Widgets::EditorView editor; - EditorModelStub model; - model.makeTaskAvailable(); - editor.setModel(&model); - - auto startDateEdit = editor.findChild(QStringLiteral("startDateEdit")); - QVERIFY(!startDateEdit->isVisibleTo(&editor)); - - auto dueDateEdit = editor.findChild(QStringLiteral("dueDateEdit")); - QVERIFY(!dueDateEdit->isVisibleTo(&editor)); - - auto doneButton = editor.findChild(QStringLiteral("doneButton")); - QVERIFY(!doneButton->isVisibleTo(&editor)); - - // WHEN - model.setPropertyAndSignal("hasTaskProperties", true); - - // THEN - QVERIFY(startDateEdit->isVisibleTo(&editor)); - QVERIFY(dueDateEdit->isVisibleTo(&editor)); - QVERIFY(doneButton->isVisibleTo(&editor)); - } - void shouldDisplayModelProperties() { // GIVEN Widgets::EditorView editor; EditorModelStub model; model.makeTaskAvailable(); - model.setProperty("hasTaskProperties", true); model.setProperty("title", "My title"); model.setProperty("text", "\nMy text"); model.setProperty("startDate", QDate::currentDate());