Documentation/Nightly/Developers/Layouts
From Slicer Wiki
Home < Documentation < Nightly < Developers < Layouts
For the latest Slicer documentation, visit the read-the-docs. |
Contents
Layout
Main classes
- vtkMRMLLayoutNode: Node that describes the layout of the views. There is only one layout node in the scene (singleton)
- vtkMRMLLayoutLogic: Control/observe the layout node. Automatically create the view nodes if needed (referenced in the layout node description but not in the scene).
- vtkMRMLAbstractViewNode: Abstract class for all the view nodes (such as vtkMRMLSliceNode, vtkMRMLViewNode, vtkMRMLChartViewNode) that can be into a layout.
ctkLayoutManager
: Mechanism to convert the layout description (xml) into a Qt layout with Qt widgets.- qMRMLLayoutManager: Specialized version of ctkLayoutManager to handle MRML only views and properties.
- qSlicerLayoutManager: Specialized version of qMRMLLayoutManager to handle Slicer specific behaviors. The Slicer layout manager is accessible from the qSlicerApplication singleton.
Layout mechanism
How to change the layout ?
How to register a new layout ?
qMRMLLayoutSliceViewFactory* mrmlSliceViewFactory = qobject_cast<qMRMLLayoutSliceViewFactory*>( d->app->layoutManager()->mrmlViewFactory("vtkMRMLSliceNode")); qSlicerCustomLayoutSliceViewFactory* customSliceViewFactory = new qSlicerCustomLayoutSliceViewFactory(d->app->layoutManager()); customSliceViewFactory->setSliceLogics(mrmlSliceViewFactory->sliceLogics()); d->app->layoutManager()->unregisterViewFactory(mrmlSliceViewFactory); d->app->layoutManager()->registerViewFactory(customSliceViewFactory);
View XML elements
vtkMRMLLayoutNode* layoutNode = vtkMRMLLayoutNode::SafeDownCast( this->mrmlScene()->GetSingletonNode("vtkMRMLLayoutNode","vtkMRMLLayoutNode")); std::string layoutDescription = layoutNode->GetLayoutDescription(index);
Layout descriptions can be modified using the SetLayoutDescription method
Example
Example of qSlicerCustomLayoutSliceViewFactory:
#ifndef __qSlicerAstroVolumeLayoutSliceViewFactory_h #define __qSlicerAstroVolumeLayoutSliceViewFactory_h // SlicerQt includes #include "qMRMLLayoutManager.h" #include "qMRMLLayoutManager_p.h" // VTK includes #include <vtkWeakPointer.h> #include "qSlicerAstroVolumeModuleExport.h" class qSlicerAstroVolumeLayoutSliceViewFactoryPrivate; /// \ingroup Slicer_QtModules_AstroVolume class Q_SLICER_QTMODULES_ASTROVOLUME_EXPORT qSlicerAstroVolumeLayoutSliceViewFactory : public qMRMLLayoutSliceViewFactory { Q_OBJECT public: typedef qMRMLLayoutSliceViewFactory Superclass; qSlicerAstroVolumeLayoutSliceViewFactory(QObject* parent); virtual ~qSlicerAstroVolumeLayoutSliceViewFactory(); virtual QString viewClassName()const; protected: virtual QWidget* createViewFromNode(vtkMRMLAbstractViewNode* viewNode); virtual void deleteView(vtkMRMLAbstractViewNode* viewNode); private: Q_DECLARE_PRIVATE(qSlicerAstroVolumeLayoutSliceViewFactory); Q_DISABLE_COPY(qSlicerAstroVolumeLayoutSliceViewFactory); }; #endif
//----------------------------------------------------------------------------- qSlicerAstroVolumeLayoutSliceViewFactory::qSlicerAstroVolumeLayoutSliceViewFactory(QObject* _parent) : Superclass(_parent) { } //----------------------------------------------------------------------------- qSlicerAstroVolumeLayoutSliceViewFactory::~qSlicerAstroVolumeLayoutSliceViewFactory() { } //----------------------------------------------------------------------------- QWidget* qSlicerAstroVolumeLayoutSliceViewFactory::createViewFromNode(vtkMRMLAbstractViewNode* viewNode) { if (!this->layoutManager() || !viewNode) {// can't create a slice widget if there is no parent widget Q_ASSERT(viewNode); return 0; } // there is a unique slice widget per node Q_ASSERT(!this->viewWidget(viewNode)); qMRMLSliceAstroWidget * sliceWidget = new qMRMLSliceAstroWidget(this->layoutManager()->viewport()); sliceWidget->sliceController()->setControllerButtonGroup(this->SliceControllerButtonGroup); QString sliceLayoutName(viewNode->GetLayoutName()); QString sliceViewLabel(viewNode->GetLayoutLabel()); vtkMRMLSliceNode* sliceNode = vtkMRMLSliceNode::SafeDownCast(viewNode); QColor sliceLayoutColor = QColor::fromRgbF(sliceNode->GetLayoutColor()[0], sliceNode->GetLayoutColor()[1], sliceNode->GetLayoutColor()[2]); sliceWidget->setSliceViewName(sliceLayoutName); sliceWidget->setObjectName(QString("qMRMLSliceWidget" + sliceLayoutName)); sliceWidget->setSliceViewLabel(sliceViewLabel); sliceWidget->setSliceViewColor(sliceLayoutColor); sliceWidget->setMRMLScene(this->mrmlScene()); sliceWidget->setMRMLSliceNode(sliceNode); sliceWidget->setSliceLogics(this->sliceLogics()); this->sliceLogics()->AddItem(sliceWidget->sliceLogic()); return sliceWidget; } void qSlicerAstroVolumeLayoutSliceViewFactory::deleteView(vtkMRMLAbstractViewNode *viewNode) { qMRMLSliceAstroWidget* sliceWidget = qobject_cast<qMRMLSliceAstroWidget*>(this->viewWidget(viewNode)); if (sliceWidget) { this->sliceLogics()->RemoveItem(sliceWidget->sliceLogic()); } this->Superclass::deleteView(viewNode); } QString qSlicerAstroVolumeLayoutSliceViewFactory::viewClassName() const { return "vtkMRMLSliceNode"; }