15 #include "mapMetaProperty.h" 23 this->
SetAlgorithm(dynamic_cast<map::algorithm::facet::MetaPropertyAlgorithmInterface *>(pAlgorithm));
28 emit beginResetModel();
30 m_pMetaInterface = pMetaInterface;
31 this->UpdateMetaProperties();
43 return m_MetaProperties.size();
59 if (!m_pMetaInterface)
66 if (index.row() <
static_cast<int>(m_MetaProperties.size()))
68 map::algorithm::MetaPropertyInfo *pInfo = m_MetaProperties[index.row()];
70 switch (index.column())
73 if (Qt::DisplayRole == role && index.row() <
static_cast<int>(m_MetaProperties.size()))
75 result = QVariant(pInfo->getName().c_str());
79 if (Qt::DisplayRole == role && !pInfo->isReadable())
81 result = QVariant(
"value is not accessible");
83 else if (pInfo->isReadable() && (Qt::DisplayRole == role || (Qt::EditRole == role && pInfo->isWritable())))
85 result = GetPropertyValue(pInfo, role);
96 Qt::ItemFlags
flags = QAbstractItemModel::flags(index);
98 if (index.row() <
static_cast<int>(m_MetaProperties.size()))
100 map::algorithm::MetaPropertyInfo *pInfo = m_MetaProperties[index.row()];
101 if (index.column() == 1)
103 if (index.data(Qt::EditRole).isValid() && pInfo->isWritable())
105 flags |= Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable;
115 if ((Qt::DisplayRole == role) && (Qt::Horizontal == orientation))
119 return QVariant(
"Property");
121 else if (section == 1)
123 return QVariant(
"Value");
131 if (!index.isValid() || (
static_cast<int>(m_MetaProperties.size()) <= index.row()) || (1 != index.column()))
136 if (Qt::EditRole == role)
138 map::algorithm::MetaPropertyInfo *pInfo = m_MetaProperties[index.row()];
140 bool result = SetPropertyValue(pInfo, value);
144 emit beginResetModel();
145 this->UpdateMetaProperties();
146 emit endResetModel();
155 void QmitkMAPAlgorithmModel::UpdateMetaProperties()
const 157 if (m_pMetaInterface)
159 m_MetaProperties = m_pMetaInterface->getPropertyInfos();
163 m_MetaProperties.clear();
167 QVariant QmitkMAPAlgorithmModel::GetPropertyValue(
const map::algorithm::MetaPropertyInfo *pInfo,
int role)
const 169 if (!m_pMetaInterface)
174 map::algorithm::facet::MetaPropertyAlgorithmInterface::MetaPropertyPointer prop =
175 m_pMetaInterface->getProperty(pInfo);
184 if (role == Qt::DisplayRole)
186 result = QVariant(QString(
"Error. Cannot unwrap MetaProperty. Name: ") + QString::fromStdString(pInfo->getName()));
189 if (prop->getMetaPropertyTypeInfo() ==
typeid(bool))
192 if (map::core::unwrapCastedMetaProperty(prop, val))
194 result = QVariant(val);
197 else if (prop->getMetaPropertyTypeInfo() ==
typeid(int))
200 if (map::core::unwrapCastedMetaProperty(prop, val))
202 result = QVariant(val);
205 else if (prop->getMetaPropertyTypeInfo() ==
typeid(
unsigned int))
208 if (map::core::unwrapCastedMetaProperty(prop, val))
210 result = QVariant(val);
213 else if (prop->getMetaPropertyTypeInfo() ==
typeid(long))
216 if (map::core::unwrapCastedMetaProperty(prop, val))
218 result = QVariant(qlonglong(val));
221 else if (prop->getMetaPropertyTypeInfo() ==
typeid(
unsigned long))
224 if (map::core::unwrapCastedMetaProperty(prop, val))
226 result = QVariant(qulonglong(val));
229 else if (prop->getMetaPropertyTypeInfo() ==
typeid(float))
232 if (map::core::unwrapCastedMetaProperty(prop, val))
234 result = QVariant(val);
237 else if (prop->getMetaPropertyTypeInfo() ==
typeid(double))
240 if (map::core::unwrapCastedMetaProperty(prop, val))
242 result = QVariant(val);
245 else if (prop->getMetaPropertyTypeInfo() ==
typeid(map::core::String))
247 map::core::String val;
248 if (map::core::unwrapCastedMetaProperty(prop, val))
250 result = QVariant(QString::fromStdString(val));
255 if (role == Qt::DisplayRole)
257 result = QVariant(QString(
"Error. Cannot offer MetaProperty because of unsupported type. Property name: ") +
258 QString::fromStdString(pInfo->getName()) + QString(
"; type name: ") +
259 QString(prop->getMetaPropertyTypeName()));
265 template <
typename TValueType>
266 bool QmitkMAPAlgorithmModel::CheckCastAndSetProp(
const map::algorithm::MetaPropertyInfo *pInfo,
const QVariant &value)
269 if (pInfo->getTypeInfo() ==
typeid(TValueType) && value.canConvert<TValueType>())
273 TValueType val = value.value<TValueType>();
274 map::core::MetaPropertyBase::Pointer spMetaProp = map::core::MetaProperty<TValueType>::New(val).GetPointer();
276 result = m_pMetaInterface->setProperty(pInfo, spMetaProp);
281 bool QmitkMAPAlgorithmModel::SetPropertyValue(
const map::algorithm::MetaPropertyInfo *pInfo,
const QVariant &value)
283 if (!m_pMetaInterface)
288 bool result = CheckCastAndSetProp<bool>(pInfo, value);
291 result = CheckCastAndSetProp<int>(pInfo, value);
293 result = CheckCastAndSetProp<unsigned int>(pInfo, value);
295 result = CheckCastAndSetProp<long>(pInfo, value);
297 result = CheckCastAndSetProp<unsigned long>(pInfo, value);
299 result = CheckCastAndSetProp<float>(pInfo, value);
301 result = CheckCastAndSetProp<double>(pInfo, value);
302 if (!result && pInfo->getTypeInfo() ==
typeid(map::core::String))
304 map::core::String val = value.toString().toStdString();
305 map::core::MetaPropertyBase::Pointer spMetaProp = map::core::MetaProperty<map::core::String>::New(val).GetPointer();
307 result = m_pMetaInterface->setProperty(pInfo, spMetaProp);
int columnCount(const QModelIndex &parent=QModelIndex()) const override
QVariant headerData(int section, Qt::Orientation orientation, int role) const override
Qt::ItemFlags flags(const QModelIndex &index) const override
QVariant data(const QModelIndex &index, int role) const override
int rowCount(const QModelIndex &parent=QModelIndex()) const override
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
QmitkMAPAlgorithmModel(QObject *parent=nullptr)
void SetAlgorithm(map::algorithm::RegistrationAlgorithmBase *pAlgorithm)