50 #ifndef PROPERTYNAMELISTMODEL_HH_
51 #define PROPERTYNAMELISTMODEL_HH_
53 #include <OpenMesh/Core/Utils/BaseProperty.hh>
55 #include <QAbstractListModel>
71 static const char *entity2str(ENTITY_FILTER entity);
75 TypeInfoWrapper(
const std::type_info & ti,
const char *friendlyName) : ti(&ti), friendlyName(friendlyName) {}
76 TypeInfoWrapper(
const std::type_info & ti) : ti(&ti),friendlyName(
"") {}
78 operator const std::type_info *()
const {
return ti; }
79 operator const std::type_info &()
const {
return *ti; }
80 operator const char *()
const {
return friendlyName; }
82 const std::type_info *operator->()
const {
return ti; }
83 const std::type_info &
get()
const {
return *ti; }
84 const char *getName()
const {
return friendlyName; }
91 return strcmp(ti->name(), other.ti->name()) == 0;
95 return strcmp(ti->name(), other.ti->name()) < 0;
99 const std::type_info *ti;
100 const char *friendlyName;
106 propName_(propName), typeinfo_(typeinfo), entity(entity) {}
108 QString toString()
const {
109 return tr(
"%3 %1 : %2").arg(propName_.c_str()).arg(friendlyTypeName()).arg(QString::fromUtf8(entity2str(entity)));
112 bool operator==(
const PROP_INFO &rhs)
const {
113 return propName_ == rhs.propName_ && typeinfo_ == rhs.typeinfo_ && entity == rhs.entity;
116 bool operator<(
const PROP_INFO &rhs)
const {
117 if (entity != rhs.entity)
return entity < rhs.entity;
119 int result = propName_.compare(rhs.propName_);
120 if (result)
return result < 0;
122 return typeinfo_ < rhs.typeinfo_;
125 inline bool isFaceProp()
const {
return entity == EF_FACE; }
126 inline bool isEdgeProp()
const {
return entity == EF_EDGE; }
127 inline bool isHalfedgeProp()
const {
return entity == EF_HALFEDGE; }
128 inline bool isVertexProp()
const {
return entity == EF_VERTEX; }
130 inline const std::string &propName()
const {
return propName_; }
131 inline const char *friendlyTypeName()
const {
return typeinfo_.getName(); }
133 inline ENTITY_FILTER entityType()
const {
return entity; }
136 std::string propName_;
138 ENTITY_FILTER entity;
145 virtual int rowCount(
const QModelIndex & parent = QModelIndex())
const;
146 virtual QVariant data(
const QModelIndex & index,
int role = Qt::DisplayRole)
const;
147 virtual QVariant headerData(
int section, Qt::Orientation orientation,
int role = Qt::DisplayRole)
const;
154 template<
typename MeshT>
155 void refresh(MeshT *mesh, ENTITY_FILTER entityFilterMask, std::type_info *typeIdFilter) {
156 std::vector<PROP_INFO> propList;
159 if (entityFilterMask & EF_FACE)
160 gatherProperties(mesh, mesh->fprops_begin(), mesh->fprops_end(), typeIdFilter, std::back_inserter(propList), EF_FACE);
162 if (entityFilterMask & EF_EDGE)
163 gatherProperties(mesh, mesh->eprops_begin(), mesh->eprops_end(), typeIdFilter, std::back_inserter(propList), EF_EDGE);
165 if (entityFilterMask & EF_HALFEDGE)
166 gatherProperties(mesh, mesh->hprops_begin(), mesh->hprops_end(), typeIdFilter, std::back_inserter(propList), EF_HALFEDGE);
168 if (entityFilterMask & EF_VERTEX)
169 gatherProperties(mesh, mesh->vprops_begin(), mesh->vprops_end(), typeIdFilter, std::back_inserter(propList), EF_VERTEX);
172 std::sort(propList.begin(), propList.end());
174 if (propList != propList_) {
177 propList_.swap(propList);
190 template<
typename MeshT,
typename OUTPUT_ITERATOR>
191 void gatherProperties(MeshT *mesh,
192 typename MeshT::prop_iterator props_first,
193 typename MeshT::prop_iterator props_last,
194 std::type_info *typeIdFilter, OUTPUT_ITERATOR oit,
195 ENTITY_FILTER entity) {
197 for (
typename MeshT::prop_iterator pit = props_first; pit != props_last; ++pit) {
199 if (!baseProp)
continue;
202 TYPE_INFO_SET::const_iterator sane_prop_it = sane_prop_types.find(bp_type);
203 if ((typeIdFilter == 0 ||
TypeInfoWrapper(*typeIdFilter) == bp_type) && sane_prop_it != sane_prop_types.end()) {
204 *oit++ = PROP_INFO(baseProp->
name(), *sane_prop_it, entity);
209 const PROP_INFO &operator[] (
size_t index) {
210 return propList_[index];
214 std::vector<PROP_INFO> propList_;
228 typedef std::set<TypeInfoWrapper> TYPE_INFO_SET;
230 static const TYPE_INFO_SET sane_prop_types;
Wraps the information of a type.
void refresh(MeshT *mesh, ENTITY_FILTER entityFilterMask, std::type_info *typeIdFilter)
const std::string & name() const
Return the name of the property.
bool tryInsertionsDeletions(std::vector< PROP_INFO > &propList)