File indexing completed on 2025-01-19 04:56:38
0001 /* 0002 * SPDX-FileCopyrightText: 2014 Kevin Ottens <ervin@kde.org> 0003 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0004 */ 0005 0006 0007 #include "applicationmodel.h" 0008 0009 #include "presentation/availablepagesmodel.h" 0010 #include "presentation/availablesourcesmodel.h" 0011 #include "presentation/editormodel.h" 0012 #include "presentation/pagemodel.h" 0013 #include "presentation/runningtaskmodel.h" 0014 0015 #include "utils/dependencymanager.h" 0016 #include "utils/jobhandler.h" 0017 0018 using namespace Presentation; 0019 0020 ApplicationModel::ApplicationModel(QObject *parent) 0021 : QObject(parent), 0022 m_errorHandler(nullptr) 0023 { 0024 MetaTypes::registerAll(); 0025 } 0026 0027 ApplicationModel::~ApplicationModel() 0028 { 0029 Utils::JobHandler::clear(); 0030 } 0031 0032 QObject *ApplicationModel::availableSources() 0033 { 0034 if (!m_availableSources) { 0035 auto model = Utils::DependencyManager::globalInstance().create<AvailableSourcesModel>(); 0036 model->setErrorHandler(errorHandler()); 0037 m_availableSources = model; 0038 } 0039 return m_availableSources.data(); 0040 } 0041 0042 QObject *ApplicationModel::availablePages() 0043 { 0044 if (!m_availablePages) { 0045 auto model = Utils::DependencyManager::globalInstance().create<AvailablePagesModel>(); 0046 model->setErrorHandler(errorHandler()); 0047 m_availablePages = model; 0048 } 0049 return m_availablePages.data(); 0050 } 0051 0052 QObject *ApplicationModel::currentPage() 0053 { 0054 return m_currentPage.data(); 0055 } 0056 0057 QObject *ApplicationModel::editor() 0058 { 0059 if (!m_editor) { 0060 auto model = Utils::DependencyManager::globalInstance().create<EditorModel>(); 0061 model->setErrorHandler(errorHandler()); 0062 m_editor = model; 0063 } 0064 0065 return m_editor.data(); 0066 } 0067 0068 RunningTaskModelInterface *ApplicationModel::runningTaskModel() 0069 { 0070 if (!m_runningTaskModel) { 0071 auto model = Utils::DependencyManager::globalInstance().create<RunningTaskModel>(); 0072 m_runningTaskModel = model; 0073 m_runningTaskModel->setErrorHandler(errorHandler()); 0074 } 0075 return m_runningTaskModel.data(); 0076 } 0077 0078 ErrorHandler *ApplicationModel::errorHandler() const 0079 { 0080 return m_errorHandler; 0081 } 0082 0083 void ApplicationModel::setCurrentPage(QObject *page) 0084 { 0085 if (page == m_currentPage) 0086 return; 0087 0088 m_currentPage = QObjectPtr(page); 0089 0090 if (m_currentPage) { 0091 m_currentPage->setParent(nullptr); 0092 0093 auto pageModel = m_currentPage.staticCast<PageModel>(); 0094 Q_ASSERT(pageModel); 0095 pageModel->setErrorHandler(errorHandler()); 0096 } 0097 0098 emit currentPageChanged(page); 0099 } 0100 0101 void ApplicationModel::setErrorHandler(ErrorHandler *errorHandler) 0102 { 0103 m_errorHandler = errorHandler; 0104 if (m_availableSources) 0105 m_availableSources.staticCast<AvailableSourcesModel>()->setErrorHandler(errorHandler); 0106 if (m_availablePages) 0107 m_availablePages.staticCast<AvailablePagesModel>()->setErrorHandler(errorHandler); 0108 if (m_editor) 0109 m_editor.staticCast<EditorModel>()->setErrorHandler(errorHandler); 0110 if (m_runningTaskModel) 0111 m_runningTaskModel.staticCast<RunningTaskModel>()->setErrorHandler(errorHandler); 0112 if (m_currentPage) 0113 m_currentPage.staticCast<PageModel>()->setErrorHandler(errorHandler); 0114 } 0115 0116 #include "moc_applicationmodel.cpp"