17#include "mitkMessage.h"
18#include "mitkProperties.h"
19#include "mitkRenderingManager.h"
23 QAbstractTableModel(parent),
34 m_DataStorage->AddNodeEvent.RemoveListener(m_ListenerAddNode);
35 m_DataStorage->ChangedNodeEvent.RemoveListener(m_ListenerChangeNode);
36 m_DataStorage->InteractorChangedNodeEvent.RemoveListener(m_ListenerChangeNode);
37 m_DataStorage->RemoveNodeEvent.RemoveListener(m_ListenerRemoveNode);
49 m_DataStorage->RemoveNodeEvent.AddListener(m_ListenerRemoveNode);
50 m_DataStorage->ChangedNodeEvent.AddListener(m_ListenerChangeNode);
51 m_DataStorage->InteractorChangedNodeEvent.AddListener(m_ListenerChangeNode);
59 MITK_ERROR <<
"DataStorage has to be set before adding the first zone node.";
60 mitkThrow() <<
"DataStorage has to be set before adding the first zone node.";
71 mitk::DataStorage::SetOfObjects::ConstPointer sourceNodes =
m_DataStorage->GetSources(node);
72 mitk::DataStorage::SetOfObjects::ConstIterator baseNodeIt = sourceNodes->Begin();
73 while ( baseNodeIt != sourceNodes->End() && baseNodeIt->Value() !=
m_BaseNode ) { ++baseNodeIt; }
76 if ( baseNodeIt == sourceNodes->End() ) {
return; }
79 this->insertRow(newRowIndex);
80 m_ZoneNodes.at(newRowIndex) =
const_cast<mitk::DataNode*
>(node);
83 emit dataChanged(this->index(newRowIndex, 0), this->index(newRowIndex, this->
columnCount()));
89 unsigned int index = 0;
90 DataNodeVector::iterator current =
m_ZoneNodes.begin();
93 if ( *current == node ) {
break; }
104 this->
removeRows(index, 1, QModelIndex(),
false);
126 unsigned int row = oldNodeIt -
m_ZoneNodes.begin();
127 emit dataChanged(this->index(row, 0), this->index(row, this->
columnCount()));
142 if ( role != Qt::DisplayRole ) {
return QVariant(QVariant::Invalid); }
144 if ( orientation == Qt::Horizontal )
148 case 0:
return QVariant(
"Name");
149 case 1:
return QVariant(
"Size");
150 case 2:
return QVariant(
"Color");
155 return QVariant(section+1);
158 return QVariant(QVariant::Invalid);
163 if (index.column() == 1 || index.column() == 2) {
return Qt::ItemIsSelectable | Qt::ItemIsEnabled; }
165 return Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled;
171 if (
static_cast<unsigned int>(index.row()) >=
m_ZoneNodes.size()
172 || index.column() >= this->columnCount())
174 return QVariant(QVariant::Invalid);
177 mitk::DataNode::Pointer curNode =
m_ZoneNodes.at(index.row());
181 case Qt::BackgroundRole:
184 if ( curNode->GetColor(color) )
186 QColor qColor(color[0] * 255, color[1] * 255, color[2] * 255);
187 if (qColor.isValid()) {
return QVariant(QBrush(qColor)); }
194 case Qt::DisplayRole:
196 switch ( index.column() )
200 return QString::fromStdString(curNode->GetName());
207 return static_cast<int>(floatValue);
211 return QVariant(QVariant::Invalid);
217 if ( curNode->GetColor(color) )
219 QColor qColor(color[0] * 255, color[1] * 255, color[2] * 255);
221 if (qColor == Qt::darkGreen) {
return QVariant(
"Green"); }
222 else if (qColor == Qt::red) {
return QVariant(
"Red"); }
223 else if (qColor == Qt::blue) {
return QVariant(
"Blue"); }
224 else if (qColor == Qt::yellow) {
return QVariant(
"Yellow"); }
225 else {
return QVariant(qColor.name()); }
227 else {
return QVariant(QVariant::Invalid); }
234 return QVariant(QVariant::Invalid);
239 if (role == Qt::EditRole)
241 if (
static_cast<unsigned int>(index.row()) >=
m_ZoneNodes.size()
242 || index.column() >= this->columnCount())
247 mitk::DataNode::Pointer curNode =
m_ZoneNodes.at(index.row());
249 switch ( index.column() )
253 curNode->SetName(value.toString().toStdString());
260 if (curNode->GetData() !=
nullptr)
270 QColor color(value.toString());
271 curNode->SetColor(color.redF(), color.greenF(), color.blueF());
278 emit dataChanged(index, index);
282 mitk::RenderingManager::GetInstance()->RequestUpdateAll();
289 this->beginInsertRows(parent, row, row+count-1);
291 for (
int n = 0; n < count; ++n )
296 this->endInsertRows();
303 return this->
removeRows(row, count, parent,
true);
308 if (
static_cast<unsigned int>(row+count) >
m_ZoneNodes.size() ) {
return false; }
310 this->beginRemoveRows(parent, row, row+count-1);
312 for (
int n = count-1; n >= 0; --n )
314 DataNodeVector::iterator it =
m_ZoneNodes.begin()+row+n;
315 mitk::DataNode::Pointer curNode = *it;
324 this->endRemoveRows();
Implementation of the QAbstractTableModel for ultrasound risk zones. This class manages the data mode...
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
Return names for the columns, numbers for the rows and invalid for DisplayRole.
DataNodeVector m_ZoneNodes
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Return model data of the selected cell.
int columnCount(const QModelIndex &parent=QModelIndex()) const override
Return number of columns (3) of the model.
mitk::DataStorage::Pointer m_DataStorage
void SetDataStorage(mitk::DataStorage::Pointer dataStorage, mitk::DataNode::Pointer baseNode)
Set data storage and base node for the zone nodes of this model. The node event listeners will only r...
bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex()) override
Remove given rows from the model.
QmitkUSZonesDataModel(QObject *parent=nullptr)
void RemoveNode(const mitk::DataNode *)
Qt::ItemFlags flags(const QModelIndex &index) const override
Return selectable and enabled for column 1 (size); selectable, enabled and editable for every other c...
void AddNode(const mitk::DataNode *)
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
Set model data for the selected cell.
~QmitkUSZonesDataModel() override
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Return number of rows of the model.
bool insertRows(int row, int count, const QModelIndex &parent=QModelIndex()) override
Insert empty rows into the model (creates zone nodes).
mitk::DataNode::Pointer m_BaseNode
void ChangeNode(const mitk::DataNode *)
static void UpdateSurface(itk::SmartPointer< mitk::DataNode >)
Creates Vtk Sphere according to current radius. The radius is gotten from the float property "zone....
static const char * DATANODE_PROPERTY_SIZE
static const char * DATANODE_PROPERTY_CREATED