Slicer  4.11
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 
85  Q_PROPERTY(QString interactionNodeSingletonTag READ interactionNodeSingletonTag WRITE setInteractionNodeSingletonTag)
86 
87  Q_PROPERTY(bool selectNodeUponCreation READ selectNodeUponCreation WRITE setSelectNodeUponCreation)
91  Q_PROPERTY(QString noneDisplay READ noneDisplay WRITE setNoneDisplay)
92 
93  Q_PROPERTY(QComboBox::SizeAdjustPolicy sizeAdjustPolicy READ sizeAdjustPolicy WRITE setSizeAdjustPolicy)
94 
95 public:
96  typedef QWidget Superclass;
97 
100  explicit qMRMLNodeComboBox(QWidget* parent = nullptr);
101  ~qMRMLNodeComboBox() override;
102 
106  Q_INVOKABLE vtkMRMLScene* mrmlScene()const;
107 
111  QStringList nodeTypes()const;
112  void setNodeTypes(const QStringList& nodeTypes);
113 
116  inline void setShowHidden(bool);
117  inline bool showHidden()const;
118 
125  inline void setShowChildNodeTypes(bool show);
126  inline bool showChildNodeTypes()const;
127 
131  inline void setHideChildNodeTypes(const QStringList& nodeTypes);
132  inline QStringList hideChildNodeTypes()const;
133 
144  Q_INVOKABLE void addAttribute(const QString& nodeType,
145  const QString& attributeName,
146  const QVariant& attributeValue = QVariant());
149  Q_INVOKABLE void removeAttribute(const QString& nodeType,
150  const QString& attributeName);
151 
156  void setBaseName(const QString& baseName, const QString& nodeType = "");
157  QString baseName(const QString& nodeType = "")const;
158 
163  Q_INVOKABLE void setNodeTypeLabel(const QString& label, const QString& nodeType);
164  Q_INVOKABLE QString nodeTypeLabel(const QString& nodeType)const;
165 
168  Q_INVOKABLE int nodeCount()const;
169 
173  Q_INVOKABLE vtkMRMLNode* nodeFromIndex(int index)const;
174 
176  Q_INVOKABLE vtkMRMLNode* currentNode()const;
177 
180  QString currentNodeID()const;
181 
184  Q_INVOKABLE QString currentNodeId()const;
185 
189  bool selectNodeUponCreation()const;
190  void setSelectNodeUponCreation(bool value);
191 
194  bool noneEnabled()const;
197  void setNoneEnabled(bool enable);
198 
201  bool addEnabled()const;
202  void setAddEnabled(bool enable);
203 
206  bool removeEnabled()const;
207  void setRemoveEnabled(bool enable);
208 
211  bool editEnabled()const;
212  void setEditEnabled(bool enable);
213 
215  bool renameEnabled()const;
216  void setRenameEnabled(bool enable);
217 
220  QString noneDisplay()const;
221 
224  void setNoneDisplay(const QString& displayName);
225 
227  QList<vtkMRMLNode*> nodes()const;
228 
232  QAbstractItemModel* model()const;
233 
237  Q_INVOKABLE qMRMLSortFilterProxyModel* sortFilterProxyModel()const;
238 
243  qMRMLSceneModel* sceneModel()const;
244 
252  qMRMLNodeFactory* nodeFactory()const;
253 
255  QComboBox::SizeAdjustPolicy sizeAdjustPolicy()const;
256  void setSizeAdjustPolicy(QComboBox::SizeAdjustPolicy policy);
257 
267  Q_INVOKABLE virtual void addMenuAction(QAction *newAction);
268 
269  virtual QString interactionNodeSingletonTag()const;
270  virtual void setInteractionNodeSingletonTag(const QString& tag);
271 
272 public slots:
275  virtual void setMRMLScene(vtkMRMLScene* scene);
276 
278  void setCurrentNode(vtkMRMLNode* node);
279 
282  void setCurrentNode(const QString& nodeID);
283 
286  void setCurrentNodeID(const QString& nodeID);
287 
292  void setCurrentNodeIndex(int index);
293 
303  virtual vtkMRMLNode* addNode(QString nodeType);
304 
311  virtual vtkMRMLNode* addNode();
312 
315  virtual void removeCurrentNode();
316 
318  virtual void editCurrentNode();
319 
323  virtual void renameCurrentNode();
324 
325 signals:
328  void currentNodeChanged(vtkMRMLNode* node);
329 
332  void currentNodeIDChanged(const QString& id);
333 
340  void nodeActivated(vtkMRMLNode* node);
341 
347  void currentNodeChanged(bool validNode);
348 
351 
354  void nodeAdded(vtkMRMLNode* node);
355 
357  void nodeAddedByUser(vtkMRMLNode* node);
358 
361  void nodeAboutToBeRemoved(vtkMRMLNode* node);
362 
365 
367  void currentNodeRenamed(const QString& newName);
368 
370  void nodeAboutToBeEdited(vtkMRMLNode* node);
371 
372 protected:
374  qMRMLNodeComboBox(QAbstractItemModel* model, QWidget* parent = nullptr);
375  qMRMLNodeComboBox(qMRMLNodeComboBoxPrivate* pimpl, QWidget* parent = nullptr);
376  QAbstractItemModel* rootModel()const;
377 
378  void setComboBox(QComboBox* comboBox);
379 
382  QComboBox* comboBox()const;
383 
384  void changeEvent(QEvent* event) override;
385 
386 protected slots:
387  void activateExtraItem(const QModelIndex& index);
388  void emitCurrentNodeChanged();
389  void emitNodeActivated(int currentIndex);
390  void emitNodesAdded(const QModelIndex & parent, int start, int end);
391  void emitNodesAboutToBeRemoved(const QModelIndex & parent, int start, int end);
392  void refreshIfCurrentNodeHidden();
393 
394 protected:
395  QScopedPointer<qMRMLNodeComboBoxPrivate> d_ptr;
396 
397 private:
398  Q_DECLARE_PRIVATE(qMRMLNodeComboBox);
399  Q_DISABLE_COPY(qMRMLNodeComboBox);
400 };
401 
402 // --------------------------------------------------------------------------
403 void qMRMLNodeComboBox::setShowHidden(bool enable)
404 {
405  this->sortFilterProxyModel()->setShowHidden(enable);
406 }
407 
408 // --------------------------------------------------------------------------
410 {
411  return this->sortFilterProxyModel()->showHidden();
412 }
413 
414 // --------------------------------------------------------------------------
416 {
417  this->sortFilterProxyModel()->setShowChildNodeTypes(show);
418 }
419 
420 // --------------------------------------------------------------------------
422 {
423  return this->sortFilterProxyModel()->showChildNodeTypes();
424 }
425 
426 // --------------------------------------------------------------------------
427 void qMRMLNodeComboBox::setHideChildNodeTypes(const QStringList& _nodeTypes)
428 {
429  this->sortFilterProxyModel()->setHideChildNodeTypes(_nodeTypes);
430 }
431 
432 // --------------------------------------------------------------------------
433 QStringList qMRMLNodeComboBox::hideChildNodeTypes()const
434 {
435  return this->sortFilterProxyModel()->hideChildNodeTypes();
436 }
437 
438 #endif
void setHideChildNodeTypes(const QStringList &nodeTypes)
QStringList hideChildNodeTypes() const
A set of MRML Nodes that supports serialization and undo/redo.
Definition: vtkMRMLScene.h:61
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:167