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 0eeeaa260a..67907a29ce 100644 --- a/Plugins/org.mitk.gui.qt.viewbrowser/src/internal/ViewBrowserView.cpp +++ b/Plugins/org.mitk.gui.qt.viewbrowser/src/internal/ViewBrowserView.cpp @@ -1,172 +1,190 @@ /*=================================================================== 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 ) { // 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&))); + InitTreeView(); +} + +void ViewBrowserView::InitTreeView() +{ + m_ContextMenu = new QMenu(m_Controls.m_PluginTreeView); + m_Controls.m_PluginTreeView->setContextMenuPolicy(Qt::CustomContextMenu); + m_TreeModel = new QStandardItemModel(); QStandardItem *item = m_TreeModel->invisibleRootItem(); berry::IPerspectiveRegistry* perspRegistry = berry::PlatformUI::GetWorkbench()->GetPerspectiveRegistry(); std::vector perspectives(perspRegistry->GetPerspectives()); bool skip = false; berry::IViewRegistry* viewRegistry = berry::PlatformUI::GetWorkbench()->GetViewRegistry(); std::vector views(viewRegistry->GetViews()); - MITK_INFO << "PERSPECTIVES"; for (unsigned int i=0; i preparedRow; mitk::QtPerspectiveItem* pItem = new mitk::QtPerspectiveItem(QString::fromStdString(p->GetLabel())); pItem->m_Perspective = p; preparedRow << pItem; item->appendRow(preparedRow); for (unsigned int i=0; i secondRow; mitk::QtViewItem* vItem = new mitk::QtViewItem(QString::fromStdString(v->GetLabel())); vItem->m_View = v; 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::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); - m_Controls.m_PluginTreeView->setModel(m_TreeModel); -// m_Controls.m_PluginTreeView->expandAll(); + // m_Controls.m_PluginTreeView->expandAll(); } 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); + // 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 ); + // 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::MapSignal() +{ + if (m_RegisteredPerspective!=NULL) + { + MITK_INFO << m_RegisteredPerspective->GetId(); + berry::IPerspectiveRegistry* perspRegistry = berry::PlatformUI::GetWorkbench()->GetPerspectiveRegistry(); + perspRegistry->ClonePerspective(m_RegisteredPerspective->GetId(), "TESTPERSPECTIVE", m_RegisteredPerspective); + InitTreeView(); + } +} + void ViewBrowserView::CustomMenuRequested(QPoint pos) { - // m_ContextMenu->popup(m_Controls.m_PerspectiveTree->viewport()->mapToGlobal(pos)); + + QStandardItem* item = m_TreeModel->itemFromIndex(m_Controls.m_PluginTreeView->indexAt(pos)); + + if (m_ContextMenu!=NULL && item!=NULL && dynamic_cast< mitk::QtPerspectiveItem* >(item) ) + { + m_ContextMenu->clear(); + m_RegisteredPerspective = dynamic_cast< mitk::QtPerspectiveItem* >(item)->m_Perspective; + + QAction* action = new QAction("Clone Perspective", this); + m_ContextMenu->addAction(action); + connect(action, SIGNAL(triggered()), SLOT(MapSignal())); + + m_ContextMenu->popup(m_Controls.m_PluginTreeView->viewport()->mapToGlobal(pos)); + } } 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..0911aedbb5 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,75 @@ /*=================================================================== 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 +#include +#include +#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); + void MapSignal(); protected: virtual void CreateQtPartControl(QWidget *parent); virtual void SetFocus(); + void InitTreeView(); + /// \brief called by QmitkFunctionality when DataManager's selection has changed virtual void OnSelectionChanged( berry::IWorkbenchPart::Pointer source, const QList& nodes ); Ui::ViewBrowserViewControls m_Controls; - QStandardItemModel* m_TreeModel; + QStandardItemModel* m_TreeModel; + QMenu* m_ContextMenu; + berry::IPerspectiveDescriptor::Pointer m_RegisteredPerspective; }; #endif // ViewBrowserView_h diff --git a/Plugins/org.mitk.gui.qt.viewbrowser/src/internal/ViewBrowserViewControls.ui b/Plugins/org.mitk.gui.qt.viewbrowser/src/internal/ViewBrowserViewControls.ui index b563b0e280..b1cfb95dd8 100644 --- a/Plugins/org.mitk.gui.qt.viewbrowser/src/internal/ViewBrowserViewControls.ui +++ b/Plugins/org.mitk.gui.qt.viewbrowser/src/internal/ViewBrowserViewControls.ui @@ -1,47 +1,54 @@ ViewBrowserViewControls 0 0 752 974 0 0 QmitkTemplate - + + + true + + + false + + Qt::Vertical QSizePolicy::Expanding 20 220