diff --git a/src/presentation/CMakeLists.txt b/src/presentation/CMakeLists.txt index 59b9aa80..49fb7c0c 100644 --- a/src/presentation/CMakeLists.txt +++ b/src/presentation/CMakeLists.txt @@ -1,23 +1,22 @@ set(presentation_SRCS applicationmodel.cpp editormodel.cpp availablepagesmodel.cpp availablepagessortfilterproxymodel.cpp availablesourcesmodel.cpp contextpagemodel.cpp errorhandler.cpp errorhandlingmodelbase.cpp inboxpagemodel.cpp metatypes.cpp pagemodel.cpp projectpagemodel.cpp querytreemodelbase.cpp runningtaskmodelinterface.cpp runningtaskmodel.cpp taskfilterproxymodel.cpp - taskapplicationmodel.cpp workdaypagemodel.cpp ) add_library(presentation STATIC ${presentation_SRCS}) target_link_libraries(presentation Qt5::Core Qt5::Gui KF5::I18n domain utils) diff --git a/src/presentation/applicationmodel.cpp b/src/presentation/applicationmodel.cpp index b76aa0d3..1dfa9c61 100644 --- a/src/presentation/applicationmodel.cpp +++ b/src/presentation/applicationmodel.cpp @@ -1,120 +1,133 @@ /* 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 "applicationmodel.h" #include "presentation/availablepagesmodel.h" #include "presentation/availablesourcesmodel.h" #include "presentation/editormodel.h" #include "presentation/errorhandler.h" #include "presentation/pagemodel.h" +#include "presentation/runningtaskmodel.h" #include "utils/dependencymanager.h" #include "utils/jobhandler.h" using namespace Presentation; ApplicationModel::ApplicationModel(QObject *parent) : QObject(parent), m_errorHandler(Q_NULLPTR) { MetaTypes::registerAll(); } ApplicationModel::~ApplicationModel() { Utils::JobHandler::clear(); } QObject *ApplicationModel::availableSources() { if (!m_availableSources) { auto model = Utils::DependencyManager::globalInstance().create(); model->setErrorHandler(errorHandler()); m_availableSources = model; } return m_availableSources.data(); } QObject *ApplicationModel::availablePages() { if (!m_availablePages) { auto model = Utils::DependencyManager::globalInstance().create(); model->setErrorHandler(errorHandler()); m_availablePages = model; } return m_availablePages.data(); } QObject *ApplicationModel::currentPage() { return m_currentPage.data(); } QObject *ApplicationModel::editor() { if (!m_editor) { auto model = Utils::DependencyManager::globalInstance().create(); model->setErrorHandler(errorHandler()); m_editor = model; } 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; } void ApplicationModel::setCurrentPage(QObject *page) { if (page == m_currentPage) return; m_currentPage = QObjectPtr(page); if (m_currentPage) { m_currentPage->setParent(Q_NULLPTR); auto pageModel = m_currentPage.staticCast(); Q_ASSERT(pageModel); pageModel->setErrorHandler(errorHandler()); } emit currentPageChanged(page); } void ApplicationModel::setErrorHandler(ErrorHandler *errorHandler) { m_errorHandler = errorHandler; if (m_availableSources) m_availableSources.staticCast()->setErrorHandler(errorHandler); if (m_availablePages) 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/applicationmodel.h b/src/presentation/applicationmodel.h index c177820d..5b96ec56 100644 --- a/src/presentation/applicationmodel.h +++ b/src/presentation/applicationmodel.h @@ -1,79 +1,83 @@ /* 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 PRESENTATION_APPLICATIONMODEL_H #define PRESENTATION_APPLICATIONMODEL_H #include #include "domain/datasourcerepository.h" #include "domain/datasourcequeries.h" #include "domain/taskrepository.h" #include "presentation/metatypes.h" +#include "presentation/runningtaskmodelinterface.h" namespace Presentation { class ErrorHandler; class ApplicationModel : public QObject { Q_OBJECT Q_PROPERTY(QObject* availableSources READ availableSources) 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; explicit ApplicationModel(QObject *parent = Q_NULLPTR); ~ApplicationModel(); QObject *availableSources(); QObject *availablePages(); QObject *currentPage(); QObject *editor(); + Presentation::RunningTaskModelInterface *runningTaskModel(); ErrorHandler *errorHandler() const; public slots: void setCurrentPage(QObject *page); void setErrorHandler(ErrorHandler *errorHandler); signals: void currentPageChanged(QObject *page); private: QObjectPtr m_availableSources; QObjectPtr m_availablePages; QObjectPtr m_currentPage; QObjectPtr m_editor; + RunningTaskModelInterface::Ptr m_runningTaskModel; ErrorHandler *m_errorHandler; }; } #endif // PRESENTATION_APPLICATIONMODEL_H diff --git a/src/presentation/taskapplicationmodel.cpp b/src/presentation/taskapplicationmodel.cpp deleted file mode 100644 index 626236c0..00000000 --- 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/presentation/taskapplicationmodel.h b/src/presentation/taskapplicationmodel.h deleted file mode 100644 index b71103fb..00000000 --- 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/zanshin/app/main.cpp b/src/zanshin/app/main.cpp index 9995fe7d..307c002f 100644 --- a/src/zanshin/app/main.cpp +++ b/src/zanshin/app/main.cpp @@ -1,128 +1,128 @@ /* 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 #include #include #include #include #include "widgets/taskapplicationcomponents.h" #include "widgets/availablepagesview.h" #include "widgets/availablesourcesview.h" #include "widgets/editorview.h" #include "widgets/pageview.h" -#include "presentation/taskapplicationmodel.h" +#include "presentation/applicationmodel.h" #include "utils/dependencymanager.h" #include "aboutdata.h" #include "dependencies.h" #include #include #include #include int main(int argc, char **argv) { KLocalizedString::setApplicationDomain("zanshin"); QApplication app(argc, argv); App::initializeDependencies(); auto aboutData = App::getAboutData(); QCommandLineParser parser; KAboutData::setApplicationData(aboutData); parser.addVersionOption(); parser.addHelpOption(); aboutData.setupCommandLine(&parser); parser.process(app); aboutData.processCommandLine(&parser); 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); layout->addWidget(components->pageView()); widget->setLayout(layout); auto sourcesDock = new QDockWidget(i18n("Sources")); sourcesDock->setObjectName(QStringLiteral("sourcesDock")); sourcesDock->setWidget(components->availableSourcesView()); auto pagesDock = new QDockWidget(i18n("Pages")); pagesDock->setObjectName(QStringLiteral("pagesDock")); pagesDock->setWidget(components->availablePagesView()); auto editorDock = new QDockWidget(i18n("Editor")); editorDock->setObjectName(QStringLiteral("editorDock")); editorDock->setWidget(components->editorView()); auto window = new KXmlGuiWindow; window->setCentralWidget(widget); window->addDockWidget(Qt::RightDockWidgetArea, editorDock); window->addDockWidget(Qt::LeftDockWidgetArea, pagesDock); window->addDockWidget(Qt::LeftDockWidgetArea, sourcesDock); auto actions = components->globalActions(); actions.insert(QStringLiteral("dock_sources"), sourcesDock->toggleViewAction()); actions.insert(QStringLiteral("dock_pages"), pagesDock->toggleViewAction()); actions.insert(QStringLiteral("dock_editor"), editorDock->toggleViewAction()); auto ac = window->actionCollection(); ac->addAction(KStandardAction::Quit, window, SLOT(close())); for (auto it = actions.constBegin(); it != actions.constEnd(); ++it) { auto shortcut = it.value()->shortcut(); if (!shortcut.isEmpty()) { ac->setDefaultShortcut(it.value(), shortcut); } ac->addAction(it.key(), it.value()); } window->setupGUI(QSize(1024, 600), KXmlGuiWindow::ToolBar | KXmlGuiWindow::Keys | KXmlGuiWindow::Save | KXmlGuiWindow::Create); delete window->findChild("help_contents"); delete window->findChild("help_whats_this"); window->show(); { auto &deps = Utils::DependencyManager::globalInstance(); auto repo = deps.create(); repo->windowNeedsDataBackend(window); } return app.exec(); } diff --git a/src/zanshin/kontact/part.cpp b/src/zanshin/kontact/part.cpp index 37f6bb13..7553b18b 100644 --- a/src/zanshin/kontact/part.cpp +++ b/src/zanshin/kontact/part.cpp @@ -1,92 +1,92 @@ /* This file is part of Zanshin Copyright 2011 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 "part.h" #include #include #include #include #include #include #include "../app/aboutdata.h" #include "../app/dependencies.h" -#include "presentation/taskapplicationmodel.h" +#include "presentation/applicationmodel.h" #include "widgets/taskapplicationcomponents.h" #include "widgets/availablepagesview.h" #include "widgets/availablesourcesview.h" #include "widgets/editorview.h" #include "widgets/pageview.h" #include "utils/dependencymanager.h" K_PLUGIN_FACTORY(PartFactory, registerPlugin();) Part::Part(QWidget *parentWidget, QObject *parent, const QVariantList &) : KParts::ReadOnlyPart(parent) { App::initializeDependencies(); setComponentName(QStringLiteral("zanshin"), QStringLiteral("zanshin")); auto splitter = new QSplitter(parentWidget); 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()); splitter->addWidget(sidebar); splitter->addWidget(components->pageView()); splitter->addWidget(components->editorView()); setWidget(splitter); auto actions = components->globalActions(); auto ac = actionCollection(); for (auto it = actions.constBegin(); it != actions.constEnd(); ++it) { auto shortcut = it.value()->shortcut(); if (!shortcut.isEmpty()) { ac->setDefaultShortcut(it.value(), shortcut); } ac->addAction(it.key(), it.value()); } setXMLFile(QStringLiteral("zanshin_part.rc"), true); } Part::~Part() { } bool Part::openFile() { return false; } #include "part.moc" diff --git a/tests/units/presentation/CMakeLists.txt b/tests/units/presentation/CMakeLists.txt index a82aa4a1..7b02a2e1 100644 --- a/tests/units/presentation/CMakeLists.txt +++ b/tests/units/presentation/CMakeLists.txt @@ -1,19 +1,18 @@ zanshin_auto_tests( applicationmodeltest editormodeltest availablepagesmodeltest availablepagessortfilterproxymodeltest availablesourcesmodeltest errorhandlertest errorhandlingmodelbasetest inboxpagemodeltest metatypestest pagemodeltest projectpagemodeltest querytreemodeltest runningtaskmodeltest - taskapplicationmodeltest taskfilterproxymodeltest contextpagemodeltest workdaypagemodeltest ) diff --git a/tests/units/presentation/applicationmodeltest.cpp b/tests/units/presentation/applicationmodeltest.cpp index 16cb8708..d3673221 100644 --- a/tests/units/presentation/applicationmodeltest.cpp +++ b/tests/units/presentation/applicationmodeltest.cpp @@ -1,239 +1,260 @@ /* 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/applicationmodel.h" #include "presentation/availablepagesmodel.h" #include "presentation/availablesourcesmodel.h" #include "presentation/editormodel.h" #include "presentation/pagemodel.h" #include "presentation/errorhandler.h" +#include "presentation/runningtaskmodel.h" #include "testlib/fakejob.h" using namespace mockitopp; using namespace mockitopp::matcher; class FakeErrorHandler : public Presentation::ErrorHandler { public: void doDisplayMessage(const QString &message) override { m_message = message; } QString m_message; }; class FakePageModel : public Presentation::PageModel { Q_OBJECT public: explicit FakePageModel(QObject *parent = Q_NULLPTR) : Presentation::PageModel(parent) {} Domain::Task::Ptr addItem(const QString &, const QModelIndex &) Q_DECL_OVERRIDE { return {}; } void removeItem(const QModelIndex &) Q_DECL_OVERRIDE {} void promoteItem(const QModelIndex &) Q_DECL_OVERRIDE {} private: QAbstractItemModel *createCentralListModel() Q_DECL_OVERRIDE { return {}; } }; class ApplicationModelTest : public QObject { Q_OBJECT public: explicit ApplicationModelTest(QObject *parent = Q_NULLPTR) : QObject(parent) { Utils::DependencyManager::globalInstance().add( [] (Utils::DependencyManager *) { return new Presentation::AvailablePagesModel(Domain::DataSourceQueries::Ptr(), Domain::ProjectQueries::Ptr(), Domain::ProjectRepository::Ptr(), Domain::ContextQueries::Ptr(), Domain::ContextRepository::Ptr(), Domain::TaskQueries::Ptr(), Domain::TaskRepository::Ptr()); }); Utils::DependencyManager::globalInstance().add( [] (Utils::DependencyManager *) { return new Presentation::EditorModel; }); Utils::DependencyManager::globalInstance().add( [] (Utils::DependencyManager *) { 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: void shouldProvideAvailableSourcesModel() { // GIVEN Presentation::ApplicationModel app; // WHEN QObject *available = app.availableSources(); // THEN QVERIFY(qobject_cast(available)); } void shouldProvideAvailablePagesModel() { // GIVEN Presentation::ApplicationModel app; // WHEN QObject *available = app.availablePages(); // THEN QVERIFY(qobject_cast(available)); } void shouldProvideCurrentPage() { // GIVEN Presentation::ApplicationModel app; QVERIFY(!app.currentPage()); QSignalSpy spy(&app, &Presentation::ApplicationModel::currentPageChanged); // WHEN auto page = new FakePageModel(this); app.setCurrentPage(page); // THEN QCOMPARE(app.currentPage(), page); QCOMPARE(spy.count(), 1); QCOMPARE(spy.takeFirst().at(0).value(), page); } void shouldSupportNullPage() { // GIVEN Presentation::ApplicationModel app; auto page = new FakePageModel(this); app.setCurrentPage(page); QCOMPARE(app.currentPage(), page); QSignalSpy spy(&app, &Presentation::ApplicationModel::currentPageChanged); // WHEN app.setCurrentPage(Q_NULLPTR); // THEN QVERIFY(!app.currentPage()); QCOMPARE(spy.count(), 1); QVERIFY(!spy.takeFirst().at(0).value()); } void shouldTakeOwnershipOfCurrentPage() { // GIVEN auto page = QPointer(new FakePageModel(this)); { Presentation::ApplicationModel app; // WHEN app.setCurrentPage(page.data()); // THEN QVERIFY(!page->parent()); QCOMPARE(app.currentPage(), page.data()); } // We don't crash and page is deleted QVERIFY(!page); } void shouldProvideEditorModel() { // GIVEN Presentation::ApplicationModel app; // WHEN QObject *page = app.editor(); // THEN QVERIFY(qobject_cast(page)); } + void shouldProvideRunningTaskModel() + { + // GIVEN + Presentation::ApplicationModel app; + + // WHEN + QObject *model = app.runningTaskModel(); + + // THEN + QVERIFY(qobject_cast(model)); + } + void shouldSetErrorHandlerToAllModels() { // GIVEN // An ErrorHandler FakeErrorHandler errorHandler; Presentation::ApplicationModel app; app.setCurrentPage(new FakePageModel); // WHEN app.setErrorHandler(&errorHandler); // THEN auto availableSource = static_cast(app.availableSources()); 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; app.setErrorHandler(&errorHandler2); // THEN QCOMPARE(availableSource->errorHandler(), &errorHandler2); QCOMPARE(availablePages->errorHandler(), &errorHandler2); QCOMPARE(editor->errorHandler(), &errorHandler2); QCOMPARE(page->errorHandler(), &errorHandler2); + QCOMPARE(runningTask->errorHandler(), &errorHandler2); } void shouldClearJobHandlersOnExit() { // GIVEN auto app = new Presentation::ApplicationModel; Utils::JobHandler::install(new FakeJob, [] { qFatal("Shouldn't happen"); }); QCOMPARE(Utils::JobHandler::jobCount(), 1); // WHEN delete app; // THEN QCOMPARE(Utils::JobHandler::jobCount(), 0); QTest::qWait(FakeJob::DURATION * 2); } }; ZANSHIN_TEST_MAIN(ApplicationModelTest) #include "applicationmodeltest.moc" diff --git a/tests/units/presentation/taskapplicationmodeltest.cpp b/tests/units/presentation/taskapplicationmodeltest.cpp deleted file mode 100644 index 87434b12..00000000 --- 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"