Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
QmitkDataStorageComboBoxWithSelectNone.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
14 #include <QDebug>
15 
17 
19  : QmitkDataStorageComboBox(parent, autoSelectNewNodes)
20  , m_CurrentPath("")
21 {
22 }
23 
25  const mitk::NodePredicateBase* predicate,
26  QWidget* parent,
27  bool autoSelectNewNodes)
28  : QmitkDataStorageComboBox(dataStorage, predicate, parent, autoSelectNewNodes)
29 {
30 }
31 
33 {
34 }
35 
37 {
38  int index = QmitkDataStorageComboBox::Find(dataNode);
39  if (index != -1)
40  {
41  index += 1;
42  }
43  return index;
44 }
45 
47 {
48  mitk::DataNode::Pointer result = nullptr;
49 
50  if (this->HasIndex(index))
51  {
52  if (index != 0)
53  {
54  result = m_Nodes.at(index - 1);
55  }
56  }
57  return result;
58 }
59 
61 {
62  return this->GetNode(this->currentIndex());
63 }
64 
66 {
67  int index = Find(node);
68  if (index == -1)
69  {
70  // didn't find it, so set the value to 0.
71  index = 0;
72  }
73 
74  this->setCurrentIndex(index);
75 }
76 
78 {
79  if(index > 0 && this->HasIndex(index))
80  {
81  RemoveNodeAndPropertyLists(index - 1);
82  // remove node name from combobox
83  this->removeItem(index);
84  }
85 }
86 
88 {
89  if (index > 0 && this->HasIndex(index))
90  {
91  // if node is identical, we only update the name in the QComboBoxItem
92  if (dataNode == m_Nodes.at(index - 1))
93  {
94  this->setItemText(index, QString::fromStdString(dataNode->GetName()));
95  }
96  else
97  {
98  QmitkDataStorageComboBox::InsertNode(index - 1, dataNode);
99  }
100  }
101 }
102 
104 {
105  return (m_Nodes.size() > 0 && index <= m_Nodes.size());
106 }
107 
109 {
110  if (index != 0)
111  {
112  QmitkDataStorageComboBox::InsertNode(index - 1, dataNode);
113  }
114 }
115 
117 {
119  this->insertItem(0, ZERO_ENTRY_STRING);
120 }
121 
123 {
124  this->setItemText(0, zeroEntryString);
125  this->setCurrentIndex(0);
126 }
127 
129 {
130  return m_CurrentPath;
131 }
132 
134 {
135  m_CurrentPath = path;
136 }
virtual void SetSelectedNode(const mitk::DataNode::Pointer &node)
Sets the combo box to the index that contains the specified node, or 0 if the node cannot be found...
void SetNode(int index, const mitk::DataNode *dataNode) override
Set a DataNode in the ComboBox at the specified index (if the index exists). Internally the method ju...
Data management class that handles &#39;was created by&#39; relations.
mitk::DataNode::Pointer GetSelectedNode() const override
Returns the selected DataNode or nullptr if there is none, or the current index is zero...
Displays all or a subset (defined by a predicate) of nodes of the Data Storage.
std::vector< mitk::DataNode * > m_Nodes
virtual void InsertNode(int index, const mitk::DataNode *dataNode)
Inserts a new node at the given index. If the index does not exist, the data node is simply appended ...
static const QString ZERO_ENTRY_STRING
Stores the string that will be present on index 0, currently equal to "please select".
void RemoveNode(int index) override
Removes a node from the ComboBox at a specified index (if the index exists). Gets called when a DataS...
bool HasIndex(unsigned int index) const
Checks if the given index is within range.
mitk::DataNode::Pointer GetNode(int index) const override
Retrieves the node at a given index, where if index is zero, will always return nullptr.
virtual void setCurrentValue(const QString &path)
Set the current file path.
void Reset() override
Reset function whenever datastorage or predicate changes.
virtual QString currentValue() const
Get the current file path.
void InsertNode(int index, const mitk::DataNode *dataNode) override
Inserts a new node at the given index, unless index is 0, which is silently ignored.
virtual int Find(const mitk::DataNode *dataNode) const
Searches for a given node and returns a valid index or -1 if the node was not found.
virtual void Reset()
Reset function whenever data storage or predicate changes.
void SetZeroEntryText(const QString &zeroEntryString)
Set the string that will be present on index 0.
Interface for evaluation conditions used in the DataStorage class GetSubset() method.
QmitkDataStorageComboBoxWithSelectNone(QWidget *parent=nullptr, bool autoSelectNewNodes=false)
Calls base class constructor.
Class for nodes of the DataTree.
Definition: mitkDataNode.h:57
bool GetName(std::string &nodeName, const mitk::BaseRenderer *renderer=nullptr, const char *propertyKey="name") const
Convenience access method for accessing the name of an object (instance of StringProperty with proper...
Definition: mitkDataNode.h:369
int Find(const mitk::DataNode *dataNode) const override
Searches for a given node, returning the index if found.