19 #include "internal/QmitkCommonActivator.h"
20 #include "internal/QmitkDataNodeItemModel.h"
38 #include <ctkServiceTracker.h>
41 #include <QItemSelectionModel>
42 #include <QApplication>
43 #include <QMessageBox>
44 #include <QScrollArea>
45 #include <QVBoxLayout>
47 class QmitkAbstractViewPrivate
53 , m_PrefServiceTracker(QmitkCommonActivator::GetContext())
54 , m_DataStorageServiceTracker(QmitkCommonActivator::GetContext())
56 , m_DataNodeItemModel(new QmitkDataNodeItemModel)
57 , m_DataNodeSelectionModel(new QItemSelectionModel(m_DataNodeItemModel))
58 , m_InDataStorageChanged(false)
60 m_PrefServiceTracker.open();
61 m_DataStorageServiceTracker.open();
64 ~QmitkAbstractViewPrivate()
66 delete m_DataNodeSelectionModel;
67 delete m_DataNodeItemModel;
69 m_PrefServiceTracker.close();
70 m_DataStorageServiceTracker.close();
81 if(!m_InDataStorageChanged)
83 m_InDataStorageChanged =
true;
85 q->DataStorageModified();
86 m_InDataStorageChanged =
false;
98 if(!m_InDataStorageChanged)
100 m_InDataStorageChanged =
true;
101 q->NodeRemoved(node);
102 q->DataStorageModified();
103 m_InDataStorageChanged =
false;
115 if(!m_InDataStorageChanged)
117 m_InDataStorageChanged =
true;
118 q->NodeChanged(node);
119 q->DataStorageModified();
120 m_InDataStorageChanged =
false;
135 q->OnNullSelection(sourcepart);
141 q->OnSelectionChanged(sourcepart, this->DataNodeSelectionToQList(_DataNodeSelection));
151 ctkServiceTracker<berry::IPreferencesService*> m_PrefServiceTracker;
153 ctkServiceTracker<mitk::IDataStorageService*> m_DataStorageServiceTracker;
169 QmitkDataNodeItemModel* m_DataNodeItemModel;
174 QItemSelectionModel* m_DataNodeSelectionModel;
179 QScopedPointer<berry::ISelectionListener> m_BlueBerrySelectionListener;
185 bool m_InDataStorageChanged;
190 : d(new QmitkAbstractViewPrivate(this))
194 void QmitkAbstractView::CreatePartControl(QWidget* parent)
198 auto scrollArea =
new QScrollArea;
200 scrollArea->setFrameShadow(QFrame::Plain);
201 scrollArea->setFrameShape(QFrame::NoFrame);
202 scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
203 scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
206 d->m_Parent =
new QWidget;
214 scrollArea->setWidgetResizable(
true);
215 scrollArea->setWidget(d->m_Parent);
218 QWidget* parentQWidget =
static_cast<QWidget*
>(parent);
219 auto parentLayout =
new QVBoxLayout(parentQWidget);
220 parentLayout->setMargin(0);
221 parentLayout->setSpacing(0);
222 parentLayout->addWidget(scrollArea);
225 parentQWidget->setLayout(parentLayout);
227 this->AfterCreateQtPartControl();
230 void QmitkAbstractView::AfterCreateQtPartControl()
232 this->SetSelectionProvider();
236 ( d.data(), &QmitkAbstractViewPrivate::NodeAddedProxy ) );
238 ( d.data(), &QmitkAbstractViewPrivate::NodeChangedProxy ) );
240 ( d.data(), &QmitkAbstractViewPrivate::NodeRemovedProxy ) );
245 prefs->OnChanged.AddListener(
247 &QmitkAbstractView::OnPreferencesChanged));
251 d.data(), &QmitkAbstractViewPrivate::BlueBerrySelectionChanged));
252 this->
GetSite()->GetWorkbenchWindow()->GetSelectionService()->AddPostSelectionListener(d->m_BlueBerrySelectionListener.data());
264 this->OnPreferencesChanged(this->
GetPreferences().Cast<berry::IBerryPreferences>().GetPointer());
272 ( d.data(), &QmitkAbstractViewPrivate::NodeAddedProxy ) );
274 ( d.data(), &QmitkAbstractViewPrivate::NodeRemovedProxy) );
276 ( d.data(), &QmitkAbstractViewPrivate::NodeChangedProxy ) );
281 prefs->OnChanged.RemoveListener(
283 &QmitkAbstractView::OnPreferencesChanged));
300 void QmitkAbstractView::SetSelectionProvider()
304 d->m_SelectionProvider->SetItemSelectionModel(GetDataNodeSelectionModel());
308 QItemSelectionModel *QmitkAbstractView::GetDataNodeSelectionModel()
const
317 void QmitkAbstractView::DataStorageModified()
332 if (renderPart)
return renderPart;
335 QList<berry::IEditorReference::Pointer> editors = page->GetEditorReferences();
336 for (QList<berry::IEditorReference::Pointer>::iterator i = editors.begin();
337 i != editors.end(); ++i)
340 if (page->IsPartVisible(part))
343 if (renderPart)
return renderPart;
348 QList<berry::IViewReference::Pointer> views = page->GetViewReferences();
349 for(QList<berry::IViewReference::Pointer>::iterator i = views.begin();
350 i != views.end(); ++i)
353 if (page->IsPartVisible(part))
356 if (renderPart)
return renderPart;
361 if (strategies ==
NONE)
return nullptr;
365 bool activate =
false;
373 if(strategies &
OPEN)
381 catch (
const berry::PartInitException&)
389 editorPart = page->FindEditor(input);
394 page->Activate(editorPart);
398 page->BringToTop(editorPart);
409 if (renderPart ==
nullptr)
return;
413 renderingManager->RequestUpdateAll(requestType);
427 QMessageBox::critical ( parent,
"Exception caught!", str );
438 QApplication::setOverrideCursor( QCursor(Qt::WaitCursor) );
443 QApplication::setOverrideCursor( QCursor(Qt::BusyCursor) );
458 QApplication::restoreOverrideCursor();
465 QString
id =
"/" + (
const_cast<QmitkAbstractView*
>(
this))->GetViewSite()->GetId();
474 if (dsService !=
nullptr)
486 if (dsService !=
nullptr)
498 return d->DataNodeSelectionToQList(currentSelection);
503 return this->
GetSite()->GetWorkbenchWindow()->GetSelectionService()->GetSelection();
510 return d->DataNodeSelectionToQList(currentSelection);
515 return this->
GetSite()->GetWorkbenchWindow()->GetSelectionService()->GetSelection(
"org.mitk.views.datamanager");
519 QItemSelectionModel::SelectionFlags flags)
const
522 if (datamanagerView.
IsNull())
return;
530 if (currentSelection.
IsNull())
return;
536 const QList<mitk::DataNode::Pointer>& )
546 if (currentSelection.
IsNull())
return QList<mitk::DataNode::Pointer>();
547 return QList<mitk::DataNode::Pointer>::fromStdList(currentSelection->GetSelectedDataNodes());
564 QList<mitk::DataNode::Pointer> nodes;
573 if (d->m_SelectionProvider->GetItemSelectionModel() ==
nullptr)
575 d->m_SelectionProvider->SetItemSelectionModel(d->m_DataNodeSelectionModel);
577 else if (d->m_SelectionProvider->GetItemSelectionModel() != d->m_DataNodeSelectionModel)
579 MITK_WARN <<
"A custom data node selection model has been set. Ignoring call to FireNodesSelected().";
585 d->m_DataNodeSelectionModel->clearSelection();
586 d->m_DataNodeItemModel->clear();
594 d->m_DataNodeItemModel->clear();
597 d->m_DataNodeItemModel->AddDataNode(node);
599 d->m_DataNodeSelectionModel->select(QItemSelection(d->m_DataNodeItemModel->index(0,0), d->m_DataNodeItemModel->index(nodes.size()-1, 0)),
600 QItemSelectionModel::ClearAndSelect);
A BlueBerry selection provider for mitk::DataNode selections.
mitk::IRenderWindowPart * GetRenderWindowPart(IRenderWindowPartStrategies strategies=NONE) const
virtual void RemovePostSelectionListener(ISelectionListener *listener)=0
virtual void RequestUpdate(mitk::RenderingManager::RequestType requestType=mitk::RenderingManager::REQUEST_UPDATE_ALL)=0
void HandleException(std::exception &e, QWidget *parent=nullptr, bool showDialog=true) const
virtual ~QmitkAbstractView()
void FireNodeSelected(mitk::DataNode::Pointer node)
void UnRegister(bool del=true) const
berry::IPreferences::Pointer GetPreferences() const
virtual mitk::IRenderingManager * GetRenderingManager() const =0
void RequestRenderWindowUpdate(mitk::RenderingManager::RequestType requestType=mitk::RenderingManager::REQUEST_UPDATE_ALL)
virtual IDataStorageReference::Pointer GetDataStorage() const =0
void SetDataManagerSelection(const berry::ISelection::ConstPointer &selection, QItemSelectionModel::SelectionFlags flags=QItemSelectionModel::ClearAndSelect) const
Interface for a MITK Workbench Part providing a render window.
void RestoreOverrideCursor()
virtual SmartPointer< IPreferences > GetSystemPreferences()=0
virtual void FireNodesSelected(const QList< mitk::DataNode::Pointer > &nodes)
berry::SmartPointer< Self > Pointer
virtual void CreateQtPartControl(QWidget *parent)=0
mitk::IDataStorageReference::Pointer GetDataStorageReference() const
bool IsDataManagerSelectionValid() const
A convenient base class for MITK related BlueBerry Views.
bool IsCurrentSelectionValid() const
ObjectType * GetPointer() const
QList< mitk::DataNode::Pointer > GetDataManagerSelection() const
void SynchronizeDataManagerSelection() const
SmartPointer< Other > Cast() const
static berry::IEditorPart::Pointer OpenEditor(berry::IWorkbenchPage::Pointer page, berry::IEditorInput::Pointer input, const QString &editorId, bool activate=false)
mitk::DataStorage::Pointer GetDataStorage() const
berry::SmartPointer< Self > Pointer
An interface for accessing a mitk::RenderingManager instance.
QList< mitk::DataNode::Pointer > GetCurrentSelection() const
Class for nodes of the DataTree.
IWorkbenchPartSite::Pointer GetSite() const override