16 #include "mapMetaProperty.h" 23 QAbstractTableModel(parent),
24 m_pMetaInterface(nullptr)
31 SetAlgorithm(map::algorithm::RegistrationAlgorithmBase *pAlgorithm)
33 this->
SetAlgorithm(dynamic_cast<map::algorithm::facet::MetaPropertyAlgorithmInterface*>(pAlgorithm));
38 SetAlgorithm(map::algorithm::facet::MetaPropertyAlgorithmInterface *pMetaInterface)
40 emit beginResetModel();
42 m_pMetaInterface = pMetaInterface;
43 this->UpdateMetaProperties();
57 return m_MetaProperties.size();
72 data(
const QModelIndex &index,
int role)
const 84 if(index.row()<m_MetaProperties.size())
86 map::algorithm::MetaPropertyInfo* pInfo = m_MetaProperties[index.row()];
88 switch(index.column())
91 if(Qt::DisplayRole == role && index.row()<m_MetaProperties.size())
93 result = QVariant(pInfo->getName().c_str());
97 if (Qt::DisplayRole == role && !pInfo->isReadable())
99 result = QVariant(
"value is not accessible");
101 else if (pInfo->isReadable() && (Qt::DisplayRole == role || (Qt::EditRole == role && pInfo->isWritable())))
103 result = GetPropertyValue(pInfo,role);
114 flags(
const QModelIndex &index)
const 116 Qt::ItemFlags
flags = QAbstractItemModel::flags(index);
118 if(index.row()<m_MetaProperties.size())
120 map::algorithm::MetaPropertyInfo* pInfo = m_MetaProperties[index.row()];
121 if (index.column() == 1)
123 if (index.data(Qt::EditRole).isValid() && pInfo->isWritable())
125 flags |= Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable;
135 headerData(
int section, Qt::Orientation orientation,
int role)
const 137 if( (Qt::DisplayRole == role) &&
138 (Qt::Horizontal == orientation))
142 return QVariant(
"Property");
146 return QVariant(
"Value");
154 setData(
const QModelIndex &index,
const QVariant &value,
int role)
156 if(!index.isValid() || (m_MetaProperties.size() <= index.row()) || (1 != index.column()))
161 if(Qt::EditRole == role)
163 map::algorithm::MetaPropertyInfo* pInfo = m_MetaProperties[index.row()];
165 bool result = SetPropertyValue(pInfo,value);
169 emit beginResetModel();
170 this->UpdateMetaProperties();
171 emit endResetModel();
183 UpdateMetaProperties()
const 187 m_MetaProperties = m_pMetaInterface->getPropertyInfos();
191 m_MetaProperties.clear();
197 GetPropertyValue(
const map::algorithm::MetaPropertyInfo* pInfo,
int role)
const 199 if(!m_pMetaInterface)
204 map::algorithm::facet::MetaPropertyAlgorithmInterface::MetaPropertyPointer prop = m_pMetaInterface->getProperty(pInfo);
213 if (role == Qt::DisplayRole)
215 result = QVariant(QString(
"Error. Cannot unwrap MetaProperty. Name: ")+QString::fromStdString(pInfo->getName()));
218 if (prop->getMetaPropertyTypeInfo()==
typeid(bool))
221 if (map::core::unwrapCastedMetaProperty(prop,val))
223 result = QVariant(val);
226 else if (prop->getMetaPropertyTypeInfo()==
typeid(int))
229 if (map::core::unwrapCastedMetaProperty(prop,val))
231 result = QVariant(val);
234 else if (prop->getMetaPropertyTypeInfo()==
typeid(
unsigned int))
237 if (map::core::unwrapCastedMetaProperty(prop,val))
239 result = QVariant(val);
242 else if (prop->getMetaPropertyTypeInfo()==
typeid(long))
245 if (map::core::unwrapCastedMetaProperty(prop,val))
247 result = QVariant(qlonglong(val));
250 else if (prop->getMetaPropertyTypeInfo()==
typeid(
unsigned long))
253 if (map::core::unwrapCastedMetaProperty(prop,val))
255 result = QVariant(qulonglong(val));
258 else if (prop->getMetaPropertyTypeInfo()==
typeid(float))
261 if (map::core::unwrapCastedMetaProperty(prop,val))
263 result = QVariant(val);
266 else if (prop->getMetaPropertyTypeInfo()==
typeid(double))
269 if (map::core::unwrapCastedMetaProperty(prop,val))
271 result = QVariant(val);
274 else if (prop->getMetaPropertyTypeInfo()==
typeid(map::core::String))
276 map::core::String val;
277 if (map::core::unwrapCastedMetaProperty(prop,val))
279 result = QVariant(QString::fromStdString(val));
284 if (role == Qt::DisplayRole)
286 result = QVariant(QString(
"Error. Cannot offer MetaProperty because of unsupported type. Property name: ")+QString::fromStdString(pInfo->getName())+QString(
"; type name: ")+QString(prop->getMetaPropertyTypeName()));
292 template <
typename TValueType>
295 CheckCastAndSetProp(
const map::algorithm::MetaPropertyInfo* pInfo,
const QVariant& value)
298 if (pInfo->getTypeInfo()==
typeid(TValueType) && value.canConvert<TValueType>())
301 TValueType val = value.value<TValueType>();
302 map::core::MetaPropertyBase::Pointer spMetaProp = map::core::MetaProperty<TValueType>::New(val).GetPointer();
304 result = m_pMetaInterface->setProperty(pInfo,spMetaProp);
311 SetPropertyValue(
const map::algorithm::MetaPropertyInfo* pInfo,
const QVariant& value)
313 if(!m_pMetaInterface)
318 bool result = CheckCastAndSetProp<bool>(pInfo,value);
320 if (!result) result = CheckCastAndSetProp<int>(pInfo,value);
321 if (!result) result = CheckCastAndSetProp<unsigned int>(pInfo,value);
322 if (!result) result = CheckCastAndSetProp<long>(pInfo,value);
323 if (!result) result = CheckCastAndSetProp<unsigned long>(pInfo,value);
324 if (!result) result = CheckCastAndSetProp<float>(pInfo,value);
325 if (!result) result = CheckCastAndSetProp<double>(pInfo,value);
326 if (!result && pInfo->getTypeInfo()==
typeid(map::core::String))
328 map::core::String val = value.toString().toStdString();
329 map::core::MetaPropertyBase::Pointer spMetaProp = map::core::MetaProperty<map::core::String>::New(val).GetPointer();
331 result = m_pMetaInterface->setProperty(pInfo,spMetaProp);
void SetAlgorithm(map::algorithm::RegistrationAlgorithmBase *pAlgorithm)
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const
virtual Qt::ItemFlags flags(const QModelIndex &index) const
DataCollection - Class to facilitate loading/accessing structured data.
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)
QMAPAlgorithmModel(QObject *parent=nullptr)
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const