diff --git a/Plugins/org.mitk.gui.qt.viewnavigator/files.cmake b/Plugins/org.mitk.gui.qt.viewnavigator/files.cmake index 23ba108374..a4e8dac4c9 100644 --- a/Plugins/org.mitk.gui.qt.viewnavigator/files.cmake +++ b/Plugins/org.mitk.gui.qt.viewnavigator/files.cmake @@ -1,46 +1,45 @@ set(SRC_CPP_FILES QmitkViewNavigatorWidget.cpp - -# mitkQtPerspectiveItem.h -# mitkQtViewItem.h + QmitkPerspectiveItem.h + QmitkViewItem.h ) set(INTERNAL_CPP_FILES mitkPluginActivator.cpp QmitkViewNavigatorView.cpp ) set(UI_FILES src/QmitkViewNavigatorWidgetControls.ui ) 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(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/src/mitkQtPerspectiveItem.h b/Plugins/org.mitk.gui.qt.viewnavigator/src/QmitkPerspectiveItem.h similarity index 51% rename from Plugins/org.mitk.gui.qt.viewnavigator/src/mitkQtPerspectiveItem.h rename to Plugins/org.mitk.gui.qt.viewnavigator/src/QmitkPerspectiveItem.h index 644aa14611..84eea69df3 100644 --- a/Plugins/org.mitk.gui.qt.viewnavigator/src/mitkQtPerspectiveItem.h +++ b/Plugins/org.mitk.gui.qt.viewnavigator/src/QmitkPerspectiveItem.h @@ -1,44 +1,38 @@ /*============================================================================ 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 _PerspectiveItem -#define _PerspectiveItem +#ifndef QMITKPERSPECTIVEITEM_H +#define QMITKPERSPECTIVEITEM_H #include #include -namespace mitk -{ - -class QtPerspectiveItem : public QStandardItem +class QmitkPerspectiveItem : public QStandardItem { public: - QtPerspectiveItem(QString string) : - QStandardItem(string) - { - } - QtPerspectiveItem(const QIcon& icon, QString string) : - QStandardItem(icon, string) - { - } - berry::IPerspectiveDescriptor::Pointer m_Perspective; + QmitkPerspectiveItem(QString string) + : QStandardItem(string) + { + } - QStringList m_Tags; - QString m_Description; -private: + QmitkPerspectiveItem(const QIcon &icon, QString string) + : QStandardItem(icon, string) + { + } + berry::IPerspectiveDescriptor::Pointer m_Perspective; + QStringList m_Tags; + QString m_Description; }; -} - -#endif +#endif // QMITKPERSPECTIVEITEM_H diff --git a/Plugins/org.mitk.gui.qt.viewnavigator/src/mitkQtViewItem.h b/Plugins/org.mitk.gui.qt.viewnavigator/src/QmitkViewItem.h similarity index 53% rename from Plugins/org.mitk.gui.qt.viewnavigator/src/mitkQtViewItem.h rename to Plugins/org.mitk.gui.qt.viewnavigator/src/QmitkViewItem.h index 34e71b487d..ac7464f384 100644 --- a/Plugins/org.mitk.gui.qt.viewnavigator/src/mitkQtViewItem.h +++ b/Plugins/org.mitk.gui.qt.viewnavigator/src/QmitkViewItem.h @@ -1,45 +1,38 @@ /*============================================================================ 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 _ViewItem -#define _ViewItem +#ifndef QMITKVIEWITEM_H +#define QMITKVIEWITEM_H #include -#include #include -namespace mitk -{ - -class QtViewItem : public QStandardItem +class QmitkViewItem : public QStandardItem { public: - QtViewItem(QString string) : - QStandardItem(string) - { - } - QtViewItem(const QIcon& icon, QString string) : - QStandardItem(icon, string) - { - } - berry::IViewDescriptor::Pointer m_View; - QStringList m_Tags; - QString m_Description; + QmitkViewItem(QString string) + : QStandardItem(string) + { + } -private: + QmitkViewItem(const QIcon& icon, QString string) + : QStandardItem(icon, string) + { + } + berry::IViewDescriptor::Pointer m_View; + QStringList m_Tags; + QString m_Description; }; -} - -#endif +#endif // QMITKVIEWITEM_H diff --git a/Plugins/org.mitk.gui.qt.viewnavigator/src/QmitkViewNavigatorWidget.cpp b/Plugins/org.mitk.gui.qt.viewnavigator/src/QmitkViewNavigatorWidget.cpp index 7b2d6e96ef..b2cb98245d 100644 --- a/Plugins/org.mitk.gui.qt.viewnavigator/src/QmitkViewNavigatorWidget.cpp +++ b/Plugins/org.mitk.gui.qt.viewnavigator/src/QmitkViewNavigatorWidget.cpp @@ -1,697 +1,700 @@ /*============================================================================ 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. ============================================================================*/ -//Qmitk headers -#include "QmitkViewNavigatorWidget.h" +// View navigator plugin +#include +#include +#include // Blueberry #include #include #include #include #include #include #include #include #include #include // MITK #include // Qt #include #include #include #include #include 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 (int i = 0; i < ids.size(); ++i) { result.append(this->GetKeywords(ids[i])); } return result; } private: QHash m_Keywords; }; class ClassFilterProxyModel : public QSortFilterProxyModel { private : bool hasToBeDisplayed(const QModelIndex index) const; bool displayElement(const QModelIndex index) const; public: ClassFilterProxyModel(QObject *parent = nullptr); bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override; }; ClassFilterProxyModel::ClassFilterProxyModel(QObject *parent): QSortFilterProxyModel(parent) { } bool ClassFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const { QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent); return hasToBeDisplayed(index); } bool ClassFilterProxyModel::displayElement(const QModelIndex index) const { - bool result = false; QString type = sourceModel()->data(index, Qt::DisplayRole).toString(); QStandardItem * item = dynamic_cast(sourceModel())->itemFromIndex(index); if (type.contains(filterRegExp())) { return true; } + + QmitkViewItem* viewItem = dynamic_cast(item); + if (nullptr != viewItem) { - mitk::QtViewItem* viewItem = dynamic_cast(item); - if (viewItem) + for (int i = 0; i < viewItem->m_Tags.size(); ++i) { - for (int i = 0; i < viewItem->m_Tags.size(); ++i) - { - if (viewItem->m_Tags[i].contains(filterRegExp())) - { - return true; - } - } - if (viewItem->m_Description.contains(filterRegExp())) + if (viewItem->m_Tags[i].contains(filterRegExp())) { return true; } } + if (viewItem->m_Description.contains(filterRegExp())) + { + return true; + } } + + QmitkPerspectiveItem* perspectiveItem = dynamic_cast(item); + if (nullptr != perspectiveItem) { - mitk::QtPerspectiveItem* viewItem = dynamic_cast(item); - if (viewItem) + for (int i = 0; i < perspectiveItem->m_Tags.size(); ++i) { - for (int i = 0; i < viewItem->m_Tags.size(); ++i) - { - if (viewItem->m_Tags[i].contains(filterRegExp())) - { - return true; - } - } - if (viewItem->m_Description.contains(filterRegExp())) + if (perspectiveItem->m_Tags[i].contains(filterRegExp())) { return true; } } + if (perspectiveItem->m_Description.contains(filterRegExp())) + { + return true; + } } - return result; + return false; } bool ClassFilterProxyModel::hasToBeDisplayed(const QModelIndex index) const { bool result = false; if ( sourceModel()->rowCount(index) > 0 ) { for( int ii = 0; ii < sourceModel()->rowCount(index); ii++) { QModelIndex childIndex = sourceModel()->index(ii,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* p) : parentWidget(p) { } 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 { parentWidget->m_ActivePerspective = perspective; parentWidget->UpdateTreeList(); } void PerspectiveSavedAs(const berry::IWorkbenchPage::Pointer& /*page*/, const berry::IPerspectiveDescriptor::Pointer& /*oldPerspective*/, const berry::IPerspectiveDescriptor::Pointer& newPerspective) override { parentWidget->m_ActivePerspective = newPerspective; parentWidget->UpdateTreeList(); } void PerspectiveDeactivated(const berry::IWorkbenchPage::Pointer& /*page*/, const berry::IPerspectiveDescriptor::Pointer& /*perspective*/) override { parentWidget->m_ActivePerspective = nullptr; parentWidget->UpdateTreeList(); } void PerspectiveOpened(const berry::IWorkbenchPage::Pointer& /*page*/, const berry::IPerspectiveDescriptor::Pointer& /*perspective*/) override { parentWidget->UpdateTreeList(); } void PerspectiveClosed(const berry::IWorkbenchPage::Pointer& /*page*/, const berry::IPerspectiveDescriptor::Pointer& /*perspective*/) override { parentWidget->m_ActivePerspective = nullptr; parentWidget->UpdateTreeList(); } using IPerspectiveListener::PerspectiveChanged; void PerspectiveChanged(const berry::IWorkbenchPage::Pointer&, const berry::IPerspectiveDescriptor::Pointer&, const berry::IWorkbenchPartReference::Pointer& partRef, const std::string& changeId) { if (changeId=="viewHide" && partRef->GetId()=="org.mitk.views.viewnavigator") berry::PlatformUI::GetWorkbench()->GetActiveWorkbenchWindow()->RemovePerspectiveListener(parentWidget->m_PerspectiveListener.data()); else parentWidget->UpdateTreeList(nullptr, partRef.GetPointer(), changeId); } private: QmitkViewNavigatorWidget* 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 (a==nullptr || b==nullptr) return false; return a->text().compare(b->text()) < 0; } QmitkViewNavigatorWidget::QmitkViewNavigatorWidget(berry::IWorkbenchWindow::Pointer window, QWidget * parent, Qt::WindowFlags ) : QWidget(parent) , m_Window(window) { m_Generated = false; this->CreateQtPartControl(this); } QmitkViewNavigatorWidget::~QmitkViewNavigatorWidget() { m_Window->RemovePerspectiveListener(m_PerspectiveListener.data()); } void QmitkViewNavigatorWidget::setFocus() { m_Controls.lineEdit->setFocus(); } void QmitkViewNavigatorWidget::CreateQtPartControl( QWidget *parent ) { // create GUI widgets from the Qt Designer's .ui file m_PerspectiveListener.reset(new ViewNavigatorPerspectiveListener(this)); m_Window->AddPerspectiveListener(m_PerspectiveListener.data()); m_Parent = parent; 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); //proxyModel->setFilterFixedString("Diff"); m_Controls.m_PluginTreeView->setModel(m_FilterProxyModel); this->UpdateTreeList(); } void QmitkViewNavigatorWidget::UpdateTreeList(QStandardItem* root, berry::IWorkbenchPartReference *partRef, const std::string &changeId) { berry::IWorkbenchPage::Pointer page = m_Window->GetActivePage(); if (page.IsNull()) return; if( !m_Generated ) { m_Generated = FillTreeList(); } if (root==nullptr) root = m_TreeModel->invisibleRootItem(); for (int i=0; irowCount(); i++) { QStandardItem* item = root->child(i); QFont font; - if (dynamic_cast(item)) + QmitkPerspectiveItem* perspectiveItem = dynamic_cast(item); + if (nullptr != perspectiveItem) { - mitk::QtPerspectiveItem* pItem = dynamic_cast(item); berry::IPerspectiveDescriptor::Pointer currentPersp = page->GetPerspective(); - if (currentPersp.IsNotNull() && currentPersp->GetId()==pItem->m_Perspective->GetId()) + if (currentPersp.IsNotNull() && currentPersp->GetId()==perspectiveItem->m_Perspective->GetId()) font.setBold(true); - pItem->setFont(font); + perspectiveItem->setFont(font); } - mitk::QtViewItem* vItem = dynamic_cast(item); - if (vItem) + + QmitkViewItem* viewItem = dynamic_cast(item); + if (nullptr != viewItem) { QList viewParts(page->GetViews()); for (int i=0; iGetPartName()==vItem->m_View->GetLabel()) + if(viewParts[i]->GetPartName()==viewItem->m_View->GetLabel()) { font.setBold(true); break; } - if( partRef!=nullptr && partRef->GetId()==vItem->m_View->GetId() && changeId=="viewHide") + if( partRef!=nullptr && partRef->GetId()==viewItem->m_View->GetId() && changeId=="viewHide") font.setBold(false); - vItem->setFont(font); + viewItem->setFont(font); } + UpdateTreeList(item, partRef, changeId); } } bool QmitkViewNavigatorWidget::FillTreeList() { // active workbench window available? if (m_Window.IsNull()) return false; // active page available? berry::IWorkbenchPage::Pointer page = m_Window->GetActivePage(); if (page.IsNull()) return false; // everything is fine and we can remove the window listener if (m_WindowListener != nullptr) berry::PlatformUI::GetWorkbench()->RemoveWindowListener(m_WindowListener.data()); // initialize tree model m_TreeModel->clear(); QStandardItem *treeRootItem = m_TreeModel->invisibleRootItem(); // get all available perspectives berry::IPerspectiveRegistry* perspRegistry = berry::PlatformUI::GetWorkbench()->GetPerspectiveRegistry(); QList perspectiveDescriptors(perspRegistry->GetPerspectives()); qSort(perspectiveDescriptors.begin(), perspectiveDescriptors.end(), comparePerspectives); // get all Keywords KeywordRegistry keywordRegistry; berry::IPerspectiveDescriptor::Pointer currentPersp = page->GetPerspective(); //QStringList perspectiveExcludeList = berry::PlatformUI::GetWorkbench()->GetActiveWorkbenchWindow()->GetPerspectiveExcludeList(); std::vector< QStandardItem* > categoryItems; QStandardItem *perspectiveRootItem = new QStandardItem("Perspectives"); perspectiveRootItem->setEditable(false); perspectiveRootItem->setFont(QFont("", 12, QFont::Normal)); treeRootItem->appendRow(perspectiveRootItem); for (int i=0; iGetId()) { skipPerspective = true; break; } if (skipPerspective) continue; */ //QIcon* pIcon = static_cast(p->GetImageDescriptor()->CreateImage()); - mitk::QtPerspectiveItem* pItem = new mitk::QtPerspectiveItem(p->GetLabel()); - pItem->m_Perspective = p; - pItem->m_Description = p->GetDescription(); + QmitkPerspectiveItem* perspectiveItem = new QmitkPerspectiveItem(p->GetLabel()); + perspectiveItem->m_Perspective = p; + perspectiveItem->m_Description = p->GetDescription(); QStringList keylist = p->GetKeywordReferences(); - pItem->m_Tags = keywordRegistry.GetKeywords(keylist); - pItem->setEditable(false); + perspectiveItem->m_Tags = keywordRegistry.GetKeywords(keylist); + perspectiveItem->setEditable(false); QFont font; font.setBold(true); if (currentPersp.IsNotNull() && currentPersp->GetId()==p->GetId()) - pItem->setFont(font); + perspectiveItem->setFont(font); QStringList catPath = p->GetCategoryPath(); if (catPath.isEmpty()) { - perspectiveRootItem->appendRow(pItem); + perspectiveRootItem->appendRow(perspectiveItem); } else { QStandardItem* categoryItem = nullptr; for (unsigned int c=0; ctext() == catPath.front()) { categoryItem = categoryItems.at(c); break; } } if (categoryItem==nullptr) { categoryItem = new QStandardItem(QIcon(),catPath.front()); categoryItems.push_back(categoryItem); } categoryItem->setEditable(false); - categoryItem->appendRow(pItem); + categoryItem->appendRow(perspectiveItem); categoryItem->setFont(QFont("", 12, QFont::Normal)); } } std::sort(categoryItems.begin(), categoryItems.end(), compareQStandardItems); for (unsigned int i=0; iappendRow(categoryItems.at(i)); // get all available views berry::IViewRegistry* viewRegistry = berry::PlatformUI::GetWorkbench()->GetViewRegistry(); QList viewDescriptors(viewRegistry->GetViews()); QList viewParts(page->GetViews()); qSort(viewDescriptors.begin(), viewDescriptors.end(), compareViews); auto emptyItem = new QStandardItem(); emptyItem->setFlags(Qt::ItemIsEnabled); treeRootItem->appendRow(emptyItem); //QStringList viewExcludeList = berry::PlatformUI::GetWorkbench()->GetActiveWorkbenchWindow()->GetViewExcludeList(); //There currently is no way to get the list of excluded views at application start 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")); QStandardItem* viewRootItem = new QStandardItem(QIcon(),"Views"); viewRootItem->setFont(QFont("", 12, QFont::Normal)); viewRootItem->setEditable(false); treeRootItem->appendRow(viewRootItem); categoryItems.clear(); QStandardItem* noCategoryItem = new QStandardItem(QIcon(),"Miscellaneous"); noCategoryItem->setEditable(false); noCategoryItem->setFont(QFont("", 12, QFont::Normal)); for (int i = 0; i < viewDescriptors.size(); ++i) { berry::IViewDescriptor::Pointer v = viewDescriptors[i]; bool skipView = false; for(int e=0; eGetId()) { skipView = true; break; } if (skipView) continue; QStringList catPath = v->GetCategoryPath(); QIcon icon = v->GetImageDescriptor(); - mitk::QtViewItem* vItem = new mitk::QtViewItem(icon, v->GetLabel()); - vItem->m_View = v; - vItem->setToolTip(v->GetDescription()); - vItem->m_Description = v->GetDescription(); + QmitkViewItem* viewItem = new QmitkViewItem(icon, v->GetLabel()); + viewItem->m_View = v; + viewItem->setToolTip(v->GetDescription()); + viewItem->m_Description = v->GetDescription(); QStringList keylist = v->GetKeywordReferences(); - vItem->m_Tags = keywordRegistry.GetKeywords(keylist); - vItem->setEditable(false); + viewItem->m_Tags = keywordRegistry.GetKeywords(keylist); + viewItem->setEditable(false); for (int i=0; iGetPartName()==v->GetLabel()) { QFont font; font.setBold(true); - vItem->setFont(font); + viewItem->setFont(font); break; } if (catPath.empty()) - noCategoryItem->appendRow(vItem); + noCategoryItem->appendRow(viewItem); else { QStandardItem* categoryItem = nullptr; for (unsigned int c=0; ctext() == catPath.front()) { categoryItem = categoryItems.at(c); break; } if (categoryItem==nullptr) { categoryItem = new QStandardItem(QIcon(),catPath.front()); categoryItems.push_back(categoryItem); } categoryItem->setEditable(false); - categoryItem->appendRow(vItem); + categoryItem->appendRow(viewItem); categoryItem->setFont(QFont("", 12, QFont::Normal)); } } std::sort(categoryItems.begin(), categoryItems.end(), compareQStandardItems); for (unsigned int i=0; iappendRow(categoryItems.at(i)); if (noCategoryItem->hasChildren()) viewRootItem->appendRow(noCategoryItem); m_Controls.m_PluginTreeView->expandAll(); return true; } void QmitkViewNavigatorWidget::FilterChanged() { QString filterString = m_Controls.lineEdit->text(); // if (filterString.size() > 0 ) m_Controls.m_PluginTreeView->expandAll(); // else // m_Controls.m_PluginTreeView->collapseAll(); // QRegExp::PatternSyntax syntax = QRegExp::RegExp; Qt::CaseSensitivity caseSensitivity = Qt::CaseInsensitive; QString strPattern = "^*" + filterString; QRegExp regExp(strPattern, caseSensitivity); m_FilterProxyModel->setFilterRegExp(regExp); } void QmitkViewNavigatorWidget::ItemClicked(const QModelIndex &index) { QStandardItem* item = m_TreeModel->itemFromIndex(m_FilterProxyModel->mapToSource(index)); - if ( dynamic_cast< mitk::QtPerspectiveItem* >(item) ) + QmitkPerspectiveItem* perspectiveItem = dynamic_cast(item); + if (nullptr != perspectiveItem) { try { - mitk::QtPerspectiveItem* pItem = dynamic_cast< mitk::QtPerspectiveItem* >(item); - berry::PlatformUI::GetWorkbench()->ShowPerspective( pItem->m_Perspective->GetId(), berry::PlatformUI::GetWorkbench()->GetActiveWorkbenchWindow() ); + berry::PlatformUI::GetWorkbench()->ShowPerspective(perspectiveItem->m_Perspective->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; } - else if ( dynamic_cast< mitk::QtViewItem* >(item) ) + + QmitkViewItem* viewItem = dynamic_cast(item); + if (nullptr != viewItem) { berry::IWorkbenchPage::Pointer page = berry::PlatformUI::GetWorkbench()->GetActiveWorkbenchWindow()->GetActivePage(); if (page.IsNotNull()) { try { - mitk::QtViewItem* vItem = dynamic_cast< mitk::QtViewItem* >(item); - page->ShowView(vItem->m_View->GetId()); + page->ShowView(viewItem->m_View->GetId()); } catch (const berry::PartInitException& e) { BERRY_ERROR << "Error: " << e.what() << std::endl; } } } } void QmitkViewNavigatorWidget::SaveCurrentPerspectiveAs() { berry::IHandlerService* handlerService = m_Window->GetService(); try { handlerService->ExecuteCommand(berry::IWorkbenchCommandConstants::WINDOW_SAVE_PERSPECTIVE_AS, berry::UIElement::Pointer()); FillTreeList(); } catch(const berry::NotHandledException&) {} catch(const berry::CommandException& e) { MITK_ERROR << e.what(); } } 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::PlatformUI::GetWorkbench()->GetActiveWorkbenchWindow()->GetActivePage()->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); // if ( page->GetPerspective().IsNull() ) // { // berry::IPerspectiveRegistry* perspRegistry = berry::PlatformUI::GetWorkbench()->GetPerspectiveRegistry(); // berry::PlatformUI::GetWorkbench()->ShowPerspective( perspRegistry->GetDefaultPerspective(), berry::PlatformUI::GetWorkbench()->GetActiveWorkbenchWindow() ); // } } } 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 = berry::PlatformUI::GetWorkbench()->GetActiveWorkbenchWindow()->GetActivePage(); page->CloseAllPerspectives(true, true); // berry::IPerspectiveRegistry* perspRegistry = berry::PlatformUI::GetWorkbench()->GetPerspectiveRegistry(); // berry::PlatformUI::GetWorkbench()->ShowPerspective( perspRegistry->GetDefaultPerspective(), berry::PlatformUI::GetWorkbench()->GetActiveWorkbenchWindow() ); } } 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 (m_ContextMenu==nullptr) return; m_ContextMenu->clear(); 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->addSeparator(); - - if ( item!=nullptr && dynamic_cast< mitk::QtPerspectiveItem* >(item) ) + QmitkPerspectiveItem* perspectiveItem = dynamic_cast(item); + if (nullptr != perspectiveItem) { - berry::IPerspectiveDescriptor::Pointer persp = dynamic_cast< mitk::QtPerspectiveItem* >(item)->m_Perspective; + berry::IPerspectiveDescriptor::Pointer persp = perspectiveItem->m_Perspective; if (this->m_ActivePerspective.IsNotNull() && this->m_ActivePerspective == persp) { - //m_ContextMenu->addSeparator(); - QAction* saveAsAction = new QAction("Save 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())); m_ContextMenu->addSeparator(); QAction* closeAllAction = new QAction("Close all perspectives", this); m_ContextMenu->addAction(closeAllAction); connect(closeAllAction, SIGNAL(triggered()), SLOT(CloseAllPerspectives())); m_ContextMenu->popup(m_Controls.m_PluginTreeView->viewport()->mapToGlobal(pos)); } diff --git a/Plugins/org.mitk.gui.qt.viewnavigator/src/QmitkViewNavigatorWidget.h b/Plugins/org.mitk.gui.qt.viewnavigator/src/QmitkViewNavigatorWidget.h index 2e81f31644..889065f740 100644 --- a/Plugins/org.mitk.gui.qt.viewnavigator/src/QmitkViewNavigatorWidget.h +++ b/Plugins/org.mitk.gui.qt.viewnavigator/src/QmitkViewNavigatorWidget.h @@ -1,88 +1,86 @@ /*============================================================================ 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_INCLUDED #define _QMITKViewNavigatorWidget_H_INCLUDED //QT headers #include #include #include #include "ui_QmitkViewNavigatorWidgetControls.h" #include #include #include #include #include #include #include #include -#include -#include class ClassFilterProxyModel; /** @brief */ class QmitkViewNavigatorWidget : public QWidget { //this is needed for all Qt objects that should have a MOC object (everything that derives from QObject) Q_OBJECT public: QmitkViewNavigatorWidget (berry::IWorkbenchWindow::Pointer window, QWidget* parent = nullptr, Qt::WindowFlags f = nullptr); ~QmitkViewNavigatorWidget() override; virtual void CreateQtPartControl(QWidget *parent); void setFocus(); bool FillTreeList(); void UpdateTreeList(QStandardItem* item = nullptr, berry::IWorkbenchPartReference* partRef=nullptr, const std::string& changeId=""); QScopedPointer m_PerspectiveListener; QScopedPointer m_WindowListener; public slots: void CustomMenuRequested(QPoint pos); void ItemClicked(const QModelIndex &index); void SaveCurrentPerspectiveAs(); void ResetCurrentPerspective(); void CloseAllPerspectives(); void ClosePerspective(); void ExpandAll(); void CollapseAll(); void FilterChanged(); protected: friend class ViewNavigatorPerspectiveListener; // member variables Ui::QmitkViewNavigatorWidgetControls m_Controls; QWidget* m_Parent; QStandardItemModel* m_TreeModel; ClassFilterProxyModel* m_FilterProxyModel; QMenu* m_ContextMenu; berry::IPerspectiveDescriptor::Pointer m_ActivePerspective; bool m_Generated; private: berry::IWorkbenchWindow::Pointer m_Window; }; #endif // _QMITKViewNavigatorWidget_H_INCLUDED