Documentation/4.10/Developers/Layouts

From Slicer Wiki
Jump to: navigation, search
Home < Documentation < 4.10 < Developers < Layouts


For the latest Slicer documentation, visit the read-the-docs.


Layout

Main classes

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";
}