Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
QmitkDataManagerView.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #include "QmitkDataManagerView.h"
14 
15 // mitk gui qt datamanager
16 #include "internal/QmitkDataManagerItemDelegate.h"
17 #include "internal/QmitkNodeTableViewKeyFilter.h"
18 
19 // mitk core
20 #include <mitkCommon.h>
21 #include <mitkCoreObjectFactory.h>
23 #include <mitkImageCast.h>
24 #include <mitkITKImageImport.h>
26 #include <mitkNodePredicateAnd.h>
27 #include <mitkNodePredicateData.h>
29 #include <mitkNodePredicateNot.h>
30 #include <mitkNodePredicateOr.h>
32 #include <mitkProperties.h>
34 
35 // qt widgets module
36 #include <QmitkCustomVariants.h>
39 #include <QmitkIOUtil.h>
41 
42 // beery plugins
44 #include <berryIContributor.h>
45 #include <berryIEditorPart.h>
46 #include <berryIEditorRegistry.h>
49 #include <berryIWorkbenchPage.h>
50 #include <berryPlatform.h>
51 #include <berryPlatformUI.h>
52 
53 // mitk core services plugin
56 
57 // mitk gui common plugin
58 #include <mitkDataNodeObject.h>
60 #include <mitkIRenderingManager.h>
61 
62 // mitk gui qt application plugin
65 
66 // mitk gui qt common plugin
67 #include <QmitkDnDFrameWidget.h>
68 
69 // qt
70 #include <QGridLayout>
71 #include <QVBoxLayout>
72 #include <QAction>
73 #include <QTreeView>
74 #include <QSignalMapper>
75 
76 const QString QmitkDataManagerView::VIEW_ID = "org.mitk.views.datamanager";
77 
79  : m_ItemDelegate(nullptr)
80 {
81 }
82 
84 {
85  // nothing here
86 }
87 
89 {
91  m_Parent = parent;
92 
94  assert(prefs);
95 
96  //# GUI
97  m_NodeTreeModel = new QmitkDataStorageTreeModel(GetDataStorage(), prefs->GetBool("Place new nodes on top", true));
98  m_NodeTreeModel->setParent(parent);
99  m_NodeTreeModel->SetAllowHierarchyChange(prefs->GetBool("Allow changing of parent node", false));
100  m_SurfaceDecimation = prefs->GetBool("Use surface decimation", false);
101  // Prepare filters
106 
108  m_FilterModel->setSourceModel(m_NodeTreeModel);
111 
112  m_NodeTreeView = new QTreeView;
113  m_NodeTreeView->setHeaderHidden(true);
114  m_NodeTreeView->setSelectionMode(QAbstractItemView::ExtendedSelection);
115  m_NodeTreeView->setSelectionBehavior(QAbstractItemView::SelectRows);
116  m_NodeTreeView->setAlternatingRowColors(true);
117  m_NodeTreeView->setDragEnabled(true);
118  m_NodeTreeView->setDropIndicatorShown(true);
119  m_NodeTreeView->setAcceptDrops(true);
120  m_NodeTreeView->setContextMenuPolicy(Qt::CustomContextMenu);
121  m_NodeTreeView->setModel(m_FilterModel);
122  m_NodeTreeView->setTextElideMode(Qt::ElideMiddle);
123  m_NodeTreeView->installEventFilter(new QmitkNodeTableViewKeyFilter(this, GetDataStorage()));
124 
125  m_ItemDelegate = new QmitkDataManagerItemDelegate(m_NodeTreeView);
126  m_NodeTreeView->setItemDelegate(m_ItemDelegate);
127 
128  connect(m_NodeTreeModel, SIGNAL(rowsInserted(const QModelIndex&, int, int)), this, SLOT(NodeTreeViewRowsInserted(const QModelIndex&, int, int)));
129  connect(m_NodeTreeModel, SIGNAL(rowsRemoved(const QModelIndex&, int, int)), this, SLOT(NodeTreeViewRowsRemoved(const QModelIndex&, int, int)));
130  connect(m_NodeTreeView->selectionModel(), SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)), this, SLOT(NodeSelectionChanged(const QItemSelection &, const QItemSelection &)));
132 
133  // data node context menu and menu actions
137  connect(m_NodeTreeView, SIGNAL(customContextMenuRequested(const QPoint&)), m_DataNodeContextMenu, SLOT(OnContextMenuRequested(const QPoint&)));
138 
140  QList<berry::IEditorDescriptor::Pointer> editors = editorRegistry->GetEditors("*.mitk");
141  if (editors.size() > 1)
142  {
143  m_ShowInMapper = new QSignalMapper(this);
144  foreach(berry::IEditorDescriptor::Pointer descriptor, editors)
145  {
146  QAction* action = new QAction(descriptor->GetLabel(), this);
147  m_ShowInActions << action;
148  m_ShowInMapper->connect(action, SIGNAL(triggered()), m_ShowInMapper, SLOT(map()));
149  m_ShowInMapper->setMapping(action, descriptor->GetId());
150  }
151  connect(m_ShowInMapper, SIGNAL(mapped(QString)), this, SLOT(ShowIn(QString)));
152  }
153 
154  QGridLayout* dndFrameWidgetLayout = new QGridLayout;
155  dndFrameWidgetLayout->addWidget(m_NodeTreeView, 0, 0);
156  dndFrameWidgetLayout->setContentsMargins(0, 0, 0, 0);
157 
159  m_DnDFrameWidget->setLayout(dndFrameWidgetLayout);
160 
161  QVBoxLayout* layout = new QVBoxLayout(parent);
162  layout->addWidget(m_DnDFrameWidget);
163  layout->setContentsMargins(0, 0, 0, 0);
164 
165  m_Parent->setLayout(layout);
166 }
167 
169 {
170 }
171 
173 // Node tree modification
175 void QmitkDataManagerView::NodeTreeViewRowsInserted(const QModelIndex& parent, int /*start*/, int /*end*/)
176 {
177  QModelIndex viewIndex = m_FilterModel->mapFromSource(parent);
178  m_NodeTreeView->setExpanded(viewIndex, true);
179 
180  // a new row was inserted
181  if (m_CurrentRowCount == 0 && m_NodeTreeModel->rowCount() == 1)
182  {
185  }
186 }
187 
188 void QmitkDataManagerView::NodeTreeViewRowsRemoved(const QModelIndex& /*parent*/, int /*start*/, int /*end*/)
189 {
191 }
192 
193 void QmitkDataManagerView::NodeSelectionChanged(const QItemSelection& /*selected*/, const QItemSelection& /*deselected*/)
194 {
195  auto selectedNodes = GetCurrentSelection();
196  auto nodeSet = m_NodeTreeModel->GetNodeSet();
197 
198  for (auto node : nodeSet)
199  {
200  if (node.IsNotNull())
201  {
202  node->SetSelected(selectedNodes.contains(node));
203  }
204  }
205  m_DataNodeContextMenu->SetSelectedNodes(selectedNodes);
206 }
207 
209 {
210  ToggleVisibilityAction::Run(GetSite(), GetDataStorage(), QList<mitk::DataNode::Pointer>());
211 }
212 
213 void QmitkDataManagerView::ShowIn(const QString& editorId)
214 {
215  berry::IWorkbenchPage::Pointer page = GetSite()->GetPage();
217  page->OpenEditor(input, editorId, false, berry::IWorkbenchPage::MATCH_ID);
218 }
219 
221 {
222  // m_FilterModel->invalidate();
223  // fix as proposed by R. Khlebnikov in the mitk-users mail from 02.09.2014
224  QMetaObject::invokeMethod(m_FilterModel, "invalidate", Qt::QueuedConnection);
225 }
226 
228 {
229  if (m_NodeTreeModel->GetPlaceNewNodesOnTopFlag() != prefs->GetBool("Place new nodes on top", true))
230  {
232  }
233 
234  bool hideHelperObjects = !prefs->GetBool("Show helper objects", false);
236  {
237  if (hideHelperObjects)
238  {
240  }
241  else
242  {
244  }
245  }
246 
247  bool hideNodesWithNoData = !prefs->GetBool("Show nodes containing no data", false);
249  {
250  if (hideNodesWithNoData)
251  {
253  }
254  else
255  {
257  }
258  }
259  m_NodeTreeView->expandAll();
260 
261  m_SurfaceDecimation = prefs->GetBool("Use surface decimation", false);
263 
264  m_NodeTreeModel->SetAllowHierarchyChange(prefs->GetBool("Allow changing of parent node", false));
265 
267 }
268 
269 QItemSelectionModel* QmitkDataManagerView::GetDataNodeSelectionModel() const
270 {
271  return m_NodeTreeView->selectionModel();
272 }
QSignalMapper * m_ShowInMapper
Maps "Show in" actions to editor ids.
void CreateQtPartControl(QWidget *parent) override
void ShowIn(const QString &editorId)
Opens the editor with the given id using the current data storage.
mitk::NodePredicateBase::Pointer m_NodeWithNoDataFilterPredicate
vcl_size_t m_CurrentRowCount
saves the current amount of rows shown in the data manager
mitk::IDataStorageReference::Pointer GetDataStorageReference() const
SmartPointer< Other > Cast() const
QmitkDataStorageTreeModel * m_NodeTreeModel
A plain widget as the base pane.
void SetAllowHierarchyChange(bool allowHierarchyChange)
Set whether to allow hierarchy changes by dragging and dropping.
static Pointer New()
void NodeChanged(const mitk::DataNode *node) override
virtual QList< mitk::DataNode::Pointer > GetNodeSet() const
QmitkDataManagerItemDelegate * m_ItemDelegate
QmitkDataStorageFilterProxyModel * m_FilterModel
QmitkDataNodeContextMenu * m_DataNodeContextMenu
The context menu that shows up when right clicking on a node.
virtual bool GetBool(const QString &key, bool def) const =0
void OnPreferencesChanged(const berry::IBerryPreferences *prefs) override
mitk::NodePredicateBase::Pointer m_HelperObjectFilterPredicate
static const QString VIEW_ID
static IRenderWindowPart * OpenRenderWindowPart(berry::IWorkbenchPage::Pointer page, bool activatedEditor=true)
Uses &#39;GetRenderWindowPart&#39; to open the a render window part with a certain strategy: Calls &#39;GetRender...
An editor input based on a mitk::DataStorage.
void SetPlaceNewNodesOnTop(bool _PlaceNewNodesOnTop)
static Pointer New()
void SetSelectedNodes(const QList< mitk::DataNode::Pointer > &selectedNodes)
QList< QAction * > m_ShowInActions
A list of "Show in" actions.
void NodeTreeViewRowsInserted(const QModelIndex &parent, int start, int end)
When rows are inserted auto expand them.
static Pointer New(mitk::BaseData *_arg)
virtual QList< IEditorDescriptor::Pointer > GetEditors(const QString &fileName)=0
static IWorkbench * GetWorkbench()
int rowCount(const QModelIndex &parent=QModelIndex()) const override
bool HasFilterPredicate(mitk::NodePredicateBase::Pointer pred)
bool RemoveFilterPredicate(mitk::NodePredicateBase::Pointer pred)
void SetSurfaceDecimation(bool surfaceDecimation)
void Run(berry::IWorkbenchPartSite::Pointer workbenchPartSite, mitk::DataStorage::Pointer dataStorage, const QList< mitk::DataNode::Pointer > &selectedNodes, mitk::BaseRenderer *baseRenderer)
Enables loading data into a MITK application via Drag&#39;n Drop.
static Pointer New(const char *_arg)
void AddFilterPredicate(mitk::NodePredicateBase::Pointer pred)
MITKMATCHPOINTREGISTRATION_EXPORT ResultImageType::Pointer map(const InputImageType *input, const RegistrationType *registration, bool throwOnOutOfInputAreaError=false, const double &paddingValue=0, const ResultImageGeometryType *resultGeometry=nullptr, bool throwOnMappingError=true, const double &errorValue=0, mitk::ImageMappingInterpolator::Type interpolatorType=mitk::ImageMappingInterpolator::Linear)
mitk::DataStorage::Pointer GetDataStorage() const
QTreeView * m_NodeTreeView
The Table view to show the selected nodes.
void NodeSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
Whenever the selection changes set the "selected" property respectively.
bool m_SurfaceDecimation
flag indicating whether a surface created from a selected decimation is decimated with vtkQuadricDeci...
QmitkDnDFrameWidget * m_DnDFrameWidget
void SetDataStorage(mitk::DataStorage *dataStorage)
QList< mitk::DataNode::Pointer > GetCurrentSelection() const
void NodeTreeViewRowsRemoved(const QModelIndex &parent, int start, int end)
will setup m_CurrentRowCount
void Run(berry::IWorkbenchPartSite::Pointer workbenchPartSite, mitk::DataStorage::Pointer dataStorage)
virtual IEditorRegistry * GetEditorRegistry() const =0
berry::IPreferences::Pointer GetPreferences() const
Class for nodes of the DataTree.
Definition: mitkDataNode.h:57
IWorkbenchPartSite::Pointer GetSite() const override