Difference between revisions of "Views Without Multi Widget"

From mitk.org
Jump to navigation Jump to search
m
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
 
 
==== Motivation ====
 
==== Motivation ====
  
Line 18: Line 17:
 
# In your plug-ins ''manifest_headers.cmake'' file, change the plug-in dependency ''org.mitk.gui.qt.common'' to ''org.mitk.gui.qt.common.legacy''
 
# In your plug-ins ''manifest_headers.cmake'' file, change the plug-in dependency ''org.mitk.gui.qt.common'' to ''org.mitk.gui.qt.common.legacy''
 
   
 
   
<pre><nowiki>
+
<syntaxhighlight lang="cmake">
 
set(Require-Plugin org.mitk.gui.qt.common.legacy)
 
set(Require-Plugin org.mitk.gui.qt.common.legacy)
</nowiki></pre>
+
</syntaxhighlight>
  
 
This will keep your plug-in functional for the time being. However, you should consider migrating your plug-in code to the new API (see below).
 
This will keep your plug-in functional for the time being. However, you should consider migrating your plug-in code to the new API (see below).
Line 30: Line 29:
 
The most prominent change is that you should now inherit your View class from [http://docs.mitk.org/nightly-qt4/classQmitkAbstractView.html QmitkAbstractView] instead of [http://docs.mitk.org/nightly-qt4/classQmitkFunctionality.html QmitkFunctionality] and direct calls to a [http://docs.mitk.org/nightly-qt4/classQmitkStdMultiWidget.html QmitkStdMultiWidget] instance should be avoided.
 
The most prominent change is that you should now inherit your View class from [http://docs.mitk.org/nightly-qt4/classQmitkAbstractView.html QmitkAbstractView] instead of [http://docs.mitk.org/nightly-qt4/classQmitkFunctionality.html QmitkFunctionality] and direct calls to a [http://docs.mitk.org/nightly-qt4/classQmitkStdMultiWidget.html QmitkStdMultiWidget] instance should be avoided.
  
 
+
<syntaxhighlight lang="cpp">
<pre><nowiki>#!highlight cpp
 
 
//#include <QmitkStdMultiWidget.h> <-- Remove this include
 
//#include <QmitkStdMultiWidget.h> <-- Remove this include
 
//#include <QmitkFunctionality.h> <-- Remove this include
 
//#include <QmitkFunctionality.h> <-- Remove this include
Line 38: Line 36:
 
//class MyView : public QmitkFunctionality {...};
 
//class MyView : public QmitkFunctionality {...};
 
class MyView : public QmitkAbstractView {...};
 
class MyView : public QmitkAbstractView {...};
</nowiki></pre>
+
</syntaxhighlight>
 
 
  
 
You must implement the method [http://docs.mitk.org/nightly-qt4/BlueBerry/reference/api/html/structberry_1_1IWorkbenchPart.html#aebf0038640de5c2bed36a325efcbd3d7 SetFocus()]. Previously, an empty default implementation was provided by [http://docs.mitk.org/nightly-qt4/classQmitkFunctionality.html QmitkFunctionality] which generally is not a good default.
 
You must implement the method [http://docs.mitk.org/nightly-qt4/BlueBerry/reference/api/html/structberry_1_1IWorkbenchPart.html#aebf0038640de5c2bed36a325efcbd3d7 SetFocus()]. Previously, an empty default implementation was provided by [http://docs.mitk.org/nightly-qt4/classQmitkFunctionality.html QmitkFunctionality] which generally is not a good default.
  
 
+
<syntaxhighlight lang="cpp">
<pre><nowiki>#!highlight cpp
 
 
void SetFocus()
 
void SetFocus()
 
{
 
{
 
   m_Controls->someWidget->setFocus();
 
   m_Controls->someWidget->setFocus();
 
}
 
}
</nowiki></pre>
+
</syntaxhighlight>
 
 
  
 
You can have a look at a commit fixing the API issues for a very simple plug-in here:
 
You can have a look at a commit fixing the API issues for a very simple plug-in here:
Line 67: Line 62:
 
about a method's usage, please consult its [http://docs.mitk.org/nightly-qt4 Doxygen documentation].
 
about a method's usage, please consult its [http://docs.mitk.org/nightly-qt4 Doxygen documentation].
  
 
+
{| class="wikitable" width=100% style="background-color:#ffffff;"
{| class="wikitable" style="background-color:#ffffff;"
 
 
| '''[http://docs.mitk.org/nightly-qt4/classQmitkFunctionality.html QmitkFunctionality]'''
 
| '''[http://docs.mitk.org/nightly-qt4/classQmitkFunctionality.html QmitkFunctionality]'''
 
| '''[http://docs.mitk.org/nightly-qt4/classQmitkAbstractView.html QmitkAbstractView]'''  
 
| '''[http://docs.mitk.org/nightly-qt4/classQmitkAbstractView.html QmitkAbstractView]'''  
Line 117: Line 111:
 
The direct usage of the [http://docs.mitk.org/nightly-qt4/classQmitkStdMultiWidget.html QmitkStdMultiWidget] API via an instance returned by QmitkFunctionality::GetActiveStdMultiWidget() is now deprecated. Use the table below to look up the corresponding methods offered by the new interfaces.
 
The direct usage of the [http://docs.mitk.org/nightly-qt4/classQmitkStdMultiWidget.html QmitkStdMultiWidget] API via an instance returned by QmitkFunctionality::GetActiveStdMultiWidget() is now deprecated. Use the table below to look up the corresponding methods offered by the new interfaces.
  
{| class="wikitable" style="background-color:#ffffff;"
+
{| class="wikitable" width=100% style="background-color:#ffffff;"
 
| '''[http://docs.mitk.org/nightly-qt4/classQmitkStdMultiWidget.html QmitkStdMultiWidget]'''
 
| '''[http://docs.mitk.org/nightly-qt4/classQmitkStdMultiWidget.html QmitkStdMultiWidget]'''
 
| '''[http://docs.mitk.org/nightly-qt4/structmitk_1_1IRenderWindowPart.html IRenderWindowPart]'''
 
| '''[http://docs.mitk.org/nightly-qt4/structmitk_1_1IRenderWindowPart.html IRenderWindowPart]'''

Revision as of 17:14, 4 December 2014

Motivation

In the past, BlueBerry-based MITK Views always had a hard dependency on the QmitkStdMultiWidget (the big widget with four render windows, in the center of the application). This dependency was partly due to API misuse but also due to the lack of a proper abstraction layer.

Recently, more use cases popped up which require a specialized render window editor. However the functionality offered by most MITK Views is tied to the QmitkStdMultiWidget although they would theoretically be functional in a much broader scope.


Recent Changes

To enable MITK Views to work together with an abstract render window editor, the work on bug #10963 has been merged into MITK master on 23.02.2012.

If you wrote your own MITK View it is likely that you will be affected by these changes. The changes make it necessary that you take one of two possible actions in order to keep your View working:

  1. In your plug-ins manifest_headers.cmake file, change the plug-in dependency org.mitk.gui.qt.common to org.mitk.gui.qt.common.legacy

<syntaxhighlight lang="cmake"> set(Require-Plugin org.mitk.gui.qt.common.legacy) </syntaxhighlight>

This will keep your plug-in functional for the time being. However, you should consider migrating your plug-in code to the new API (see below).

  1. Keep your plug-in dependencies as they are and fix your plug-in code. See the guideline below.


Fixing API usage

The most prominent change is that you should now inherit your View class from QmitkAbstractView instead of QmitkFunctionality and direct calls to a QmitkStdMultiWidget instance should be avoided.

<syntaxhighlight lang="cpp"> //#include <QmitkStdMultiWidget.h> <-- Remove this include //#include <QmitkFunctionality.h> <-- Remove this include

  1. include <QmitkAbstractView.h>

//class MyView : public QmitkFunctionality {...}; class MyView : public QmitkAbstractView {...}; </syntaxhighlight>

You must implement the method SetFocus(). Previously, an empty default implementation was provided by QmitkFunctionality which generally is not a good default.

<syntaxhighlight lang="cpp"> void SetFocus() {

 m_Controls->someWidget->setFocus();

} </syntaxhighlight>

You can have a look at a commit fixing the API issues for a very simple plug-in here:

https://github.com/MITK/MITK-ProjectTemplate/commit/5ccc8d0048848e2c2968f1f64d8467bc0901df9b


API changes

The QmitkFunctionality API has been replaced by the one provided by QmitkAbstractView, mitk::IRenderWindowPart, and related interfaces.


QmitkFunctionality API Mapping

The following table maps the deprecated QmitkFunctionality API to the new API offered by QmitkAbstractView or related interfaces. If you are unsure about a method's usage, please consult its Doxygen documentation.

QmitkFunctionality QmitkAbstractView
void OnSelectionChanged(std::vector<mitk::DataNode*>) void OnSelectionChanged(berry::IWorkbenchPart::Pointer, const QList<mitk::DataNode::Pointer>&)
mitk::DataStorage::Pointer GetDefaultDataStorage() mitk::DataStorage::Pointer GetDataStorage()
bool IsActivated() X (remeber the state yourself by implementing the mitk::ILifecycleAwarePart interface)
QmitkStdMultiWidget* GetActiveStdMultiWidget(bool) mitk::IRenderWindowPart* GetRenderWindowPart(IRenderWindowPartStrategies)
m_Parent X (remember the parent yourself in CreateQtPartControl(QWidget*) )
bool IsExclusiveFunctionality() X (implement the mitk::IZombieViewPart interface to indicate special behavior)
mitk::IRenderWindowPartListener
void StdMultiWidgetAvailable(QmitkStdMultiWidget&) void RenderWindowPartActivated(mitk::IRenderWindowPart*)
mitk::ILifecycleAwarePart
void Visible() void Visible()
void Hidden() void Hidden()
mitk::IZombieViewPart
void Deactivated() void ActivatedZombieView (berry::IWorkbenchPartReference::Pointer)


QmitkStdMultiWidget API Mapping

The direct usage of the QmitkStdMultiWidget API via an instance returned by QmitkFunctionality::GetActiveStdMultiWidget() is now deprecated. Use the table below to look up the corresponding methods offered by the new interfaces.

QmitkStdMultiWidget IRenderWindowPart ILinkedRenderWindowPart
GetTimeNavigationController() GetTimeNavigationController()
GetRenderWindow[X]() GetRenderWindow(const QString&)
GetCrossPosition() GetSelectedPosition()
MoveCrossToPosition(const mitk::Point3D&) SetSelectedPosition()
GetSlicesRotator() GetSlicesRotator()
GetSlicesSwiveller() GetSlicesSwiveller()
SetWidgetPlanesVisibility(bool) EnableSlicingPlanes(bool)
RequestUpdate() RequestUpdate()
ForceImmediateUpdate() ForceImmediateUpdate()
DisableColoredRectangles() EnableDecorations(false, QStringList(DECORATION_BORDER))
DisableDepartmentLogo() EnableDecorations(false, QStringList(DECORATION_LOGO))
DisableGradientBackground() EnableDecorations(false, QStringList(DECORATION_BACKGROUND))

Calls to the global mitk::RenderingManager instance should be replaced by calls to the mitk::IRenderingManager instance returned by the mitk::IRenderWindowPart::GetRenderingManager() method.

If a rendering update is requested from a QmitkAbstractView subclass, the request should be done by calling QmitkAbstractView::RequestRenderWindowUpdate().