19 #include "mapMetaProperty.h"
27 this->
SetAlgorithm(dynamic_cast<map::algorithm::facet::MetaPropertyAlgorithmInterface *>(pAlgorithm));
32 emit beginResetModel();
34 m_pMetaInterface = pMetaInterface;
35 this->UpdateMetaProperties();
47 return m_MetaProperties.size();
63 if (!m_pMetaInterface)
70 if (index.row() < m_MetaProperties.size())
72 map::algorithm::MetaPropertyInfo *pInfo = m_MetaProperties[index.row()];
74 switch (index.column())
77 if (Qt::DisplayRole == role && index.row() < m_MetaProperties.size())
79 result = QVariant(pInfo->getName().c_str());
83 if (Qt::DisplayRole == role && !pInfo->isReadable())
85 result = QVariant(
"value is not accessible");
87 else if (pInfo->isReadable() && (Qt::DisplayRole == role || (Qt::EditRole == role && pInfo->isWritable())))
89 result = GetPropertyValue(pInfo, role);
100 Qt::ItemFlags
flags = QAbstractItemModel::flags(index);
102 if (index.row() < m_MetaProperties.size())
104 map::algorithm::MetaPropertyInfo *pInfo = m_MetaProperties[index.row()];
105 if (index.column() == 1)
107 if (index.data(Qt::EditRole).isValid() && pInfo->isWritable())
109 flags |= Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable;
119 if ((Qt::DisplayRole == role) && (Qt::Horizontal == orientation))
123 return QVariant(
"Property");
125 else if (section == 1)
127 return QVariant(
"Value");
135 if (!index.isValid() || (m_MetaProperties.size() <= index.row()) || (1 != index.column()))
140 if (Qt::EditRole == role)
142 map::algorithm::MetaPropertyInfo *pInfo = m_MetaProperties[index.row()];
144 bool result = SetPropertyValue(pInfo, value);
148 emit beginResetModel();
149 this->UpdateMetaProperties();
150 emit endResetModel();
159 void QmitkMAPAlgorithmModel::UpdateMetaProperties()
const
161 if (m_pMetaInterface)
163 m_MetaProperties = m_pMetaInterface->getPropertyInfos();
167 m_MetaProperties.clear();
171 QVariant QmitkMAPAlgorithmModel::GetPropertyValue(
const map::algorithm::MetaPropertyInfo *pInfo,
int role)
const
173 if (!m_pMetaInterface)
178 map::algorithm::facet::MetaPropertyAlgorithmInterface::MetaPropertyPointer prop =
179 m_pMetaInterface->getProperty(pInfo);
188 if (role == Qt::DisplayRole)
190 result = QVariant(QString(
"Error. Cannot unwrap MetaProperty. Name: ") + QString::fromStdString(pInfo->getName()));
193 if (prop->getMetaPropertyTypeInfo() ==
typeid(bool))
196 if (map::core::unwrapCastedMetaProperty(prop, val))
198 result = QVariant(val);
201 else if (prop->getMetaPropertyTypeInfo() ==
typeid(int))
204 if (map::core::unwrapCastedMetaProperty(prop, val))
206 result = QVariant(val);
209 else if (prop->getMetaPropertyTypeInfo() ==
typeid(
unsigned int))
212 if (map::core::unwrapCastedMetaProperty(prop, val))
214 result = QVariant(val);
217 else if (prop->getMetaPropertyTypeInfo() ==
typeid(long))
220 if (map::core::unwrapCastedMetaProperty(prop, val))
222 result = QVariant(qlonglong(val));
225 else if (prop->getMetaPropertyTypeInfo() ==
typeid(
unsigned long))
228 if (map::core::unwrapCastedMetaProperty(prop, val))
230 result = QVariant(qulonglong(val));
233 else if (prop->getMetaPropertyTypeInfo() ==
typeid(float))
236 if (map::core::unwrapCastedMetaProperty(prop, val))
238 result = QVariant(val);
241 else if (prop->getMetaPropertyTypeInfo() ==
typeid(double))
244 if (map::core::unwrapCastedMetaProperty(prop, val))
246 result = QVariant(val);
249 else if (prop->getMetaPropertyTypeInfo() ==
typeid(map::core::String))
251 map::core::String val;
252 if (map::core::unwrapCastedMetaProperty(prop, val))
254 result = QVariant(QString::fromStdString(val));
259 if (role == Qt::DisplayRole)
261 result = QVariant(QString(
"Error. Cannot offer MetaProperty because of unsupported type. Property name: ") +
262 QString::fromStdString(pInfo->getName()) + QString(
"; type name: ") +
263 QString(prop->getMetaPropertyTypeName()));
269 template <
typename TValueType>
270 bool QmitkMAPAlgorithmModel::CheckCastAndSetProp(
const map::algorithm::MetaPropertyInfo *pInfo,
const QVariant &value)
273 if (pInfo->getTypeInfo() ==
typeid(TValueType) && value.canConvert<TValueType>())
277 TValueType val = value.value<TValueType>();
280 result = m_pMetaInterface->setProperty(pInfo, spMetaProp);
285 bool QmitkMAPAlgorithmModel::SetPropertyValue(
const map::algorithm::MetaPropertyInfo *pInfo,
const QVariant &value)
287 if (!m_pMetaInterface)
292 bool result = CheckCastAndSetProp<bool>(pInfo, value);
295 result = CheckCastAndSetProp<int>(pInfo, value);
297 result = CheckCastAndSetProp<unsigned int>(pInfo, value);
299 result = CheckCastAndSetProp<long>(pInfo, value);
301 result = CheckCastAndSetProp<unsigned long>(pInfo, value);
303 result = CheckCastAndSetProp<float>(pInfo, value);
305 result = CheckCastAndSetProp<double>(pInfo, value);
306 if (!result && pInfo->getTypeInfo() ==
typeid(map::core::String))
308 map::core::String val = value.toString().toStdString();
311 result = m_pMetaInterface->setProperty(pInfo, spMetaProp);
itk::SmartPointer< Self > Pointer
virtual QVariant data(const QModelIndex &index, int role) const
QmitkMAPAlgorithmModel(QObject *parent=NULL)
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
virtual bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const
virtual Qt::ItemFlags flags(const QModelIndex &index) const
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const
void SetAlgorithm(map::algorithm::RegistrationAlgorithmBase *pAlgorithm)
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.