diff --git a/src/presentation/CMakeLists.txt b/src/presentation/CMakeLists.txt --- a/src/presentation/CMakeLists.txt +++ b/src/presentation/CMakeLists.txt @@ -15,7 +15,6 @@ runningtaskmodelinterface.cpp runningtaskmodel.cpp taskfilterproxymodel.cpp - taskapplicationmodel.cpp workdaypagemodel.cpp ) diff --git a/src/presentation/applicationmodel.h b/src/presentation/applicationmodel.h --- a/src/presentation/applicationmodel.h +++ b/src/presentation/applicationmodel.h @@ -32,6 +32,7 @@ #include "domain/taskrepository.h" #include "presentation/metatypes.h" +#include "presentation/runningtaskmodelinterface.h" namespace Presentation { @@ -44,6 +45,7 @@ Q_PROPERTY(QObject* availablePages READ availablePages) Q_PROPERTY(QObject* currentPage READ currentPage WRITE setCurrentPage NOTIFY currentPageChanged) Q_PROPERTY(QObject* editor READ editor) + Q_PROPERTY(RunningTaskModelInterface* runningTaskModel READ runningTaskModel) Q_PROPERTY(Presentation::ErrorHandler* errorHandler READ errorHandler WRITE setErrorHandler) public: typedef QSharedPointer Ptr; @@ -55,6 +57,7 @@ QObject *availablePages(); QObject *currentPage(); QObject *editor(); + Presentation::RunningTaskModelInterface *runningTaskModel(); ErrorHandler *errorHandler() const; @@ -70,6 +73,7 @@ QObjectPtr m_availablePages; QObjectPtr m_currentPage; QObjectPtr m_editor; + RunningTaskModelInterface::Ptr m_runningTaskModel; ErrorHandler *m_errorHandler; }; diff --git a/src/presentation/applicationmodel.cpp b/src/presentation/applicationmodel.cpp --- a/src/presentation/applicationmodel.cpp +++ b/src/presentation/applicationmodel.cpp @@ -29,6 +29,7 @@ #include "presentation/editormodel.h" #include "presentation/errorhandler.h" #include "presentation/pagemodel.h" +#include "presentation/runningtaskmodel.h" #include "utils/dependencymanager.h" #include "utils/jobhandler.h" @@ -83,6 +84,16 @@ return m_editor.data(); } +RunningTaskModelInterface *ApplicationModel::runningTaskModel() +{ + if (!m_runningTaskModel) { + auto model = Utils::DependencyManager::globalInstance().create(); + m_runningTaskModel = model; + m_runningTaskModel->setErrorHandler(errorHandler()); + } + return m_runningTaskModel.data(); +} + ErrorHandler *ApplicationModel::errorHandler() const { return m_errorHandler; @@ -115,6 +126,8 @@ m_availablePages.staticCast()->setErrorHandler(errorHandler); if (m_editor) m_editor.staticCast()->setErrorHandler(errorHandler); + if (m_runningTaskModel) + m_runningTaskModel.staticCast()->setErrorHandler(errorHandler); if (m_currentPage) m_currentPage.staticCast()->setErrorHandler(errorHandler); } diff --git a/src/presentation/taskapplicationmodel.h b/src/presentation/taskapplicationmodel.h deleted file mode 100644 --- a/src/presentation/taskapplicationmodel.h +++ /dev/null @@ -1,50 +0,0 @@ -/* This file is part of Zanshin - - Copyright 2016-2017 David Faure - - 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 TASKAPPLICATIONMODEL_H -#define TASKAPPLICATIONMODEL_H - -#include "applicationmodel.h" -#include "runningtaskmodelinterface.h" - -namespace Presentation { - -class TaskApplicationModel : public ApplicationModel -{ - Q_OBJECT - Q_PROPERTY(RunningTaskModelInterface* runningTaskModel READ runningTaskModel) -public: - typedef QSharedPointer Ptr; - - explicit TaskApplicationModel(QObject *parent = Q_NULLPTR); - ~TaskApplicationModel(); - - Presentation::RunningTaskModelInterface *runningTaskModel(); - -private: - RunningTaskModelInterface::Ptr m_runningTaskModel; -}; - -} - -#endif // TASKAPPLICATIONMODEL_H diff --git a/src/presentation/taskapplicationmodel.cpp b/src/presentation/taskapplicationmodel.cpp deleted file mode 100644 --- a/src/presentation/taskapplicationmodel.cpp +++ /dev/null @@ -1,48 +0,0 @@ -/* This file is part of Zanshin - - Copyright 2016-2017 David Faure - - 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 "taskapplicationmodel.h" - -#include "runningtaskmodel.h" -#include "utils/dependencymanager.h" - -using namespace Presentation; - -TaskApplicationModel::TaskApplicationModel(QObject *parent) - : ApplicationModel(parent) -{ -} - -TaskApplicationModel::~TaskApplicationModel() -{ -} - -RunningTaskModelInterface *TaskApplicationModel::runningTaskModel() -{ - if (!m_runningTaskModel) { - auto model = Utils::DependencyManager::globalInstance().create(); - m_runningTaskModel = model; - m_runningTaskModel->setErrorHandler(errorHandler()); - } - return m_runningTaskModel.data(); -} diff --git a/src/zanshin/app/main.cpp b/src/zanshin/app/main.cpp --- a/src/zanshin/app/main.cpp +++ b/src/zanshin/app/main.cpp @@ -37,7 +37,7 @@ #include "widgets/editorview.h" #include "widgets/pageview.h" -#include "presentation/taskapplicationmodel.h" +#include "presentation/applicationmodel.h" #include "utils/dependencymanager.h" @@ -66,7 +66,7 @@ auto widget = new QWidget; auto components = new Widgets::TaskApplicationComponents(widget); - components->setModel(Presentation::TaskApplicationModel::Ptr::create()); + components->setModel(Presentation::ApplicationModel::Ptr::create()); auto layout = new QVBoxLayout; layout->setContentsMargins(0, 0, 0, 0); diff --git a/src/zanshin/kontact/part.cpp b/src/zanshin/kontact/part.cpp --- a/src/zanshin/kontact/part.cpp +++ b/src/zanshin/kontact/part.cpp @@ -34,7 +34,7 @@ #include "../app/aboutdata.h" #include "../app/dependencies.h" -#include "presentation/taskapplicationmodel.h" +#include "presentation/applicationmodel.h" #include "widgets/taskapplicationcomponents.h" #include "widgets/availablepagesview.h" @@ -57,7 +57,7 @@ auto sidebar = new QSplitter(Qt::Vertical, parentWidget); auto components = new Widgets::TaskApplicationComponents(parentWidget); - components->setModel(Presentation::TaskApplicationModel::Ptr::create()); + components->setModel(Presentation::ApplicationModel::Ptr::create()); sidebar->addWidget(components->availablePagesView()); sidebar->addWidget(components->availableSourcesView()); 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 @@ -12,7 +12,6 @@ projectpagemodeltest querytreemodeltest runningtaskmodeltest - taskapplicationmodeltest taskfilterproxymodeltest contextpagemodeltest workdaypagemodeltest 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 @@ -33,6 +33,7 @@ #include "presentation/editormodel.h" #include "presentation/pagemodel.h" #include "presentation/errorhandler.h" +#include "presentation/runningtaskmodel.h" #include "testlib/fakejob.h" @@ -91,6 +92,11 @@ return new Presentation::AvailableSourcesModel(Domain::DataSourceQueries::Ptr(), Domain::DataSourceRepository::Ptr()); }); + Utils::DependencyManager::globalInstance().add( + [] (Utils::DependencyManager *) { + return new Presentation::RunningTaskModel(Domain::TaskQueries::Ptr(), + Domain::TaskRepository::Ptr()); + }); } private slots: @@ -184,6 +190,18 @@ QVERIFY(qobject_cast(page)); } + void shouldProvideRunningTaskModel() + { + // GIVEN + Presentation::ApplicationModel app; + + // WHEN + QObject *model = app.runningTaskModel(); + + // THEN + QVERIFY(qobject_cast(model)); + } + void shouldSetErrorHandlerToAllModels() { // GIVEN @@ -201,10 +219,12 @@ auto availablePages = static_cast(app.availablePages()); auto editor = static_cast(app.editor()); auto page = static_cast(app.currentPage()); + auto runningTask = static_cast(app.runningTaskModel()); QCOMPARE(availableSource->errorHandler(), &errorHandler); QCOMPARE(availablePages->errorHandler(), &errorHandler); QCOMPARE(editor->errorHandler(), &errorHandler); QCOMPARE(page->errorHandler(), &errorHandler); + QCOMPARE(runningTask->errorHandler(), &errorHandler); // WHEN FakeErrorHandler errorHandler2; @@ -216,6 +236,7 @@ QCOMPARE(availablePages->errorHandler(), &errorHandler2); QCOMPARE(editor->errorHandler(), &errorHandler2); QCOMPARE(page->errorHandler(), &errorHandler2); + QCOMPARE(runningTask->errorHandler(), &errorHandler2); } void shouldClearJobHandlersOnExit() diff --git a/tests/units/presentation/taskapplicationmodeltest.cpp b/tests/units/presentation/taskapplicationmodeltest.cpp deleted file mode 100644 --- a/tests/units/presentation/taskapplicationmodeltest.cpp +++ /dev/null @@ -1,70 +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 "utils/dependencymanager.h" -#include "utils/jobhandler.h" -#include "utils/mockobject.h" - -#include "presentation/taskapplicationmodel.h" -#include "presentation/runningtaskmodel.h" - -#include "testlib/fakejob.h" - -using namespace mockitopp; -using namespace mockitopp::matcher; - - -class TaskApplicationModelTest : public QObject -{ - Q_OBJECT -public: - explicit TaskApplicationModelTest(QObject *parent = Q_NULLPTR) - : QObject(parent) - { - Utils::DependencyManager::globalInstance().add( - [] (Utils::DependencyManager *) { - return new Presentation::RunningTaskModel(Domain::TaskQueries::Ptr(), - Domain::TaskRepository::Ptr()); - }); - } - -private slots: - void shouldProvideRunningTaskModel() - { - // GIVEN - Presentation::TaskApplicationModel app; - - // WHEN - QObject *model = app.runningTaskModel(); - - // THEN - QVERIFY(qobject_cast(model)); - } - -}; - -ZANSHIN_TEST_MAIN(TaskApplicationModelTest) - -#include "taskapplicationmodeltest.moc"