Commit f148f284 authored by finetjul's avatar finetjul
Browse files

BUG: When a node is hidden in qMRMLNodeComboBox, refresh to select None

if there is no more nodes in the list.

git-svn-id: http://svn.slicer.org/Slicer4/trunk@15601 3bd1e089-480b-0410-8dfb-8563597acbee
parent 6c5cbc1d
......@@ -25,6 +25,7 @@ CREATE_TEST_SOURCELIST(Tests ${KIT}CxxTests.cxx
qMRMLNodeComboBoxTest3.cxx
qMRMLNodeComboBoxTest4.cxx
qMRMLNodeComboBoxTest5.cxx
qMRMLNodeComboBoxTest6.cxx
qMRMLNodeFactoryTest1.cxx
qMRMLSceneCategoryModelTest1.cxx
qMRMLSceneColorTableModelTest1.cxx
......@@ -98,6 +99,7 @@ SIMPLE_TEST( qMRMLNodeComboBoxTest2 )
SCENE_TEST( qMRMLNodeComboBoxTest3 diffusionEditor.mrml )
SIMPLE_TEST( qMRMLNodeComboBoxTest4 )
SIMPLE_TEST( qMRMLNodeComboBoxTest5 )
SIMPLE_TEST( qMRMLNodeComboBoxTest6 )
SIMPLE_TEST( qMRMLNodeFactoryTest1 )
SIMPLE_TEST( qMRMLSceneCategoryModelTest1 )
SIMPLE_TEST( qMRMLSceneColorTableModelTest1 )
......
/*==============================================================================
Program: 3D Slicer
Copyright (c) 2010 Kitware Inc.
See Doc/copyright/copyright.txt
or http://www.slicer.org/copyright/copyright.txt for details.
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
This file was originally developed by Julien Finet, Kitware Inc.
and was partially funded by NIH grant 3P41RR013218-12S1
==============================================================================*/
// QT includes
#include <QApplication>
#include <QDebug>
#include <QTimer>
// qMRML includes
#include "qMRMLNodeComboBox.h"
#include "qMRMLSceneModel.h"
// MRML includes
#include <vtkMRMLModelNode.h>
#include <vtkMRMLScene.h>
// VTK includes
#include "vtkSmartPointer.h"
// STD includes
#include <stdlib.h>
#include <iostream>
int qMRMLNodeComboBoxTest6( int argc, char * argv [] )
{
QApplication app(argc, argv);
qMRMLNodeComboBox nodeSelector;
nodeSelector.setNodeTypes(QStringList("vtkMRMLModelNode"));
nodeSelector.setNoneEnabled(true);
nodeSelector.addAttribute("vtkMRMLModelNode", "foo", 1);
/*
qMRMLNodeComboBox nodeSelector2;
nodeSelector2.setNodeTypes(QStringList("vtkMRMLModelNode"));
nodeSelector2.setNoneEnabled(false);
nodeSelector2.addAttribute("vtkMRMLModelNode", "foo", 0);
*/
vtkSmartPointer<vtkMRMLScene> scene = vtkSmartPointer<vtkMRMLScene>::New();
vtkSmartPointer<vtkMRMLModelNode> modelNode = vtkSmartPointer<vtkMRMLModelNode>::New();
modelNode->SetAttribute("foo", "1");
scene->AddNode(modelNode);
nodeSelector.setMRMLScene(scene);
nodeSelector.setCurrentNode(modelNode);
nodeSelector.show();
/*
nodeSelector2.setMRMLScene(scene);
nodeSelector2.setCurrentNode(modelNode);
nodeSelector2.show();
*/
if (argc < 2 || QString(argv[1]) != "-I")
{
QTimer::singleShot(200, &app, SLOT(quit()));
}
app.processEvents();
modelNode->SetAttribute("foo", "0");
modelNode->Modified();
qDebug() <<"modified";
return app.exec();
}
......@@ -140,6 +140,10 @@ void qMRMLNodeComboBoxPrivate::setModel(QAbstractItemModel* model)
q, SLOT(emitNodesAdded(const QModelIndex&, int, int)));
q->connect(model, SIGNAL(rowsAboutToBeRemoved(const QModelIndex&, int,int)),
q, SLOT(emitNodesAboutToBeRemoved(const QModelIndex&, int, int)));
q->connect(model, SIGNAL(rowsRemoved(const QModelIndex&, int,int)),
q, SLOT(refreshCurrentItem()));
q->connect(model, SIGNAL(modelReset()), q, SLOT(refreshCurrentItem()));
q->connect(model, SIGNAL(layoutChanged()), q, SLOT(refreshCurrentItem()));
}
// --------------------------------------------------------------------------
......@@ -755,3 +759,9 @@ void qMRMLNodeComboBox::emitNodesAboutToBeRemoved(const QModelIndex & parent, in
}
}
}
//--------------------------------------------------------------------------
void qMRMLNodeComboBox::refreshCurrentItem()
{
this->setCurrentNode(this->currentNode());
}
......@@ -245,6 +245,7 @@ protected slots:
void emitCurrentNodeChanged(int index);
void emitNodesAdded(const QModelIndex & parent, int start, int end);
void emitNodesAboutToBeRemoved(const QModelIndex & parent, int start, int end);
void refreshCurrentItem();
protected:
QScopedPointer<qMRMLNodeComboBoxPrivate> d_ptr;
......
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