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 7b76d348 authored by finetjul's avatar finetjul
Browse files

ENH: Remove obsolete qMRMLNodeSelector. qMRMLNodeComboBox should be used instead

git-svn-id: http://svn.slicer.org/Slicer4/trunk@13922 3bd1e089-480b-0410-8dfb-8563597acbee
parent 8973ed79
......@@ -5,18 +5,18 @@
#include <ctkPimpl.h>
/// qMRML includes
#include "qMRMLNodeSelector.h"
#include "qMRMLNodeComboBox.h"
#include "qMRMLWidgetsExport.h"
class qMRMLNodeTreeSelectorPrivate;
class QMRML_WIDGETS_EXPORT qMRMLNodeTreeSelector : public qMRMLNodeSelector
class QMRML_WIDGETS_EXPORT qMRMLNodeTreeSelector : public qMRMLNodeComboBox
{
Q_OBJECT
public:
/// Superclass typedef
typedef qMRMLNodeSelector Superclass;
typedef qMRMLNodeComboBox Superclass;
/// Constructors
explicit qMRMLNodeTreeSelector(QWidget* parent = 0);
......
......@@ -29,7 +29,7 @@
#include <qCTKFlowLayout.h>
// qMRML includes
#include <qMRMLNodeSelector.h>
#include <qMRMLNodeComboBox.h>
#include <qMRMLNodeFactory.h>
/// ModuleDescriptionParser includes
......@@ -400,14 +400,14 @@ QWidget* qSlicerCLIModuleUIHelperPrivate::createStringTagWidget(const ModulePara
}
//-----------------------------------------------------------------------------
WIDGET_VALUE_WRAPPER(Point, qMRMLNodeSelector, currentNodeId, setCurrentNode, String);
WIDGET_VALUE_WRAPPER(Point, qMRMLNodeComboBox, currentNodeId, setCurrentNode, String);
//-----------------------------------------------------------------------------
QWidget* qSlicerCLIModuleUIHelperPrivate::createPointTagWidget(const ModuleParameter& moduleParameter)
{
QString _label = QString::fromStdString(moduleParameter.GetLabel());
QString _name = QString::fromStdString(moduleParameter.GetName());
qMRMLNodeSelector * widget = new qMRMLNodeSelector;
qMRMLNodeComboBox* widget = new qMRMLNodeComboBox;
widget->setNodeTypes(QStringList("vtkMRMLFiducialListNode"));
//TODO - title + " FiducialList"
//TODO - tparameter->SetNewNodeEnabled(1);
......@@ -424,14 +424,14 @@ QWidget* qSlicerCLIModuleUIHelperPrivate::createPointTagWidget(const ModuleParam
}
//-----------------------------------------------------------------------------
WIDGET_VALUE_WRAPPER(Region, qMRMLNodeSelector, currentNodeId, setCurrentNode, String);
WIDGET_VALUE_WRAPPER(Region, qMRMLNodeComboBox, currentNodeId, setCurrentNode, String);
//-----------------------------------------------------------------------------
QWidget* qSlicerCLIModuleUIHelperPrivate::createRegionTagWidget(const ModuleParameter& moduleParameter)
{
QString _label = QString::fromStdString(moduleParameter.GetLabel());
QString _name = QString::fromStdString(moduleParameter.GetName());
qMRMLNodeSelector * widget = new qMRMLNodeSelector;
qMRMLNodeComboBox* widget = new qMRMLNodeComboBox;
widget->setNodeTypes(QStringList("vtkMRMLROIListNode"));
//TODO - title + " RegionList"
//TODO - tparameter->SetNewNodeEnabled(1);
......@@ -447,7 +447,7 @@ QWidget* qSlicerCLIModuleUIHelperPrivate::createRegionTagWidget(const ModulePara
}
//-----------------------------------------------------------------------------
WIDGET_VALUE_WRAPPER(Image, qMRMLNodeSelector, currentNodeId, setCurrentNode, String);
WIDGET_VALUE_WRAPPER(Image, qMRMLNodeComboBox, currentNodeId, setCurrentNode, String);
//-----------------------------------------------------------------------------
QWidget* qSlicerCLIModuleUIHelperPrivate::createImageTagWidget(const ModuleParameter& moduleParameter)
......@@ -487,7 +487,7 @@ QWidget* qSlicerCLIModuleUIHelperPrivate::createImageTagWidget(const ModuleParam
QString _label = QString::fromStdString(moduleParameter.GetLabel());
QString _name = QString::fromStdString(moduleParameter.GetName());
qMRMLNodeSelector * widget = new qMRMLNodeSelector;
qMRMLNodeComboBox * widget = new qMRMLNodeComboBox;
widget->setNodeTypes(QStringList(nodeType));
widget->setMRMLScene(this->CLIModuleWidget->mrmlScene());
QObject::connect(this->CLIModuleWidget, SIGNAL(mrmlSceneChanged(vtkMRMLScene*)),
......@@ -505,7 +505,7 @@ QWidget* qSlicerCLIModuleUIHelperPrivate::createImageTagWidget(const ModuleParam
}
//-----------------------------------------------------------------------------
WIDGET_VALUE_WRAPPER(Geometry, qMRMLNodeSelector, currentNodeId, setCurrentNode, String);
WIDGET_VALUE_WRAPPER(Geometry, qMRMLNodeComboBox, currentNodeId, setCurrentNode, String);
//-----------------------------------------------------------------------------
QWidget* qSlicerCLIModuleUIHelperPrivate::createGeometryTagWidget(const ModuleParameter& moduleParameter)
......@@ -535,7 +535,7 @@ QWidget* qSlicerCLIModuleUIHelperPrivate::createGeometryTagWidget(const ModulePa
QString _label = QString::fromStdString(moduleParameter.GetLabel());
QString _name = QString::fromStdString(moduleParameter.GetName());
qMRMLNodeSelector * widget = new qMRMLNodeSelector;
qMRMLNodeComboBox * widget = new qMRMLNodeComboBox;
widget->setShowHidden(showHidden);
widget->setNodeTypes(QStringList(nodeType));
widget->setMRMLScene(this->CLIModuleWidget->mrmlScene());
......@@ -548,7 +548,7 @@ QWidget* qSlicerCLIModuleUIHelperPrivate::createGeometryTagWidget(const ModulePa
}
//-----------------------------------------------------------------------------
WIDGET_VALUE_WRAPPER(Table, qMRMLNodeSelector, currentNodeId, setCurrentNode, String);
WIDGET_VALUE_WRAPPER(Table, qMRMLNodeComboBox, currentNodeId, setCurrentNode, String);
//-----------------------------------------------------------------------------
QWidget* qSlicerCLIModuleUIHelperPrivate::createTableTagWidget(const ModuleParameter& moduleParameter)
......@@ -573,7 +573,7 @@ QWidget* qSlicerCLIModuleUIHelperPrivate::createTableTagWidget(const ModuleParam
QString _label = QString::fromStdString(moduleParameter.GetLabel());
QString _name = QString::fromStdString(moduleParameter.GetName());
qMRMLNodeSelector * widget = new qMRMLNodeSelector;
qMRMLNodeComboBox * widget = new qMRMLNodeComboBox;
widget->setNodeTypes(QStringList(nodeType));
widget->setMRMLScene(this->CLIModuleWidget->mrmlScene());
QObject::connect(this->CLIModuleWidget, SIGNAL(mrmlSceneChanged(vtkMRMLScene*)),
......@@ -585,7 +585,7 @@ QWidget* qSlicerCLIModuleUIHelperPrivate::createTableTagWidget(const ModuleParam
}
//-----------------------------------------------------------------------------
WIDGET_VALUE_WRAPPER(Transform, qMRMLNodeSelector, currentNodeId, setCurrentNode, String);
WIDGET_VALUE_WRAPPER(Transform, qMRMLNodeComboBox, currentNodeId, setCurrentNode, String);
//-----------------------------------------------------------------------------
QWidget* qSlicerCLIModuleUIHelperPrivate::createTransformTagWidget(const ModuleParameter& moduleParameter)
......@@ -606,7 +606,7 @@ QWidget* qSlicerCLIModuleUIHelperPrivate::createTransformTagWidget(const ModuleP
QString _label = QString::fromStdString(moduleParameter.GetLabel());
QString _name = QString::fromStdString(moduleParameter.GetName());
qMRMLNodeSelector * widget = new qMRMLNodeSelector;
qMRMLNodeComboBox * widget = new qMRMLNodeComboBox;
widget->setNodeTypes(QStringList(nodeType));
widget->setMRMLScene(this->CLIModuleWidget->mrmlScene());
QObject::connect(this->CLIModuleWidget, SIGNAL(mrmlSceneChanged(vtkMRMLScene*)),
......
......@@ -40,10 +40,6 @@ SET(qMRMLWidgets_SRCS
qMRMLNodeComboBox.h
qMRMLNodeFactory.cxx
qMRMLNodeFactory.h
qMRMLNodeSelector.cxx
qMRMLNodeSelector.h
qMRMLNodeTreeSelector.cxx
qMRMLNodeTreeSelector.h
qMRMLSceneFactoryWidget.cxx
qMRMLSceneFactoryWidget.h
qMRMLSceneModel.cxx
......@@ -86,8 +82,6 @@ SET(qMRMLWidgets_MOC_SRCS
qMRMLMatrixWidget.h
qMRMLNodeComboBox.h
qMRMLNodeFactory.h
qMRMLNodeSelector.h
qMRMLNodeTreeSelector.h
qMRMLSceneFactoryWidget.h
qMRMLSceneModel.h
qMRMLSliceViewWidget.h
......
......@@ -14,10 +14,6 @@ SET(designer_plugin_SRCS
qMRMLMatrixWidgetPlugin.h
qMRMLNodeComboBoxPlugin.cxx
qMRMLNodeComboBoxPlugin.h
qMRMLNodeSelectorPlugin.cxx
qMRMLNodeSelectorPlugin.h
qMRMLNodeTreeSelectorPlugin.cxx
qMRMLNodeTreeSelectorPlugin.h
qMRMLSliceViewWidgetPlugin.cxx
qMRMLSliceViewWidgetPlugin.h
qMRMLThreeDRenderViewPlugin.cxx
......@@ -47,8 +43,6 @@ SET(designer_plugin_MOC_SRCS
qMRMLListWidgetPlugin.h
qMRMLMatrixWidgetPlugin.h
qMRMLNodeComboBoxPlugin.h
qMRMLNodeSelectorPlugin.h
qMRMLNodeTreeSelectorPlugin.h
qMRMLSceneFactoryWidgetPlugin.h
qMRMLSliceViewWidgetPlugin.h
qMRMLThreeDRenderViewPlugin.h
......
......@@ -5,8 +5,6 @@
#include "qMRMLListWidgetPlugin.h"
#include "qMRMLMatrixWidgetPlugin.h"
#include "qMRMLNodeComboBoxPlugin.h"
#include "qMRMLNodeSelectorPlugin.h"
#include "qMRMLNodeTreeSelectorPlugin.h"
#include "qMRMLSliceViewWidgetPlugin.h"
#include "qMRMLThreeDRenderViewPlugin.h"
#include "qMRMLTransformSlidersPlugin.h"
......@@ -34,8 +32,6 @@ public:
<< new qMRMLListWidgetPlugin
<< new qMRMLMatrixWidgetPlugin
<< new qMRMLNodeComboBoxPlugin
<< new qMRMLNodeSelectorPlugin
<< new qMRMLNodeTreeSelectorPlugin
<< new qMRMLThreeDRenderViewPlugin
<< new qMRMLSliceViewWidgetPlugin
<< new qMRMLTransformSlidersPlugin
......
......@@ -8,9 +8,8 @@ CREATE_TEST_SOURCELIST(Tests ${KIT}CxxTests.cxx
qMRMLMatrixWidgetTest1.cxx
qMRMLModelTest1.cxx
qMRMLNodeComboBoxTest1.cxx
qMRMLNodeComboBoxTest2.cxx
qMRMLNodeFactoryTest1.cxx
qMRMLNodeSelectorTest1.cxx
qMRMLNodeTreeSelectorTest1.cxx
qMRMLSceneFactoryWidgetTest1.cxx
qMRMLSceneModelTest1.cxx
qMRMLTransformProxyModelTest1.cxx
......@@ -44,9 +43,8 @@ SIMPLE_TEST( qMRMLListWidgetTest1 )
SIMPLE_TEST( qMRMLMatrixWidgetTest1 )
SIMPLE_TEST( qMRMLModelTest1 )
SIMPLE_TEST( qMRMLNodeComboBoxTest1 )
SIMPLE_TEST( qMRMLNodeComboBoxTest2 )
SIMPLE_TEST( qMRMLNodeFactoryTest1 )
SIMPLE_TEST( qMRMLNodeSelectorTest1 )
SIMPLE_TEST( qMRMLNodeTreeSelectorTest1 )
SIMPLE_TEST( qMRMLSceneFactoryWidgetTest1 )
SIMPLE_TEST( qMRMLSceneModelTest1 )
SIMPLE_TEST( qMRMLTransformProxyModelTest1 )
......
......@@ -47,7 +47,7 @@ int qMRMLNodeComboBoxTest1( int argc, char * argv [] )
// no type has been given yet -> no item shoud be listed
if (nodeSelector.nodeCount())
{
std::cerr << __LINE__ << " - qMRMLNodeSelector::count() failed: " << nodeSelector.count() << " " << nodeSelector.nodeCount() << std::endl;
std::cerr << __LINE__ << " - qMRMLNodeSelector::count() failed: " << nodeSelector.nodeCount() << std::endl;
return EXIT_FAILURE;
}
......@@ -112,7 +112,7 @@ int qMRMLNodeComboBoxTest1( int argc, char * argv [] )
return EXIT_FAILURE;
}
sceneFactory.deleteScene();
if (nodeSelector.count() != 0)
if (nodeSelector.nodeCount() != 0)
{
std::cerr << __LINE__ << " - qMRMLNodeSelector: mrml scene events failed."
<< std::endl;
......@@ -144,7 +144,7 @@ int qMRMLNodeComboBoxTest1( int argc, char * argv [] )
if (nodeSelector.nodeCount() != 4)
{
std::cerr << __LINE__ << " - qMRMLNodeSelector: attribute filtering failed."
<< nodeSelector.count() << std::endl;
<< nodeSelector.nodeCount() << std::endl;
return EXIT_FAILURE;
}
......@@ -155,7 +155,7 @@ int qMRMLNodeComboBoxTest1( int argc, char * argv [] )
nodeSelector.setNodeTypes(QStringList("vtkMRMLNonlinearTransformNode"));
if (nodeSelector.nodeCount() != 3)
{
std::cerr << __LINE__ << " - qMRMLNodeSelector: node type filtering failed." << nodeSelector.count() << std::endl;
std::cerr << __LINE__ << " - qMRMLNodeSelector: node type filtering failed." << nodeSelector.nodeCount() << std::endl;
return EXIT_FAILURE;
}
nodeSelector.setShowChildNodeTypes(false);
......
// QT includes
#include <QApplication>
// qMRML includes
#include "qMRMLNodeComboBox.h"
#include "qMRMLSceneFactoryWidget.h"
// MRML includes
#include "vtkMRMLScene.h"
// STD includes
#include <stdlib.h>
#include <iostream>
int qMRMLNodeComboBoxTest2( int argc, char * argv [] )
{
QApplication app(argc, argv);
qMRMLNodeComboBox nodeSelector;
qMRMLSceneFactoryWidget sceneFactory;
sceneFactory.generateScene();
int currentCount = nodeSelector.nodeCount();
if (currentCount != 0)
{
std::cerr << __LINE__ << " - Error in count() - Expected: 0, current:" << currentCount << std::endl;
return EXIT_FAILURE;
}
// Test: setMRMLScene()/mrmlScene()
nodeSelector.setMRMLScene(sceneFactory.mrmlScene());
if (nodeSelector.mrmlScene() != sceneFactory.mrmlScene())
{
std::cerr << __LINE__ << " - qMRMLNodeSelector::setMRMLScene() failed." << std::endl;
return EXIT_FAILURE;
}
// test a second time, just to make sure methods are well reinit.
sceneFactory.generateScene();
nodeSelector.setMRMLScene(sceneFactory.mrmlScene());
if (nodeSelector.mrmlScene() != sceneFactory.mrmlScene())
{
std::cerr << __LINE__ << " - qMRMLNodeSelector::setMRMLScene() failed." << std::endl;
return EXIT_FAILURE;
}
// no type has been given yet -> no item shoud be listed
if (nodeSelector.nodeCount())
{
std::cerr << __LINE__ << " - qMRMLNodeSelector::count() failed." << std::endl;
return EXIT_FAILURE;
}
sceneFactory.generateNode();
sceneFactory.generateNode();
sceneFactory.generateNode();
sceneFactory.generateNode();
sceneFactory.generateNode();
// no type has been given yet -> no item shoud be listed
if (nodeSelector.nodeCount())
{
std::cerr << __LINE__ << " - qMRMLNodeSelector::count() failed." << std::endl;
return EXIT_FAILURE;
}
nodeSelector.setMRMLScene(0);
if (nodeSelector.mrmlScene() != 0)
{
std::cerr << __LINE__ << " - qMRMLNodeSelector::setMRMLScene() failed." << std::endl;
return EXIT_FAILURE;
}
// test nodeType
sceneFactory.generateScene();
sceneFactory.generateNode("vtkMRMLViewNode");
nodeSelector.setNodeTypes(QStringList("vtkMRMLViewNode"));
nodeSelector.setMRMLScene(sceneFactory.mrmlScene());
if (nodeSelector.nodeCount() != 1)
{
std::cerr << __LINE__ << " - qMRMLNodeSelector: NodeType failed." << std::endl;
return EXIT_FAILURE;
}
sceneFactory.generateNode("vtkMRMLViewNode");
if (nodeSelector.nodeCount() != 2)
{
std::cerr << __LINE__ << " - qMRMLNodeSelector: NodeType failed." << std::endl;
return EXIT_FAILURE;
}
sceneFactory.mrmlScene()->RemoveNode(sceneFactory.mrmlScene()->GetNthNode(0));
if (nodeSelector.nodeCount() != 1)
{
std::cerr << __LINE__ << " - qMRMLNodeSelector: NodeType failed." << std::endl;
return EXIT_FAILURE;
}
sceneFactory.mrmlScene()->RemoveNode(sceneFactory.mrmlScene()->GetNthNode(0));
if (nodeSelector.nodeCount() != 0)
{
std::cerr << __LINE__ << " - qMRMLNodeSelector: NodeType failed." << std::endl;
return EXIT_FAILURE;
}
sceneFactory.generateNode("vtkMRMLViewNode");
if (nodeSelector.nodeCount() != 1)
{
std::cerr << __LINE__ << " - qMRMLNodeSelector: NodeType failed." << std::endl;
return EXIT_FAILURE;
}
sceneFactory.deleteScene();
if (nodeSelector.nodeCount() != 0)
{
std::cerr << __LINE__ << " - qMRMLNodeSelector: mrml scene events failed." << std::endl;
return EXIT_FAILURE;
}
if (nodeSelector.currentNode() != 0)
{
std::cerr << __LINE__ << " - qMRMLNodeSelector: currentNode failed." << std::endl;
return EXIT_FAILURE;
}
// FIXME: add more basic tests here
// Check Attributes
sceneFactory.generateScene();
sceneFactory.generateNode("vtkMRMLViewNode");
sceneFactory.generateNode("vtkMRMLViewNode");
sceneFactory.generateNode("vtkMRMLViewNode");
sceneFactory.generateNode("vtkMRMLViewNode");
sceneFactory.generateNode("vtkMRMLViewNode");
vtkMRMLNode* node = sceneFactory.mrmlScene()->GetNthNode(0);
node->SetAttribute("foo", "bar");
node = sceneFactory.mrmlScene()->GetNthNode(1);
node->SetAttribute("foo", "bar2");
nodeSelector.addAttribute("vtkMRMLViewNode", "foo", QString("bar2"));
nodeSelector.setMRMLScene(sceneFactory.mrmlScene());
if (nodeSelector.nodeCount() != 4)
{
std::cerr << __LINE__ << " - qMRMLNodeSelector: attribute filtering failed."
<< nodeSelector.nodeCount() << std::endl;
return EXIT_FAILURE;
}
// Check hide child node type
sceneFactory.generateNode("vtkMRMLNonlinearTransformNode");
sceneFactory.generateNode("vtkMRMLNonlinearTransformNode");
sceneFactory.generateNode("vtkMRMLGridTransformNode");
nodeSelector.setNodeTypes(QStringList("vtkMRMLNonlinearTransformNode"));
if (nodeSelector.nodeCount() != 3)
{
std::cerr << __LINE__ << " - qMRMLNodeSelector: node type filtering failed." << nodeSelector.nodeCount() << std::endl;
return EXIT_FAILURE;
}
nodeSelector.setShowChildNodeTypes(false);
if (nodeSelector.nodeCount() != 2)
{
std::cerr << __LINE__ << " - qMRMLNodeSelector: show child node types failed." << std::endl;
return EXIT_FAILURE;
}
nodeSelector.setShowChildNodeTypes(true);
if (nodeSelector.nodeCount() != 3)
{
std::cerr << __LINE__ << " - qMRMLNodeSelector: show child node types failed." << std::endl;
return EXIT_FAILURE;
}
nodeSelector.setHideChildNodeTypes(QStringList("vtkMRMLGridTransformNode"));
if (nodeSelector.nodeCount() != 2)
{
std::cerr << __LINE__ << " - qMRMLNodeSelector: show child node types failed." << std::endl;
return EXIT_FAILURE;
}
// Checks with more than 1 type
QStringList types;
types << "vtkMRMLViewNode" << "vtkMRMLCameraNode";
//test setNodeTypes()/nodeTypes()
nodeSelector.setNodeTypes(types);
if (nodeSelector.nodeTypes() != types)
{
std::cerr << __LINE__ << " - qMRMLNodeSelector::setNodeTypes() failed." << std::endl;
return EXIT_FAILURE;
}
sceneFactory.generateScene();
sceneFactory.generateNode(types[0]);
sceneFactory.generateNode(types[0]);
sceneFactory.generateNode(types[0]);
sceneFactory.generateNode("vtkMRMLLinearTransformNode");
sceneFactory.generateNode(types[1]);
sceneFactory.generateNode(types[1]);
nodeSelector.setMRMLScene(sceneFactory.mrmlScene());
if (nodeSelector.nodeCount() != 5)
{
std::cerr << __LINE__ << " - qMRMLNodeSelector:NodeTypeS: setMRMLScene fails." << std::endl;
return EXIT_FAILURE;
}
sceneFactory.generateNode(types[1]);
if (nodeSelector.nodeCount() != 6)
{
std::cerr << __LINE__ << " - qMRMLNodeSelector:NodeTypeS: node added to the scene fails." << std::endl;
return EXIT_FAILURE;
}
nodeSelector.setMRMLScene(0);
currentCount = nodeSelector.nodeCount();
if (currentCount != 0)
{
std::cerr << __LINE__ << " - Error in count() - Expected: 0, current:" << currentCount << std::endl;
return EXIT_FAILURE;
}
//
// Let's connect the sceneFactory with the widget
//
QObject::connect(&sceneFactory, SIGNAL(mrmlSceneChanged(vtkMRMLScene*)),
&nodeSelector, SLOT(setMRMLScene(vtkMRMLScene*)));
// Let's check the state of the buttons
sceneFactory.generateScene();
// Test: setMRMLScene()/mrmlScene()
nodeSelector.setMRMLScene(sceneFactory.mrmlScene());
if (nodeSelector.mrmlScene() != sceneFactory.mrmlScene())
{
std::cerr << __LINE__ << " - qMRMLNodeSelector::setMRMLScene() failed." << std::endl;
return EXIT_FAILURE;
}
sceneFactory.deleteScene();
return EXIT_SUCCESS;
}
......@@ -4,6 +4,7 @@
#include <QAbstractProxyModel>
#include <QAction>
#include <QDebug>
#include <QHBoxLayout>
#include <QStandardItemModel>
// qMRMLWidgets includes
......@@ -20,6 +21,7 @@
// -----------------------------------------------------------------------------
class qMRMLNodeComboBoxPrivate: public ctkPrivate<qMRMLNodeComboBox>
{
CTK_DECLARE_PUBLIC(qMRMLNodeComboBox);
public:
qMRMLNodeComboBoxPrivate();
void init();
......@@ -28,6 +30,7 @@ public:
void updateNoneItem();
void updateActionItems();
QComboBox* ComboBox;
qMRMLNodeFactory* MRMLNodeFactory;
qMRMLSceneModel* MRMLSceneModel;
bool SelectNodeUponCreation;
......@@ -35,11 +38,14 @@ public:
bool AddEnabled;
bool RemoveEnabled;
bool EditEnabled;
private:
void setModel(QAbstractItemModel* model);
};
// -----------------------------------------------------------------------------
qMRMLNodeComboBoxPrivate::qMRMLNodeComboBoxPrivate()
{
this->ComboBox = 0;
this->MRMLNodeFactory = 0;
this->MRMLSceneModel = 0;
this->SelectNodeUponCreation = true;
......@@ -54,6 +60,11 @@ void qMRMLNodeComboBoxPrivate::init()
{
CTK_P(qMRMLNodeComboBox);
Q_ASSERT(this->MRMLNodeFactory == 0);
this->ComboBox = new QComboBox(p);
p->setLayout(new QHBoxLayout);
p->layout()->addWidget(this->ComboBox);
p->setContentsMargins(0,0,0,0);
this->MRMLNodeFactory = new qMRMLNodeFactory(p);
QAbstractItemModel* model = p->createSceneModel();
......@@ -69,14 +80,22 @@ void qMRMLNodeComboBoxPrivate::init()
qMRMLSortFilterProxyModel* sortFilterModel = new qMRMLSortFilterProxyModel(p);
sortFilterModel->setSourceModel(model);
p->setModel(sortFilterModel);
this->setModel(sortFilterModel);
p->connect(p, SIGNAL(currentIndexChanged(int)), p, SLOT(emitCurrentNodeChanged(int)));
p->connect(p->model(), SIGNAL(rowsInserted(const QModelIndex&, int,int)),
p->setEnabled(p->mrmlScene() != 0);
}
// --------------------------------------------------------------------------
void qMRMLNodeComboBoxPrivate::setModel(QAbstractItemModel* model)
{
CTK_P(qMRMLNodeComboBox);
this->ComboBox->setModel(model);
p->connect(model, SIGNAL(rowsInserted(const QModelIndex&, int,int)),
p, SLOT(emitNodesAdded(const QModelIndex&, int, int)));
p->connect(p->model(), SIGNAL(rowsAboutToBeRemoved(const QModelIndex&, int,int)),
p->connect(model, SIGNAL(rowsAboutToBeRemoved(const QModelIndex&, int,int)),
p, SLOT(emitNodesAboutToBeRemoved(const QModelIndex&, int, int)));
p->setEnabled(p->mrmlScene() != 0);
}
// --------------------------------------------------------------------------
......@@ -84,7 +103,7 @@ vtkMRMLNode* qMRMLNodeComboBoxPrivate::mrmlNode(int index)const
{
CTK_P(const qMRMLNodeComboBox);
QString nodeId =
p->itemData(index, qMRML::UIDRole).toString();
this->ComboBox->itemData(index, qMRML::UIDRole).toString();
if (nodeId.isEmpty())
{
return 0;
......@@ -150,7 +169,7 @@ void qMRMLNodeComboBoxPrivate::updateActionItems()
}
this->MRMLSceneModel->setPostItems(p->mrmlScene(), extraItems);
QObject::connect(p->view(), SIGNAL(clicked(const QModelIndex& )),
QObject::connect(this->ComboBox->view(), SIGNAL(clicked(const QModelIndex& )),
p, SLOT(activateExtraItem(const QModelIndex& )),
Qt::UniqueConnection);
}
......@@ -169,21 +188,22 @@ qMRMLNodeComboBox::qMRMLNodeComboBox(QWidget* _parent) : Superclass(_parent)
// --------------------------------------------------------------------------
void qMRMLNodeComboBox::activateExtraItem(const QModelIndex& index)
{
CTK_D(qMRMLNodeComboBox);
// FIXME: check the type of the item on a different role instead of the display role
QString data = this->model()->data(index, Qt::DisplayRole).toString();
if (data == "Add Node")
{
this->hidePopup();
d->ComboBox->hidePopup();
this->addNode();
}