diff --git a/CoreUI/Bundles/org.mitk.gui.qt.common/files.cmake b/CoreUI/Bundles/org.mitk.gui.qt.common/files.cmake index c3599f96fa..b7938ef751 100755 --- a/CoreUI/Bundles/org.mitk.gui.qt.common/files.cmake +++ b/CoreUI/Bundles/org.mitk.gui.qt.common/files.cmake @@ -1,47 +1,49 @@ SET(SRC_CPP_FILES QmitkCloseProjectAction.cpp QmitkDnDFrameWidget.cpp QmitkDataNodeSelectionProvider.cpp QmitkFileOpenAction.cpp QmitkFileExitAction.cpp QmitkFunctionality.cpp + QmitkFunctionality2.cpp QmitkStatusBar.cpp QmitkStdMultiWidgetEditor.cpp QmitkPreferencesDialog.cpp QmitkFunctionalityCoordinator.cpp ) SET(INTERNAL_CPP_FILES QmitkDataNodeSelection.cpp QmitkCommonActivator.cpp + QmitkFunctionalityUtil.cpp ) SET(MOC_H_FILES src/QmitkCloseProjectAction.h src/QmitkFileOpenAction.h src/QmitkFileExitAction.h src/QmitkPreferencesDialog.h src/QmitkStdMultiWidgetEditor.h src/QmitkDnDFrameWidget.h src/internal/QmitkCommonActivator.h ) SET(CACHED_RESOURCE_FILES plugin.xml ) # todo: add some qt style sheet resources SET(QRC_FILES resources/resources.qrc ) 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/CoreUI/Bundles/org.mitk.gui.qt.common/src/QmitkFunctionality.cpp b/CoreUI/Bundles/org.mitk.gui.qt.common/src/QmitkFunctionality.cpp index 30046a9ac7..bc2d495811 100755 --- a/CoreUI/Bundles/org.mitk.gui.qt.common/src/QmitkFunctionality.cpp +++ b/CoreUI/Bundles/org.mitk.gui.qt.common/src/QmitkFunctionality.cpp @@ -1,516 +1,353 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include "QmitkFunctionality.h" +#include "internal/QmitkFunctionalityUtil.h" // other includes -#include "mitkLogMacros.h" +#include // mitk Includes -#include "mitkMessage.h" -#include "mitkIDataStorageService.h" -#include "mitkDataStorageEditorInput.h" -#include +#include +#include // berry Includes -#include #include +#include +#include // Qmitk Includes #include // Qt Includes #include #include #include QmitkFunctionality::QmitkFunctionality() : m_Parent(0) , m_Active(false) , m_Visible(false) , m_SelectionProvider(0) , m_HandlesMultipleDataStorages(false) , m_InDataStorageChanged(false) { m_PreferencesService = berry::Platform::GetServiceRegistry().GetServiceById(berry::IPreferencesService::ID); } void QmitkFunctionality::SetHandleMultipleDataStorages(bool multiple) { m_HandlesMultipleDataStorages = multiple; } bool QmitkFunctionality::HandlesMultipleDataStorages() const { return m_HandlesMultipleDataStorages; } mitk::DataStorage::Pointer QmitkFunctionality::GetDataStorage() const { mitk::IDataStorageService::Pointer service = berry::Platform::GetServiceRegistry().GetServiceById(mitk::IDataStorageService::ID); if (service.IsNotNull()) { if (m_HandlesMultipleDataStorages) return service->GetActiveDataStorage()->GetDataStorage(); else return service->GetDefaultDataStorage()->GetDataStorage(); } return 0; } - mitk::DataStorage::Pointer QmitkFunctionality::GetDefaultDataStorage() const { mitk::IDataStorageService::Pointer service = berry::Platform::GetServiceRegistry().GetServiceById(mitk::IDataStorageService::ID); return service->GetDefaultDataStorage()->GetDataStorage(); } void QmitkFunctionality::CreatePartControl(void* parent) { // scrollArea QScrollArea* scrollArea = new QScrollArea; //QVBoxLayout* scrollAreaLayout = new QVBoxLayout(scrollArea); scrollArea->setFrameShadow(QFrame::Plain); scrollArea->setFrameShape(QFrame::NoFrame); scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); // m_Parent m_Parent = new QWidget; //m_Parent->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding)); this->CreateQtPartControl(m_Parent); //scrollAreaLayout->addWidget(m_Parent); //scrollArea->setLayout(scrollAreaLayout); // set the widget now scrollArea->setWidgetResizable(true); scrollArea->setWidget(m_Parent); // add the scroll area to the real parent (the view tabbar) QWidget* parentQWidget = static_cast(parent); QVBoxLayout* parentLayout = new QVBoxLayout(parentQWidget); parentLayout->setMargin(0); parentLayout->setSpacing(0); parentLayout->addWidget(scrollArea); // finally set the layout containing the scroll area to the parent widget (= show it) parentQWidget->setLayout(parentLayout); this->AfterCreateQtPartControl(); } void QmitkFunctionality::AfterCreateQtPartControl() { // REGISTER DATASTORAGE LISTENER this->GetDefaultDataStorage()->AddNodeEvent.AddListener( mitk::MessageDelegate1 ( this, &QmitkFunctionality::NodeAddedProxy ) ); this->GetDefaultDataStorage()->ChangedNodeEvent.AddListener( mitk::MessageDelegate1 ( this, &QmitkFunctionality::NodeChangedProxy ) ); this->GetDefaultDataStorage()->RemoveNodeEvent.AddListener( mitk::MessageDelegate1 ( this, &QmitkFunctionality::NodeRemovedProxy ) ); // REGISTER PREFERENCES LISTENER berry::IBerryPreferences::Pointer prefs = this->GetPreferences().Cast(); if(prefs.IsNotNull()) prefs->OnChanged.AddListener(berry::MessageDelegate1(this, &QmitkFunctionality::OnPreferencesChanged)); // REGISTER FOR WORKBENCH SELECTION EVENTS m_BlueBerrySelectionListener = berry::ISelectionListener::Pointer(new berry::SelectionChangedAdapter(this , &QmitkFunctionality::BlueBerrySelectionChanged)); this->GetSite()->GetWorkbenchWindow()->GetSelectionService()->AddPostSelectionListener(/*"org.mitk.views.datamanager",*/ m_BlueBerrySelectionListener); // REGISTER A SELECTION PROVIDER - QmitkFunctionality::SelectionProvider::Pointer _SelectionProvider - = QmitkFunctionality::SelectionProvider::New(this); + QmitkFunctionalitySelectionProvider::Pointer _SelectionProvider + = QmitkFunctionalitySelectionProvider::New(this); m_SelectionProvider = _SelectionProvider.GetPointer(); this->GetSite()->SetSelectionProvider(berry::ISelectionProvider::Pointer(m_SelectionProvider)); // EMULATE INITIAL SELECTION EVENTS // by default a a multi widget is always available this->StdMultiWidgetAvailable(*this->GetActiveStdMultiWidget()); // send datamanager selection this->OnSelectionChanged(this->GetDataManagerSelection()); // send preferences changed event this->OnPreferencesChanged(this->GetPreferences().Cast().GetPointer()); } void QmitkFunctionality::ClosePart() { } void QmitkFunctionality::ClosePartProxy() { this->GetDefaultDataStorage()->AddNodeEvent.RemoveListener( mitk::MessageDelegate1 ( this, &QmitkFunctionality::NodeAddedProxy ) ); this->GetDefaultDataStorage()->RemoveNodeEvent.RemoveListener( mitk::MessageDelegate1 ( this, &QmitkFunctionality::NodeRemovedProxy) ); this->GetDefaultDataStorage()->ChangedNodeEvent.RemoveListener( mitk::MessageDelegate1 ( this, &QmitkFunctionality::NodeChangedProxy ) ); berry::IBerryPreferences::Pointer prefs = this->GetPreferences().Cast(); if(prefs.IsNotNull()) { prefs->OnChanged.RemoveListener(berry::MessageDelegate1(this, &QmitkFunctionality::OnPreferencesChanged)); // flush the preferences here (disabled, everyone should flush them by themselves at the right moment) // prefs->Flush(); } // REMOVE SELECTION PROVIDER this->GetSite()->SetSelectionProvider(berry::ISelectionProvider::Pointer(NULL)); berry::ISelectionService* s = GetSite()->GetWorkbenchWindow()->GetSelectionService(); if(s) { s->RemovePostSelectionListener(m_BlueBerrySelectionListener); } this->ClosePart(); } QmitkFunctionality::~QmitkFunctionality() { this->Register(); this->ClosePartProxy(); this->UnRegister(false); } -std::vector QmitkFunctionality::GetCurrentSelection() const -{ - berry::ISelection::ConstPointer selection( this->GetSite()->GetWorkbenchWindow()->GetSelectionService()->GetSelection()); - // buffer for the data manager selection - mitk::DataNodeSelection::ConstPointer currentSelection = selection.Cast(); - return this->DataNodeSelectionToVector(currentSelection); -} - -std::vector QmitkFunctionality::GetDataManagerSelection() const -{ - berry::ISelection::ConstPointer selection( this->GetSite()->GetWorkbenchWindow()->GetSelectionService()->GetSelection("org.mitk.views.datamanager")); - // buffer for the data manager selection - mitk::DataNodeSelection::ConstPointer currentSelection = selection.Cast(); - return this->DataNodeSelectionToVector(currentSelection); -} - void QmitkFunctionality::OnPreferencesChanged( const berry::IBerryPreferences* ) { } -void QmitkFunctionality::OnSelectionChanged(std::vector /*nodes*/) -{ -} - void QmitkFunctionality::BlueBerrySelectionChanged(berry::IWorkbenchPart::Pointer sourcepart, berry::ISelection::ConstPointer selection) { if(sourcepart.IsNull() || sourcepart->GetSite()->GetId() != "org.mitk.views.datamanager") return; mitk::DataNodeSelection::ConstPointer _DataNodeSelection = selection.Cast(); this->OnSelectionChanged(this->DataNodeSelectionToVector(_DataNodeSelection)); } - -std::vector QmitkFunctionality::DataNodeSelectionToVector(mitk::DataNodeSelection::ConstPointer currentSelection) const -{ - - std::vector selectedNodes; - if(currentSelection.IsNull()) - return selectedNodes; - - mitk::DataNodeObject* _DataNodeObject = 0; - mitk::DataNode* _DataNode = 0; - - for(mitk::DataNodeSelection::iterator it = currentSelection->Begin(); - it != currentSelection->End(); ++it) - { - _DataNodeObject = dynamic_cast((*it).GetPointer()); - if(_DataNodeObject) - { - _DataNode = _DataNodeObject->GetDataNode(); - if(_DataNode) - selectedNodes.push_back(_DataNode); - } - } - - return selectedNodes; -} - bool QmitkFunctionality::IsVisible() const { return m_Visible; } void QmitkFunctionality::SetFocus() { } void QmitkFunctionality::Activated() { } void QmitkFunctionality::Deactivated() { } void QmitkFunctionality::StdMultiWidgetAvailable( QmitkStdMultiWidget& /*stdMultiWidget*/ ) { } void QmitkFunctionality::StdMultiWidgetNotAvailable() { } -void QmitkFunctionality::NodeAddedProxy( const mitk::DataNode* node ) -{ - // garantuee no recursions when a new node event is thrown in NodeAdded() - if(!m_InDataStorageChanged) - { - m_InDataStorageChanged = true; - this->NodeAdded(node); - this->DataStorageChanged(); - m_InDataStorageChanged = false; - } - -} - -void QmitkFunctionality::NodeAdded( const mitk::DataNode* /*node*/ ) -{ - -} - -void QmitkFunctionality::NodeRemovedProxy( const mitk::DataNode* node ) -{ - // garantuee no recursions when a new node event is thrown in NodeAdded() - if(!m_InDataStorageChanged) - { - m_InDataStorageChanged = true; - this->NodeRemoved(node); - this->DataStorageChanged(); - m_InDataStorageChanged = false; - } -} - -void QmitkFunctionality::NodeRemoved( const mitk::DataNode* /*node*/ ) -{ - -} - void QmitkFunctionality::DataStorageChanged() { } QmitkStdMultiWidget* QmitkFunctionality::GetActiveStdMultiWidget() { QmitkStdMultiWidget* activeStdMultiWidget = 0; berry::IEditorPart::Pointer editor = this->GetSite()->GetPage()->GetActiveEditor(); if (editor.Cast().IsNotNull()) { activeStdMultiWidget = editor.Cast()->GetStdMultiWidget(); } else { mitk::DataStorageEditorInput::Pointer editorInput; editorInput = new mitk::DataStorageEditorInput(); // open a new multi-widget editor, but do not give it the focus berry::IEditorPart::Pointer editor = this->GetSite()->GetPage()->OpenEditor(editorInput, QmitkStdMultiWidgetEditor::EDITOR_ID, false); activeStdMultiWidget = editor.Cast()->GetStdMultiWidget(); } return activeStdMultiWidget; } void QmitkFunctionality::HandleException( const char* str, QWidget* parent, bool showDialog ) const { //itkGenericOutputMacro( << "Exception caught: " << str ); MITK_ERROR << str; if ( showDialog ) { QMessageBox::critical ( parent, "Exception caught!", str ); } } - void QmitkFunctionality::HandleException( std::exception& e, QWidget* parent, bool showDialog ) const { HandleException( e.what(), parent, showDialog ); } void QmitkFunctionality::StdMultiWidgetClosed( QmitkStdMultiWidget& /*stdMultiWidget*/ ) { } void QmitkFunctionality::WaitCursorOn() { QApplication::setOverrideCursor( QCursor(Qt::WaitCursor) ); } void QmitkFunctionality::BusyCursorOn() { QApplication::setOverrideCursor( QCursor(Qt::BusyCursor) ); } void QmitkFunctionality::WaitCursorOff() { this->RestoreOverrideCursor(); } void QmitkFunctionality::BusyCursorOff() { this->RestoreOverrideCursor(); } void QmitkFunctionality::RestoreOverrideCursor() { QApplication::restoreOverrideCursor(); } berry::IPreferences::Pointer QmitkFunctionality::GetPreferences() const { berry::IPreferencesService::Pointer prefService = m_PreferencesService.Lock(); // const_cast workaround for bad programming: const uncorrectness this->GetViewSite() should be const std::string id = "/" + (const_cast(this))->GetViewSite()->GetId(); return prefService.IsNotNull() ? prefService->GetSystemPreferences()->Node(id): berry::IPreferences::Pointer(0); } void QmitkFunctionality::Visible() { } void QmitkFunctionality::Hidden() { } -void QmitkFunctionality::NodeChanged( const mitk::DataNode* /*node*/ ) -{ - -} - -void QmitkFunctionality::NodeChangedProxy( const mitk::DataNode* node ) -{ - // garantuee no recursions when a new node event is thrown in NodeAdded() - if(!m_InDataStorageChanged) - { - m_InDataStorageChanged = true; - this->NodeChanged(node); - this->DataStorageChanged(); - m_InDataStorageChanged = false; - } -} - bool QmitkFunctionality::IsExclusiveFunctionality() const { return true; } void QmitkFunctionality::SetVisible( bool visible ) { m_Visible = visible; } void QmitkFunctionality::SetActivated( bool activated ) { m_Active = activated; } bool QmitkFunctionality::IsActivated() const { return m_Active; } -QmitkFunctionality::SelectionProvider::SelectionProvider( QmitkFunctionality* _Functionality ) -: m_Functionality(_Functionality) -{ - -} - -QmitkFunctionality::SelectionProvider::~SelectionProvider() -{ - m_Functionality = 0; -} - -void QmitkFunctionality::SelectionProvider::AddSelectionChangedListener( berry::ISelectionChangedListener::Pointer listener ) -{ - m_SelectionEvents.AddListener(listener); -} - - -berry::ISelection::ConstPointer QmitkFunctionality::SelectionProvider::GetSelection() const -{ - return m_CurrentSelection; -} - -void QmitkFunctionality::SelectionProvider::RemoveSelectionChangedListener( berry::ISelectionChangedListener::Pointer listener ) -{ - m_SelectionEvents.RemoveListener(listener); -} - -void QmitkFunctionality::SelectionProvider::SetSelection( berry::ISelection::Pointer selection ) -{ - m_CurrentSelection = selection.Cast(); -} - -void QmitkFunctionality::SelectionProvider::FireNodesSelected( std::vector nodes ) -{ - mitk::DataNodeSelection::Pointer sel(new mitk::DataNodeSelection(nodes)); - m_CurrentSelection = sel; - berry::SelectionChangedEvent::Pointer event(new berry::SelectionChangedEvent(berry::ISelectionProvider::Pointer(this) - , m_CurrentSelection)); - m_SelectionEvents.selectionChanged(event); - -} - -void QmitkFunctionality::FireNodeSelected( mitk::DataNode* node ) -{ - std::vector nodes; - nodes.push_back(node); - this->FireNodesSelected(nodes); -} - -void QmitkFunctionality::FireNodesSelected( std::vector nodes ) -{ - if( !m_SelectionProvider ) - return; - - std::vector nodesSmartPointers; - for (std::vector::iterator it = nodes.begin() - ; it != nodes.end(); it++) - { - nodesSmartPointers.push_back( *it ); - } - m_SelectionProvider->FireNodesSelected(nodesSmartPointers); - -} diff --git a/CoreUI/Bundles/org.mitk.gui.qt.common/src/QmitkFunctionality.h b/CoreUI/Bundles/org.mitk.gui.qt.common/src/QmitkFunctionality.h index ebec1585a1..963df3a66d 100755 --- a/CoreUI/Bundles/org.mitk.gui.qt.common/src/QmitkFunctionality.h +++ b/CoreUI/Bundles/org.mitk.gui.qt.common/src/QmitkFunctionality.h @@ -1,445 +1,393 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef QMITKFUNCTIONALITY_H_ #define QMITKFUNCTIONALITY_H_ #ifdef __MINGW32__ // We need to inlclude winbase.h here in order to declare // atomic intrinsics like InterlockedIncrement correctly. // Otherwhise, they would be declared wrong within qatomic_windows.h . #include #endif //# blueberry stuff #include -#include #include -#include #include -#include -#include + +#include //# mitk stuff #include #include "mitkDataNodeSelection.h" #include -#include //# forward declarations class QmitkStdMultiWidget; -class QScrollArea; + +namespace mitk { + class DataNode; +} + +namespace berry { + struct IBerryPreferences; +} + +class QmitkFunctionalitySelectionProvider; /// /// \class QmitkFunctionality /// /// \brief The base class of all MITK related blueberry views (~ in the old version of MITK, this was called "Functionality") /// /// QmitkFunctionality provides several convenience methods that eases the introduction of a new view: /// ///
    ///
  1. Access to the DataStorage (~ the shared data repository) ///
  2. Access to the StdMultiWidget (the 2x2 RenderWindow arrangement) ///
  3. Access to and update notification for the functionality/view preferences ///
  4. Access to and update notification for the current DataNode selection / to DataNode selection events send through the SelectionService ///
  5. Methods to send DataNode selections through the SelectionService ///
  6. Some events for unproblematic inter-View communication (e.g. when to add/remove interactors) ///
  7. Some minor important convenience methods (like changing the mouse cursor/exception handling) ///
/// /// Please use the Activated/Deactivated method to add/remove interactors, disabling multiwidget crosshair or anything which may /// "affect" other functionalities. For further reading please have a look at QmitkFunctionality::IsExclusiveFunctionality(). /// class MITK_QT_COMMON QmitkFunctionality : public berry::QtViewPart { //# public virtual methods which can be overwritten public: /// /// Creates smartpointer typedefs /// berryObjectMacro(QmitkFunctionality) /// /// Nothing to do in the standard ctor. Initiliaze your GUI in CreateQtPartControl(QWidget*) /// \see berry::QtViewPart::CreateQtPartControl(QWidget*) /// QmitkFunctionality(); /// /// Disconnects all standard event listeners /// virtual ~QmitkFunctionality(); /// /// Called, when the WorkbenchPart gets closed /// by the user directly or by closing the whole /// app (e.g. for removing event listeners) /// virtual void ClosePart(); /// /// Called when the selection in the workbench changed /// virtual void OnSelectionChanged(std::vector /*nodes*/); /// /// Called when the preferences object of this view changed. /// \see GetPreferences() /// virtual void OnPreferencesChanged(const berry::IBerryPreferences*); /// /// Make this view manage multiple DataStorage. If set to true GetDataStorage() /// will return the currently active DataStorage (and not the default one). /// \see GetDataStorage() /// void SetHandleMultipleDataStorages(bool multiple); /// /// \return true if this view handles multiple DataStorages, false otherwise /// bool HandlesMultipleDataStorages() const; /// /// Called when a StdMultiWidget is available. Should not be used anymore, see GetActiveStdMultiWidget() /// \see GetActiveStdMultiWidget() /// virtual void StdMultiWidgetAvailable(QmitkStdMultiWidget& stdMultiWidget); /// /// Called when a StdMultiWidget is available. Should not be used anymore, see GetActiveStdMultiWidget() /// \see GetActiveStdMultiWidget() /// virtual void StdMultiWidgetClosed(QmitkStdMultiWidget& stdMultiWidget); /// /// Called when no StdMultiWidget is available anymore. Should not be used anymore, see GetActiveStdMultiWidget() /// \see GetActiveStdMultiWidget() /// virtual void StdMultiWidgetNotAvailable(); /// /// Only called when IsExclusiveFunctionality() returns true. /// \see IsExclusiveFunctionality() /// virtual void Activated(); /// /// \return true if this view is currently activated, false otherwise /// bool IsActivated() const; /// /// Only called when IsExclusiveFunctionality() returns true. /// \see IsExclusiveFunctionality() /// virtual void Deactivated(); /// /// Some functionalities need to add special interactors, removes the crosshair from the stdmultiwidget, etc. /// In this case the functionality has to tidy up when changing to another functionality /// which also wants to change the "default configuration". In the old Qt3-based /// version of MITK, two functionalities could never be opened at the same time so that the /// methods Activated() and Deactivated() were the right place for the functionalitites to /// add/remove their interactors, etc. This is still true for the new MITK Workbench, /// but as there can be several functionalities visible at the same time, the behaviour concerning /// when Activated() and Deactivated() are called has changed: /// /// 1. Activated() and Deactivated() are only called if IsExclusiveFunctionality() returns true /// /// 2. If only one standalone functionality is or becomes visible, Activated() will be called on that functionality /// /// 3. If two or more standalone functionalities are visible, /// Activated() will be called on the functionality that receives focus, Deactivated() will be called /// on the one that looses focus, gets hidden or closed /// /// /// As a consequence of 1. if you overwrite IsExclusiveFunctionality() and let it return false, you /// signalize the MITK Workbench that this functionality does nothing to the "default configuration" /// and can easily be visible while other functionalities are also visible. /// /// By default the method returns true. /// /// \return true if this functionality is meant to work as a standalone view, false otherwise /// virtual bool IsExclusiveFunctionality() const; /// /// Informs other parts of the workbench that node is selected via the blueberry selection service. /// void FireNodeSelected(mitk::DataNode* node); /// /// Informs other parts of the workbench that the nodes are selected via the blueberry selection service. /// void FireNodesSelected(std::vector nodes); /// /// Called when this functionality becomes visible ( no matter what IsExclusiveFunctionality() returns ) /// virtual void Visible(); /// /// \return true if this view is currently visible, false otherwise /// bool IsVisible() const; /// /// Called when this functionality is hidden ( no matter what IsExclusiveFunctionality() returns ) /// virtual void Hidden(); //# protected virtual methods which can be overwritten protected: /// /// Called when a DataStorage Add event was thrown. May be reimplemented /// by deriving classes. /// virtual void NodeAdded(const mitk::DataNode* node); /// /// Called when a DataStorage Changed event was thrown. May be reimplemented /// by deriving classes. /// virtual void NodeChanged(const mitk::DataNode* /*node*/); /// /// Called when a DataStorage Remove event was thrown. May be reimplemented /// by deriving classes. /// virtual void NodeRemoved(const mitk::DataNode* node); /// /// Called when a DataStorage add *or* remove *or* change event was thrown. May be reimplemented /// by deriving classes. /// virtual void DataStorageChanged(); /// /// \return the selection of the currently active part of the workbench or an empty vector /// if nothing is selected /// std::vector GetCurrentSelection() const; /// /// Returns the current selection made in the datamanager bundle or an empty vector /// if nothing`s selected or if the bundle does not exist /// std::vector GetDataManagerSelection() const; /// /// Returns the Preferences object for this Functionality. /// Important: When refering to this preferences, e.g. in a PreferencePage: The ID /// for this preferences object is "/", e.g. "/org.mitk.views.datamanager" /// berry::IPreferences::Pointer GetPreferences() const; /// /// Returns the default or the currently active DataStorage if m_HandlesMultipleDataStorages /// is set to true /// \see SetHandleMultipleDataStorages(bool) /// \see HandlesMultipleDataStorages() /// mitk::DataStorage::Pointer GetDataStorage() const; /// /// \return always returns the default DataStorage /// mitk::DataStorage::Pointer GetDefaultDataStorage() const; /// /// Returns the default and active StdMultiWidget. /// If there is not StdMultiWidget yet a new one is created in this method! /// QmitkStdMultiWidget* GetActiveStdMultiWidget(); /// /// Outputs an error message to the console and displays a message box containing /// the exception description. /// \param e the exception which should be handled /// \param showDialog controls, whether additionally a message box should be /// displayed to inform the user that something went wrong /// void HandleException( std::exception& e, QWidget* parent = NULL, bool showDialog = true ) const; /// /// Calls HandleException ( std::exception&, QWidget*, bool ) internally /// \see HandleException ( std::exception&, QWidget*, bool ) /// void HandleException( const char* str, QWidget* parent = NULL, bool showDialog = true ) const; /// /// Convenient method to set and reset a wait cursor ("hourglass") /// void WaitCursorOn(); /// /// Convenient method to restore the standard cursor /// void WaitCursorOff(); /// /// Convenient method to set and reset a busy cursor /// void BusyCursorOn(); /// /// Convenient method to restore the standard cursor /// void BusyCursorOff(); /// /// Convenient method to restore the standard cursor /// void RestoreOverrideCursor(); //# other public methods which should not be overwritten public: /// /// Creates a scroll area for this view and calls CreateQtPartControl then /// void CreatePartControl(void* parent); /// /// Called when this view receives the focus. Same as Activated() /// \see Activated() /// void SetFocus(); /// /// Called when a DataStorage Add Event was thrown. Sets /// m_InDataStorageChanged to true and calls NodeAdded afterwards. /// \see m_InDataStorageChanged /// void NodeAddedProxy(const mitk::DataNode* node); /// /// Called when a DataStorage remove event was thrown. Sets /// m_InDataStorageChanged to true and calls NodeRemoved afterwards. /// \see m_InDataStorageChanged /// void NodeRemovedProxy(const mitk::DataNode* node); /// /// Called when a DataStorage changed event was thrown. Sets /// m_InDataStorageChanged to true and calls NodeChanged afterwards. /// \see m_InDataStorageChanged /// void NodeChangedProxy(const mitk::DataNode* node); /// /// Toggles the visible flag m_Visible /// void SetVisible(bool visible); /// /// Toggles the activated flag m_Activated /// void SetActivated(bool activated); /// /// Called, when the WorkbenchPart gets closed for removing event listeners /// Internally this method calls ClosePart after it removed the listeners registered /// by QmitkFunctionality. By having this proxy method the user does not have to /// call QmitkFunctionality::ClosePart() when overwriting ClosePart() /// void ClosePartProxy(); - /// - /// Internal class for selection providing - /// - class SelectionProvider: virtual public berry::Object, virtual public berry::ISelectionProvider - { - public: - /// - /// Creates smartpointer typedefs - /// - berryObjectMacro(QmitkFunctionality::SelectionProvider) - /// - /// Create a selection provider for the given _Functionality - /// - berryNewMacro1Param(QmitkFunctionality::SelectionProvider, QmitkFunctionality*) - //# ISelectionProvider methods - /// - /// \see ISelectionProvider::AddSelectionChangedListener() - /// - virtual void AddSelectionChangedListener(berry::ISelectionChangedListener::Pointer listener); - /// - /// \see ISelectionProvider::GetSelection() - /// - virtual berry::ISelection::ConstPointer GetSelection() const; - /// - /// \see ISelectionProvider::RemoveSelectionChangedListener() - /// - virtual void RemoveSelectionChangedListener(berry::ISelectionChangedListener::Pointer listener); - /// - /// \see ISelectionProvider::SetSelection() - /// - virtual void SetSelection(berry::ISelection::Pointer selection); - /// - /// Sends the nodes as selected to the workbench - /// - void FireNodesSelected( std::vector nodes ); - protected: - /// - /// nothing to do here - /// - SelectionProvider(QmitkFunctionality* _Functionality); - /// - /// nothing to do here - /// - virtual ~SelectionProvider(); - /// - /// the functionality parent - /// - QmitkFunctionality* m_Functionality; - /// - /// Holds the current selection (selection made by m_Functionality !!!) - /// - mitk::DataNodeSelection::Pointer m_CurrentSelection; - /// - /// The selection events other parts can listen too - /// - berry::ISelectionChangedListener::Events m_SelectionEvents; - }; - //# other protected methods which should not be overwritten (or which are deprecated) protected: /// /// Called immediately after CreateQtPartControl(). /// Here standard event listeners for a QmitkFunctionality are registered /// void AfterCreateQtPartControl(); /// /// code to activate the last visible functionality /// void ActivateLastVisibleFunctionality(); /// /// reactions to selection events from data manager (and potential other senders) /// void BlueBerrySelectionChanged(berry::IWorkbenchPart::Pointer sourcepart, berry::ISelection::ConstPointer selection); /// /// Converts a mitk::DataNodeSelection to a std::vector (possibly empty /// std::vector DataNodeSelectionToVector(mitk::DataNodeSelection::ConstPointer currentSelection) const; //# protected fields protected: /// /// helper stuff to observe BlueBerry selections /// friend struct berry::SelectionChangedAdapter; /// /// Saves the parent of this view (this is the scrollarea created in CreatePartControl(void*) /// \see CreatePartControl(void*) /// QWidget* m_Parent; /// /// Saves if this view is the currently active one. /// bool m_Active; /// /// Saves if this view is visible /// bool m_Visible; //# private fields: private: /// /// Holds the current selection (selection made by this Functionality !!!) /// - SelectionProvider* m_SelectionProvider; + QmitkFunctionalitySelectionProvider* m_SelectionProvider; /// /// object to observe BlueBerry selections /// berry::ISelectionListener::Pointer m_BlueBerrySelectionListener; /// /// Saves if this view handles multiple datastorages /// bool m_HandlesMultipleDataStorages; /// /// Saves if this class is currently working on DataStorage changes. /// This is a protector variable to avoid recursive calls on event listener functions. bool m_InDataStorageChanged; /// /// saves all visible functionalities /// std::set m_VisibleFunctionalities; /// /// The Preferences Service to retrieve and store preferences. /// berry::IPreferencesService::WeakPtr m_PreferencesService; }; #endif /*QMITKFUNCTIONALITY_H_*/ diff --git a/CoreUI/Bundles/org.mitk.gui.qt.common/src/QmitkFunctionality2.cpp b/CoreUI/Bundles/org.mitk.gui.qt.common/src/QmitkFunctionality2.cpp new file mode 100644 index 0000000000..20d2b22647 --- /dev/null +++ b/CoreUI/Bundles/org.mitk.gui.qt.common/src/QmitkFunctionality2.cpp @@ -0,0 +1,143 @@ +/*========================================================================= + + Program: Medical Imaging & Interaction Toolkit + Language: C++ + Date: $Date$ + Version: $Revision$ + + Copyright (c) German Cancer Research Center, Division of Medical and + Biological Informatics. All rights reserved. + See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + + =========================================================================*/ + +#include "QmitkFunctionality.h" +#include "internal/QmitkFunctionalityUtil.h" + +#include +#include + +#include + +std::vector QmitkFunctionality::GetCurrentSelection() const +{ + berry::ISelection::ConstPointer selection( this->GetSite()->GetWorkbenchWindow()->GetSelectionService()->GetSelection()); + // buffer for the data manager selection + mitk::DataNodeSelection::ConstPointer currentSelection = selection.Cast(); + return this->DataNodeSelectionToVector(currentSelection); +} + +std::vector QmitkFunctionality::GetDataManagerSelection() const +{ + berry::ISelection::ConstPointer selection( this->GetSite()->GetWorkbenchWindow()->GetSelectionService()->GetSelection("org.mitk.views.datamanager")); + // buffer for the data manager selection + mitk::DataNodeSelection::ConstPointer currentSelection = selection.Cast(); + return this->DataNodeSelectionToVector(currentSelection); +} + +void QmitkFunctionality::OnSelectionChanged(std::vector /*nodes*/) +{ +} + +std::vector QmitkFunctionality::DataNodeSelectionToVector(mitk::DataNodeSelection::ConstPointer currentSelection) const +{ + + std::vector selectedNodes; + if(currentSelection.IsNull()) + return selectedNodes; + + mitk::DataNodeObject* _DataNodeObject = 0; + mitk::DataNode* _DataNode = 0; + + for(mitk::DataNodeSelection::iterator it = currentSelection->Begin(); + it != currentSelection->End(); ++it) + { + _DataNodeObject = dynamic_cast((*it).GetPointer()); + if(_DataNodeObject) + { + _DataNode = _DataNodeObject->GetDataNode(); + if(_DataNode) + selectedNodes.push_back(_DataNode); + } + } + + return selectedNodes; +} + +void QmitkFunctionality::NodeAddedProxy( const mitk::DataNode* node ) +{ + // garantuee no recursions when a new node event is thrown in NodeAdded() + if(!m_InDataStorageChanged) + { + m_InDataStorageChanged = true; + this->NodeAdded(node); + this->DataStorageChanged(); + m_InDataStorageChanged = false; + } + +} + +void QmitkFunctionality::NodeAdded( const mitk::DataNode* /*node*/ ) +{ + +} + +void QmitkFunctionality::NodeRemovedProxy( const mitk::DataNode* node ) +{ + // garantuee no recursions when a new node event is thrown in NodeAdded() + if(!m_InDataStorageChanged) + { + m_InDataStorageChanged = true; + this->NodeRemoved(node); + this->DataStorageChanged(); + m_InDataStorageChanged = false; + } +} + +void QmitkFunctionality::NodeRemoved( const mitk::DataNode* /*node*/ ) +{ + +} + +void QmitkFunctionality::NodeChanged( const mitk::DataNode* /*node*/ ) +{ + +} + +void QmitkFunctionality::NodeChangedProxy( const mitk::DataNode* node ) +{ + // garantuee no recursions when a new node event is thrown in NodeAdded() + if(!m_InDataStorageChanged) + { + m_InDataStorageChanged = true; + this->NodeChanged(node); + this->DataStorageChanged(); + m_InDataStorageChanged = false; + } +} + +void QmitkFunctionality::FireNodeSelected( mitk::DataNode* node ) +{ + std::vector nodes; + nodes.push_back(node); + this->FireNodesSelected(nodes); +} + +void QmitkFunctionality::FireNodesSelected( std::vector nodes ) +{ + if( !m_SelectionProvider ) + return; + + std::vector nodesSmartPointers; + for (std::vector::iterator it = nodes.begin() + ; it != nodes.end(); it++) + { + nodesSmartPointers.push_back( *it ); + } + m_SelectionProvider->FireNodesSelected(nodesSmartPointers); + +} diff --git a/CoreUI/Bundles/org.mitk.gui.qt.common/src/internal/QmitkFunctionalityUtil.cpp b/CoreUI/Bundles/org.mitk.gui.qt.common/src/internal/QmitkFunctionalityUtil.cpp new file mode 100644 index 0000000000..c68c518b0a --- /dev/null +++ b/CoreUI/Bundles/org.mitk.gui.qt.common/src/internal/QmitkFunctionalityUtil.cpp @@ -0,0 +1,63 @@ +/*========================================================================= + + Program: Medical Imaging & Interaction Toolkit + Language: C++ + Date: $Date$ + Version: $Revision$ + + Copyright (c) German Cancer Research Center, Division of Medical and + Biological Informatics. All rights reserved. + See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + + =========================================================================*/ + + +#include "QmitkFunctionalityUtil.h" + +#include "../QmitkFunctionality.h" + +QmitkFunctionalitySelectionProvider::QmitkFunctionalitySelectionProvider( QmitkFunctionality* _Functionality ) +: m_Functionality(_Functionality) +{ + +} + +QmitkFunctionalitySelectionProvider::~QmitkFunctionalitySelectionProvider() +{ + m_Functionality = 0; +} + +void QmitkFunctionalitySelectionProvider::AddSelectionChangedListener( berry::ISelectionChangedListener::Pointer listener ) +{ + m_SelectionEvents.AddListener(listener); +} + + +berry::ISelection::ConstPointer QmitkFunctionalitySelectionProvider::GetSelection() const +{ + return m_CurrentSelection; +} + +void QmitkFunctionalitySelectionProvider::RemoveSelectionChangedListener( berry::ISelectionChangedListener::Pointer listener ) +{ + m_SelectionEvents.RemoveListener(listener); +} + +void QmitkFunctionalitySelectionProvider::SetSelection( berry::ISelection::Pointer selection ) +{ + m_CurrentSelection = selection.Cast(); +} + +void QmitkFunctionalitySelectionProvider::FireNodesSelected( std::vector nodes ) +{ + mitk::DataNodeSelection::Pointer sel(new mitk::DataNodeSelection(nodes)); + m_CurrentSelection = sel; + berry::SelectionChangedEvent::Pointer event(new berry::SelectionChangedEvent(berry::ISelectionProvider::Pointer(this) + , m_CurrentSelection)); + m_SelectionEvents.selectionChanged(event); + +} diff --git a/CoreUI/Bundles/org.mitk.gui.qt.common/src/internal/QmitkFunctionalityUtil.h b/CoreUI/Bundles/org.mitk.gui.qt.common/src/internal/QmitkFunctionalityUtil.h new file mode 100644 index 0000000000..1f2bdcc48e --- /dev/null +++ b/CoreUI/Bundles/org.mitk.gui.qt.common/src/internal/QmitkFunctionalityUtil.h @@ -0,0 +1,92 @@ +/*========================================================================= + + Program: Medical Imaging & Interaction Toolkit + Language: C++ + Date: $Date$ + Version: $Revision$ + + Copyright (c) German Cancer Research Center, Division of Medical and + Biological Informatics. All rights reserved. + See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + + =========================================================================*/ + + +#ifndef QMITKFUNCTIONALITYUTIL_H +#define QMITKFUNCTIONALITYUTIL_H + +#include + +class QmitkFunctionality; + +#include +#include + +/// +/// Internal class for selection providing +/// +class QmitkFunctionalitySelectionProvider: public berry::ISelectionProvider +{ + +public: + + /// + /// Creates smartpointer typedefs + /// + berryObjectMacro(QmitkFunctionalitySelectionProvider) + /// + /// Create a selection provider for the given _Functionality + /// + berryNewMacro1Param(QmitkFunctionalitySelectionProvider, QmitkFunctionality*) + + //# ISelectionProvider methods + /// + /// \see ISelectionProvider::AddSelectionChangedListener() + /// + virtual void AddSelectionChangedListener(berry::ISelectionChangedListener::Pointer listener); + /// + /// \see ISelectionProvider::GetSelection() + /// + virtual berry::ISelection::ConstPointer GetSelection() const; + /// + /// \see ISelectionProvider::RemoveSelectionChangedListener() + /// + virtual void RemoveSelectionChangedListener(berry::ISelectionChangedListener::Pointer listener); + /// + /// \see ISelectionProvider::SetSelection() + /// + virtual void SetSelection(berry::ISelection::Pointer selection); + /// + /// Sends the nodes as selected to the workbench + /// + void FireNodesSelected( std::vector nodes ); + +protected: + + /// + /// nothing to do here + /// + QmitkFunctionalitySelectionProvider(QmitkFunctionality* _Functionality); + /// + /// nothing to do here + /// + virtual ~QmitkFunctionalitySelectionProvider(); + /// + /// the functionality parent + /// + QmitkFunctionality* m_Functionality; + /// + /// Holds the current selection (selection made by m_Functionality !!!) + /// + mitk::DataNodeSelection::Pointer m_CurrentSelection; + /// + /// The selection events other parts can listen too + /// + berry::ISelectionChangedListener::Events m_SelectionEvents; +}; + +#endif // QMITKFUNCTIONALITYUTIL_H