close

Вход

Забыли?

вход по аккаунту

?

QtPortInSlicer - How to write a module

код для вставкиСкачать
Port of 3D Slicer to Qt
Julien Finet & Jean-Christophe Fillion-Robin
Kitware Inc.
June 22th 2010
Background
тАв Slicer version 3.x use KWWidgets
тАУ VTK-style interface to Tk
тАУ 3D Slicer 1.x, 2.x used Tk directly
тАв Qt
тАУ Embedded Linux, Mac OS X, Windows,
Linux/X11, Windows CE/Mobile, Symbian,
Maemo
тАУ Commercial/LGPL
тАУ 600+ classes
тАУ Tens of thousands of applications
тАУ 15+ millions of users
Qt тАУ How to get Qt
тАв Required version: Qt 4.6.2
тАв Building Slicer with Qt
тАУ Use Superbuild
тАУ http://www.slicer.org/slicerWiki/index.php/Slice
r4:Build_Instructions
Events with KWWidgets
1. Connect
vtkCallbackCommand
vtkObject::AddObserver
2. Fire event
vtkObject::InvokeEvent()
3. Process
myClass::myMethod()
Events with KWWidgets
Node
Selected
Event
Object 1
Object2
Callback
Object 2
Events with KWWidgets
1) Connect
this->CallbackCommand = vtkCallbackCommand::New();
this->CallbackCommand->SetClientData(object2);
this->CallbackCommand->SetCallback(vtkObject2::MethodX);
Node
Selected
Event
Object 1
Object2
Callback
Object 2
MethodX
Events with KWWidgets
1) Connect
object1>AddObserver(vtkObject1::NodeSelectedEvent,
this>CallbackCommand);
Node
Selected
Event
Object 1
Object2
Callback
Object 2
Events with KWWidgets
2) Signal
void vtkObject1::Method2(){
тАж
this->InvokeEvent(vtkObject1::NodeSelectedEvent, NULL);
}
Node
Selected
Event
Object 1
Method2
Object2
Callback
Object 2
Events with KWWidgets
3) Process
void vtkObject2::MethodX(vtkObject *caller, unsigned long event, void *callData )
{
if (vtkObject2::SafeDownCast(caller) && event == vtkObject2::NodeSelectedEvent)
{
тАж
Node
Selected
Event
Object 1
Object2
Callback
Object 2
MethodX
Events with Qt
1. Connect
QObject::connect(obj1,signal, obj2, slot);
2. Fire event
emit mySignal();
3. Process
myClass::mySlot();
Events with Qt
Node
Selected
Signal
Object 1
Object 2
Events with Qt
1) Connect
this->QObject::connect(obj1, SIGNAL(nodeSelected(vtkMRMLNode*)),
obj2, SLOT(methodX(vtkMRMLNode*)));
Node
Selected
Signal
Object 1
Object 2
Events with Qt
2) Signal
void vtkObject1::Method2(){
тАж
emit this->currentNodeSelected(node);
}
Node
Selected
Signal
Object 1
Object 2
Events with Qt
3) Process
void vtkObject2::MethodX(vtkMRMLNode* node)
{
тАж
}
Node
Selected
Signal
Object 1
Object 2
MethodX
Qt and VTK: qVTKConnect
тАв qvtkConnect(
vtkObject* vtk_obj,
unsigned long vtk_event,
const QObject* qt_obj,
const char* qt_slot,
float priority = 0.0)
тАв Also: qvtkReconnect, qvtkDisconnect,
qvtkDisconnectAllтАж
Qt and VTK: qVTKConnect
Usage
QVTK_OBJECT adds
the function qvtkConnect()
тАж
// CTK includes
#include <ctkVTKObject.h>
тАж
class MyWidget: public QWidget
{
Q_OBJECT
QVTK_OBJECT
public:
void setNode(vtkMRMLNode* mrmlNode);
protected slots:
void onMRMLNodeModified(vtkObject* sender);
};
void MyWidget
::setNode(vtkMRMLNode* mrmlNode)
{
тАж
qvtkConnect(
mrmlNode,
vtkCommand::ModifiedEvent,
this,
SLOT(onMRMLNodeModified(vtkObject*)));
тАж
}
void MyWidget
::onMRMLNodeModified(vtkObject* sender)
{
vtkMRMLNode* node =
vtkMRMLNode::SafeDowncast(sender);
тАж
}
Interaction between MRML & Qt
valueChanged
(double)
Modified
Event
Qt Slider
MRML Node
Module
Widget
void onNodeModified( vtkMRMLNode* node)
{
slider->setValue(node->GetValue());
}
void onValueChanged(double newValue)
{
node->SetValue(newValue);
}
Private Implementation
тАв Hide the implementation details of an
interface
тАв http://en.wikipedia.org/wiki/Opaque_pointer
#include "qCTKPimpl.h"
тАж
class MyButtonPrivate;
тАж
class MyButton : public QAbstractButton
{
Q_OBJECT
public:
тАж
private:
CTK_DECLARE_PRIVATE(MyButton);
};
friend
DonтАЩt forget to declare the private class
class MyButtonPrivate;
ctkPrivateInterface<MyButton, MyButtonPrivate> ctk_d;
Private Implementation
class MyButtonPrivate : public
qCTKPrivate<MyButton>
{
public:
CTK_DECLARE_PUBLIC(MyButton);
void init();
bool Collapsed;
тАж
};
void MyButtonPrivate::init()
{
CTK_P(MyButton);
MyButton* p = ctk_p()
p->setCheckable(true);
this->Collapsed = false;
}
MyButtonPrivate* d = ctk_d()
MyButton::MyButton(QWidget* parent)
:QAbstractButton(parent)
{
CTK_INIT_PRIVATE(MyButton);
ctk_d()->init();
}
void MyButton::collapse(bool c)
{
CTK_D(MyButton);
if (c == d->Collapsed)
{
return;
}
тАж
}
Slicer3 vs SlicerQt
тАв SlicerQt
Qt only
тАв Slicer3
KWWidgets + Qt
Slicer Architecture
Base/Logic
Base/QTCore
Base/QTGUI
MRML
Slicer
qMRML
Widgets
CTK
Core
QtCore
CTK
Widgets
QtGUI
Modules
тАв Core Modules: Slicer3/Base/QTCoreModules
тАУ Transforms qSlicerTransformsModule
тАУтАж
тАв Loadable Modules: Slicer3/QTModules
тАУ TractographyFiducialSeeding
libqSlicerTractographyFiducialSeedingModule.so
тАУ Volumes libqSlicerVolumesModule.so
тАУ тАж
тАв CLI Modules: Slicer3/Applications/CLI
тАУтАж
QTCLI
тАв Same idea than KWWidgets
тАУ Parse XML to build UI
тАв Support
тАУ Shared Libraries
тАУ Executables
тАУ Python
UI panel in Slicer
3) Dynamically created panel
QTCLI: Example
1) Xml description
тАж
<parameters>
<label>Registration Parameters</label>
<description>Parameters used for registration</description>
<integer>
<name>HistogramBins</name>
<flag>b</flag>
<longflag>histogrambins</longflag>
<description>Number of histogram bins to use for Mattes
Mutual Information. </description>
<label>Histogram Bins</label>
<default>30</default>
<constraints>
<minimum>1</minimum>
<maximum>500</maximum>
<step>5</step>
</constraints>
</integer>
тАж
тАж
If (paramType == тАЬintegerтАЭ)
{
QSlider* intParameter = new QSlider(registrationParameters);
intParameter->setMinimum(paramMin);
intParameter->setMaximum(paramMax);
intParameter->setStep(paramStep);
intParameter->setValue(paramValue);
QObject::connect(intParameter, SIGNAL(valueChanged(int)), this, SIGNAL(onParamValueChanged(int)));
}
else if (paramType == тАЬdoubleтАЭ)
тАж
2) Parse parameters and generate UI
Plugin Mechanism
тАв Previously: itksys::DynamicLoader(dlopen)
тАв Now: Use the QT Plugins framework
тАж
class Q_SLICER_QTMODULES_VOLUMES_EXPORT qSlicerVolumesModule :
public qSlicerAbstractLoadableModule
{
Q_INTERFACES(qSlicerAbstractLoadableModule);
public:
тАж
};
тАж
Q_EXPORT_PLUGIN2(qSlicerVolumesModule, qSlicerVolumesModule);
тАж
QPluginLoader loader;
loader.setFileName(pluginPath);
loader.load();
QObject * object = this->Loader.instance();
qSlicerAbstractLoadableModule* module = qobject_cast<qSlicerAbstractLoadableModule*>(object);
Plugin header
Plugin implementation
Plugin Loader
Loadable Modules: Logic + UI
Module Plugin
(qSlicerAbstractModule)
create()
create()
Module Widget
(qSlicerAbstractModuleWidget)
Logic
(vtkSlicerModuleLogic)
Module Designer UI
qSlicerтАжModuleWidget.ui
vtkMRMLScene
Widgets Awareness
Library
QTCore QtGui VTK
CTK/Libs/Core
Yes
CTK/Libs/Widgets
Yes
CTK/Libs/Visualization/VTK/Core
Yes
Yes
CTK/Libs/Visualization/VTK/Widgets
Yes
Yes
Slicer3/Libs/qMRMLWidgets
Yes
Slicer3/Base/QTCore
Yes
Slicer3/Base/QTGUI
Yes
MRML App.
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
CTK Widgets commontk.org
тАв http://www.commontk.org/index.php/Documentation/ImageGallery
ctkFixedTitleComboBox
ctkCollapsibleGroupBox
ctkCollapsibleButton
ctkColorPickerButton
ctkTreeComboBox
qMRMLWidgets
тАв http://wiki.slicer.org/slicerWiki/index.php/Slicer3:Developers:
Projects:QtSlicer/Gallery
тАв Usually contains the slot setMRMLScene(vtkMRMLScene*)
qMRMLNodeSelector
qMRMLListWidget
qMRMLWindowLevelWidget
qMRMLTreeWidget
Widgets in Qt Designer
тАв A plugin must be created
тАУ Slicer3/Libs/qMRMLWidgets/Plugins/qMRMLNodeSel
ectorPlugin.[h|cxx]
тАв More info on
тАУ http://wiki.slicer.org/slicerWiki/index.php/Slicer3:Devel
opers:Projects:QtSlicer/Tutorials/WidgetWriting
Widget Example
Qt Designer
class QCTK_WIDGETS_EXPORT qCTKCollapsibleButton :
public QAbstractButton
{
Q_OBJECT
Q_PROPERTY(bool collapsed READ collapsed WRITE setCollapsed)
Q_PROPERTY(int collapsedHeight READ collapsedHeight
WRITE setCollapsedHeight)
тАж
public:
void setCollapsed(bool);
bool collapsed()const;
void setCollapsedHeight(int);
int collapsedHeight()const;
qCTKCollapsibleButton.h
10 = default value
void qCTKCollapsibleButtonPrivate::init()
{
QCTK_P(qCTKCollapsibleButton);
тАж
this->Collapsed = false;
тАж
this->CollapsedHeight = 10;
тАж
}
qCTKCollapsibleButton.cxx
Questions
тАв More info:
http://wiki.slicer.org/slicerWiki/index.php/Sli
cer3:Developers:Projects:QtSlicer
Документ
Категория
Презентации по английскому языку
Просмотров
30
Размер файла
3 606 Кб
Теги
1/--страниц
Пожаловаться на содержимое документа