diff --git a/Plugins/org.mitk.gui.qt.viewnavigator/CMakeLists.txt b/Plugins/org.mitk.gui.qt.viewnavigator/CMakeLists.txt index a759507265..1c96798764 100644 --- a/Plugins/org.mitk.gui.qt.viewnavigator/CMakeLists.txt +++ b/Plugins/org.mitk.gui.qt.viewnavigator/CMakeLists.txt @@ -1,7 +1,5 @@ project(org_mitk_gui_qt_viewnavigator) mitk_create_plugin( EXPORT_DIRECTIVE VIEWNAVIGATOR_EXPORT - EXPORTED_INCLUDE_SUFFIXES src - MODULE_DEPENDS MitkQtWidgetsExt ) diff --git a/Plugins/org.mitk.gui.qt.viewnavigator/documentation/UserManual/QmitkViewNavigator.dox b/Plugins/org.mitk.gui.qt.viewnavigator/documentation/UserManual/QmitkViewNavigator.dox index 15584ad31d..218f8d4bd5 100644 --- a/Plugins/org.mitk.gui.qt.viewnavigator/documentation/UserManual/QmitkViewNavigator.dox +++ b/Plugins/org.mitk.gui.qt.viewnavigator/documentation/UserManual/QmitkViewNavigator.dox @@ -1,43 +1,11 @@ /** \page org_mitk_views_viewnavigator The View Navigator -\imageMacro{view-manager.png,"Icon of the view navigator",2.00} - -\tableofcontents +\imageMacro{view-manager.png, "Icon of the view navigator", 2.00} \section org_mitk_views_viewnavigatorOverview Overview -This view allows for the easy navigation of the available views. - -You can select which view to open by double-clicking the name of the view in the view navigator. It provides a keyworded, grouped and searchable list of views. - -\section org_mitk_views_viewnavigatorUsage Usage - -You can toggle the View Navigator on and off by clicking on its icon in the menu bar. Alternatively it is also available via the Window->Show Views dialog. - -\imageMacro{QmitkViewNavigatorGUI.png,"The View Navigator GUI",6.00} - -Once the View Navigator has been opened you will see a list divided in workflows/perspectives and views. Via this list you can access any view or perspective provided by the application. They are further organized based on their associated category. - -An entry on the list is opened by a double left-click. - -\subsection org_mitk_views_viewnavigatorSearch Search - -You can search the lists for view/workflow names, keywords or categories. - -\imageMacro{QmitkViewNavigatorSearch.png,"Search the View Navigator",4.00} - -\subsection org_mitk_views_viewnavigatorCustomWorkflows Custom Workflows - -\imageMacro{QmitkViewNavigatorContextMenuWorkflows.png,"The workflow context menu",4.00} - -A right click on a workflow opens a context menu that allows you to copy that workflow to create your own custom one. -\note The duplicated workflow will look like the basic state of the original workflow. Any changes to the original workflow will not be copied. - -\imageMacro{QmitkViewNavigatorNewWorkflow.png,"Custom workflow creation dialog",4.00} - -Your new workflow will appear in the list and you can modify it independently of the original workflow. Any changes will be stored for future sessions unless the workflow is deleted. -\note Resetting a custom perspective will return it to the original state after duplicating. +The View Navigator allows for easy navigation of available views. +To open a view, double-click on it in the keyworded, grouped and searchable list of views. -\imageMacro{QmitkViewNavigatorContextMenuCustomWorkflow.png,"Custom workflow context menu",4.00} */ diff --git a/Plugins/org.mitk.gui.qt.viewnavigator/documentation/UserManual/QmitkViewNavigatorContextMenuCustomWorkflow.png b/Plugins/org.mitk.gui.qt.viewnavigator/documentation/UserManual/QmitkViewNavigatorContextMenuCustomWorkflow.png deleted file mode 100644 index ae0c73fd45..0000000000 Binary files a/Plugins/org.mitk.gui.qt.viewnavigator/documentation/UserManual/QmitkViewNavigatorContextMenuCustomWorkflow.png and /dev/null differ diff --git a/Plugins/org.mitk.gui.qt.viewnavigator/documentation/UserManual/QmitkViewNavigatorContextMenuWorkflows.png b/Plugins/org.mitk.gui.qt.viewnavigator/documentation/UserManual/QmitkViewNavigatorContextMenuWorkflows.png deleted file mode 100644 index 35e2689844..0000000000 Binary files a/Plugins/org.mitk.gui.qt.viewnavigator/documentation/UserManual/QmitkViewNavigatorContextMenuWorkflows.png and /dev/null differ diff --git a/Plugins/org.mitk.gui.qt.viewnavigator/documentation/UserManual/QmitkViewNavigatorGUI.png b/Plugins/org.mitk.gui.qt.viewnavigator/documentation/UserManual/QmitkViewNavigatorGUI.png deleted file mode 100644 index d72d37ba82..0000000000 Binary files a/Plugins/org.mitk.gui.qt.viewnavigator/documentation/UserManual/QmitkViewNavigatorGUI.png and /dev/null differ diff --git a/Plugins/org.mitk.gui.qt.viewnavigator/documentation/UserManual/QmitkViewNavigatorNewWorkflow.png b/Plugins/org.mitk.gui.qt.viewnavigator/documentation/UserManual/QmitkViewNavigatorNewWorkflow.png deleted file mode 100644 index a94adc04f9..0000000000 Binary files a/Plugins/org.mitk.gui.qt.viewnavigator/documentation/UserManual/QmitkViewNavigatorNewWorkflow.png and /dev/null differ diff --git a/Plugins/org.mitk.gui.qt.viewnavigator/documentation/UserManual/QmitkViewNavigatorSearch.png b/Plugins/org.mitk.gui.qt.viewnavigator/documentation/UserManual/QmitkViewNavigatorSearch.png deleted file mode 100644 index ae0c8e6378..0000000000 Binary files a/Plugins/org.mitk.gui.qt.viewnavigator/documentation/UserManual/QmitkViewNavigatorSearch.png and /dev/null differ diff --git a/Plugins/org.mitk.gui.qt.viewnavigator/documentation/doxygen/modules.dox b/Plugins/org.mitk.gui.qt.viewnavigator/documentation/doxygen/modules.dox deleted file mode 100644 index 52de3fc0c2..0000000000 --- a/Plugins/org.mitk.gui.qt.viewnavigator/documentation/doxygen/modules.dox +++ /dev/null @@ -1,16 +0,0 @@ -/** - \defgroup org_mitk_gui_qt_viewnavigator org.mitk.gui.qt.viewnavigator - \ingroup MITKPlugins - - \brief Describe your plugin here. - -*/ - -/** - \defgroup org_mitk_gui_qt_viewnavigator_internal Internal - \ingroup org_mitk_gui_qt_viewnavigator - - \brief This subcategory includes the internal classes of the org.mitk.gui.qt.viewnavigator plugin. Other - plugins must not rely on these classes. They contain implementation details and their interface - may change at any time. We mean it. -*/ diff --git a/Plugins/org.mitk.gui.qt.viewnavigator/files.cmake b/Plugins/org.mitk.gui.qt.viewnavigator/files.cmake index a4e8dac4c9..54a4224db3 100644 --- a/Plugins/org.mitk.gui.qt.viewnavigator/files.cmake +++ b/Plugins/org.mitk.gui.qt.viewnavigator/files.cmake @@ -1,45 +1,26 @@ -set(SRC_CPP_FILES - QmitkViewNavigatorWidget.cpp - QmitkPerspectiveItem.h - QmitkViewItem.h -) - -set(INTERNAL_CPP_FILES - mitkPluginActivator.cpp - QmitkViewNavigatorView.cpp -) - -set(UI_FILES - src/QmitkViewNavigatorWidgetControls.ui +set(CPP_FILES + src/internal/mitkPluginActivator.cpp + src/internal/QmitkCategoryItem.cpp + src/internal/QmitkCategoryItem.h + src/internal/QmitkViewItem.cpp + src/internal/QmitkViewItem.h + src/internal/QmitkViewNavigatorView.cpp + src/internal/QmitkViewModel.cpp + src/internal/QmitkViewModel.h + src/internal/QmitkViewProxyModel.cpp + src/internal/QmitkViewProxyModel.h ) set(MOC_H_FILES src/internal/mitkPluginActivator.h src/internal/QmitkViewNavigatorView.h - src/QmitkViewNavigatorWidget.h ) -# list of resource files which can be used by the plug-in -# system without loading the plug-ins shared library, -# for example the icon used in the menu and tabs for the -# plug-in views in the workbench +set(UI_FILES + src/internal/QmitkViewNavigatorView.ui +) + set(CACHED_RESOURCE_FILES resources/view-manager.svg plugin.xml ) - -# list of Qt .qrc files which contain additional resources -# specific to this plugin -set(QRC_FILES - -) - -set(CPP_FILES ) - -foreach(file ${SRC_CPP_FILES}) - set(CPP_FILES ${CPP_FILES} src/${file}) -endforeach(file ${SRC_CPP_FILES}) - -foreach(file ${INTERNAL_CPP_FILES}) - set(CPP_FILES ${CPP_FILES} src/internal/${file}) -endforeach(file ${INTERNAL_CPP_FILES}) diff --git a/Plugins/org.mitk.gui.qt.viewnavigator/manifest_headers.cmake b/Plugins/org.mitk.gui.qt.viewnavigator/manifest_headers.cmake index 5fcab65742..a90914a66a 100644 --- a/Plugins/org.mitk.gui.qt.viewnavigator/manifest_headers.cmake +++ b/Plugins/org.mitk.gui.qt.viewnavigator/manifest_headers.cmake @@ -1,5 +1,5 @@ -set(Plugin-Name "View Navigator") +set(Plugin-Name "View Navigator 2") set(Plugin-Version "0.1") set(Plugin-Vendor "German Cancer Research Center (DKFZ)") set(Plugin-ContactAddress "") set(Require-Plugin org.mitk.gui.qt.common) diff --git a/Plugins/org.mitk.gui.qt.viewnavigator/plugin.xml b/Plugins/org.mitk.gui.qt.viewnavigator/plugin.xml index f08d78ca51..4988ec95e4 100644 --- a/Plugins/org.mitk.gui.qt.viewnavigator/plugin.xml +++ b/Plugins/org.mitk.gui.qt.viewnavigator/plugin.xml @@ -1,12 +1,10 @@ - + enumerate="false" /> - diff --git a/Plugins/org.mitk.gui.qt.viewnavigator/src/QmitkPerspectiveItem.h b/Plugins/org.mitk.gui.qt.viewnavigator/src/QmitkPerspectiveItem.h deleted file mode 100644 index 660263f08c..0000000000 --- a/Plugins/org.mitk.gui.qt.viewnavigator/src/QmitkPerspectiveItem.h +++ /dev/null @@ -1,38 +0,0 @@ -/*============================================================================ - -The Medical Imaging Interaction Toolkit (MITK) - -Copyright (c) German Cancer Research Center (DKFZ) -All rights reserved. - -Use of this source code is governed by a 3-clause BSD license that can be -found in the LICENSE file. - -============================================================================*/ - -#ifndef QmitkPerspectiveItem_h -#define QmitkPerspectiveItem_h - -#include -#include - -class QmitkPerspectiveItem : public QStandardItem -{ -public: - - QmitkPerspectiveItem(const QString& string) - : QStandardItem(string) - { - } - - QmitkPerspectiveItem(const QIcon& icon, const QString& string) - : QStandardItem(icon, string) - { - } - - berry::IPerspectiveDescriptor::Pointer m_ItemDescriptor; - QStringList m_Tags; - QString m_Description; -}; - -#endif diff --git a/Plugins/org.mitk.gui.qt.viewnavigator/src/QmitkViewNavigatorWidget.cpp b/Plugins/org.mitk.gui.qt.viewnavigator/src/QmitkViewNavigatorWidget.cpp deleted file mode 100644 index 007c9f6457..0000000000 --- a/Plugins/org.mitk.gui.qt.viewnavigator/src/QmitkViewNavigatorWidget.cpp +++ /dev/null @@ -1,727 +0,0 @@ -/*============================================================================ - -The Medical Imaging Interaction Toolkit (MITK) - -Copyright (c) German Cancer Research Center (DKFZ) -All rights reserved. - -Use of this source code is governed by a 3-clause BSD license that can be -found in the LICENSE file. - -============================================================================*/ - -// View navigator plugin -#include -#include -#include - -// Blueberry -#include -#include -#include -#include -#include -#include -#include -#include - -// MITK -#include - -// Qt -#include -#include -#include -#include -#include - -namespace -{ - QFont getLargeFont() - { - QFont font = qApp->font(); - font.setPointSizeF(font.pointSizeF() * 1.25f); - return font; - } -} - -class KeywordRegistry -{ -public: - - KeywordRegistry() - { - berry::IExtensionRegistry* extensionPointService = berry::Platform::GetExtensionRegistry(); - auto keywordExts = extensionPointService->GetConfigurationElementsFor("org.blueberry.ui.keywords"); - for (auto keywordExtsIt = keywordExts.begin(); keywordExtsIt != keywordExts.end(); ++keywordExtsIt) - { - QString keywordId = (*keywordExtsIt)->GetAttribute("id"); - QString keywordLabels = (*keywordExtsIt)->GetAttribute("label"); - m_Keywords[keywordId].push_back(keywordLabels); - } - } - - QStringList GetKeywords(const QString& id) - { - return m_Keywords[id]; - } - - QStringList GetKeywords(const QStringList& ids) - { - QStringList result; - for (const auto& id : ids) - { - result.append(this->GetKeywords(id)); - } - return result; - } - -private: - - QHash m_Keywords; -}; - -class ClassFilterProxyModel : public QSortFilterProxyModel -{ -public: - - ClassFilterProxyModel(QObject* parent = nullptr) - : QSortFilterProxyModel(parent) - { - } - - bool filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const override - { - QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent); - - return hasToBeDisplayed(index); - } - -private: - - bool displayElement(const QModelIndex index) const - { - QString type = sourceModel()->data(index, Qt::DisplayRole).toString(); - QStandardItem* item = dynamic_cast(sourceModel())->itemFromIndex(index); - - if (type.contains(filterRegularExpression())) - { - return true; - } - - QmitkViewItem* viewItem = dynamic_cast(item); - if (nullptr != viewItem) - { - for (const auto& tag : viewItem->m_Tags) - { - if (tag.contains(filterRegularExpression())) - { - return true; - } - } - if (viewItem->m_Description.contains(filterRegularExpression())) - { - return true; - } - } - - QmitkPerspectiveItem* perspectiveItem = dynamic_cast(item); - if (nullptr != perspectiveItem) - { - for (const auto& tag : perspectiveItem->m_Tags) - { - if (tag.contains(filterRegularExpression())) - { - return true; - } - } - if (perspectiveItem->m_Description.contains(filterRegularExpression())) - { - return true; - } - } - - return false; - } - - bool hasToBeDisplayed(const QModelIndex index) const - { - bool result = false; - if (sourceModel()->rowCount(index) > 0) - { - for (int i = 0; i < sourceModel()->rowCount(index); i++) - { - QModelIndex childIndex = sourceModel()->index(i, 0, index); - if (!childIndex.isValid()) - { - break; - } - - result = hasToBeDisplayed(childIndex); - result |= displayElement(index); - - if (result) - { - break; - } - } - } - else - { - result = displayElement(index); - } - return result; - } -}; - -class ViewNavigatorPerspectiveListener: public berry::IPerspectiveListener -{ -public: - - ViewNavigatorPerspectiveListener(QmitkViewNavigatorWidget* parent) - : m_ParentWidget(parent) - { - } - - Events::Types GetPerspectiveEventTypes() const override - { - return Events::ACTIVATED | Events::SAVED_AS | Events::DEACTIVATED - // remove the following line when command framework is finished - | Events::CLOSED | Events::OPENED | Events::PART_CHANGED; - } - - void PerspectiveActivated(const berry::IWorkbenchPage::Pointer& /*page*/, - const berry::IPerspectiveDescriptor::Pointer& /*perspective*/) override - { - m_ParentWidget->UpdateTreeList(); - } - - void PerspectiveSavedAs(const berry::IWorkbenchPage::Pointer& /*page*/, - const berry::IPerspectiveDescriptor::Pointer& /*oldPerspective*/, - const berry::IPerspectiveDescriptor::Pointer& /*newPerspective*/) override - { - m_ParentWidget->UpdateTreeList(); - } - - void PerspectiveDeactivated(const berry::IWorkbenchPage::Pointer& /*page*/, - const berry::IPerspectiveDescriptor::Pointer& /*perspective*/) override - { - m_ParentWidget->m_ActivePerspective = nullptr; - } - - void PerspectiveOpened(const berry::IWorkbenchPage::Pointer& /*page*/, - const berry::IPerspectiveDescriptor::Pointer& /*perspective*/) override - { - m_ParentWidget->UpdateTreeList(); - } - - void PerspectiveClosed(const berry::IWorkbenchPage::Pointer& /*page*/, - const berry::IPerspectiveDescriptor::Pointer& /*perspective*/) override - { - m_ParentWidget->m_ActivePerspective = nullptr; - } - - using IPerspectiveListener::PerspectiveChanged; - - void PerspectiveChanged(const berry::IWorkbenchPage::Pointer& /*page*/, - const berry::IPerspectiveDescriptor::Pointer& /*perspective*/, - const berry::IWorkbenchPartReference::Pointer& partRef, const std::string& changeId) - { - if (changeId == "viewHide" && partRef->GetId() == "org.mitk.views.viewnavigator") - berry::PlatformUI::GetWorkbench()->GetActiveWorkbenchWindow()->RemovePerspectiveListener(m_ParentWidget->m_PerspectiveListener.data()); - else - m_ParentWidget->UpdateTreeList(); - } - -private: - - QmitkViewNavigatorWidget* m_ParentWidget; -}; - -class ViewNavigatorViewListener: public berry::IPartListener -{ -public: - - ViewNavigatorViewListener(QmitkViewNavigatorWidget* parent) - : m_ParentWidget(parent) - { - } - - Events::Types GetPartEventTypes() const override - { - return Events::OPENED | Events::CLOSED; - } - - void PartOpened(const berry::IWorkbenchPartReference::Pointer& partRef) override - { - if (partRef->GetId() != "org.mitk.views.viewnavigator") - { - m_ParentWidget->UpdateTreeList((partRef->GetPart(false)).GetPointer()); - } - else - { - m_ParentWidget->FillTreeList(); - m_ParentWidget->UpdateTreeList(); - } - } - - void PartClosed(const berry::IWorkbenchPartReference::Pointer& partRef) override - { - if (partRef->GetId() != "org.mitk.views.viewnavigator") - { - m_ParentWidget->UpdateTreeList(); - } - } - -private: - - QmitkViewNavigatorWidget* m_ParentWidget; -}; - -bool compareViews(const berry::IViewDescriptor::Pointer& a, const berry::IViewDescriptor::Pointer& b) -{ - if (a.IsNull() || b.IsNull()) - { - return false; - } - - return a->GetLabel().compare(b->GetLabel()) < 0; -} - -bool comparePerspectives(const berry::IPerspectiveDescriptor::Pointer& a, const berry::IPerspectiveDescriptor::Pointer& b) -{ - if (a.IsNull() || b.IsNull()) - { - return false; - } - - return a->GetLabel().compare(b->GetLabel()) < 0; -} - -bool compareQStandardItems(const QStandardItem* a, const QStandardItem* b) -{ - if (nullptr == a || nullptr== b) - { - return false; - } - - return a->text().compare(b->text()) < 0; -} - -QmitkViewNavigatorWidget::QmitkViewNavigatorWidget(berry::IWorkbenchWindow::Pointer window, - QWidget* parent, - Qt::WindowFlags) - : QWidget(parent) - , m_Window(window) -{ - this->CreateQtPartControl(this); -} - -QmitkViewNavigatorWidget::~QmitkViewNavigatorWidget() -{ - m_Window->RemovePerspectiveListener(m_PerspectiveListener.data()); - m_Window->GetPartService()->RemovePartListener(m_ViewPartListener.data()); -} - -void QmitkViewNavigatorWidget::SetFocus() -{ - m_Controls.lineEdit->setFocus(); -} - -void QmitkViewNavigatorWidget::UpdateTreeList(berry::IWorkbenchPart* workbenchPart) -{ - berry::IWorkbenchPage::Pointer page = m_Window->GetActivePage(); - if (page.IsNull()) - { - return; - } - - m_ActivePerspective = page->GetPerspective(); - QList viewParts = page->GetViews(); - - // iterate over all tree items - for (const auto& item : m_TreeModel->findItems("*", Qt::MatchWildcard | Qt::MatchRecursive)) - { - QFont font = qApp->font(); - // check if the item is a view item and if it is equal to any opened view - QmitkViewItem* viewItem = dynamic_cast(item); - if (nullptr != viewItem) - { - if (nullptr != workbenchPart && workbenchPart->GetPartName() == viewItem->m_ItemDescriptor->GetLabel()) - { - font.setBold(true); - } - else - { - for (const auto& viewPart : viewParts) - { - if (viewPart->GetPartName() == viewItem->m_ItemDescriptor->GetLabel()) - { - font.setBold(true); - break; - } - } - } - - viewItem->setFont(font); - } - else - { - // check if the item is a perspective item and if it is equal to the current perspective - QmitkPerspectiveItem* perspectiveItem = dynamic_cast(item); - if (nullptr != perspectiveItem) - { - if (m_ActivePerspective.IsNotNull() && m_ActivePerspective->GetId() == perspectiveItem->m_ItemDescriptor->GetId()) - { - font.setBold(true); - } - - perspectiveItem->setFont(font); - } - } - } -} - -bool QmitkViewNavigatorWidget::FillTreeList() -{ - // initialize tree model - m_TreeModel->clear(); - - // add all available views - this->AddViewsToTree(); - - // add all available perspectives - this->AddPerspectivesToTree(); - - m_Controls.m_PluginTreeView->expandAll(); - - return true; -} - -void QmitkViewNavigatorWidget::FilterChanged() -{ - m_Controls.m_PluginTreeView->expandAll(); - - auto pattern = m_Controls.lineEdit->text(); - QRegularExpression regExp(pattern, QRegularExpression::CaseInsensitiveOption); - m_FilterProxyModel->setFilterRegularExpression(regExp); -} - -void QmitkViewNavigatorWidget::ItemClicked(const QModelIndex &index) -{ - QStandardItem* item = m_TreeModel->itemFromIndex(m_FilterProxyModel->mapToSource(index)); - - QmitkPerspectiveItem* perspectiveItem = dynamic_cast(item); - if (nullptr != perspectiveItem) - { - try - { - berry::PlatformUI::GetWorkbench()->ShowPerspective( - perspectiveItem->m_ItemDescriptor->GetId(), berry::PlatformUI::GetWorkbench()->GetActiveWorkbenchWindow()); - } - catch (...) - { - QMessageBox::critical(nullptr, "Opening Perspective Failed", - QString("The requested perspective could not be opened.\nSee the log for details.")); - } - - return; - } - - QmitkViewItem* viewItem = dynamic_cast(item); - if (nullptr != viewItem) - { - berry::IWorkbenchPage::Pointer page = - berry::PlatformUI::GetWorkbench()->GetActiveWorkbenchWindow()->GetActivePage(); - - if (page.IsNotNull()) - { - try - { - page->ShowView(viewItem->m_ItemDescriptor->GetId()); - } - catch (const berry::PartInitException& e) - { - BERRY_ERROR << "Error: " << e.what() << std::endl; - } - } - } -} - -void QmitkViewNavigatorWidget::SaveCurrentPerspectiveAs() -{ - berry::IWorkbenchPage::Pointer page = m_Window->GetActivePage(); - berry::IPerspectiveDescriptor::Pointer currentPerspective = page->GetPerspective(); - - bool ok = false; - QString perspectiveLabel = QInputDialog::getText(this, "Save perspective as ...", - "New perspective name:", QLineEdit::Normal, - "", &ok); - - if (!ok) - { - return; - } - - if (perspectiveLabel.isEmpty()) - { - QMessageBox::information(this, "Save perspective as ...", "Please select a valid perspective name."); - return; - } - - berry::IPerspectiveRegistry* perspectiveRegistry = berry::PlatformUI::GetWorkbench()->GetPerspectiveRegistry(); - berry::IPerspectiveDescriptor::Pointer newPerspective = perspectiveRegistry->CreatePerspective(perspectiveLabel, currentPerspective); - - if (nullptr == newPerspective) - { - QMessageBox::information(this, "Save perspective as ...", "The selected perspective name is already in use."); - return; - } - - page->SavePerspectiveAs(newPerspective); - - this->FillTreeList(); - this->UpdateTreeList(); -} - -void QmitkViewNavigatorWidget::ResetCurrentPerspective() -{ - if (QMessageBox::Yes == QMessageBox(QMessageBox::Question, "Please confirm", - "Do you really want to reset the current perspective?", - QMessageBox::Yes | QMessageBox::No).exec()) - { - berry::IWorkbenchPage::Pointer page = m_Window->GetActivePage(); - page->ResetPerspective(); - } -} - -void QmitkViewNavigatorWidget::ClosePerspective() -{ - if (QMessageBox::Yes == QMessageBox(QMessageBox::Question, "Please confirm", - "Do you really want to close the current perspective?", - QMessageBox::Yes | QMessageBox::No).exec()) - { - berry::IWorkbenchPage::Pointer page = m_Window->GetActivePage(); - page->ClosePerspective(page->GetPerspective(), true, true); - } -} - -void QmitkViewNavigatorWidget::CloseAllPerspectives() -{ - if (QMessageBox::Yes == QMessageBox(QMessageBox::Question, "Please confirm", - "Do you really want to close all perspectives?", - QMessageBox::Yes | QMessageBox::No).exec()) - { - berry::IWorkbenchPage::Pointer page = m_Window->GetActivePage(); - page->CloseAllPerspectives(true, true); - } -} - -void QmitkViewNavigatorWidget::ExpandAll() -{ - m_Controls.m_PluginTreeView->expandAll(); -} - -void QmitkViewNavigatorWidget::CollapseAll() -{ - m_Controls.m_PluginTreeView->collapseAll(); -} - -void QmitkViewNavigatorWidget::CustomMenuRequested(QPoint pos) -{ - QModelIndex index = m_Controls.m_PluginTreeView->indexAt(pos); - QStandardItem* item = m_TreeModel->itemFromIndex(m_FilterProxyModel->mapToSource(index)); - - if (nullptr == m_ContextMenu) - return; - - m_ContextMenu->clear(); - - QmitkPerspectiveItem* perspectiveItem = dynamic_cast(item); - if (nullptr != perspectiveItem) - { - berry::IPerspectiveDescriptor::Pointer perspectiveDescriptor = perspectiveItem->m_ItemDescriptor; - if (this->m_ActivePerspective.IsNotNull() && this->m_ActivePerspective == perspectiveDescriptor) - { - QAction* saveAsAction = new QAction("Save perspective as ...", this); - m_ContextMenu->addAction(saveAsAction); - connect(saveAsAction, SIGNAL(triggered()), SLOT(SaveCurrentPerspectiveAs())); - m_ContextMenu->addSeparator(); - } - } - - QAction* resetAction = new QAction("Reset current perspective", this); - m_ContextMenu->addAction(resetAction); - connect(resetAction, SIGNAL(triggered()), SLOT(ResetCurrentPerspective())); - - QAction* closeAction = new QAction("Close perspective", this); - m_ContextMenu->addAction(closeAction); - connect(closeAction, SIGNAL(triggered()), SLOT(ClosePerspective())); - - QAction* closeAllAction = new QAction("Close all perspectives", this); - m_ContextMenu->addAction(closeAllAction); - connect(closeAllAction, SIGNAL(triggered()), SLOT(CloseAllPerspectives())); - - m_ContextMenu->addSeparator(); - - QAction* expandAction = new QAction("Expand tree", this); - m_ContextMenu->addAction(expandAction); - connect(expandAction, SIGNAL(triggered()), SLOT(ExpandAll())); - - QAction* collapseAction = new QAction("Collapse tree", this); - m_ContextMenu->addAction(collapseAction); - connect(collapseAction, SIGNAL(triggered()), SLOT(CollapseAll())); - - m_ContextMenu->popup(m_Controls.m_PluginTreeView->viewport()->mapToGlobal(pos)); -} - -void QmitkViewNavigatorWidget::CreateQtPartControl(QWidget* parent) -{ - // active workbench window available? - if (m_Window.IsNull()) - { - return; - } - - m_Controls.setupUi(parent); - connect(m_Controls.m_PluginTreeView, SIGNAL(customContextMenuRequested(QPoint)), SLOT(CustomMenuRequested(QPoint))); - connect(m_Controls.m_PluginTreeView, SIGNAL(doubleClicked(const QModelIndex&)), SLOT(ItemClicked(const QModelIndex&))); - connect(m_Controls.lineEdit, SIGNAL(textChanged(QString)), SLOT(FilterChanged())); - - m_ContextMenu = new QMenu(m_Controls.m_PluginTreeView); - m_Controls.m_PluginTreeView->setContextMenuPolicy(Qt::CustomContextMenu); - - // Create a new TreeModel for the data - m_TreeModel = new QStandardItemModel(); - m_FilterProxyModel = new ClassFilterProxyModel(this); - m_FilterProxyModel->setSourceModel(m_TreeModel); - m_Controls.m_PluginTreeView->setModel(m_FilterProxyModel); - - m_PerspectiveListener.reset(new ViewNavigatorPerspectiveListener(this)); - m_Window->AddPerspectiveListener(m_PerspectiveListener.data()); - - m_ViewPartListener.reset(new ViewNavigatorViewListener(this)); - m_Window->GetPartService()->AddPartListener(m_ViewPartListener.data()); -} - -void QmitkViewNavigatorWidget::AddPerspectivesToTree() -{ - berry::IPerspectiveRegistry* perspRegistry = berry::PlatformUI::GetWorkbench()->GetPerspectiveRegistry(); - QList perspectiveDescriptors(perspRegistry->GetPerspectives()); - std::sort(perspectiveDescriptors.begin(), perspectiveDescriptors.end(), comparePerspectives); - - QStandardItem* perspectiveRootItem = new QStandardItem("Perspectives"); - perspectiveRootItem->setFont(getLargeFont()); - perspectiveRootItem->setEditable(false); - QStandardItem* treeRootItem = m_TreeModel->invisibleRootItem(); - treeRootItem->appendRow(perspectiveRootItem); - - this->AddItemsToTree, QmitkPerspectiveItem>( - perspectiveDescriptors, perspectiveRootItem); -} - -void QmitkViewNavigatorWidget::AddViewsToTree() -{ - berry::IViewRegistry* viewRegistry = berry::PlatformUI::GetWorkbench()->GetViewRegistry(); - QList viewDescriptors(viewRegistry->GetViews()); - std::sort(viewDescriptors.begin(), viewDescriptors.end(), compareViews); - - auto largeFont = getLargeFont(); - - QStandardItem* viewRootItem = new QStandardItem("Views"); - viewRootItem->setFont(largeFont); - viewRootItem->setEditable(false); - QStandardItem* treeRootItem = m_TreeModel->invisibleRootItem(); - treeRootItem->appendRow(viewRootItem); - - QStandardItem* miscellaneousCategoryItem = new QStandardItem("Miscellaneous"); - miscellaneousCategoryItem->setFont(largeFont); - miscellaneousCategoryItem->setEditable(false); - - QStringList viewExcludeList; - // internal view used for the intro screen, will crash when opened directly, see T22352 - viewExcludeList.append(QString("org.blueberry.ui.internal.introview")); - viewExcludeList.append(QString("org.mitk.views.controlvisualizationpropertiesview")); - viewExcludeList.append(QString("org.mitk.views.modules")); - viewExcludeList.append(QString("org.mitk.views.viewnavigator")); - - this->AddItemsToTree, QmitkViewItem>( - viewDescriptors, viewRootItem, miscellaneousCategoryItem, viewExcludeList); -} - -template -void QmitkViewNavigatorWidget::AddItemsToTree(D itemDescriptors, QStandardItem* rootItem, - QStandardItem* miscellaneousItem, const QStringList& itemExcludeList) -{ - KeywordRegistry keywordRegistry; - std::vector categoryItems; - - for (const auto& itemDescriptor : itemDescriptors) - { - bool excludeView = itemExcludeList.contains(itemDescriptor->GetId()); - if (excludeView) - { - continue; - } - - QIcon icon = itemDescriptor->GetImageDescriptor(); - I* item = new I(icon, itemDescriptor->GetLabel()); - item->m_ItemDescriptor = itemDescriptor; - item->m_Description = itemDescriptor->GetDescription(); - item->setToolTip(itemDescriptor->GetDescription()); - - QStringList keylist = itemDescriptor->GetKeywordReferences(); - item->m_Tags = keywordRegistry.GetKeywords(keylist); - item->setEditable(false); - - QStringList categoryPath = itemDescriptor->GetCategoryPath(); - if (categoryPath.empty()) - { - // If a root item for general / non-categorized item views is given, use it. - // Otherwise put the non-categorized item views into the top root item. - if (nullptr != miscellaneousItem) - { - miscellaneousItem->appendRow(item); - } - else - { - rootItem->appendRow(item); - } - } - else - { - QStandardItem* categoryItem = nullptr; - for (const auto& currentCategoryItem : categoryItems) - { - if (currentCategoryItem->text() == categoryPath.front()) - { - categoryItem = currentCategoryItem; - break; - } - } - - if (nullptr == categoryItem) - { - categoryItem = new QStandardItem(QIcon(), categoryPath.front()); - categoryItems.push_back(categoryItem); - } - - auto font = getLargeFont(); - - categoryItem->setFont(font); - categoryItem->setEditable(false); - categoryItem->appendRow(item); - } - } - - std::sort(categoryItems.begin(), categoryItems.end(), compareQStandardItems); - for (const auto& categoryItem : categoryItems) - { - rootItem->appendRow(categoryItem); - } - - if (nullptr != miscellaneousItem && miscellaneousItem->hasChildren()) - { - rootItem->appendRow(miscellaneousItem); - } -} diff --git a/Plugins/org.mitk.gui.qt.viewnavigator/src/QmitkViewNavigatorWidget.h b/Plugins/org.mitk.gui.qt.viewnavigator/src/QmitkViewNavigatorWidget.h deleted file mode 100644 index c27effebe0..0000000000 --- a/Plugins/org.mitk.gui.qt.viewnavigator/src/QmitkViewNavigatorWidget.h +++ /dev/null @@ -1,87 +0,0 @@ -/*============================================================================ - -The Medical Imaging Interaction Toolkit (MITK) - -Copyright (c) German Cancer Research Center (DKFZ) -All rights reserved. - -Use of this source code is governed by a 3-clause BSD license that can be -found in the LICENSE file. - -============================================================================*/ -#ifndef QmitkViewNavigatorWidget_h -#define QmitkViewNavigatorWidget_h - -#include "ui_QmitkViewNavigatorWidgetControls.h" - -//QT headers -#include -#include -#include - -#include -#include -#include - -class ClassFilterProxyModel; - -/** -* @brief -* -*/ -class QmitkViewNavigatorWidget : public QWidget -{ - Q_OBJECT - -public: - - QmitkViewNavigatorWidget(berry::IWorkbenchWindow::Pointer window, - QWidget* parent = nullptr, - Qt::WindowFlags f = {}); - ~QmitkViewNavigatorWidget() override; - - void SetFocus(); - -public Q_SLOTS: - - void FilterChanged(); - void ItemClicked(const QModelIndex& index); - void SaveCurrentPerspectiveAs(); - void ResetCurrentPerspective(); - void ClosePerspective(); - void CloseAllPerspectives(); - void ExpandAll(); - void CollapseAll(); - void CustomMenuRequested(QPoint pos); - -protected: - - friend class ViewNavigatorPerspectiveListener; - friend class ViewNavigatorViewListener; - - berry::IPerspectiveDescriptor::Pointer m_ActivePerspective; - -private: - - void CreateQtPartControl(QWidget* parent); - bool FillTreeList(); - void UpdateTreeList(berry::IWorkbenchPart* workbenchPart = nullptr); - - void AddPerspectivesToTree(); - void AddViewsToTree(); - template - void AddItemsToTree(D itemDescriptors, QStandardItem* rootItem, - QStandardItem* miscellaneousItem = nullptr, const QStringList& itemExcludeList = QStringList()); - - Ui::QmitkViewNavigatorWidgetControls m_Controls; - QStandardItemModel* m_TreeModel; - ClassFilterProxyModel* m_FilterProxyModel; - QMenu* m_ContextMenu; - - QScopedPointer m_PerspectiveListener; - QScopedPointer m_ViewPartListener; - - berry::IWorkbenchWindow::Pointer m_Window; -}; - -#endif diff --git a/Plugins/org.mitk.gui.qt.viewnavigator/src/QmitkViewNavigatorWidgetControls.ui b/Plugins/org.mitk.gui.qt.viewnavigator/src/QmitkViewNavigatorWidgetControls.ui deleted file mode 100644 index 464c881007..0000000000 --- a/Plugins/org.mitk.gui.qt.viewnavigator/src/QmitkViewNavigatorWidgetControls.ui +++ /dev/null @@ -1,64 +0,0 @@ - - - QmitkViewNavigatorWidgetControls - - - - 0 - 0 - 752 - 974 - - - - - 0 - 0 - - - - QmitkTemplate - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Filter... - - - - - - - true - - - false - - - - - - - - - ctkSearchBox - QLineEdit -
ctkSearchBox.h
-
-
- - -
diff --git a/Plugins/org.mitk.gui.qt.viewnavigator/src/internal/QmitkCategoryItem.cpp b/Plugins/org.mitk.gui.qt.viewnavigator/src/internal/QmitkCategoryItem.cpp new file mode 100644 index 0000000000..4b47385e14 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.viewnavigator/src/internal/QmitkCategoryItem.cpp @@ -0,0 +1,47 @@ +/*============================================================================ + +The Medical Imaging Interaction Toolkit (MITK) + +Copyright (c) German Cancer Research Center (DKFZ) +All rights reserved. + +Use of this source code is governed by a 3-clause BSD license that can be +found in the LICENSE file. + +============================================================================*/ + +#include "QmitkCategoryItem.h" +#include "QmitkViewItem.h" + +#include + +QmitkCategoryItem::QmitkCategoryItem(const QString& category) + : QStandardItem(category) +{ + auto font = this->font(); + font.setPointSizeF(font.pointSizeF() * 1.25); + this->setFont(font); +} + +QmitkCategoryItem::~QmitkCategoryItem() +{ +} + +bool QmitkCategoryItem::HasMatch(const QRegularExpression& re) const +{ + if (!this->hasChildren()) + return false; + + const int rowCount = this->rowCount(); + + for (int row = 0; row < rowCount; ++row) + { + if (const auto* viewItem = dynamic_cast(this->child(row)); viewItem != nullptr) + { + if (viewItem->Match(re)) + return true; + } + } + + return false; +} diff --git a/Plugins/org.mitk.gui.qt.viewnavigator/src/internal/mitkPluginActivator.cpp b/Plugins/org.mitk.gui.qt.viewnavigator/src/internal/QmitkCategoryItem.h similarity index 54% copy from Plugins/org.mitk.gui.qt.viewnavigator/src/internal/mitkPluginActivator.cpp copy to Plugins/org.mitk.gui.qt.viewnavigator/src/internal/QmitkCategoryItem.h index c0312d1037..a0d9c5dd66 100644 --- a/Plugins/org.mitk.gui.qt.viewnavigator/src/internal/mitkPluginActivator.cpp +++ b/Plugins/org.mitk.gui.qt.viewnavigator/src/internal/QmitkCategoryItem.h @@ -1,24 +1,28 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ -#include "mitkPluginActivator.h" -#include "QmitkViewNavigatorView.h" +#ifndef QmitkCategoryItem_h +#define QmitkCategoryItem_h -void mitk::PluginActivator::start(ctkPluginContext* context) -{ - BERRY_REGISTER_EXTENSION_CLASS(QmitkViewNavigatorView, context) -} +#include +#include -void mitk::PluginActivator::stop(ctkPluginContext* context) +class QmitkCategoryItem : public QStandardItem { - Q_UNUSED(context) -} +public: + explicit QmitkCategoryItem(const QString& category); + ~QmitkCategoryItem() override; + + bool HasMatch(const QRegularExpression& re) const; +}; + +#endif diff --git a/Plugins/org.mitk.gui.qt.viewnavigator/src/internal/QmitkViewItem.cpp b/Plugins/org.mitk.gui.qt.viewnavigator/src/internal/QmitkViewItem.cpp new file mode 100644 index 0000000000..331b48524b --- /dev/null +++ b/Plugins/org.mitk.gui.qt.viewnavigator/src/internal/QmitkViewItem.cpp @@ -0,0 +1,94 @@ +/*============================================================================ + +The Medical Imaging Interaction Toolkit (MITK) + +Copyright (c) German Cancer Research Center (DKFZ) +All rights reserved. + +Use of this source code is governed by a 3-clause BSD license that can be +found in the LICENSE file. + +============================================================================*/ + +#include "QmitkViewItem.h" + +#include +#include +#include + +namespace +{ + QStringList GetKeywordsFromView(const berry::IViewDescriptor* view) + { + QStringList result; + + const auto* extensionRegistry = berry::Platform::GetExtensionRegistry(); + const auto configElems = extensionRegistry->GetConfigurationElementsFor("org.blueberry.ui.keywords"); + + const auto keywordRefs = view->GetKeywordReferences(); + + for (const auto& keywordRef : keywordRefs) + { + for (const auto& configElem : configElems) + { + auto id = configElem->GetAttribute("id"); + + if (id != keywordRef) + continue; + + auto keyword = configElem->GetAttribute("label"); + + if (!keyword.isEmpty()) + result.append(keyword); + } + } + + return result; + } +} + +QmitkViewItem::QmitkViewItem(const berry::IViewDescriptor* view) + : QStandardItem(view->GetImageDescriptor(), view->GetLabel()) +{ + this->setData(view->GetId()); + this->setToolTip(view->GetDescription()); + this->SetKeywords(GetKeywordsFromView(view)); +} + +QmitkViewItem::~QmitkViewItem() +{ +} + +void QmitkViewItem::SetBoldFont(bool enable) +{ + auto font = this->font(); + font.setBold(enable); + this->setFont(font); +} + +QStringList QmitkViewItem::GetKeywords() const +{ + return this->data(KeywordsRole).toStringList(); +} + +void QmitkViewItem::SetKeywords(const QStringList& keywords) +{ + this->setData(keywords, KeywordsRole); +} + +bool QmitkViewItem::Match(const QRegularExpression& re) const +{ + if (this->text().contains(re)) + return true; + + if (this->toolTip().contains(re)) + return true; + + for (const auto& keyword : this->GetKeywords()) + { + if (keyword.contains(re)) + return true; + } + + return false; +} diff --git a/Plugins/org.mitk.gui.qt.viewnavigator/src/QmitkViewItem.h b/Plugins/org.mitk.gui.qt.viewnavigator/src/internal/QmitkViewItem.h similarity index 55% rename from Plugins/org.mitk.gui.qt.viewnavigator/src/QmitkViewItem.h rename to Plugins/org.mitk.gui.qt.viewnavigator/src/internal/QmitkViewItem.h index 5776623c47..74a51bb211 100644 --- a/Plugins/org.mitk.gui.qt.viewnavigator/src/QmitkViewItem.h +++ b/Plugins/org.mitk.gui.qt.viewnavigator/src/internal/QmitkViewItem.h @@ -1,38 +1,41 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ #ifndef QmitkViewItem_h #define QmitkViewItem_h +#include #include -#include +#include + +namespace berry +{ + struct IViewDescriptor; +} class QmitkViewItem : public QStandardItem { public: + static constexpr int KeywordsRole = Qt::UserRole + 2; + + explicit QmitkViewItem(const berry::IViewDescriptor* view); + ~QmitkViewItem() override; - QmitkViewItem(const QString& string) - : QStandardItem(string) - { - } + void SetBoldFont(bool enable); - QmitkViewItem(const QIcon& icon, const QString& string) - : QStandardItem(icon, string) - { - } + QStringList GetKeywords() const; + void SetKeywords(const QStringList& keywords); - berry::IViewDescriptor::Pointer m_ItemDescriptor; - QStringList m_Tags; - QString m_Description; + bool Match(const QRegularExpression& re) const; }; #endif diff --git a/Plugins/org.mitk.gui.qt.viewnavigator/src/internal/QmitkViewModel.cpp b/Plugins/org.mitk.gui.qt.viewnavigator/src/internal/QmitkViewModel.cpp new file mode 100644 index 0000000000..10586f7079 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.viewnavigator/src/internal/QmitkViewModel.cpp @@ -0,0 +1,92 @@ +/*============================================================================ + +The Medical Imaging Interaction Toolkit (MITK) + +Copyright (c) German Cancer Research Center (DKFZ) +All rights reserved. + +Use of this source code is governed by a 3-clause BSD license that can be +found in the LICENSE file. + +============================================================================*/ + +#include "QmitkViewModel.h" + +#include "QmitkCategoryItem.h" +#include "QmitkViewItem.h" + +#include +#include + +namespace +{ + QString GetCategory(const berry::IViewDescriptor* view) + { + auto categoryPath = view->GetCategoryPath(); + + return !categoryPath.isEmpty() + ? categoryPath.first() + : ""; + } +} + +QmitkViewModel::QmitkViewModel(QObject* parent) + : QStandardItemModel(parent) +{ + const auto viewRegistry = berry::PlatformUI::GetWorkbench()->GetViewRegistry(); + const auto views = viewRegistry->GetViews(); + + for (const auto& view : views) + { + if (!view->Enumerate()) + continue; + + auto category = GetCategory(view.GetPointer()); + + if (category.isEmpty()) + category = "Other"; + + auto categoryItem = this->GetCategoryItem(category); + + if (categoryItem == nullptr) + categoryItem = this->CreateCategoryItem(category); + + categoryItem->appendRow(new QmitkViewItem(view.GetPointer())); + } +} + +QmitkViewModel::~QmitkViewModel() +{ +} + +QmitkCategoryItem* QmitkViewModel::CreateCategoryItem(const QString& category) +{ + auto categoryItem = new QmitkCategoryItem(category); + this->appendRow(categoryItem); + + return categoryItem; +} + +QmitkCategoryItem* QmitkViewModel::GetCategoryItem(const QString& category) const +{ + auto items = this->findItems(category); + + for (auto item : items) + { + auto categoryItem = dynamic_cast(item); + + if (categoryItem != nullptr) + return categoryItem; + } + + return nullptr; +} + +QmitkViewItem* QmitkViewModel::GetViewItemFromId(const QString& id) const +{ + const auto indices = this->match(this->index(0, 0), Qt::UserRole + 1, id, 1, Qt::MatchRecursive); + + return !indices.isEmpty() + ? dynamic_cast(this->itemFromIndex(indices.first())) + : nullptr; +} diff --git a/Plugins/org.mitk.gui.qt.viewnavigator/src/internal/QmitkViewModel.h b/Plugins/org.mitk.gui.qt.viewnavigator/src/internal/QmitkViewModel.h new file mode 100644 index 0000000000..8846f66ff6 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.viewnavigator/src/internal/QmitkViewModel.h @@ -0,0 +1,34 @@ +/*============================================================================ + +The Medical Imaging Interaction Toolkit (MITK) + +Copyright (c) German Cancer Research Center (DKFZ) +All rights reserved. + +Use of this source code is governed by a 3-clause BSD license that can be +found in the LICENSE file. + +============================================================================*/ + +#ifndef QmitkViewModel_h +#define QmitkViewModel_h + +#include + +class QmitkCategoryItem; +class QmitkViewItem; + +class QmitkViewModel : public QStandardItemModel +{ +public: + explicit QmitkViewModel(QObject* parent = nullptr); + ~QmitkViewModel() override; + + QmitkCategoryItem* GetCategoryItem(const QString& category) const; + QmitkViewItem* GetViewItemFromId(const QString& id) const; + +private: + QmitkCategoryItem* CreateCategoryItem(const QString& category); +}; + +#endif diff --git a/Plugins/org.mitk.gui.qt.viewnavigator/src/internal/QmitkViewNavigatorView.cpp b/Plugins/org.mitk.gui.qt.viewnavigator/src/internal/QmitkViewNavigatorView.cpp index 3443fe6ba3..6186760547 100644 --- a/Plugins/org.mitk.gui.qt.viewnavigator/src/internal/QmitkViewNavigatorView.cpp +++ b/Plugins/org.mitk.gui.qt.viewnavigator/src/internal/QmitkViewNavigatorView.cpp @@ -1,34 +1,138 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ #include "QmitkViewNavigatorView.h" -#include "QmitkViewNavigatorWidget.h" -// BlueBerry -#include +#include "QmitkViewItem.h" +#include "QmitkViewModel.h" +#include "QmitkViewProxyModel.h" -#include +#include -const std::string QmitkViewNavigatorView::VIEW_ID = "org.mitk.views.viewnavigator"; +#include -void QmitkViewNavigatorView::SetFocus() +QmitkViewNavigatorView::QmitkViewNavigatorView() + : m_Ui(new Ui::QmitkViewNavigatorView), + m_Model(nullptr), + m_ProxyModel(nullptr) { - m_ViewNavigatorWidget->SetFocus(); +} + +QmitkViewNavigatorView::~QmitkViewNavigatorView() +{ + this->GetPartService()->RemovePartListener(this); } void QmitkViewNavigatorView::CreateQtPartControl(QWidget* parent) { - parent->setLayout(new QVBoxLayout); - parent->layout()->setContentsMargins(0, 0, 0, 0); - m_ViewNavigatorWidget = new QmitkViewNavigatorWidget(this->GetSite()->GetWorkbenchWindow(), parent); - parent->layout()->addWidget(m_ViewNavigatorWidget); + m_Ui->setupUi(parent); + + m_Model = new QmitkViewModel(parent); + + m_ProxyModel = new QmitkViewProxyModel(parent); + m_ProxyModel->setSourceModel(m_Model); + + m_Ui->viewTreeView->setModel(m_ProxyModel); + m_Ui->viewTreeView->expandAll(); + + connect(m_Ui->filterLineEdit, &QLineEdit::textChanged, this, &QmitkViewNavigatorView::OnFilterTextChanged); + connect(m_Ui->viewTreeView, &QTreeView::doubleClicked, this, &QmitkViewNavigatorView::OnItemDoubleClicked); + + this->GetPartService()->AddPartListener(this); +} + +void QmitkViewNavigatorView::SetFocus() +{ + m_Ui->filterLineEdit->setFocus(); +} + +berry::IWorkbenchPage* QmitkViewNavigatorView::GetActivePage() const +{ + if (auto site = this->GetSite(); site.IsNotNull()) + { + if (auto workbenchWindow = site->GetWorkbenchWindow(); workbenchWindow.IsNotNull()) + return workbenchWindow->GetActivePage().GetPointer(); + } + + return nullptr; +} + +berry::IPartService* QmitkViewNavigatorView::GetPartService() const +{ + if (auto site = this->GetSite(); site.IsNotNull()) + { + if (auto workbenchWindow = site->GetWorkbenchWindow(); workbenchWindow.IsNotNull()) + return workbenchWindow->GetPartService(); + } + + return nullptr; +} + +void QmitkViewNavigatorView::OnFilterTextChanged(const QString& pattern) +{ + m_ProxyModel->setFilterWildcard(pattern); + m_Ui->viewTreeView->expandAll(); +} + +void QmitkViewNavigatorView::OnItemDoubleClicked(const QModelIndex& index) +{ + auto viewItem = dynamic_cast(m_Model->itemFromIndex(m_ProxyModel->mapToSource(index))); + + if (viewItem != nullptr) + { + if (auto activePage = this->GetActivePage(); activePage != nullptr) + { + try + { + activePage->ShowView(viewItem->data().toString()); + } + catch (const berry::PartInitException& e) + { + MITK_ERROR << e.what(); + } + } + } +} + +berry::IPartListener::Events::Types QmitkViewNavigatorView::GetPartEventTypes() const +{ + return Events::OPENED | Events::CLOSED; +} + +void QmitkViewNavigatorView::PartOpened(const berry::IWorkbenchPartReference::Pointer& partRef) +{ + if (partRef->GetId() != "org.mitk.views.viewnavigator") + { + auto viewItem = m_Model->GetViewItemFromId(partRef->GetId()); + + if (viewItem != nullptr) + viewItem->SetBoldFont(true); + } + else if (auto activePage = this->GetActivePage(); activePage != nullptr) + { + for (const auto& view : activePage->GetViews()) + { + auto viewItem = m_Model->GetViewItemFromId(view->GetSite()->GetId()); + + if (viewItem != nullptr) + viewItem->SetBoldFont(true); + } + } +} + +void QmitkViewNavigatorView::PartClosed(const berry::IWorkbenchPartReference::Pointer& partRef) +{ + auto viewItem = m_Model->GetViewItemFromId(partRef->GetId()); + + if (viewItem != nullptr) + viewItem->SetBoldFont(false); } diff --git a/Plugins/org.mitk.gui.qt.viewnavigator/src/internal/QmitkViewNavigatorView.h b/Plugins/org.mitk.gui.qt.viewnavigator/src/internal/QmitkViewNavigatorView.h index 7c3c7cfc07..2878040b99 100644 --- a/Plugins/org.mitk.gui.qt.viewnavigator/src/internal/QmitkViewNavigatorView.h +++ b/Plugins/org.mitk.gui.qt.viewnavigator/src/internal/QmitkViewNavigatorView.h @@ -1,44 +1,60 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ #ifndef QmitkViewNavigatorView_h #define QmitkViewNavigatorView_h +#include #include -class QmitkViewNavigatorWidget; +class QmitkViewModel; +class QmitkViewProxyModel; -/** -* @brief -* -*/ -class QmitkViewNavigatorView : public QmitkAbstractView +namespace berry { - Q_OBJECT - -public: + struct IPartService; + struct IWorkbenchPage; +} - static const std::string VIEW_ID; +namespace Ui +{ + class QmitkViewNavigatorView; +} -protected: +class QmitkViewNavigatorView : public QmitkAbstractView, public berry::IPartListener +{ + Q_OBJECT - void CreateQtPartControl(QWidget *parent) override; +public: + QmitkViewNavigatorView(); + ~QmitkViewNavigatorView() override; +private: + void CreateQtPartControl(QWidget* parent) override; void SetFocus() override; -private: + Events::Types GetPartEventTypes() const override; + void PartOpened(const berry::IWorkbenchPartReference::Pointer& partRef) override; + void PartClosed(const berry::IWorkbenchPartReference::Pointer& partRef) override; + + berry::IWorkbenchPage* GetActivePage() const; + berry::IPartService* GetPartService() const; - QmitkViewNavigatorWidget* m_ViewNavigatorWidget; + void OnFilterTextChanged(const QString& pattern); + void OnItemDoubleClicked(const QModelIndex& index); + Ui::QmitkViewNavigatorView* m_Ui; + QmitkViewModel* m_Model; + QmitkViewProxyModel* m_ProxyModel; }; #endif diff --git a/Plugins/org.mitk.gui.qt.viewnavigator/src/internal/QmitkViewNavigatorView.ui b/Plugins/org.mitk.gui.qt.viewnavigator/src/internal/QmitkViewNavigatorView.ui new file mode 100644 index 0000000000..12cdd7685f --- /dev/null +++ b/Plugins/org.mitk.gui.qt.viewnavigator/src/internal/QmitkViewNavigatorView.ui @@ -0,0 +1,55 @@ + + + QmitkViewNavigatorView + + + + 0 + 0 + 390 + 600 + + + + Form + + + + + + + + Filter: + + + filterLineEdit + + + + + + + true + + + + + + + + + QAbstractItemView::NoEditTriggers + + + true + + + true + + + + + + + + diff --git a/Plugins/org.mitk.gui.qt.viewnavigator/src/internal/QmitkViewProxyModel.cpp b/Plugins/org.mitk.gui.qt.viewnavigator/src/internal/QmitkViewProxyModel.cpp new file mode 100644 index 0000000000..8076607839 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.viewnavigator/src/internal/QmitkViewProxyModel.cpp @@ -0,0 +1,63 @@ +/*============================================================================ + +The Medical Imaging Interaction Toolkit (MITK) + +Copyright (c) German Cancer Research Center (DKFZ) +All rights reserved. + +Use of this source code is governed by a 3-clause BSD license that can be +found in the LICENSE file. + +============================================================================*/ + +#include "QmitkViewProxyModel.h" + +#include "QmitkCategoryItem.h" +#include "QmitkViewItem.h" + +#include + +QmitkViewProxyModel::QmitkViewProxyModel(QObject* parent) + : QSortFilterProxyModel(parent) +{ + this->setFilterCaseSensitivity(Qt::CaseInsensitive); + this->setSortCaseSensitivity(Qt::CaseInsensitive); +} + +QmitkViewProxyModel::~QmitkViewProxyModel() +{ +} + +bool QmitkViewProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const +{ + auto model = dynamic_cast(this->sourceModel()); + + if (model == nullptr) + return true; + + const auto re = this->filterRegularExpression(); + + auto index = model->index(sourceRow, 0, sourceParent); + const auto* item = model->itemFromIndex(index); + + if (auto viewItem = dynamic_cast(item); viewItem != nullptr) + { + return viewItem->Match(re); + } + else if (auto categoryItem = dynamic_cast(item); categoryItem != nullptr) + { + return categoryItem->HasMatch(re); + } + + return true; +} + +bool QmitkViewProxyModel::lessThan(const QModelIndex& left, const QModelIndex& right) const +{ + auto model = this->sourceModel(); + auto leftLabel = model->data(left).toString(); + auto rightLabel = model->data(right).toString(); + auto caseSensitivity = this->sortCaseSensitivity(); + + return leftLabel.compare(rightLabel, caseSensitivity) > 0; +} diff --git a/Plugins/org.mitk.gui.qt.viewnavigator/src/internal/QmitkViewNavigatorView.h b/Plugins/org.mitk.gui.qt.viewnavigator/src/internal/QmitkViewProxyModel.h similarity index 50% copy from Plugins/org.mitk.gui.qt.viewnavigator/src/internal/QmitkViewNavigatorView.h copy to Plugins/org.mitk.gui.qt.viewnavigator/src/internal/QmitkViewProxyModel.h index 7c3c7cfc07..1d7a2ffd2b 100644 --- a/Plugins/org.mitk.gui.qt.viewnavigator/src/internal/QmitkViewNavigatorView.h +++ b/Plugins/org.mitk.gui.qt.viewnavigator/src/internal/QmitkViewProxyModel.h @@ -1,44 +1,29 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ -#ifndef QmitkViewNavigatorView_h -#define QmitkViewNavigatorView_h +#ifndef QmitkViewProxyModel_h +#define QmitkViewProxyModel_h -#include +#include -class QmitkViewNavigatorWidget; - -/** -* @brief -* -*/ -class QmitkViewNavigatorView : public QmitkAbstractView +class QmitkViewProxyModel : public QSortFilterProxyModel { - Q_OBJECT - public: - - static const std::string VIEW_ID; - -protected: - - void CreateQtPartControl(QWidget *parent) override; - - void SetFocus() override; + explicit QmitkViewProxyModel(QObject* parent = nullptr); + ~QmitkViewProxyModel() override; private: - - QmitkViewNavigatorWidget* m_ViewNavigatorWidget; - + bool filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const override; + bool lessThan(const QModelIndex& left, const QModelIndex& right) const override; }; #endif diff --git a/Plugins/org.mitk.gui.qt.viewnavigator/src/internal/mitkPluginActivator.cpp b/Plugins/org.mitk.gui.qt.viewnavigator/src/internal/mitkPluginActivator.cpp index c0312d1037..bc5345b23e 100644 --- a/Plugins/org.mitk.gui.qt.viewnavigator/src/internal/mitkPluginActivator.cpp +++ b/Plugins/org.mitk.gui.qt.viewnavigator/src/internal/mitkPluginActivator.cpp @@ -1,24 +1,23 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ #include "mitkPluginActivator.h" #include "QmitkViewNavigatorView.h" void mitk::PluginActivator::start(ctkPluginContext* context) { BERRY_REGISTER_EXTENSION_CLASS(QmitkViewNavigatorView, context) } -void mitk::PluginActivator::stop(ctkPluginContext* context) +void mitk::PluginActivator::stop(ctkPluginContext*) { - Q_UNUSED(context) } diff --git a/Plugins/org.mitk.gui.qt.viewnavigator/src/internal/mitkPluginActivator.h b/Plugins/org.mitk.gui.qt.viewnavigator/src/internal/mitkPluginActivator.h index ff406fe77d..fbff7926f3 100644 --- a/Plugins/org.mitk.gui.qt.viewnavigator/src/internal/mitkPluginActivator.h +++ b/Plugins/org.mitk.gui.qt.viewnavigator/src/internal/mitkPluginActivator.h @@ -1,33 +1,32 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ #ifndef mitkPluginActivator_h #define mitkPluginActivator_h #include namespace mitk { class PluginActivator : public QObject, public ctkPluginActivator { Q_OBJECT Q_PLUGIN_METADATA(IID "org_mitk_gui_qt_viewnavigator") Q_INTERFACES(ctkPluginActivator) public: - void start(ctkPluginContext *context) override; - void stop(ctkPluginContext *context) override; - + void start(ctkPluginContext* context) override; + void stop(ctkPluginContext* context) override; }; } #endif