Slicer  4.8
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
qMRMLNodeComboBox.h
Go to the documentation of this file.
1 /*==============================================================================
2 
3  Program: 3D Slicer
4 
5  Copyright (c) Kitware Inc.
6 
7  See COPYRIGHT.txt
8  or http://www.slicer.org/copyright/copyright.txt for details.
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 
16  This file was originally developed by Julien Finet, Kitware Inc.
17  and was partially funded by NIH grant 3P41RR013218-12S1
18 
19 ==============================================================================*/
20 
21 #ifndef __qMRMLNodeComboBox_h
22 #define __qMRMLNodeComboBox_h
23 
24 // Qt includes
25 #include <QComboBox>
26 
27 // qMRML includes
29 #include "qMRMLWidgetsExport.h"
30 class qMRMLNodeFactory;
31 class qMRMLNodeComboBoxPrivate;
32 class qMRMLSceneModel;
33 
34 // VTK includes
35 class vtkMRMLNode;
36 class vtkMRMLScene;
37 
55 class QMRML_WIDGETS_EXPORT qMRMLNodeComboBox
56  : public QWidget
57 {
58  Q_OBJECT
59  Q_PROPERTY(QString currentNodeID READ currentNodeID WRITE setCurrentNodeID NOTIFY currentNodeIDChanged DESIGNABLE false)
60  Q_PROPERTY(QString currentNodeId READ currentNodeId WRITE setCurrentNode DESIGNABLE false) // \deprecated
61  Q_PROPERTY(QStringList nodeTypes READ nodeTypes WRITE setNodeTypes)
62  Q_PROPERTY(bool showHidden READ showHidden WRITE setShowHidden)
63  Q_PROPERTY(bool showChildNodeTypes READ showChildNodeTypes WRITE setShowChildNodeTypes)
64  Q_PROPERTY(QStringList hideChildNodeTypes READ hideChildNodeTypes WRITE setHideChildNodeTypes)
65 
66  Q_PROPERTY(QString baseName READ baseName WRITE setBaseName)
73  Q_PROPERTY(bool noneEnabled READ noneEnabled WRITE setNoneEnabled)
74  Q_PROPERTY(bool addEnabled READ addEnabled WRITE setAddEnabled)
75  Q_PROPERTY(bool removeEnabled READ removeEnabled WRITE setRemoveEnabled)
76  Q_PROPERTY(bool editEnabled READ editEnabled WRITE setEditEnabled)
77  Q_PROPERTY(bool renameEnabled READ renameEnabled WRITE setRenameEnabled)
78 
79  Q_PROPERTY(bool selectNodeUponCreation READ selectNodeUponCreation WRITE setSelectNodeUponCreation)
83  Q_PROPERTY(QString noneDisplay READ noneDisplay WRITE setNoneDisplay)
84 
85  Q_PROPERTY(QComboBox::SizeAdjustPolicy sizeAdjustPolicy READ sizeAdjustPolicy WRITE setSizeAdjustPolicy)
86 
87 public:
88  typedef QWidget Superclass;
89 
92  explicit qMRMLNodeComboBox(QWidget* parent = 0);
93  virtual ~qMRMLNodeComboBox();
94 
98  Q_INVOKABLE vtkMRMLScene* mrmlScene()const;
99 
103  QStringList nodeTypes()const;
104  void setNodeTypes(const QStringList& nodeTypes);
105 
108  inline void setShowHidden(bool);
109  inline bool showHidden()const;
110 
117  inline void setShowChildNodeTypes(bool show);
118  inline bool showChildNodeTypes()const;
119 
123  inline void setHideChildNodeTypes(const QStringList& nodeTypes);
124  inline QStringList hideChildNodeTypes()const;
125 
136  Q_INVOKABLE void addAttribute(const QString& nodeType,
137  const QString& attributeName,
138  const QVariant& attributeValue = QVariant());
141  Q_INVOKABLE void removeAttribute(const QString& nodeType,
142  const QString& attributeName);
143 
148  void setBaseName(const QString& baseName, const QString& nodeType = "");
149  QString baseName(const QString& nodeType = "")const;
150 
155  Q_INVOKABLE void setNodeTypeLabel(const QString& label, const QString& nodeType);
156  Q_INVOKABLE QString nodeTypeLabel(const QString& nodeType)const;
157 
160  int nodeCount()const;
161 
165  vtkMRMLNode* nodeFromIndex(int index)const;
166 
168  Q_INVOKABLE vtkMRMLNode* currentNode()const;
169 
172  QString currentNodeID()const;
173 
176  Q_INVOKABLE QString currentNodeId()const;
177 
181  bool selectNodeUponCreation()const;
182  void setSelectNodeUponCreation(bool value);
183 
186  bool noneEnabled()const;
189  void setNoneEnabled(bool enable);
190 
193  bool addEnabled()const;
194  void setAddEnabled(bool enable);
195 
198  bool removeEnabled()const;
199  void setRemoveEnabled(bool enable);
200 
203  bool editEnabled()const;
204  void setEditEnabled(bool enable);
205 
207  bool renameEnabled()const;
208  void setRenameEnabled(bool enable);
209 
212  QString noneDisplay()const;
213 
216  void setNoneDisplay(const QString& displayName);
217 
219  QList<vtkMRMLNode*> nodes()const;
220 
224  QAbstractItemModel* model()const;
225 
229  Q_INVOKABLE qMRMLSortFilterProxyModel* sortFilterProxyModel()const;
230 
235  qMRMLSceneModel* sceneModel()const;
236 
244  qMRMLNodeFactory* nodeFactory()const;
245 
247  QComboBox::SizeAdjustPolicy sizeAdjustPolicy()const;
248  void setSizeAdjustPolicy(QComboBox::SizeAdjustPolicy policy);
249 
259  Q_INVOKABLE virtual void addMenuAction(QAction *newAction);
260 
261 public slots:
264  virtual void setMRMLScene(vtkMRMLScene* scene);
265 
267  void setCurrentNode(vtkMRMLNode* node);
268 
271  void setCurrentNode(const QString& nodeID);
272 
275  void setCurrentNodeID(const QString& nodeID);
276 
281  void setCurrentNodeIndex(int index);
282 
292  virtual vtkMRMLNode* addNode(QString nodeType);
293 
300  virtual vtkMRMLNode* addNode();
301 
304  virtual void removeCurrentNode();
305 
307  virtual void editCurrentNode();
308 
312  virtual void renameCurrentNode();
313 
314 signals:
317  void currentNodeChanged(vtkMRMLNode* node);
318 
321  void currentNodeIDChanged(const QString& id);
322 
329  void nodeActivated(vtkMRMLNode* node);
330 
336  void currentNodeChanged(bool validNode);
337 
340 
343  void nodeAdded(vtkMRMLNode* node);
344 
346  void nodeAddedByUser(vtkMRMLNode* node);
347 
350  void nodeAboutToBeRemoved(vtkMRMLNode* node);
351 
354 
356  void currentNodeRenamed(const QString& newName);
357 
359  void nodeAboutToBeEdited(vtkMRMLNode* node);
360 
361 protected:
363  qMRMLNodeComboBox(QAbstractItemModel* model, QWidget* parent = 0);
364  qMRMLNodeComboBox(qMRMLNodeComboBoxPrivate* pimpl, QWidget* parent = 0);
365  QAbstractItemModel* rootModel()const;
366 
367  void setComboBox(QComboBox* comboBox);
368 
371  QComboBox* comboBox()const;
372 
373  virtual void changeEvent(QEvent* event);
374 
375 protected slots:
376  void activateExtraItem(const QModelIndex& index);
377  void emitCurrentNodeChanged();
378  void emitNodeActivated(int currentIndex);
379  void emitNodesAdded(const QModelIndex & parent, int start, int end);
380  void emitNodesAboutToBeRemoved(const QModelIndex & parent, int start, int end);
381  void refreshIfCurrentNodeHidden();
382 
383 protected:
384  QScopedPointer<qMRMLNodeComboBoxPrivate> d_ptr;
385 
386 private:
387  Q_DECLARE_PRIVATE(qMRMLNodeComboBox);
388  Q_DISABLE_COPY(qMRMLNodeComboBox);
389 };
390 
391 // --------------------------------------------------------------------------
392 void qMRMLNodeComboBox::setShowHidden(bool enable)
393 {
394  this->sortFilterProxyModel()->setShowHidden(enable);
395 }
396 
397 // --------------------------------------------------------------------------
399 {
400  return this->sortFilterProxyModel()->showHidden();
401 }
402 
403 // --------------------------------------------------------------------------
405 {
406  this->sortFilterProxyModel()->setShowChildNodeTypes(show);
407 }
408 
409 // --------------------------------------------------------------------------
411 {
412  return this->sortFilterProxyModel()->showChildNodeTypes();
413 }
414 
415 // --------------------------------------------------------------------------
416 void qMRMLNodeComboBox::setHideChildNodeTypes(const QStringList& _nodeTypes)
417 {
418  this->sortFilterProxyModel()->setHideChildNodeTypes(_nodeTypes);
419 }
420 
421 // --------------------------------------------------------------------------
422 QStringList qMRMLNodeComboBox::hideChildNodeTypes()const
423 {
424  return this->sortFilterProxyModel()->hideChildNodeTypes();
425 }
426 
427 #endif
void setHideChildNodeTypes(const QStringList &nodeTypes)
QStringList hideChildNodeTypes() const
A set of MRML Nodes that supports serialization and undo/redo.
Definition: vtkMRMLScene.h:54
bool showChildNodeTypes() const
void setShowChildNodeTypes(bool show)
Combobox that automatically displays all the nodes of the scene that match filtering criteria...
bool showHidden() const
Abstract Superclass for all specific types of MRML nodes.
Definition: vtkMRMLNode.h:135