From 503a2ff6cdbc43140b8d6887d9fd0a6598db40bc Mon Sep 17 00:00:00 2001 From: wmayer Date: Wed, 20 Oct 2021 22:33:50 +0200 Subject: [PATCH] Gui: [skip ci] improve whitespaces --- src/Gui/ActiveObjectList.cpp | 94 ++++++++++++++++++++---------------- 1 file changed, 53 insertions(+), 41 deletions(-) diff --git a/src/Gui/ActiveObjectList.cpp b/src/Gui/ActiveObjectList.cpp index aff4d1b06b..2d7bf2184d 100644 --- a/src/Gui/ActiveObjectList.cpp +++ b/src/Gui/ActiveObjectList.cpp @@ -44,93 +44,107 @@ App::DocumentObject *ActiveObjectList::getObject(const ObjectInfo &info, bool re App::DocumentObject **parent, std::string *subname) const { - if(parent) *parent = info.obj; - if(subname) *subname = info.subname; + if (parent) + *parent = info.obj; + if (subname) + *subname = info.subname; auto obj = info.obj; - if(!obj || !obj->getNameInDocument()) - return 0; - if(info.subname.size()) { + if (!obj || !obj->getNameInDocument()) + return nullptr; + if (!info.subname.empty()) { obj = obj->getSubObject(info.subname.c_str()); - if(!obj) - return 0; + if (!obj) + return nullptr; } - return resolve?obj->getLinkedObject(true):obj; + + return resolve ? obj->getLinkedObject(true) : obj; } void ActiveObjectList::setHighlight(const ObjectInfo &info, HighlightMode mode, bool enable) { - auto obj = getObject(info,false); - if(!obj) return; + auto obj = getObject(info, false); + if (!obj) + return; auto vp = dynamic_cast(Application::Instance->getViewProvider(obj)); - if(!vp) return; + if (!vp) + return; if (TreeParams::Instance()->TreeActiveAutoExpand()) { vp->getDocument()->signalExpandObject(*vp, enable ? TreeItemMode::ExpandPath : TreeItemMode::CollapseItem, info.obj, info.subname.c_str()); } - vp->getDocument()->signalHighlightObject(*vp, mode,enable,info.obj,info.subname.c_str()); + vp->getDocument()->signalHighlightObject(*vp, mode, enable, info.obj, info.subname.c_str()); } Gui::ActiveObjectList::ObjectInfo Gui::ActiveObjectList::getObjectInfo(App::DocumentObject *obj, const char *subname) const { ObjectInfo info; - info.obj = 0; - if(!obj || !obj->getNameInDocument()) + info.obj = nullptr; + if (!obj || !obj->getNameInDocument()) return info; - if(subname) { + + if (subname) { info.obj = obj; info.subname = subname; - }else{ + } + else { // If the input object is not from this document, it must be brought in // by some link type object of this document. We only accept the object // if we can find such object in the current selection. auto sels = Gui::Selection().getSelection(_Doc->getDocument()->getName(),false); - for(auto &sel : sels) { - if(sel.pObject == obj || sel.pObject->getLinkedObject(true)==obj) { + for (auto &sel : sels) { + if (sel.pObject == obj || sel.pObject->getLinkedObject(true)==obj) { info.obj = sel.pObject; break; } - for(auto dot=strchr(sel.SubName,'.');dot;dot=strchr(dot+1,'.')) { + + for (auto dot=strchr(sel.SubName,'.');dot;dot=strchr(dot+1,'.')) { std::string subname(sel.SubName,dot-sel.SubName+1); auto sobj = sel.pObject->getSubObject(subname.c_str()); - if(!sobj) break; - if(sobj == obj || sobj->getLinkedObject(true) == obj) { + if (!sobj) + break; + if (sobj == obj || sobj->getLinkedObject(true) == obj) { info.obj = sel.pObject; info.subname = subname; break; } } - if(info.obj) break; + + if (info.obj) + break; } - if(!info.obj && obj->getDocument()==_Doc->getDocument()) + + if (!info.obj && obj->getDocument()==_Doc->getDocument()) info.obj = obj; } return info; } bool Gui::ActiveObjectList::hasObject(App::DocumentObject *obj, - const char *name, const char *subname) const + const char *name, const char *subname) const { auto it = _ObjectMap.find(name); - if(it==_ObjectMap.end()) + if (it == _ObjectMap.end()) return false; - auto info = getObjectInfo(obj,subname); - return info.obj==it->second.obj && info.subname==it->second.subname; + auto info = getObjectInfo(obj, subname); + return info.obj == it->second.obj && info.subname == it->second.subname; } void Gui::ActiveObjectList::setObject(App::DocumentObject* obj, const char* name, - const char *subname, const Gui::HighlightMode& mode) + const char *subname, const Gui::HighlightMode& mode) { auto it = _ObjectMap.find(name); - if(it!=_ObjectMap.end()) { - setHighlight(it->second,mode,false); + if (it!=_ObjectMap.end()) { + setHighlight(it->second, mode, false); _ObjectMap.erase(it); } - if(!obj) return; + + if (!obj) + return; auto info = getObjectInfo(obj,subname); - if(!info.obj) { + if (!info.obj) { FC_ERR("Cannot set active object " << obj->getFullName() << '.' << (subname?subname:"") << " in document '" << _Doc->getDocument()->getName() @@ -139,7 +153,7 @@ void Gui::ActiveObjectList::setObject(App::DocumentObject* obj, const char* name } _ObjectMap[name] = info; - setHighlight(info,mode,true); + setHighlight(info, mode, true); } bool Gui::ActiveObjectList::hasObject(const char*name)const @@ -149,13 +163,11 @@ bool Gui::ActiveObjectList::hasObject(const char*name)const void ActiveObjectList::objectDeleted(const ViewProviderDocumentObject &vp) { - //maybe boost::bimap or boost::multi_index - for (auto it = _ObjectMap.begin(); it != _ObjectMap.end(); ++it) - { - if (it->second.obj == vp.getObject()) - { - _ObjectMap.erase(it); - return; + //maybe boost::bimap or boost::multi_index + for (auto it = _ObjectMap.begin(); it != _ObjectMap.end(); ++it) { + if (it->second.obj == vp.getObject()) { + _ObjectMap.erase(it); + return; + } } - } }