20 #include "mapMetaProperty.h"
27 QAbstractTableModel(parent),
28 m_pMetaInterface(NULL)
35 SetAlgorithm(map::algorithm::RegistrationAlgorithmBase *pAlgorithm)
37 this->
SetAlgorithm(dynamic_cast<map::algorithm::facet::MetaPropertyAlgorithmInterface*>(pAlgorithm));
42 SetAlgorithm(map::algorithm::facet::MetaPropertyAlgorithmInterface *pMetaInterface)
44 emit beginResetModel();
46 m_pMetaInterface = pMetaInterface;
47 this->UpdateMetaProperties();
61 return m_MetaProperties.size();
76 data(
const QModelIndex &index,
int role)
const
88 if(index.row()<m_MetaProperties.size())
90 map::algorithm::MetaPropertyInfo* pInfo = m_MetaProperties[index.row()];
92 switch(index.column())
95 if(Qt::DisplayRole == role && index.row()<m_MetaProperties.size())
97 result = QVariant(pInfo->getName().c_str());
101 if (Qt::DisplayRole == role && !pInfo->isReadable())
103 result = QVariant(
"value is not accessible");
105 else if (pInfo->isReadable() && (Qt::DisplayRole == role || (Qt::EditRole == role && pInfo->isWritable())))
107 result = GetPropertyValue(pInfo,role);
118 flags(
const QModelIndex &index)
const
120 Qt::ItemFlags
flags = QAbstractItemModel::flags(index);
122 if(index.row()<m_MetaProperties.size())
124 map::algorithm::MetaPropertyInfo* pInfo = m_MetaProperties[index.row()];
125 if (index.column() == 1)
127 if (index.data(Qt::EditRole).isValid() && pInfo->isWritable())
129 flags |= Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable;
139 headerData(
int section, Qt::Orientation orientation,
int role)
const
141 if( (Qt::DisplayRole == role) &&
142 (Qt::Horizontal == orientation))
146 return QVariant(
"Property");
150 return QVariant(
"Value");
158 setData(
const QModelIndex &index,
const QVariant &value,
int role)
160 if(!index.isValid() || (m_MetaProperties.size() <= index.row()) || (1 != index.column()))
165 if(Qt::EditRole == role)
167 map::algorithm::MetaPropertyInfo* pInfo = m_MetaProperties[index.row()];
169 bool result = SetPropertyValue(pInfo,value);
173 emit beginResetModel();
174 this->UpdateMetaProperties();
175 emit endResetModel();
187 UpdateMetaProperties()
const
191 m_MetaProperties = m_pMetaInterface->getPropertyInfos();
195 m_MetaProperties.clear();
201 GetPropertyValue(
const map::algorithm::MetaPropertyInfo* pInfo,
int role)
const
203 if(!m_pMetaInterface)
208 map::algorithm::facet::MetaPropertyAlgorithmInterface::MetaPropertyPointer prop = m_pMetaInterface->getProperty(pInfo);
217 if (role == Qt::DisplayRole)
219 result = QVariant(QString(
"Error. Cannot unwrap MetaProperty. Name: ")+QString::fromStdString(pInfo->getName()));
222 if (prop->getMetaPropertyTypeInfo()==
typeid(bool))
225 if (map::core::unwrapCastedMetaProperty(prop,val))
227 result = QVariant(val);
230 else if (prop->getMetaPropertyTypeInfo()==
typeid(int))
233 if (map::core::unwrapCastedMetaProperty(prop,val))
235 result = QVariant(val);
238 else if (prop->getMetaPropertyTypeInfo()==
typeid(
unsigned int))
241 if (map::core::unwrapCastedMetaProperty(prop,val))
243 result = QVariant(val);
246 else if (prop->getMetaPropertyTypeInfo()==
typeid(long))
249 if (map::core::unwrapCastedMetaProperty(prop,val))
251 result = QVariant(qlonglong(val));
254 else if (prop->getMetaPropertyTypeInfo()==
typeid(
unsigned long))
257 if (map::core::unwrapCastedMetaProperty(prop,val))
259 result = QVariant(qulonglong(val));
262 else if (prop->getMetaPropertyTypeInfo()==
typeid(float))
265 if (map::core::unwrapCastedMetaProperty(prop,val))
267 result = QVariant(val);
270 else if (prop->getMetaPropertyTypeInfo()==
typeid(double))
273 if (map::core::unwrapCastedMetaProperty(prop,val))
275 result = QVariant(val);
278 else if (prop->getMetaPropertyTypeInfo()==
typeid(map::core::String))
280 map::core::String val;
281 if (map::core::unwrapCastedMetaProperty(prop,val))
283 result = QVariant(QString::fromStdString(val));
288 if (role == Qt::DisplayRole)
290 result = QVariant(QString(
"Error. Cannot offer MetaProperty because of unsupported type. Property name: ")+QString::fromStdString(pInfo->getName())+QString(
"; type name: ")+QString(prop->getMetaPropertyTypeName()));
296 template <
typename TValueType>
299 CheckCastAndSetProp(
const map::algorithm::MetaPropertyInfo* pInfo,
const QVariant& value)
302 if (pInfo->getTypeInfo()==
typeid(TValueType) && value.canConvert<TValueType>())
305 TValueType val = value.value<TValueType>();
308 result = m_pMetaInterface->setProperty(pInfo,spMetaProp);
315 SetPropertyValue(
const map::algorithm::MetaPropertyInfo* pInfo,
const QVariant& value)
317 if(!m_pMetaInterface)
322 bool result = CheckCastAndSetProp<bool>(pInfo,value);
324 if (!result) result = CheckCastAndSetProp<int>(pInfo,value);
325 if (!result) result = CheckCastAndSetProp<unsigned int>(pInfo,value);
326 if (!result) result = CheckCastAndSetProp<long>(pInfo,value);
327 if (!result) result = CheckCastAndSetProp<unsigned long>(pInfo,value);
328 if (!result) result = CheckCastAndSetProp<float>(pInfo,value);
329 if (!result) result = CheckCastAndSetProp<double>(pInfo,value);
330 if (!result && pInfo->getTypeInfo()==
typeid(map::core::String))
332 map::core::String val = value.toString().toStdString();
335 result = m_pMetaInterface->setProperty(pInfo,spMetaProp);
itk::SmartPointer< Self > Pointer
QMAPAlgorithmModel(QObject *parent=NULL)
void SetAlgorithm(map::algorithm::RegistrationAlgorithmBase *pAlgorithm)
DataCollection - Class to facilitate loading/accessing structured data.
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
virtual Qt::ItemFlags flags(const QModelIndex &index) const
virtual QVariant data(const QModelIndex &index, int role) const
virtual int columnCount(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
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.