Unify and fix group handling in geofeaturegroups

This commit is contained in:
Stefan Tröger
2017-02-08 07:08:45 +01:00
committed by wmayer
parent c3a9d43143
commit fd62ef30f3
16 changed files with 121 additions and 147 deletions

View File

@@ -63,7 +63,8 @@ void GroupExtension::addObject(DocumentObject* obj)
if(!allowObject(obj))
return;
//only one group per object
//only one group per object. Note that it is allowed to be in a group and geofeaturegroup. However,
//getGroupOfObject() returns only normal groups, no GeoFeatureGroups. Hence this works.
auto *group = App::GroupExtension::getGroupOfObject(obj);
if(group && group != getExtendedObject())
group->getExtensionByType<App::GroupExtension>()->removeObject(obj);
@@ -207,15 +208,16 @@ int GroupExtension::countObjectsOfType(const Base::Type& typeId) const
DocumentObject* GroupExtension::getGroupOfObject(const DocumentObject* obj)
{
const Document* doc = obj->getDocument();
std::vector<DocumentObject*> grps = doc->getObjectsWithExtension(GroupExtension::getExtensionClassTypeId());
for (std::vector<DocumentObject*>::const_iterator it = grps.begin(); it != grps.end(); ++it) {
GroupExtension* grp = (*it)->getExtensionByType<GroupExtension>();
if (grp->hasObject(obj))
return *it;
//note that we return here only Groups, but nothing derived from it, e.g. no GeoFeatureGroups.
//That is important as there are clear differences between groups/geofeature groups (e.g. a object
//can be in only one group, and only one geofeaturegroup, however, it can be in both at the same time)
auto list = obj->getInList();
for (auto obj : list) {
if(obj->hasExtension(App::GroupExtension::getExtensionClassTypeId(), false))
return obj;
}
return 0;
return nullptr;
}
PyObject* GroupExtension::getExtensionPyObject(void) {