improve whitespaces and readability
This commit is contained in:
118
src/Gui/Tree.cpp
118
src/Gui/Tree.cpp
@@ -998,32 +998,37 @@ bool DocumentItem::createNewItem(const Gui::ViewProviderDocumentObject& obj,
|
||||
if (!obj.showInTree() || !(name=obj.getObject()->getNameInDocument()))
|
||||
return false;
|
||||
|
||||
if(!ptrs) {
|
||||
if (!ptrs) {
|
||||
auto &items = ObjectMap[name];
|
||||
if(!items) {
|
||||
if (!items) {
|
||||
items.reset(new DocumentObjectItems);
|
||||
}else if(items->size() && parent==NULL) {
|
||||
}
|
||||
else if(items->size() && parent==NULL) {
|
||||
Base::Console().Warning("DocumentItem::slotNewObject: Cannot add view provider twice.\n");
|
||||
return false;
|
||||
}
|
||||
ptrs = items;
|
||||
}
|
||||
|
||||
std::string displayName = obj.getObject()->Label.getValue();
|
||||
std::string objectName = obj.getObject()->getNameInDocument();
|
||||
DocumentObjectItem* item = new DocumentObjectItem(
|
||||
const_cast<Gui::ViewProviderDocumentObject*>(&obj), ptrs);
|
||||
if(!parent) parent = this;
|
||||
if(index<0)
|
||||
|
||||
if (!parent)
|
||||
parent = this;
|
||||
if (index<0)
|
||||
parent->addChild(item);
|
||||
else
|
||||
parent->insertChild(index,item);
|
||||
|
||||
item->setIcon(0, obj.getIcon());
|
||||
item->setText(0, QString::fromUtf8(displayName.c_str()));
|
||||
populateItem(item);
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline bool canCreateItem(const App::DocumentObject *obj, const Document *doc) {
|
||||
static bool canCreateItem(const App::DocumentObject *obj, const Document *doc)
|
||||
{
|
||||
// Note: It is possible that we receive an invalid pointer from
|
||||
// claimChildren(), e.g. if multiple properties were changed in
|
||||
// a transaction and slotChangedObject() is triggered by one
|
||||
@@ -1039,33 +1044,38 @@ static inline bool canCreateItem(const App::DocumentObject *obj, const Document
|
||||
void DocumentItem::slotDeleteObject(const Gui::ViewProviderDocumentObject& view)
|
||||
{
|
||||
auto it = ObjectMap.find(std::string(view.getObject()->getNameInDocument()));
|
||||
if(it == ObjectMap.end() || it->second->empty()) return;
|
||||
if (it == ObjectMap.end() || it->second->empty())
|
||||
return;
|
||||
|
||||
auto &items = *(it->second);
|
||||
for(auto cit=items.begin(),citNext=cit;cit!=items.end();cit=citNext) {
|
||||
for (auto cit=items.begin(),citNext=cit;cit!=items.end();cit=citNext) {
|
||||
++citNext;
|
||||
delete *cit;
|
||||
}
|
||||
if(items.empty())
|
||||
|
||||
if (items.empty())
|
||||
ObjectMap.erase(it);
|
||||
|
||||
// Check for any child of the deleted object is not in the tree, and put it
|
||||
// under document item.
|
||||
const auto &children = view.claimChildren();
|
||||
for(auto child : children) {
|
||||
if(!canCreateItem(child,pDocument))
|
||||
for (auto child : children) {
|
||||
if (!canCreateItem(child,pDocument))
|
||||
continue;
|
||||
auto it = ObjectMap.find(child->getNameInDocument());
|
||||
if(it==ObjectMap.end() || it->second->empty()) {
|
||||
if (it==ObjectMap.end() || it->second->empty()) {
|
||||
ViewProvider* vp = pDocument->getViewProvider(child);
|
||||
if(!vp || !vp->isDerivedFrom(ViewProviderDocumentObject::getClassTypeId()))
|
||||
if (!vp || !vp->isDerivedFrom(ViewProviderDocumentObject::getClassTypeId()))
|
||||
continue;
|
||||
createNewItem(static_cast<ViewProviderDocumentObject&>(*vp));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DocumentItem::populateItem(DocumentObjectItem *item, bool refresh) {
|
||||
if(item->populated && !refresh) return;
|
||||
void DocumentItem::populateItem(DocumentObjectItem *item, bool refresh)
|
||||
{
|
||||
if (item->populated && !refresh)
|
||||
return;
|
||||
|
||||
// Lazy loading policy: We will create an item for each children object if
|
||||
// a) the item is expanded, or b) there is at least one free child, i.e.
|
||||
@@ -1076,84 +1086,99 @@ void DocumentItem::populateItem(DocumentObjectItem *item, bool refresh) {
|
||||
item->setChildIndicatorPolicy(children.empty()?
|
||||
QTreeWidgetItem::DontShowIndicator:QTreeWidgetItem::ShowIndicator);
|
||||
|
||||
if(!item->populated && !item->isExpanded()) {
|
||||
if (!item->populated && !item->isExpanded()) {
|
||||
bool doPopulate = false;
|
||||
for(auto child : children) {
|
||||
if(!canCreateItem(child,pDocument))
|
||||
for (auto child : children) {
|
||||
if (!canCreateItem(child,pDocument))
|
||||
continue;
|
||||
auto it = ObjectMap.find(child->getNameInDocument());
|
||||
if(it == ObjectMap.end() || it->second->empty()) {
|
||||
if (it == ObjectMap.end() || it->second->empty()) {
|
||||
ViewProvider* vp = pDocument->getViewProvider(child);
|
||||
if(!vp || !vp->isDerivedFrom(ViewProviderDocumentObject::getClassTypeId()))
|
||||
if (!vp || !vp->isDerivedFrom(ViewProviderDocumentObject::getClassTypeId()))
|
||||
continue;
|
||||
doPopulate = true;
|
||||
break;
|
||||
}
|
||||
if((*it->second->begin())->parent() == this) {
|
||||
|
||||
if ((*it->second->begin())->parent() == this) {
|
||||
doPopulate = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!doPopulate) return;
|
||||
|
||||
if (!doPopulate)
|
||||
return;
|
||||
}
|
||||
|
||||
item->populated = true;
|
||||
|
||||
int i=-1;
|
||||
// iterate through the claimed children, and try to synchronize them with the
|
||||
// children tree item with the same order of appearance.
|
||||
for(auto child : children) {
|
||||
if(!canCreateItem(child,pDocument)) continue;
|
||||
for (auto child : children) {
|
||||
if (!canCreateItem(child,pDocument))
|
||||
continue;
|
||||
|
||||
++i; // the current index of the claimed child
|
||||
|
||||
bool found = false;
|
||||
for(int j=0,count=item->childCount();j<count;++j) {
|
||||
for (int j=0,count=item->childCount();j<count;++j) {
|
||||
QTreeWidgetItem *ci = item->child(j);
|
||||
if(ci->type() != TreeWidget::ObjectType) continue;
|
||||
if (ci->type() != TreeWidget::ObjectType)
|
||||
continue;
|
||||
|
||||
DocumentObjectItem *childItem = static_cast<DocumentObjectItem*>(ci);
|
||||
if(childItem->object()->getObject() != child) continue;
|
||||
if (childItem->object()->getObject() != child)
|
||||
continue;
|
||||
|
||||
found = true;
|
||||
if(j!=i) { // fix index if it is changed
|
||||
if (j!=i) { // fix index if it is changed
|
||||
item->removeChild(ci);
|
||||
item->insertChild(i,ci);
|
||||
}
|
||||
break;
|
||||
}
|
||||
if(found) continue;
|
||||
|
||||
if (found)
|
||||
continue;
|
||||
|
||||
// This algo will be recursively applied to newly created child items
|
||||
// through slotNewObject -> populateItem
|
||||
|
||||
auto it = ObjectMap.find(child->getNameInDocument());
|
||||
if(it==ObjectMap.end() || it->second->empty()) {
|
||||
if (it==ObjectMap.end() || it->second->empty()) {
|
||||
ViewProvider* vp = pDocument->getViewProvider(child);
|
||||
if(!vp || !vp->isDerivedFrom(ViewProviderDocumentObject::getClassTypeId()) ||
|
||||
!createNewItem(static_cast<ViewProviderDocumentObject&>(*vp),item,i,
|
||||
if (!vp || !vp->isDerivedFrom(ViewProviderDocumentObject::getClassTypeId()) ||
|
||||
!createNewItem(static_cast<ViewProviderDocumentObject&>(*vp),item,i,
|
||||
it==ObjectMap.end()?DocumentObjectItemsPtr():it->second))
|
||||
--i;
|
||||
continue;
|
||||
}
|
||||
|
||||
DocumentObjectItem *childItem = *it->second->begin();
|
||||
if(childItem->parent() != this) {
|
||||
if (childItem->parent() != this) {
|
||||
if(!createNewItem(*childItem->object(),item,i,it->second))
|
||||
--i;
|
||||
}else {
|
||||
if(item==childItem || item->isChildOfItem(childItem)) {
|
||||
}
|
||||
else {
|
||||
if (item==childItem || item->isChildOfItem(childItem)) {
|
||||
Base::Console().Error("Gui::DocumentItem::populateItem(): Cyclic dependency in %s and %s\n",
|
||||
item->object()->getObject()->Label.getValue(),
|
||||
childItem->object()->getObject()->Label.getValue());
|
||||
--i;
|
||||
continue;
|
||||
}
|
||||
|
||||
this->removeChild(childItem);
|
||||
item->insertChild(i,childItem);
|
||||
}
|
||||
}
|
||||
|
||||
App::GeoFeatureGroupExtension* grp = nullptr;
|
||||
if (item->object()->getObject()->hasExtension(App::GeoFeatureGroupExtension::getExtensionClassTypeId()))
|
||||
grp = item->object()->getObject()->getExtensionByType<App::GeoFeatureGroupExtension>();
|
||||
|
||||
for(++i;item->childCount()>i;) {
|
||||
for (++i;item->childCount()>i;) {
|
||||
QTreeWidgetItem *childItem = item->child(i);
|
||||
item->removeChild(childItem);
|
||||
if (childItem->type() == TreeWidget::ObjectType) {
|
||||
@@ -1165,17 +1190,18 @@ void DocumentItem::populateItem(DocumentObjectItem *item, bool refresh) {
|
||||
// whole tree to confirm that. Just let it be. If the other
|
||||
// parent(s) later expanded, this child item will be moved from
|
||||
// root to its parent.
|
||||
if(obj->myselves->size()==1) {
|
||||
if (obj->myselves->size()==1) {
|
||||
// We only make a difference for geofeaturegroups,
|
||||
// as otherwise it comes to confusing behavior to the user when things
|
||||
// get claimed within the group (e.g. pad/sketch, or group)
|
||||
if(grp && grp->hasObject(obj->object()->getObject(), true))
|
||||
if (grp && grp->hasObject(obj->object()->getObject(), true))
|
||||
continue;
|
||||
|
||||
this->addChild(childItem);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
delete childItem;
|
||||
}
|
||||
}
|
||||
@@ -1207,10 +1233,11 @@ void DocumentItem::slotRenameObject(const Gui::ViewProviderDocumentObject& obj)
|
||||
void DocumentItem::slotActiveObject(const Gui::ViewProviderDocumentObject& obj)
|
||||
{
|
||||
std::string objectName = obj.getObject()->getNameInDocument();
|
||||
if(ObjectMap.find(objectName) == ObjectMap.end())
|
||||
if (ObjectMap.find(objectName) == ObjectMap.end())
|
||||
return; // signal is emitted before the item gets created
|
||||
for(auto v : ObjectMap) {
|
||||
for(auto item : *v.second) {
|
||||
|
||||
for (auto v : ObjectMap) {
|
||||
for (auto item : *v.second) {
|
||||
QFont f = item->font(0);
|
||||
f.setBold(item->object() == &obj);
|
||||
item->setFont(0,f);
|
||||
@@ -1218,7 +1245,7 @@ void DocumentItem::slotActiveObject(const Gui::ViewProviderDocumentObject& obj)
|
||||
}
|
||||
}
|
||||
|
||||
void DocumentItem::slotHighlightObject (const Gui::ViewProviderDocumentObject& obj,const Gui::HighlightMode& high,bool set)
|
||||
void DocumentItem::slotHighlightObject (const Gui::ViewProviderDocumentObject& obj, const Gui::HighlightMode& high, bool set)
|
||||
{
|
||||
FOREACH_ITEM(item,obj)
|
||||
QFont f = item->font(0);
|
||||
@@ -1228,13 +1255,13 @@ void DocumentItem::slotHighlightObject (const Gui::ViewProviderDocumentObject& o
|
||||
case Gui::Underlined: f.setUnderline(set); break;
|
||||
case Gui::Overlined: f.setOverline(set); break;
|
||||
case Gui::Blue:
|
||||
if(set)
|
||||
if (set)
|
||||
item->setBackgroundColor(0,QColor(200,200,255));
|
||||
else
|
||||
item->setData(0, Qt::BackgroundColorRole,QVariant());
|
||||
break;
|
||||
case Gui::LightBlue:
|
||||
if(set)
|
||||
if (set)
|
||||
item->setBackgroundColor(0,QColor(230,230,255));
|
||||
else
|
||||
item->setData(0, Qt::BackgroundColorRole,QVariant());
|
||||
@@ -1455,6 +1482,7 @@ DocumentObjectItem::~DocumentObjectItem()
|
||||
assert(0);
|
||||
else
|
||||
myselves->erase(it);
|
||||
|
||||
connectIcon.disconnect();
|
||||
connectTool.disconnect();
|
||||
connectStat.disconnect();
|
||||
|
||||
Reference in New Issue
Block a user