1.主要的类
- vtkMRMLLayoutNode: 描述视图布局的节点,一个场景只存在一个布局节点。
- vtkMRMLLayoutLogic: 控制/观测图层节点,如果需要会自动创建视图节点(在布局节点描述中引用,而不是场景中引用)。
- vtkMRMLAbstractViewNode: 所有视图节点的抽象类(例如vtkMRMLSliceNode, vtkMRMLViewNode, vtkMRMLChartViewNode) 。
- ctkLayoutManager: 将布局描述(XML)转换成Qt布局的机制。
- qMRMLLayoutManager:ctkLayoutManager 的专用版本,只处理MRML的视图与属性。
- qSlicerLayoutManager: qMRMLLayoutManager 的专用版本,处理Slicer的特定行为。Slicer图层管理器可以通过qSlicerApplication访问。
2.如何注册一个新的布局layout?
1 qMRMLLayoutSliceViewFactory* mrmlSliceViewFactory =
2 qobject_cast<qMRMLLayoutSliceViewFactory*>(
3 d->app->layoutManager()->mrmlViewFactory("vtkMRMLSliceNode"));
4
5 qSlicerCustomLayoutSliceViewFactory* customSliceViewFactory =
6 new qSlicerCustomLayoutSliceViewFactory(d->app->layoutManager());
7 customSliceViewFactory->setSliceLogics(mrmlSliceViewFactory->sliceLogics());
8
9 d->app->layoutManager()->unregisterViewFactory(mrmlSliceViewFactory);
10 d->app->layoutManager()->registerViewFactory(customSliceViewFactory);
3.View XML(Layout description) elements
1 vtkMRMLLayoutNode* layoutNode = vtkMRMLLayoutNode::SafeDownCast(
2 this->mrmlScene()->GetSingletonNode("vtkMRMLLayoutNode","vtkMRMLLayoutNode"));
3 std::string layoutDescription = layoutNode->GetLayoutDescription(index);
采用 SetLayoutDescription方法可以修改布局描述XML。
4.示例:自定义布局 qSlicerCustomLayoutSlicerViewFactory
1 #ifndef __qSlicerAstroVolumeLayoutSliceViewFactory_h
2 #define __qSlicerAstroVolumeLayoutSliceViewFactory_h
3
4 // SlicerQt includes
5 #include "qMRMLLayoutManager.h"
6 #include "qMRMLLayoutManager_p.h"
7
8 // VTK includes
9 #include <vtkWeakPointer.h>
10 #include "qSlicerAstroVolumeModuleExport.h"///
11
12 class qSlicerAstroVolumeLayoutSliceViewFactoryPrivate;
13
14 /// \ingroup Slicer_QtModules_AstroVolume
15 class Q_SLICER_QTMODULES_ASTROVOLUME_EXPORT qSlicerAstroVolumeLayoutSliceViewFactory
16 : public qMRMLLayoutSliceViewFactory
17 {
18 Q_OBJECT
19 public:
20 typedef qMRMLLayoutSliceViewFactory Superclass;
21 qSlicerAstroVolumeLayoutSliceViewFactory(QObject* parent);
22 virtual ~qSlicerAstroVolumeLayoutSliceViewFactory();
23
24 virtual QString viewClassName()const;
25
26 protected:
27
28 virtual QWidget* createViewFromNode(vtkMRMLAbstractViewNode* viewNode);
29 virtual void deleteView(vtkMRMLAbstractViewNode* viewNode);
30
31 private:
32 Q_DECLARE_PRIVATE(qSlicerAstroVolumeLayoutSliceViewFactory);
33 Q_DISABLE_COPY(qSlicerAstroVolumeLayoutSliceViewFactory);
34 };
35
36 #endif
1 //-----------------------------------------------------------------------------
2 qSlicerAstroVolumeLayoutSliceViewFactory::qSlicerAstroVolumeLayoutSliceViewFactory(QObject* _parent)
3 : Superclass(_parent)
4 {
5 }
6
7 //-----------------------------------------------------------------------------
8 qSlicerAstroVolumeLayoutSliceViewFactory::~qSlicerAstroVolumeLayoutSliceViewFactory()
9 {
10 }
11 //-----------------------------------------------------------------------------
12 QWidget* qSlicerAstroVolumeLayoutSliceViewFactory::createViewFromNode(vtkMRMLAbstractViewNode* viewNode)
13 {
14 if (!this->layoutManager() || !viewNode)
15 {// can't create a slice widget if there is no parent widget
16 Q_ASSERT(viewNode);
17 return 0;
18 }
19
20 // there is a unique slice widget per node
21 Q_ASSERT(!this->viewWidget(viewNode));
22
23 qMRMLSliceAstroWidget * sliceWidget = new qMRMLSliceAstroWidget(this->layoutManager()->viewport());
24 sliceWidget->sliceController()->setControllerButtonGroup(this->SliceControllerButtonGroup);
25 QString sliceLayoutName(viewNode->GetLayoutName());
26 QString sliceViewLabel(viewNode->GetLayoutLabel());
27 vtkMRMLSliceNode* sliceNode = vtkMRMLSliceNode::SafeDownCast(viewNode);
28 QColor sliceLayoutColor = QColor::fromRgbF(sliceNode->GetLayoutColor()[0],
29 sliceNode->GetLayoutColor()[1],
30 sliceNode->GetLayoutColor()[2]);
31 sliceWidget->setSliceViewName(sliceLayoutName);
32 sliceWidget->setObjectName(QString("qMRMLSliceWidget" + sliceLayoutName));
33 sliceWidget->setSliceViewLabel(sliceViewLabel);
34 sliceWidget->setSliceViewColor(sliceLayoutColor);
35 sliceWidget->setMRMLScene(this->mrmlScene());
36 sliceWidget->setMRMLSliceNode(sliceNode);
37 sliceWidget->setSliceLogics(this->sliceLogics());
38
39 this->sliceLogics()->AddItem(sliceWidget->sliceLogic());
40
41 return sliceWidget;
42 }
43
44 void qSlicerAstroVolumeLayoutSliceViewFactory::deleteView(vtkMRMLAbstractViewNode *viewNode)
45 {
46 qMRMLSliceAstroWidget* sliceWidget =
47 qobject_cast<qMRMLSliceAstroWidget*>(this->viewWidget(viewNode));
48 if (sliceWidget)
49 {
50 this->sliceLogics()->RemoveItem(sliceWidget->sliceLogic());
51 }
52 this->Superclass::deleteView(viewNode);
53 }
54
55 QString qSlicerAstroVolumeLayoutSliceViewFactory::viewClassName() const
56 {
57 return "vtkMRMLSliceNode";
58 }