An update will be applied December 9th, between 12PM and 1:00PM EST (UTC -5:00). The site may be slow during that time.

Commit 6ad6fff7 authored by finetjul's avatar finetjul
Browse files

ENH: Redesign qSlicerModuleRepresentation, rework on showModuleAction()

git-svn-id: http://svn.slicer.org/Slicer4/trunk@14375 3bd1e089-480b-0410-8dfb-8563597acbee
parent 4b10a669
......@@ -182,14 +182,6 @@ qSlicerAbstractModuleRepresentation* qSlicerAbstractModule::widgetRepresentation
return 0;
}
d->WidgetRepresentation->setModule(this);
// Note: WidgetRepresentation->setLogic should be called before
// WidgetRepresentation->setMRMLScene() because some methods
// might need a logic when a MRML scene is set.
if (d->Logic)
{
d->WidgetRepresentation->setLogic(d->Logic);
}
d->WidgetRepresentation->setName(this->name());
d->WidgetRepresentation->setup();
// Note: setMRMLScene should be called after setup (just to make sure widgets
// are well written and can handle empty mrmlscene
......
......@@ -25,8 +25,8 @@ class qSlicerAbstractModuleRepresentationPrivate: public ctkPrivate<qSlicerAbstr
{
public:
qSlicerAbstractModuleRepresentationPrivate();
QString Name;
vtkWeakPointer<vtkSlicerLogic> Logic;
private:
CTK_DECLARE_PUBLIC(qSlicerAbstractModuleRepresentation);
qSlicerAbstractModule* Module;
......@@ -56,8 +56,17 @@ qSlicerAbstractModuleRepresentation::~qSlicerAbstractModuleRepresentation()
}
//-----------------------------------------------------------------------------
CTK_SET_CXX(qSlicerAbstractModuleRepresentation, const QString&, setName, Name);
CTK_GET_CXX(qSlicerAbstractModuleRepresentation, QString, name, Name);
QAction* qSlicerAbstractModuleRepresentation::createAction()
{
return 0;
}
//-----------------------------------------------------------------------------
QString qSlicerAbstractModuleRepresentation::moduleName()const
{
CTK_D(const qSlicerAbstractModuleRepresentation);
return d->Module->name();
}
//-----------------------------------------------------------------------------
vtkSlicerLogic* qSlicerAbstractModuleRepresentation::logic()const
......@@ -67,12 +76,10 @@ vtkSlicerLogic* qSlicerAbstractModuleRepresentation::logic()const
}
//-----------------------------------------------------------------------------
void qSlicerAbstractModuleRepresentation::setLogic(vtkSlicerLogic* _logic)
const qSlicerAbstractModule* qSlicerAbstractModuleRepresentation::module()const
{
// setLogic should be called only one time with valid object...
Q_ASSERT(_logic);
CTK_D(qSlicerAbstractModuleRepresentation);
d->Logic = _logic;
CTK_D(const qSlicerAbstractModuleRepresentation);
return d->Module;
}
//-----------------------------------------------------------------------------
......@@ -80,4 +87,5 @@ void qSlicerAbstractModuleRepresentation::setModule(qSlicerAbstractModule* modul
{
CTK_D(qSlicerAbstractModuleRepresentation);
d->Module = module;
d->Logic = module ? module->logic() : 0;
}
......@@ -38,28 +38,30 @@ public:
///
/// Return the action allowing to show the module
virtual QAction* showModuleAction() { return 0; }
/// 0 by default
virtual QAction* createAction();
///
/// Set/Get module name
virtual void setName(const QString& moduleName);
QString name()const;
QString moduleName()const;
protected:
///
/// All inialization code should be done in the setup
virtual void setup() = 0;
///
/// Set/Get associated Logic
void setLogic(vtkSlicerLogic* logic);
/// Return the logic of the module
vtkSlicerLogic* logic() const;
const qSlicerAbstractModule* module()const;
private:
CTK_DECLARE_PRIVATE(qSlicerAbstractModuleRepresentation);
void setModule(qSlicerAbstractModule* module);
/// Give access to qSlicerAbstractModule to the method qSlicerAbstractModuleRepresentation::setLogic
/// Give access to qSlicerAbstractModule to the method
/// qSlicerAbstractModuleRepresentation::setModule
friend class qSlicerAbstractModule;
void setModule(qSlicerAbstractModule* module);
};
#endif
......@@ -13,6 +13,10 @@
<property name="windowTitle">
<string>Colors</string>
</property>
<property name="windowIcon">
<iconset resource="../qSlicerBaseQTCoreModules.qrc">
<normaloff>:/Icons/Colors.png</normaloff>:/Icons/Colors.png</iconset>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="ctkCollapsibleButton" name="DisplayCollapsibleButton">
......@@ -284,7 +288,9 @@
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<resources>
<include location="../qSlicerBaseQTCoreModules.qrc"/>
</resources>
<connections>
<connection>
<sender>qSlicerColorsModule</sender>
......
......@@ -13,6 +13,10 @@
<property name="windowTitle">
<string>Data</string>
</property>
<property name="windowIcon">
<iconset resource="../qSlicerBaseQTCoreModules.qrc">
<normaloff>:/Icons/Data.png</normaloff>:/Icons/Data.png</iconset>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3iew">
<item>
<widget class="ctkCollapsibleButton" name="DisplayModifiyButton">
......
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
<file>Icons/Cameras.png</file>
<file>Icons/Colors.png</file>
<file>Icons/Data.png</file>
<file>Icons/LoadTransform.png</file>
<file>Icons/Transforms.png</file>
</qresource>
</RCC>
\ No newline at end of file
</RCC>
......@@ -48,12 +48,6 @@ void qSlicerCamerasModuleWidget::setup()
this, SLOT(onCameraNodeRemoved(vtkMRMLNode*)));
}
//-----------------------------------------------------------------------------
QAction* qSlicerCamerasModuleWidget::showModuleAction()
{
return new QAction(QIcon(":/Icons/Cameras.png"), tr("Show Cameras module"), this);
}
//-----------------------------------------------------------------------------
void qSlicerCamerasModuleWidget::onCurrentViewNodeChanged(vtkMRMLNode* mrmlNode)
{
......
......@@ -35,8 +35,6 @@ public:
typedef qSlicerAbstractModuleWidget Superclass;
qSlicerCamerasModuleWidget(QWidget *parent=0);
virtual QAction* showModuleAction();
public slots:
///
/// Inherited from qSlicerWidget. Reimplemented for refresh issues.
......
......@@ -38,9 +38,3 @@ void qSlicerMRMLTreeModuleWidget::setup()
d->setupUi(this);
}
//-----------------------------------------------------------------------------
QAction* qSlicerMRMLTreeModuleWidget::showModuleAction()
{
return new QAction(QIcon(":/Icons/Data.png"), tr("Show MRMLTree module"), this);
}
......@@ -34,8 +34,6 @@ public:
typedef qSlicerAbstractModuleWidget Superclass;
qSlicerMRMLTreeModuleWidget(QWidget *parent=0);
virtual QAction* showModuleAction();
protected:
virtual void setup();
......
......@@ -103,12 +103,6 @@ void qSlicerTransformsModuleWidget::setup()
d->LoadTransformPushButton->setIcon(openIcon);
}
//-----------------------------------------------------------------------------
QAction* qSlicerTransformsModuleWidget::showModuleAction()
{
return new QAction(QIcon(":/Icons/Transforms.png"), tr("Show Transforms module"), this);
}
//-----------------------------------------------------------------------------
void qSlicerTransformsModuleWidget::onCoordinateReferenceButtonPressed(int id)
{
......
......@@ -36,8 +36,6 @@ public:
typedef qSlicerAbstractModuleWidget Superclass;
qSlicerTransformsModuleWidget(QWidget *parent=0);
virtual QAction* showModuleAction();
public slots:
void loadTransform();
......
......@@ -10,7 +10,12 @@
=========================================================================auto=*/
// Qt includes
#include <QAction>
#include <QIcon>
// SlicerQt includes
#include "qSlicerAbstractModule.h"
#include "qSlicerAbstractModuleWidget.h"
//-----------------------------------------------------------------------------
......@@ -20,15 +25,15 @@ qSlicerAbstractModuleWidget::qSlicerAbstractModuleWidget(QWidget* parentWidget)
}
//-----------------------------------------------------------------------------
void qSlicerAbstractModuleWidget::setName(const QString& name)
QAction* qSlicerAbstractModuleWidget::createAction()
{
this->qSlicerAbstractModuleRepresentation::setName(name);
// better than nothing but still not that...
this->setWindowTitle(name);
QAction* action = new QAction(this->windowIcon(), this->module()->title(), this);
action->setData(this->module()->name());
return action;
}
//-----------------------------------------------------------------------------
QAction* qSlicerAbstractModuleWidget::showModuleAction()
void qSlicerAbstractModuleWidget::setup()
{
return 0;
this->setWindowTitle(module()->title());
}
......@@ -38,15 +38,12 @@ public:
/// \sa QWidget
qSlicerAbstractModuleWidget(QWidget *parent=0);
///
/// Reimplemented from qSlicerAbstractModuleRepresentation
/// Set the module unique name to the window title of the widget
virtual void setName(const QString& moduleName);
///
/// Returns a QAction if the module would like to be added in a toolbar.
/// By default, returns no QAction.
virtual QAction * showModuleAction();
virtual QAction * createAction();
protected:
virtual void setup();
};
#endif
......@@ -76,7 +76,7 @@ void qSlicerModulePanel::setModule(const QString& moduleName)
if (currentModuleWidget)
{
// Remove the current module
this->removeModule(currentModuleWidget->name());
this->removeModule(currentModuleWidget->moduleName());
}
if (module)
......@@ -107,7 +107,7 @@ void qSlicerModulePanel::addModule(const QString& moduleName)
return;
}
Q_ASSERT(!moduleWidget->name().isEmpty());
Q_ASSERT(!moduleWidget->moduleName().isEmpty());
CTK_D(qSlicerModulePanel);
......
......@@ -75,11 +75,6 @@ void qSlicerEMSegmentModuleWidget::setup()
d->PanelStack->setCurrentIndex(0);
}
//-----------------------------------------------------------------------------
QAction* qSlicerEMSegmentModuleWidget::showModuleAction()
{
return new QAction(QIcon(":/Icons/EMSegment.png"), tr("Show EMSegment module"), this);
}
//-----------------------------------------------------------------------------
void qSlicerEMSegmentModuleWidget::showPanel(int panelId)
......
......@@ -23,8 +23,6 @@ public:
typedef qSlicerAbstractModuleWidget Superclass;
qSlicerEMSegmentModuleWidget(QWidget *parent=0);
virtual QAction* showModuleAction();
public slots:
void showPanel(int panelId);
......
......@@ -13,6 +13,10 @@
<property name="windowTitle">
<string>Form</string>
</property>
<property name="windowIcon">
<iconset resource="../qSlicerMeasurementsModule.qrc">
<normaloff>:/Icons/Measurements.png</normaloff>:/Icons/Measurements.png</iconset>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
<property name="margin">
<number>6</number>
......
......@@ -18,9 +18,3 @@ void qSlicerMeasurementsModuleWidget::setup()
CTK_D(qSlicerMeasurementsModuleWidget);
d->setupUi(this);
}
//-----------------------------------------------------------------------------
QAction* qSlicerMeasurementsModuleWidget::showModuleAction()
{
return new QAction(QIcon(":/Icons/Measurements.png"), tr("Show Measurements module"), this);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment