diff --git a/src/widgets/applicationcomponents.h b/src/widgets/applicationcomponents.h --- a/src/widgets/applicationcomponents.h +++ b/src/widgets/applicationcomponents.h @@ -39,12 +39,17 @@ class QAction; class QWidget; +namespace Presentation { +class ErrorHandler; +} + namespace Widgets { class AvailablePagesView; class AvailableSourcesView; class EditorView; class PageView; +class PageViewErrorHandler; class QuickSelectDialogInterface; @@ -79,6 +84,7 @@ void onMoveItemsRequested(); private: + Presentation::ErrorHandler *errorHandler() const; void moveItems(const QModelIndex &destination, const QModelIndexList &droppedItems); QHash m_actions; @@ -90,6 +96,7 @@ PageView *m_pageView; QPointer m_editorView; + QScopedPointer m_errorHandler; QuickSelectDialogFactory m_quickSelectDialogFactory; }; diff --git a/src/widgets/applicationcomponents.cpp b/src/widgets/applicationcomponents.cpp --- a/src/widgets/applicationcomponents.cpp +++ b/src/widgets/applicationcomponents.cpp @@ -37,6 +37,7 @@ #include "availablesourcesview.h" #include "editorview.h" #include "pageview.h" +#include "pageviewerrorhandler.h" #include "quickselectdialog.h" using namespace Widgets; @@ -47,7 +48,8 @@ m_availableSourcesView(Q_NULLPTR), m_availablePagesView(Q_NULLPTR), m_pageView(Q_NULLPTR), - m_editorView(Q_NULLPTR) + m_editorView(Q_NULLPTR), + m_errorHandler(new PageViewErrorHandler) { m_quickSelectDialogFactory = [] (QWidget *parent) { return QuickSelectDialogPtr(new QuickSelectDialog(parent)); @@ -130,6 +132,7 @@ ApplicationComponents *self = const_cast(this); self->m_pageView = pageView; + self->m_errorHandler->setPageView(pageView); connect(self->m_pageView, &PageView::currentArtifactChanged, self, &ApplicationComponents::onCurrentArtifactChanged); } @@ -162,16 +165,21 @@ if (m_model == model) return; - if (m_model && m_pageView) { - disconnect(m_model.data(), 0, m_pageView, 0); + if (m_model) { + if (m_pageView) + disconnect(m_model.data(), 0, m_pageView, 0); + m_model->setProperty("errorHandler", 0); } // Delay deletion of the old model until we're out of scope auto tmp = m_model; Q_UNUSED(tmp); m_model = model; + if (m_model) + m_model->setProperty("errorHandler", QVariant::fromValue(errorHandler())); + if (m_availableSourcesView) { m_availableSourcesView->setModel(m_model ? m_model->property("availableSources").value() : Q_NULLPTR); @@ -243,6 +251,11 @@ moveItems(dlg->selectedIndex(), m_pageView->selectedIndexes()); } +Presentation::ErrorHandler *ApplicationComponents::errorHandler() const +{ + return m_errorHandler.data(); +} + void ApplicationComponents::moveItems(const QModelIndex &destination, const QModelIndexList &droppedItems) { Q_ASSERT(destination.isValid()); 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 @@ -45,6 +45,7 @@ #include "widgets/editorview.h" #include "widgets/filterwidget.h" #include "widgets/pageview.h" +#include "widgets/pageviewerrorhandler.h" #include "widgets/quickselectdialog.h" @@ -294,7 +295,7 @@ } private slots: - void shouldHaveApplicationModel() + void shouldHaveApplicationModelAndSetErrorHandler() { // GIVEN Widgets::ApplicationComponents components; @@ -305,6 +306,17 @@ // THEN QCOMPARE(components.model(), model); + auto errorHandlerBase = model->property("errorHandler").value(); + QVERIFY(errorHandlerBase); + auto errorHandler = static_cast(errorHandlerBase); + QVERIFY(errorHandler); + QVERIFY(!errorHandler->pageView()); + + // WHEN + auto pageView = components.pageView(); + + // THEN + QCOMPARE(errorHandler->pageView(), pageView); } void shouldApplyAvailableSourcesModelToAvailableSourcesView()