50 #include "PropertyNameListModel.hh"
52 #include <OpenMesh/Core/Utils/Property.hh>
53 #include <ACG/Math/VectorT.hh>
74 #ifdef ENABLE_SKELETON_SUPPORT
75 #include <ObjectTypes/Skeleton/BaseSkin.hh>
93 #ifdef ENABLE_SKELETON_SUPPORT
98 #ifdef ENABLE_SKELETON_SUPPORT
99 const PropertyNameListModel::TYPE_INFO_SET PropertyNameListModel::sane_prop_types(prop_types, prop_types + 9);
101 const PropertyNameListModel::TYPE_INFO_SET PropertyNameListModel::sane_prop_types(prop_types, prop_types + 8);
104 const char *PropertyNameListModel::entity2str(ENTITY_FILTER entity) {
120 PropertyNameListModel::PropertyNameListModel(QObject *parent) :
121 QAbstractListModel(parent) {
124 PropertyNameListModel::~PropertyNameListModel() {
127 int PropertyNameListModel::rowCount(
const QModelIndex & parent)
const {
128 return propList_.size();
131 QVariant PropertyNameListModel::data(
const QModelIndex & index,
int role)
const {
133 case Qt::DisplayRole:
134 return propList_[index.row()].toString();
136 return QVariant::Invalid;
140 QVariant PropertyNameListModel::headerData(
int section, Qt::Orientation orientation,
int role)
const {
142 case Qt::DisplayRole:
143 return tr(
"Some header. %1 %2").arg(section).arg(orientation);
146 return QAbstractListModel::headerData(section, orientation, role);
153 enum OP { INS, DEL };
154 InsDel(OP op,
int first,
int count,
int before) : op(op), first(first), count(count), before(before) {}
156 int first, count, before;
162 std::vector<InsDel> result;
163 typedef std::vector<PROP_INFO>::iterator IT;
166 for (oldIt = propList_.begin(), newIt = propList.begin(); oldIt < propList_.end() && newIt < propList.end(); ++oldIt, ++newIt) {
167 if (*oldIt == *newIt)
continue;
168 const IT nextNew = std::find(newIt+1, propList.end(), *oldIt);
169 if (nextNew != propList.end()) {
170 const int count = std::distance(newIt, nextNew);
171 result.push_back(InsDel(InsDel::INS, std::distance(propList.begin(), newIt), count, std::distance(propList_.begin(), oldIt) + correction));
176 const IT nextOld = std::find(oldIt+1, propList_.end(), *newIt);
177 if (nextOld != propList_.end()) {
178 const int count = std::distance(oldIt, nextOld);
179 result.push_back(InsDel(InsDel::DEL, std::distance(propList_.begin(), oldIt) + correction, count, 0));
186 if (oldIt < propList_.end() && newIt < propList.end()) {
190 if (oldIt < propList_.end())
191 result.push_back(InsDel(InsDel::DEL, std::distance(propList_.begin(), oldIt) + correction, std::distance(oldIt, propList_.end()), 0));
192 if (newIt < propList.end())
193 result.push_back(InsDel(InsDel::INS, std::distance(propList.begin(), newIt), std::distance(newIt, propList.end()), propList_.size() + correction));
195 for (std::vector<InsDel>::iterator it = result.begin(); it != result.end(); ++it) {
196 if (it->op == InsDel::INS) {
197 beginInsertRows(QModelIndex(), it->before, it->before + it->count - 1);
198 propList_.insert(propList_.begin() + it->before, propList.begin() + it->first, propList.begin() + it->first + it->count);
201 beginRemoveRows(QModelIndex(), it->first, it->first + it->count - 1);
202 propList_.erase(propList_.begin() + it->first, propList_.begin() + it->first + it->count);
207 if (propList_ != propList) {
208 std::cerr <<
"Apparently, the function PropertyNameListModel::tryInsertionsDeletions() has an implementation error." << std::endl;
209 throw std::logic_error(
"Apparently, the function PropertyNameListModel::tryInsertionsDeletions() has an implementation error.");
Default property class for any type T.
bool tryInsertionsDeletions(std::vector< PROP_INFO > &propList)