diff --git a/Plugins/org.mitk.gui.qt.viewbrowser/src/internal/ViewBrowserView.cpp b/Plugins/org.mitk.gui.qt.viewbrowser/src/internal/ViewBrowserView.cpp index 2cdf6d4740..6df35d76b0 100644 --- a/Plugins/org.mitk.gui.qt.viewbrowser/src/internal/ViewBrowserView.cpp +++ b/Plugins/org.mitk.gui.qt.viewbrowser/src/internal/ViewBrowserView.cpp @@ -1,210 +1,182 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ // Blueberry #include #include #include #include #include // Qmitk #include "ViewBrowserView.h" #include #include // Qt #include #include #include const std::string ViewBrowserView::VIEW_ID = "org.mitk.views.viewbrowser"; void ViewBrowserView::SetFocus() { } void ViewBrowserView::CreateQtPartControl( QWidget *parent ) { - std::map viewMap; - - berry::IViewRegistry* viewRegistry = berry::PlatformUI::GetWorkbench()->GetViewRegistry(); - std::vector views(viewRegistry->GetViews()); - for (unsigned int i=0; iGetId()] = views[i]; - } - - - // create GUI widgets from the Qt Designer's .ui file - m_Controls.setupUi( parent ); - connect( m_Controls.m_PluginTreeView, SIGNAL(customContextMenuRequested(QPoint)), SLOT(CustomMenuRequested(QPoint))); - connect( m_Controls.m_PluginTreeView, SIGNAL(clicked(const QModelIndex&)), SLOT(ItemClicked(const QModelIndex&))); + m_Controls.setupUi( parent ); + connect( m_Controls.m_PluginTreeView, SIGNAL(customContextMenuRequested(QPoint)), SLOT(CustomMenuRequested(QPoint))); + connect( m_Controls.m_PluginTreeView, SIGNAL(clicked(const QModelIndex&)), SLOT(ItemClicked(const QModelIndex&))); - m_TreeModel = new QStandardItemModel(); - QStandardItem *item = m_TreeModel->invisibleRootItem(); + // Create a new TreeModel for the data + m_TreeModel = new QStandardItemModel(); + FillTreeList(); - berry::IPerspectiveRegistry* perspRegistry = berry::PlatformUI::GetWorkbench()->GetPerspectiveRegistry(); - std::vector perspectives(perspRegistry->GetPerspectives()); - bool skip = false; + m_Controls.m_PluginTreeView->setModel(m_TreeModel); +} - berry::IWorkbenchWindow::Pointer curWin = berry::PlatformUI::GetWorkbench()->GetActiveWorkbenchWindow(); - std::string currentPersp = ""; - if (curWin.IsNotNull()) - { - if (curWin->GetActivePage().IsNotNull()) - { - berry::IPerspectiveDescriptor::Pointer persps = curWin->GetActivePage()->GetPerspective(); - currentPersp=persps->GetId(); - } - } - for (unsigned int i=0; iclear(); + QStandardItem *item = m_TreeModel->invisibleRootItem(); + + // Get all available views and create a map of all views + std::map viewMap; + berry::IViewRegistry* viewRegistry = berry::PlatformUI::GetWorkbench()->GetViewRegistry(); + std::vector views(viewRegistry->GetViews()); + for (unsigned int i=0; iGetId()] = views[i]; + } + + // Get all available perspectives + berry::IPerspectiveRegistry* perspRegistry = berry::PlatformUI::GetWorkbench()->GetPerspectiveRegistry(); + std::vector perspectives(perspRegistry->GetPerspectives()); + + // Get the current Window and the current active Perspective if possible + berry::IWorkbenchWindow::Pointer curWin = berry::PlatformUI::GetWorkbench()->GetActiveWorkbenchWindow(); + std::string currentPersp = ""; + if (curWin.IsNotNull()) + { + if (curWin->GetActivePage().IsNotNull()) { - berry::IPerspectiveDescriptor::Pointer p = perspectives.at(i); - QList< QStandardItem*> preparedRow; - mitk::QtPerspectiveItem* pItem = new mitk::QtPerspectiveItem(QString::fromStdString(p->GetLabel())); - pItem->m_Perspective = p; - preparedRow << pItem; - item->appendRow(preparedRow); - if (currentPersp.compare(p->GetId())==0) - { - if (curWin.IsNull()) - continue; - berry::IWorkbenchPage::Pointer activePage = curWin->GetActivePage(); - std::vector< std::string > currentViews = activePage->GetShowViewShortcuts(); - for (int j = 0; j < currentViews.size(); ++j) - { - QList secondRow; - - mitk::QtViewItem* vItem = new mitk::QtViewItem(QString::fromStdString(currentViews[j])); - vItem->m_View = viewMap[currentViews[j]]; - secondRow << vItem; - preparedRow.first()->appendRow(secondRow); - } - } - - // if perspectiveExcludeList is set, it contains the id-strings of perspectives, which - // should not appear as an menu-entry in the perspective menu - // if (perspectiveExcludeList.size() > 0) - // { - // for (unsigned int i=0; iGetId()) - // { - // skip = true; - // break; - // } - // } - // if (skip) - // { - // skip = false; - // continue; - // } - // } - - // QAction* perspAction = new berry::QtOpenPerspectiveAction(window, - // *perspIt, perspGroup); - // mapPerspIdToAction.insert(std::make_pair((*perspIt)->GetId(), perspAction)); + berry::IPerspectiveDescriptor::Pointer persps = curWin->GetActivePage()->GetPerspective(); + currentPersp=persps->GetId(); } + } - + // Fill the TreeModel + for (unsigned int i=0; i preparedRow; - QStandardItem* pItem = new QStandardItem("All Views"); + mitk::QtPerspectiveItem* pItem = new mitk::QtPerspectiveItem(QString::fromStdString(p->GetLabel())); + pItem->m_Perspective = p; preparedRow << pItem; item->appendRow(preparedRow); - for (int i = 0; i < views.size(); ++i) - { - QList secondRow; - mitk::QtViewItem* vItem = new mitk::QtViewItem(QString::fromStdString(views[i]->GetLabel())); - vItem->m_View = views[i]; - secondRow << vItem; - preparedRow.first()->appendRow(secondRow); - } - - - //berry::QTOpenPers - - - // adding a row to the invisible root item produces a root element - //item->appendRow(preparedRow); - - //QList secondRow =prepareRow("111", "222", "333"); - // adding a row to an item starts a subtree - //preparedRow.first()->appendRow(secondRow); - - //QList preparedRow =prepareRow("first", "second", "third"); + // If the current perspective is the active perspective add current views + if (currentPersp.compare(p->GetId())==0) + { + if (curWin.IsNull()) + continue; + berry::IWorkbenchPage::Pointer activePage = curWin->GetActivePage(); + std::vector< std::string > currentViews = activePage->GetShowViewShortcuts(); + for (int j = 0; j < currentViews.size(); ++j) + { + QList secondRow; - m_Controls.m_PluginTreeView->setModel(m_TreeModel); -// m_Controls.m_PluginTreeView->expandAll(); + mitk::QtViewItem* vItem = new mitk::QtViewItem(QString::fromStdString(currentViews[j])); + vItem->m_View = viewMap[currentViews[j]]; + secondRow << vItem; + preparedRow.first()->appendRow(secondRow); + } + } + } + + // Add a list with all available views + QList< QStandardItem*> preparedRow; + QStandardItem* pItem = new QStandardItem("All Views"); + preparedRow << pItem; + item->appendRow(preparedRow); + for (int i = 0; i < views.size(); ++i) + { + QList secondRow; + mitk::QtViewItem* vItem = new mitk::QtViewItem(QString::fromStdString(views[i]->GetLabel())); + vItem->m_View = views[i]; + secondRow << vItem; + preparedRow.first()->appendRow(secondRow); + } } void ViewBrowserView::OnSelectionChanged( berry::IWorkbenchPart::Pointer /*source*/, const QList& nodes ) { // iterate all selected objects, adjust warning visibility foreach( mitk::DataNode::Pointer node, nodes ) { if( node.IsNotNull() ) { return; } } } void ViewBrowserView::ItemClicked(const QModelIndex &index) { QStandardItem* item = m_TreeModel->itemFromIndex(index); if ( dynamic_cast< mitk::QtPerspectiveItem* >(item) ) { try { // berry::IWorkbenchPage::Pointer page = berry::PlatformUI::GetWorkbench()->GetActiveWorkbenchWindow()->GetActivePage(); // page->CloseAllPerspectives(false, false); mitk::QtPerspectiveItem* pItem = dynamic_cast< mitk::QtPerspectiveItem* >(item); // page->ClosePerspective( pItem->m_Perspective, true, false ); berry::PlatformUI::GetWorkbench()->ShowPerspective( pItem->m_Perspective->GetId(), berry::PlatformUI::GetWorkbench()->GetActiveWorkbenchWindow() ); } catch (...) { QMessageBox::critical(0, "Opening Perspective Failed", QString("The requested perspective could not be opened.\nSee the log for details.")); } } else if ( dynamic_cast< mitk::QtViewItem* >(item) ) { 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()); } catch (berry::PartInitException e) { BERRY_ERROR << "Error: " << e.displayText() << std::endl; } } } } void ViewBrowserView::CustomMenuRequested(QPoint pos) { // m_ContextMenu->popup(m_Controls.m_PerspectiveTree->viewport()->mapToGlobal(pos)); } \ No newline at end of file diff --git a/Plugins/org.mitk.gui.qt.viewbrowser/src/internal/ViewBrowserView.h b/Plugins/org.mitk.gui.qt.viewbrowser/src/internal/ViewBrowserView.h index 69ed283a58..06ec773ce6 100644 --- a/Plugins/org.mitk.gui.qt.viewbrowser/src/internal/ViewBrowserView.h +++ b/Plugins/org.mitk.gui.qt.viewbrowser/src/internal/ViewBrowserView.h @@ -1,67 +1,70 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef ViewBrowserView_h #define ViewBrowserView_h #include #include #include "ui_ViewBrowserViewControls.h" #include /** \brief ViewBrowserView \warning This class is not yet documented. Use "git blame" and ask the author to provide basic documentation. \sa QmitkAbstractView \ingroup ${plugin_target}_internal */ class ViewBrowserView : public QmitkAbstractView { // this is needed for all Qt objects that should have a Qt meta-object // (everything that derives from QObject and wants to have signal/slots) Q_OBJECT public: static const std::string VIEW_ID; protected slots: /// \brief Called when the user clicks the GUI button void CustomMenuRequested(QPoint pos); void ItemClicked(const QModelIndex &index); protected: virtual void CreateQtPartControl(QWidget *parent); virtual void SetFocus(); /// \brief called by QmitkFunctionality when DataManager's selection has changed virtual void OnSelectionChanged( berry::IWorkbenchPart::Pointer source, const QList& nodes ); + /// \brief Fills the TreeList with the available perspectives and views. + void FillTreeList(); + Ui::ViewBrowserViewControls m_Controls; QStandardItemModel* m_TreeModel; }; #endif // ViewBrowserView_h