From 04be1a4af9c98f0002ddc457dd922777445767d3 Mon Sep 17 00:00:00 2001 From: Uwe Date: Sat, 4 Dec 2021 02:57:34 +0100 Subject: [PATCH] [GUI] code style fixes for Tree.cpp tons of style fixes by MSVC (the idea was initially just to fix the code style issues from commit 92a8e0e3d8f38 and then MSVC found many more) --- src/Gui/Tree.cpp | 2523 ++++++++++++++++++++++++---------------------- 1 file changed, 1291 insertions(+), 1232 deletions(-) diff --git a/src/Gui/Tree.cpp b/src/Gui/Tree.cpp index f02f0a5f87..2e2c0f41a5 100644 --- a/src/Gui/Tree.cpp +++ b/src/Gui/Tree.cpp @@ -67,7 +67,7 @@ #include "Widgets.h" #include "ExpressionCompleter.h" -FC_LOG_LEVEL_INIT("Tree",false,true,true) +FC_LOG_LEVEL_INIT("Tree", false, true, true) #define _TREE_PRINT(_level,_func,_msg) \ _FC_PRINT(FC_LOG_INSTANCE,_level,_func, '['< TreeWidget::documentPixmap; std::unique_ptr TreeWidget::documentPartialPixmap; -std::set TreeWidget::Instances; -static TreeWidget *_LastSelectedTreeWidget; +std::set TreeWidget::Instances; +static TreeWidget* _LastSelectedTreeWidget; const int TreeWidget::DocumentType = 1000; const int TreeWidget::ObjectType = 1001; bool _DragEventFilter; @@ -113,7 +113,7 @@ void TreeParams::set##_name(_type value) {\ FC_TREEPARAM_DEFS -void TreeParams::OnChange(Base::Subject &, const char* sReason) { +void TreeParams::OnChange(Base::Subject&, const char* sReason) { #undef FC_TREEPARAM_DEF #define FC_TREEPARAM_DEF(_name,_type,_Type,_default) \ @@ -134,7 +134,7 @@ void TreeParams::OnChange(Base::Subject &, const char* sReason) { } void TreeParams::onSyncSelectionChanged() { - if(!TreeParams::Instance()->SyncSelection() || !Gui::Selection().hasSelection()) + if (!TreeParams::Instance()->SyncSelection() || !Gui::Selection().hasSelection()) return; TreeWidget::scrollItemToTop(); } @@ -148,9 +148,9 @@ void TreeParams::onDocumentModeChanged() { App::GetApplication().setActiveDocument(App::GetApplication().getActiveDocument()); } -TreeParams *TreeParams::Instance() { - static TreeParams *instance; - if(!instance) +TreeParams* TreeParams::Instance() { + static TreeParams* instance; + if (!instance) instance = new TreeParams; return instance; } @@ -170,7 +170,7 @@ struct Stats { DEFINE_STATS - void init() { + void init() { #undef DEFINE_STAT #define DEFINE_STAT(_name) \ FC_DURATION_INIT(_name);\ @@ -200,8 +200,8 @@ struct Stats { struct TimingInfo { bool timed = false; FC_TIME_POINT t; - FC_DURATION &d; - TimingInfo(FC_DURATION &d) + FC_DURATION& d; + TimingInfo(FC_DURATION& d) :d(d) { _FC_TIME_INIT(t); @@ -210,9 +210,9 @@ struct TimingInfo { stop(); } void stop() { - if(!timed) { + if (!timed) { timed = true; - FC_DURATION_PLUS(d,t); + FC_DURATION_PLUS(d, t); } } void reset() { @@ -244,10 +244,10 @@ typedef std::set DocumentObjectItems; class Gui::DocumentObjectData { public: - DocumentItem *docItem; + DocumentItem* docItem; DocumentObjectItems items; - ViewProviderDocumentObject *viewObject; - DocumentObjectItem *rootItem; + ViewProviderDocumentObject* viewObject; + DocumentObjectItem* rootItem; std::vector children; std::set childSet; bool removeChildrenFromRoot; @@ -261,16 +261,16 @@ public: Connection connectTool; Connection connectStat; - DocumentObjectData(DocumentItem *docItem, ViewProviderDocumentObject* vpd) - : docItem(docItem), viewObject(vpd),rootItem(0) + DocumentObjectData(DocumentItem* docItem, ViewProviderDocumentObject* vpd) + : docItem(docItem), viewObject(vpd), rootItem(0) { // Setup connections connectIcon = viewObject->signalChangeIcon.connect( - boost::bind(&DocumentObjectData::slotChangeIcon, this)); + boost::bind(&DocumentObjectData::slotChangeIcon, this)); connectTool = viewObject->signalChangeToolTip.connect( - boost::bind(&DocumentObjectData::slotChangeToolTip, this, bp::_1)); + boost::bind(&DocumentObjectData::slotChangeToolTip, this, bp::_1)); connectStat = viewObject->signalChangeStatusTip.connect( - boost::bind(&DocumentObjectData::slotChangeStatusTip, this, bp::_1)); + boost::bind(&DocumentObjectData::slotChangeStatusTip, this, bp::_1)); removeChildrenFromRoot = viewObject->canRemoveChildrenFromRoot(); itemHidden = !viewObject->showInTree(); @@ -278,7 +278,7 @@ public: label2 = viewObject->getObject()->Label2.getValue(); } - const char *getTreeName() const { + const char* getTreeName() const { return docItem->getTreeName(); } @@ -290,28 +290,29 @@ public: bool updateChildren(bool checkVisibility) { auto newChildren = viewObject->claimChildren(); auto obj = viewObject->getObject(); - std::set newSet; + std::set newSet; bool updated = false; for (auto child : newChildren) { auto childVp = docItem->getViewProvider(child); if (!childVp) continue; - if(child && child->getNameInDocument()) { - if(!newSet.insert(child).second) { + if (child && child->getNameInDocument()) { + if (!newSet.insert(child).second) { TREE_WARN("duplicate child item " << obj->getFullName() << '.' << child->getNameInDocument()); - }else if(!childSet.erase(child)) { + } + else if (!childSet.erase(child)) { // this means new child detected updated = true; - if(child->getDocument()==obj->getDocument() && - child->getDocument()==docItem->document()->getDocument()) + if (child->getDocument() == obj->getDocument() && + child->getDocument() == docItem->document()->getDocument()) { - auto &parents = docItem->_ParentMap[child]; - if(parents.insert(obj).second && child->Visibility.getValue()) { + auto& parents = docItem->_ParentMap[child]; + if (parents.insert(obj).second && child->Visibility.getValue()) { bool showable = false; - for(auto parent : parents) { - if(!parent->hasChildElement() - && parent->getLinkedObject(false)==parent) + for (auto parent : parents) { + if (!parent->hasChildElement() + && parent->getLinkedObject(false) == parent) { showable = true; break; @@ -341,12 +342,12 @@ public: } } // We still need to check the order of the children - updated = updated || children!=newChildren; + updated = updated || children != newChildren; children.swap(newChildren); childSet.swap(newSet); - if(updated && checkVisibility) { - for(auto child : children) { + if (updated && checkVisibility) { + for (auto child : children) { auto childVp = docItem->getViewProvider(child); if (childVp && child->getDocument() == obj->getDocument()) childVp->setShowable(docItem->isObjectShowable(child)); @@ -356,9 +357,9 @@ public: } void testStatus(bool resetStatus = false) { - QIcon icon,icon2; - for(auto item : items) - item->testStatus(resetStatus,icon,icon2); + QIcon icon, icon2; + for (auto item : items) + item->testStatus(resetStatus, icon, icon2); } void slotChangeIcon() { @@ -366,34 +367,34 @@ public: } void slotChangeToolTip(const QString& tip) { - for(auto item : items) + for (auto item : items) item->setToolTip(0, tip); } void slotChangeStatusTip(const QString& tip) { - for(auto item : items) + for (auto item : items) item->setStatusTip(0, tip); } }; // --------------------------------------------------------------------------- -class DocumentItem::ExpandInfo: +class DocumentItem::ExpandInfo : public std::unordered_map { public: - void restore(Base::XMLReader &reader) { + void restore(Base::XMLReader& reader) { int level = reader.level(); int count = reader.getAttributeAsInteger("count"); - for(int i=0;irestore(reader); } - reader.readEndElement("Expand",level-1); + reader.readEndElement("Expand", level - 1); } }; @@ -405,21 +406,21 @@ TreeWidgetEditDelegate::TreeWidgetEditDelegate(QObject* parent) } QWidget* TreeWidgetEditDelegate::createEditor( - QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &index) const + QWidget* parent, const QStyleOptionViewItem&, const QModelIndex& index) const { auto ti = static_cast(index.internalPointer()); - if(ti->type()!=TreeWidget::ObjectType || index.column()>1) + if (ti->type() != TreeWidget::ObjectType || index.column() > 1) return 0; - DocumentObjectItem *item = static_cast(ti); - App::DocumentObject *obj = item->object()->getObject(); - auto &prop = index.column()?obj->Label2:obj->Label; + DocumentObjectItem* item = static_cast(ti); + App::DocumentObject* obj = item->object()->getObject(); + auto& prop = index.column() ? obj->Label2 : obj->Label; std::ostringstream str; str << "Change " << obj->getNameInDocument() << '.' << prop.getName(); App::GetApplication().setActiveTransaction(str.str().c_str()); FC_LOG("create editor transaction " << App::GetApplication().getActiveTransaction()); - ExpLineEdit *le = new ExpLineEdit(parent); + ExpLineEdit* le = new ExpLineEdit(parent); le->setFrame(false); le->setReadOnly(prop.isReadOnly()); le->bind(App::ObjectIdentifier(prop)); @@ -429,14 +430,14 @@ QWidget* TreeWidgetEditDelegate::createEditor( // --------------------------------------------------------------------------- -TreeWidget::TreeWidget(const char *name, QWidget* parent) - : QTreeWidget(parent), SelectionObserver(true,0), contextItem(0) +TreeWidget::TreeWidget(const char* name, QWidget* parent) + : QTreeWidget(parent), SelectionObserver(true, 0), contextItem(0) , searchObject(0), searchDoc(0), searchContextDoc(0) , editingItem(0), currentDocItem(0) , myName(name) { Instances.insert(this); - if(!_LastSelectedTreeWidget) + if (!_LastSelectedTreeWidget) _LastSelectedTreeWidget = this; this->setDragEnabled(true); @@ -450,27 +451,27 @@ TreeWidget::TreeWidget(const char *name, QWidget* parent) this->showHiddenAction = new QAction(this); this->showHiddenAction->setCheckable(true); connect(this->showHiddenAction, SIGNAL(triggered()), - this, SLOT(onShowHidden())); + this, SLOT(onShowHidden())); this->hideInTreeAction = new QAction(this); this->hideInTreeAction->setCheckable(true); connect(this->hideInTreeAction, SIGNAL(triggered()), - this, SLOT(onHideInTree())); + this, SLOT(onHideInTree())); this->createGroupAction = new QAction(this); connect(this->createGroupAction, SIGNAL(triggered()), - this, SLOT(onCreateGroup())); + this, SLOT(onCreateGroup())); this->relabelObjectAction = new QAction(this); #ifndef Q_OS_MAC this->relabelObjectAction->setShortcut(Qt::Key_F2); #endif connect(this->relabelObjectAction, SIGNAL(triggered()), - this, SLOT(onRelabelObject())); + this, SLOT(onRelabelObject())); this->finishEditingAction = new QAction(this); connect(this->finishEditingAction, SIGNAL(triggered()), - this, SLOT(onFinishEditing())); + this, SLOT(onFinishEditing())); this->selectDependentsAction = new QAction(this); connect(this->selectDependentsAction, SIGNAL(triggered()), @@ -478,34 +479,34 @@ TreeWidget::TreeWidget(const char *name, QWidget* parent) this->closeDocAction = new QAction(this); connect(this->closeDocAction, SIGNAL(triggered()), - this, SLOT(onCloseDoc())); + this, SLOT(onCloseDoc())); this->reloadDocAction = new QAction(this); connect(this->reloadDocAction, SIGNAL(triggered()), - this, SLOT(onReloadDoc())); + this, SLOT(onReloadDoc())); this->skipRecomputeAction = new QAction(this); this->skipRecomputeAction->setCheckable(true); connect(this->skipRecomputeAction, SIGNAL(toggled(bool)), - this, SLOT(onSkipRecompute(bool))); + this, SLOT(onSkipRecompute(bool))); this->allowPartialRecomputeAction = new QAction(this); this->allowPartialRecomputeAction->setCheckable(true); connect(this->allowPartialRecomputeAction, SIGNAL(toggled(bool)), - this, SLOT(onAllowPartialRecompute(bool))); + this, SLOT(onAllowPartialRecompute(bool))); this->markRecomputeAction = new QAction(this); connect(this->markRecomputeAction, SIGNAL(triggered()), - this, SLOT(onMarkRecompute())); + this, SLOT(onMarkRecompute())); this->recomputeObjectAction = new QAction(this); connect(this->recomputeObjectAction, SIGNAL(triggered()), - this, SLOT(onRecomputeObject())); + this, SLOT(onRecomputeObject())); this->searchObjectsAction = new QAction(this); this->searchObjectsAction->setText(tr("Search...")); this->searchObjectsAction->setStatusTip(tr("Search for objects")); connect(this->searchObjectsAction, SIGNAL(triggered()), - this, SLOT(onSearchObjects())); + this, SLOT(onSearchObjects())); // Setup connections connectNewDocument = Application::Instance->signalNewDocument.connect(boost::bind(&TreeWidget::slotNewDocument, this, bp::_1, bp::_2)); @@ -519,7 +520,7 @@ TreeWidget::TreeWidget(const char *name, QWidget* parent) // change, not view provider's own property, which is what the signal below // for connectChangedViewObj = Application::Instance->signalChangedObject.connect( - boost::bind(&TreeWidget::slotChangedViewObject, this, bp::_1, bp::_2)); + boost::bind(&TreeWidget::slotChangedViewObject, this, bp::_1, bp::_2)); // make sure to show a horizontal scrollbar if needed this->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents); @@ -544,28 +545,28 @@ TreeWidget::TreeWidget(const char *name, QWidget* parent) this->selectTimer->setSingleShot(true); connect(this->statusTimer, SIGNAL(timeout()), - this, SLOT(onUpdateStatus())); + this, SLOT(onUpdateStatus())); connect(this, SIGNAL(itemEntered(QTreeWidgetItem*, int)), - this, SLOT(onItemEntered(QTreeWidgetItem*))); + this, SLOT(onItemEntered(QTreeWidgetItem*))); connect(this, SIGNAL(itemCollapsed(QTreeWidgetItem*)), - this, SLOT(onItemCollapsed(QTreeWidgetItem*))); + this, SLOT(onItemCollapsed(QTreeWidgetItem*))); connect(this, SIGNAL(itemExpanded(QTreeWidgetItem*)), - this, SLOT(onItemExpanded(QTreeWidgetItem*))); + this, SLOT(onItemExpanded(QTreeWidgetItem*))); connect(this, SIGNAL(itemSelectionChanged()), - this, SLOT(onItemSelectionChanged())); + this, SLOT(onItemSelectionChanged())); connect(this, SIGNAL(itemChanged(QTreeWidgetItem*, int)), - this, SLOT(onItemChanged(QTreeWidgetItem*, int))); + this, SLOT(onItemChanged(QTreeWidgetItem*, int))); connect(this->preselectTimer, SIGNAL(timeout()), - this, SLOT(onPreSelectTimer())); + this, SLOT(onPreSelectTimer())); connect(this->selectTimer, SIGNAL(timeout()), - this, SLOT(onSelectTimer())); + this, SLOT(onSelectTimer())); preselectTime.start(); setupText(); - if(!documentPixmap) { + if (!documentPixmap) { documentPixmap.reset(new QPixmap(Gui::BitmapFactory().pixmap("Document"))); QIcon icon(*documentPixmap); - documentPartialPixmap.reset(new QPixmap(icon.pixmap(documentPixmap->size(),QIcon::Disabled))); + documentPartialPixmap.reset(new QPixmap(icon.pixmap(documentPixmap->size(), QIcon::Disabled))); } } @@ -579,113 +580,115 @@ TreeWidget::~TreeWidget() connectShowHidden.disconnect(); connectChangedViewObj.disconnect(); Instances.erase(this); - if(_LastSelectedTreeWidget == this) + if (_LastSelectedTreeWidget == this) _LastSelectedTreeWidget = 0; } -const char *TreeWidget::getTreeName() const { +const char* TreeWidget::getTreeName() const { return myName.c_str(); } // reimpelement to select only objects in the active document void TreeWidget::selectAll() { auto gdoc = Application::Instance->getDocument( - App::GetApplication().getActiveDocument()); - if(!gdoc) + App::GetApplication().getActiveDocument()); + if (!gdoc) return; auto itDoc = DocumentMap.find(gdoc); - if(itDoc == DocumentMap.end()) + if (itDoc == DocumentMap.end()) return; - if(TreeParams::Instance()->RecordSelection()) + if (TreeParams::Instance()->RecordSelection()) Gui::Selection().selStackPush(); Gui::Selection().clearSelection(); - Gui::Selection().setSelection(gdoc->getDocument()->getName(),gdoc->getDocument()->getObjects()); + Gui::Selection().setSelection(gdoc->getDocument()->getName(), gdoc->getDocument()->getObjects()); } -bool TreeWidget::isObjectShowable(App::DocumentObject *obj) { - if(!obj || !obj->getNameInDocument()) +bool TreeWidget::isObjectShowable(App::DocumentObject* obj) { + if (!obj || !obj->getNameInDocument()) return true; - Gui::Document *doc = Application::Instance->getDocument(obj->getDocument()); - if(!doc) + Gui::Document* doc = Application::Instance->getDocument(obj->getDocument()); + if (!doc) return true; - if(Instances.empty()) + if (Instances.empty()) return true; auto tree = *Instances.begin(); auto it = tree->DocumentMap.find(doc); - if(it != tree->DocumentMap.end()) + if (it != tree->DocumentMap.end()) return it->second->isObjectShowable(obj); return true; } static bool _DisableCheckTopParent; -void TreeWidget::checkTopParent(App::DocumentObject *&obj, std::string &subname) { - if(_DisableCheckTopParent) +void TreeWidget::checkTopParent(App::DocumentObject*& obj, std::string& subname) { + if (_DisableCheckTopParent) return; - if(Instances.size() && obj && obj->getNameInDocument()) { + if (Instances.size() && obj && obj->getNameInDocument()) { auto tree = *Instances.begin(); auto it = tree->DocumentMap.find(Application::Instance->getDocument(obj->getDocument())); - if(it != tree->DocumentMap.end()) { - if(tree->statusTimer->isActive()) { + if (it != tree->DocumentMap.end()) { + if (tree->statusTimer->isActive()) { bool locked = tree->blockConnection(true); tree->_updateStatus(false); tree->blockConnection(locked); } - auto parent = it->second->getTopParent(obj,subname); - if(parent) + auto parent = it->second->getTopParent(obj, subname); + if (parent) obj = parent; } } } void TreeWidget::resetItemSearch() { - if(!searchObject) + if (!searchObject) return; auto it = ObjectTable.find(searchObject); - if(it != ObjectTable.end()) { - for(auto &data : it->second) { - if(!data) + if (it != ObjectTable.end()) { + for (auto& data : it->second) { + if (!data) continue; - for(auto item : data->items) + for (auto item : data->items) static_cast(item)->restoreBackground(); } } searchObject = 0; } -void TreeWidget::startItemSearch(QLineEdit *edit) { +void TreeWidget::startItemSearch(QLineEdit* edit) { resetItemSearch(); searchDoc = 0; searchContextDoc = 0; auto sels = selectedItems(); - if(sels.size() == 1) { - if(sels.front()->type() == DocumentType) { + if (sels.size() == 1) { + if (sels.front()->type() == DocumentType) { searchDoc = static_cast(sels.front())->document(); - } else if(sels.front()->type() == ObjectType) { + } + else if (sels.front()->type() == ObjectType) { auto item = static_cast(sels.front()); searchDoc = item->object()->getDocument(); searchContextDoc = item->getOwnerDocument()->document(); } - }else + } + else searchDoc = Application::Instance->activeDocument(); - App::DocumentObject *obj = 0; - if(searchContextDoc && searchContextDoc->getDocument()->getObjects().size()) + App::DocumentObject* obj = 0; + if (searchContextDoc && searchContextDoc->getDocument()->getObjects().size()) obj = searchContextDoc->getDocument()->getObjects().front(); - else if(searchDoc && searchDoc->getDocument()->getObjects().size()) + else if (searchDoc && searchDoc->getDocument()->getObjects().size()) obj = searchDoc->getDocument()->getObjects().front(); - if(obj) + if (obj) static_cast(edit)->setDocumentObject(obj); } -void TreeWidget::itemSearch(const QString &text, bool select) { +void TreeWidget::itemSearch(const QString& text, bool select) { resetItemSearch(); auto docItem = getDocumentItem(searchDoc); - if(!docItem) { + if (!docItem) { docItem = getDocumentItem(Application::Instance->activeDocument()); - if(!docItem) { + if (!docItem) { FC_TRACE("item search no document"); resetItemSearch(); return; @@ -693,122 +696,125 @@ void TreeWidget::itemSearch(const QString &text, bool select) { } auto doc = docItem->document()->getDocument(); - const auto &objs = doc->getObjects(); - if(objs.empty()) { + const auto& objs = doc->getObjects(); + if (objs.empty()) { FC_TRACE("item search no objects"); return; } std::string txt(text.toUtf8().constData()); try { - if(txt.empty()) + if (txt.empty()) return; - if(txt.find("<<") == std::string::npos) { + if (txt.find("<<") == std::string::npos) { auto pos = txt.find('.'); - if(pos==std::string::npos) + if (pos == std::string::npos) txt += '.'; - else if(pos!=txt.size()-1) { - txt.insert(pos+1,"<<"); - if(txt.back()!='.') + else if (pos != txt.size() - 1) { + txt.insert(pos + 1, "<<"); + if (txt.back() != '.') txt += '.'; txt += ">>."; } - }else if(txt.back() != '.') + } + else if (txt.back() != '.') txt += '.'; txt += "_self"; - auto path = App::ObjectIdentifier::parse(objs.front(),txt); - if(path.getPropertyName() != "_self") { + auto path = App::ObjectIdentifier::parse(objs.front(), txt); + if (path.getPropertyName() != "_self") { FC_TRACE("Object " << txt << " not found in " << doc->getName()); return; } auto obj = path.getDocumentObject(); - if(!obj) { + if (!obj) { FC_TRACE("Object " << txt << " not found in " << doc->getName()); return; } std::string subname = path.getSubObjectName(); - App::DocumentObject *parent = 0; - if(searchContextDoc) { + App::DocumentObject* parent = 0; + if (searchContextDoc) { auto it = DocumentMap.find(searchContextDoc); - if(it!=DocumentMap.end()) { - parent = it->second->getTopParent(obj,subname); - if(parent) { + if (it != DocumentMap.end()) { + parent = it->second->getTopParent(obj, subname); + if (parent) { obj = parent; docItem = it->second; doc = docItem->document()->getDocument(); } } } - if(!parent) { - parent = docItem->getTopParent(obj,subname); - while(!parent) { - if(docItem->document()->getDocument() == obj->getDocument()) { + if (!parent) { + parent = docItem->getTopParent(obj, subname); + while (!parent) { + if (docItem->document()->getDocument() == obj->getDocument()) { // this shouldn't happen FC_LOG("Object " << txt << " not found in " << doc->getName()); return; } auto it = DocumentMap.find(Application::Instance->getDocument(obj->getDocument())); - if(it==DocumentMap.end()) + if (it == DocumentMap.end()) return; docItem = it->second; - parent = docItem->getTopParent(obj,subname); + parent = docItem->getTopParent(obj, subname); } obj = parent; } - auto item = docItem->findItemByObject(true,obj,subname.c_str()); - if(!item) { + auto item = docItem->findItemByObject(true, obj, subname.c_str()); + if (!item) { FC_TRACE("item " << txt << " not found in " << doc->getName()); return; } scrollToItem(item); Selection().setPreselect(obj->getDocument()->getName(), - obj->getNameInDocument(), subname.c_str(),0,0,0,2); - if(select) { + obj->getNameInDocument(), subname.c_str(), 0, 0, 0, 2); + if (select) { Gui::Selection().selStackPush(); Gui::Selection().clearSelection(); Gui::Selection().addSelection(obj->getDocument()->getName(), - obj->getNameInDocument(),subname.c_str()); + obj->getNameInDocument(), subname.c_str()); Gui::Selection().selStackPush(); - }else{ + } + else { searchObject = item->object()->getObject(); item->setBackground(0, QColor(255, 255, 0, 100)); } FC_TRACE("found item " << txt); - } catch(...) + } + catch (...) { FC_TRACE("item " << txt << " search exception in " << doc->getName()); } } -Gui::Document *TreeWidget::selectedDocument() { - for(auto tree : Instances) { - if(!tree->isVisible()) +Gui::Document* TreeWidget::selectedDocument() { + for (auto tree : Instances) { + if (!tree->isVisible()) continue; auto sels = tree->selectedItems(); - if(sels.size()==1 && sels[0]->type()==DocumentType) + if (sels.size() == 1 && sels[0]->type() == DocumentType) return static_cast(sels[0])->document(); } return 0; } void TreeWidget::updateStatus(bool delay) { - for(auto tree : Instances) + for (auto tree : Instances) tree->_updateStatus(delay); } void TreeWidget::_updateStatus(bool delay) { - if(!delay) { - if(ChangedObjects.size() || NewObjects.size()) + if (!delay) { + if (ChangedObjects.size() || NewObjects.size()) onUpdateStatus(); return; } int timeout = TreeParams::Instance()->StatusTimeout(); - if (timeout<0) + if (timeout < 0) timeout = 1; FC_LOG("delay update status"); statusTimer->start(timeout); } -void TreeWidget::contextMenuEvent (QContextMenuEvent * e) +void TreeWidget::contextMenuEvent(QContextMenuEvent* e) { // ask workbenches and view provider, ... MenuItem view; @@ -824,7 +830,7 @@ void TreeWidget::contextMenuEvent (QContextMenuEvent * e) QActionGroup subMenuGroup(&subMenu); subMenuGroup.setExclusive(true); connect(&subMenuGroup, SIGNAL(triggered(QAction*)), - this, SLOT(onActivateDocument(QAction*))); + this, SLOT(onActivateDocument(QAction*))); MenuManager::getInstance()->setupContextMenu(&view, contextMenu); // get the current item @@ -838,11 +844,11 @@ void TreeWidget::contextMenuEvent (QContextMenuEvent * e) contextMenu.addAction(this->showHiddenAction); contextMenu.addAction(this->searchObjectsAction); contextMenu.addAction(this->closeDocAction); - if(doc->testStatus(App::Document::PartialDoc)) + if (doc->testStatus(App::Document::PartialDoc)) contextMenu.addAction(this->reloadDocAction); else { - for(auto d : doc->getDependentDocuments()) { - if(d->testStatus(App::Document::PartialDoc)) { + for (auto d : doc->getDependentDocuments()) { + if (d->testStatus(App::Document::PartialDoc)) { contextMenu.addAction(this->reloadDocAction); break; } @@ -851,7 +857,7 @@ void TreeWidget::contextMenuEvent (QContextMenuEvent * e) this->skipRecomputeAction->setChecked(doc->testStatus(App::Document::SkipRecompute)); contextMenu.addAction(this->skipRecomputeAction); this->allowPartialRecomputeAction->setChecked(doc->testStatus(App::Document::AllowPartialRecompute)); - if(doc->testStatus(App::Document::SkipRecompute)) + if (doc->testStatus(App::Document::SkipRecompute)) contextMenu.addAction(this->allowPartialRecomputeAction); contextMenu.addAction(this->markRecomputeAction); contextMenu.addAction(this->createGroupAction); @@ -873,7 +879,7 @@ void TreeWidget::contextMenuEvent (QContextMenuEvent * e) break; } } - + showHiddenAction->setChecked(doc->ShowHidden.getValue()); contextMenu.addAction(this->showHiddenAction); @@ -905,7 +911,7 @@ void TreeWidget::contextMenuEvent (QContextMenuEvent * e) if (!editAct.isEmpty()) { QAction* topact = contextMenu.actions().front(); for (QList::iterator it = editAct.begin(); it != editAct.end(); ++it) - contextMenu.insertAction(topact,*it); + contextMenu.insertAction(topact, *it); QAction* first = editAct.front(); contextMenu.setDefaultAction(first); if (objitem->object()->isEditing()) @@ -941,18 +947,21 @@ void TreeWidget::contextMenuEvent (QContextMenuEvent * e) if (contextMenu.actions().count() > 0) { try { contextMenu.exec(QCursor::pos()); - } catch (Base::Exception &e) { + } + catch (Base::Exception& e) { e.ReportException(); - } catch (std::exception &e) { + } + catch (std::exception& e) { FC_ERR("C++ exception: " << e.what()); - } catch (...) { + } + catch (...) { FC_ERR("Unknown exception"); } contextItem = 0; } } -void TreeWidget::hideEvent(QHideEvent *ev) { +void TreeWidget::hideEvent(QHideEvent* ev) { // No longer required. Visibility is now handled inside onUpdateStatus() by // UpdateDisabler. #if 0 @@ -963,14 +972,14 @@ void TreeWidget::hideEvent(QHideEvent *ev) { QTreeWidget::hideEvent(ev); } -void TreeWidget::showEvent(QShowEvent *ev) { +void TreeWidget::showEvent(QShowEvent* ev) { // No longer required. Visibility is now handled inside onUpdateStatus() by // UpdateDisabler. #if 0 TREE_TRACE("attaching selection observer"); this->attachSelection(); int timeout = TreeParams::Instance()->SelectionTimeout(); - if(timeout<=0) + if (timeout <= 0) timeout = 1; selectTimer->start(timeout); _updateStatus(); @@ -986,8 +995,8 @@ void TreeWidget::onCreateGroup() DocumentItem* docitem = static_cast(this->contextItem); App::Document* doc = docitem->document()->getDocument(); QString cmd = QString::fromLatin1("App.getDocument(\"%1\").addObject" - "(\"App::DocumentObjectGroup\",\"%2\")") - .arg(QString::fromLatin1(doc->getName()), name); + "(\"App::DocumentObjectGroup\",\"%2\")") + .arg(QString::fromLatin1(doc->getName()), name); Gui::Command::runCommand(Gui::Command::App, cmd.toUtf8()); } else if (this->contextItem->type() == ObjectType) { @@ -996,10 +1005,10 @@ void TreeWidget::onCreateGroup() App::DocumentObject* obj = objitem->object()->getObject(); App::Document* doc = obj->getDocument(); QString cmd = QString::fromLatin1("App.getDocument(\"%1\").getObject(\"%2\")" - ".newObject(\"App::DocumentObjectGroup\",\"%3\")") - .arg(QString::fromLatin1(doc->getName()), - QString::fromLatin1(obj->getNameInDocument()), - name); + ".newObject(\"App::DocumentObjectGroup\",\"%3\")") + .arg(QString::fromLatin1(doc->getName()), + QString::fromLatin1(obj->getNameInDocument()), + name); Gui::Command::runCommand(Gui::Command::App, cmd.toUtf8()); } } @@ -1024,7 +1033,7 @@ void TreeWidget::onStartEditing() if (!obj || !obj->getNameInDocument()) return; auto doc = const_cast(objitem->getOwnerDocument()->document()); - MDIView *view = doc->getActiveView(); + MDIView* view = doc->getActiveView(); if (view) getMainWindow()->setActiveWindow(view); // Always open a transaction here doesn't make much sense because: @@ -1040,7 +1049,7 @@ void TreeWidget::onStartEditing() if (!ok) doc->abortCommand(); #else editingItem = objitem; - if(!doc->setEdit(objitem->object(), edit)) + if (!doc->setEdit(objitem->object(), edit)) editingItem = 0; #endif } @@ -1173,99 +1182,99 @@ void TreeWidget::onMarkRecompute() void TreeWidget::onRecomputeObject() { std::vector objs; - for(auto ti : selectedItems()) { + for (auto ti : selectedItems()) { if (ti->type() == ObjectType) { DocumentObjectItem* objitem = static_cast(ti); objs.push_back(objitem->object()->getObject()); objs.back()->enforceRecompute(); } } - if(objs.empty()) + if (objs.empty()) return; App::AutoTransaction committer("Recompute object"); - objs.front()->getDocument()->recompute(objs,true); + objs.front()->getDocument()->recompute(objs, true); } -DocumentItem *TreeWidget::getDocumentItem(const Gui::Document *doc) const { +DocumentItem* TreeWidget::getDocumentItem(const Gui::Document* doc) const { auto it = DocumentMap.find(doc); - if(it != DocumentMap.end()) + if (it != DocumentMap.end()) return it->second; return 0; } -void TreeWidget::selectAllInstances(const ViewProviderDocumentObject &vpd) { - if(!isConnectionAttached()) +void TreeWidget::selectAllInstances(const ViewProviderDocumentObject& vpd) { + if (!isConnectionAttached()) return; - if(selectTimer->isActive()) + if (selectTimer->isActive()) onSelectTimer(); else _updateStatus(false); - for(const auto &v : DocumentMap) + for (const auto& v : DocumentMap) v.second->selectAllInstances(vpd); } -TreeWidget *TreeWidget::instance() { +TreeWidget* TreeWidget::instance() { auto res = _LastSelectedTreeWidget; - if(res && res->isVisible()) + if (res && res->isVisible()) return res; - for(auto inst : Instances) { - if(!res) res = inst; - if(inst->isVisible()) + for (auto inst : Instances) { + if (!res) res = inst; + if (inst->isVisible()) return inst; } return res; } -std::vector TreeWidget::getSelection(App::Document *doc) +std::vector TreeWidget::getSelection(App::Document* doc) { std::vector ret; - TreeWidget *tree = instance(); - if(!tree || !tree->isConnectionAttached()) { - for(auto pTree : Instances) - if(pTree->isConnectionAttached()) { + TreeWidget* tree = instance(); + if (!tree || !tree->isConnectionAttached()) { + for (auto pTree : Instances) + if (pTree->isConnectionAttached()) { tree = pTree; break; } } - if(!tree) return ret; + if (!tree) return ret; - if(tree->selectTimer->isActive()) + if (tree->selectTimer->isActive()) tree->onSelectTimer(); else tree->_updateStatus(false); - for(auto ti : tree->selectedItems()) { - if(ti->type() != ObjectType) continue; + for (auto ti : tree->selectedItems()) { + if (ti->type() != ObjectType) continue; auto item = static_cast(ti); auto vp = item->object(); auto obj = vp->getObject(); - if(!obj || !obj->getNameInDocument()) { + if (!obj || !obj->getNameInDocument()) { FC_WARN("skip invalid object"); continue; } - if(doc && obj->getDocument()!=doc) { + if (doc && obj->getDocument() != doc) { FC_LOG("skip objects not from current document"); continue; } - ViewProviderDocumentObject *parentVp = 0; + ViewProviderDocumentObject* parentVp = 0; auto parent = item->getParentItem(); - if(parent) { + if (parent) { parentVp = parent->object(); - if(!parentVp->getObject()->getNameInDocument()) { + if (!parentVp->getObject()->getNameInDocument()) { FC_WARN("skip '" << obj->getFullName() << "' with invalid parent"); continue; } } ret.emplace_back(); - auto &sel = ret.back(); + auto& sel = ret.back(); sel.topParent = 0; std::ostringstream ss; - item->getSubName(ss,sel.topParent); - if(!sel.topParent) + item->getSubName(ss, sel.topParent); + if (!sel.topParent) sel.topParent = obj; else ss << obj->getNameInDocument() << '.'; @@ -1276,33 +1285,33 @@ std::vector TreeWidget::getSelection(App::Document *doc) return ret; } -void TreeWidget::selectAllLinks(App::DocumentObject *obj) { - if(!isConnectionAttached()) +void TreeWidget::selectAllLinks(App::DocumentObject* obj) { + if (!isConnectionAttached()) return; - if(!obj || !obj->getNameInDocument()) { + if (!obj || !obj->getNameInDocument()) { TREE_ERR("invalid object"); return; } - if(selectTimer->isActive()) + if (selectTimer->isActive()) onSelectTimer(); else _updateStatus(false); - for(auto link: App::GetApplication().getLinksTo(obj,App::GetLinkRecursive)) + for (auto link : App::GetApplication().getLinksTo(obj, App::GetLinkRecursive)) { - if(!link || !link->getNameInDocument()) { + if (!link || !link->getNameInDocument()) { TREE_ERR("invalid linked object"); continue; } auto vp = dynamic_cast( - Application::Instance->getViewProvider(link)); - if(!vp) { + Application::Instance->getViewProvider(link)); + if (!vp) { TREE_ERR("invalid view provider of the linked object"); continue; } - for(auto &v : DocumentMap) + for (auto& v : DocumentMap) v.second->selectAllInstances(*vp); } } @@ -1318,40 +1327,40 @@ void TreeWidget::onActivateDocument(QAction* active) QByteArray docname = active->data().toByteArray(); Gui::Document* doc = Application::Instance->getDocument((const char*)docname); if (doc && !doc->setActiveView()) - doc->setActiveView(0,View3DInventor::getClassTypeId()); + doc->setActiveView(0, View3DInventor::getClassTypeId()); } -Qt::DropActions TreeWidget::supportedDropActions () const +Qt::DropActions TreeWidget::supportedDropActions() const { return Qt::LinkAction | Qt::CopyAction | Qt::MoveAction; } -bool TreeWidget::event(QEvent *e) +bool TreeWidget::event(QEvent* e) { #if 0 if (e->type() == QEvent::ShortcutOverride) { - QKeyEvent* ke = static_cast(e); + QKeyEvent* ke = static_cast(e); switch (ke->key()) { - case Qt::Key_Delete: - ke->accept(); + case Qt::Key_Delete: + ke->accept(); } } #endif return QTreeWidget::event(e); } -bool TreeWidget::eventFilter(QObject *, QEvent *ev) { +bool TreeWidget::eventFilter(QObject*, QEvent* ev) { switch (ev->type()) { case QEvent::KeyPress: case QEvent::KeyRelease: { - QKeyEvent *ke = static_cast(ev); + QKeyEvent* ke = static_cast(ev); if (ke->key() != Qt::Key_Escape) { // Qt 5 only recheck key modifier on mouse move, so generate a fake // event to trigger drag cursor change - QMouseEvent *mouseEvent = new QMouseEvent(QEvent::MouseMove, - mapFromGlobal(QCursor::pos()), QCursor::pos(), Qt::NoButton, - QApplication::mouseButtons(), QApplication::queryKeyboardModifiers()); - QApplication::postEvent(this,mouseEvent); + QMouseEvent* mouseEvent = new QMouseEvent(QEvent::MouseMove, + mapFromGlobal(QCursor::pos()), QCursor::pos(), Qt::NoButton, + QApplication::mouseButtons(), QApplication::queryKeyboardModifiers()); + QApplication::postEvent(this, mouseEvent); } break; } @@ -1361,59 +1370,65 @@ bool TreeWidget::eventFilter(QObject *, QEvent *ev) { return false; } -void TreeWidget::keyPressEvent(QKeyEvent *event) +void TreeWidget::keyPressEvent(QKeyEvent* event) { #if 0 if (event && event->matches(QKeySequence::Delete)) { event->ignore(); } #endif - if(event->matches(QKeySequence::Find)) { + if (event->matches(QKeySequence::Find)) { event->accept(); onSearchObjects(); return; - }else if(event->modifiers() == Qt::AltModifier) { - if(event->key() == Qt::Key_Left) { - for(auto &item: selectedItems()) { + } + else if (event->modifiers() == Qt::AltModifier) { + if (event->key() == Qt::Key_Left) { + for (auto& item : selectedItems()) { item->setExpanded(false); } event->accept(); return; - }else if(event->key() == Qt::Key_Right) { - for(auto &item: selectedItems()) { + } + else if (event->key() == Qt::Key_Right) { + for (auto& item : selectedItems()) { item->setExpanded(true); } event->accept(); return; - }else if(event->key() == Qt::Key_Up) { - for(auto &item: selectedItems()) { + } + else if (event->key() == Qt::Key_Up) { + for (auto& item : selectedItems()) { item->setExpanded(true); - for (auto &child: childrenOfItem(*item)) { + for (auto& child : childrenOfItem(*item)) { child->setExpanded(false); } } event->accept(); return; - }else if(event->key() == Qt::Key_Down) { - for(auto &item: selectedItems()) { + } + else if (event->key() == Qt::Key_Down) { + for (auto& item : selectedItems()) { item->setExpanded(true); - for (auto &child: childrenOfItem(*item)) { + for (auto& child : childrenOfItem(*item)) { child->setExpanded(true); } } event->accept(); return; } - }else if(event->key() == Qt::Key_Left) { + } + else if (event->key() == Qt::Key_Left) { auto index = currentIndex(); - if(index.column()==1) { + if (index.column() == 1) { setCurrentIndex(model()->index(index.row(), 0, index.parent())); event->accept(); return; } - }else if(event->key() == Qt::Key_Right) { + } + else if (event->key() == Qt::Key_Right) { auto index = currentIndex(); - if(index.column()==0) { + if (index.column() == 0) { setCurrentIndex(model()->index(index.row(), 1, index.parent())); event->accept(); return; @@ -1422,7 +1437,7 @@ void TreeWidget::keyPressEvent(QKeyEvent *event) QTreeWidget::keyPressEvent(event); } -void TreeWidget::mouseDoubleClickEvent (QMouseEvent * event) +void TreeWidget::mouseDoubleClickEvent(QMouseEvent* event) { QTreeWidgetItem* item = itemAt(event->pos()); if (!item) return; @@ -1432,13 +1447,13 @@ void TreeWidget::mouseDoubleClickEvent (QMouseEvent * event) //QTreeWidget::mouseDoubleClickEvent(event); Gui::Document* doc = static_cast(item)->document(); if (!doc) return; - if(doc->getDocument()->testStatus(App::Document::PartialDoc)) { + if (doc->getDocument()->testStatus(App::Document::PartialDoc)) { contextItem = item; onReloadDoc(); return; } - if(!doc->setActiveView()) - doc->setActiveView(0,View3DInventor::getClassTypeId()); + if (!doc->setActiveView()) + doc->setActiveView(0, View3DInventor::getClassTypeId()); } else if (item->type() == TreeWidget::ObjectType) { DocumentObjectItem* objitem = static_cast(item); @@ -1473,19 +1488,22 @@ void TreeWidget::mouseDoubleClickEvent (QMouseEvent * event) manager->addLine(MacroManager::Gui, ss.str().c_str()); } } - } catch (Base::Exception &e) { + } + catch (Base::Exception& e) { e.ReportException(); - } catch (std::exception &e) { + } + catch (std::exception& e) { FC_ERR("C++ exception: " << e.what()); - } catch (...) { + } + catch (...) { FC_ERR("Unknown exception"); } } void TreeWidget::startDragging() { - if(state() != NoState) + if (state() != NoState) return; - if(selectedItems().empty()) + if (selectedItems().empty()) return; setState(DraggingState); @@ -1497,21 +1515,21 @@ void TreeWidget::startDragging() { void TreeWidget::startDrag(Qt::DropActions supportedActions) { QTreeWidget::startDrag(supportedActions); - if(_DragEventFilter) { + if (_DragEventFilter) { _DragEventFilter = false; qApp->removeEventFilter(this); } } -QMimeData * TreeWidget::mimeData (const QList items) const +QMimeData* TreeWidget::mimeData(const QList items) const { #if 0 // all selected items must reference an object from the same document - App::Document* doc=0; - for (QList::ConstIterator it = items.begin(); it != items.end(); ++it) { + App::Document* doc = 0; + for (QList::ConstIterator it = items.begin(); it != items.end(); ++it) { if ((*it)->type() != TreeWidget::ObjectType) return 0; - App::DocumentObject* obj = static_cast(*it)->object()->getObject(); + App::DocumentObject* obj = static_cast(*it)->object()->getObject(); if (!doc) doc = obj->getDocument(); else if (doc != obj->getDocument()) @@ -1521,29 +1539,29 @@ QMimeData * TreeWidget::mimeData (const QList items) const return QTreeWidget::mimeData(items); } -bool TreeWidget::dropMimeData(QTreeWidgetItem *parent, int index, - const QMimeData *data, Qt::DropAction action) +bool TreeWidget::dropMimeData(QTreeWidgetItem* parent, int index, + const QMimeData* data, Qt::DropAction action) { return QTreeWidget::dropMimeData(parent, index, data, action); } -void TreeWidget::dragEnterEvent(QDragEnterEvent * event) +void TreeWidget::dragEnterEvent(QDragEnterEvent* event) { QTreeWidget::dragEnterEvent(event); } -void TreeWidget::dragLeaveEvent(QDragLeaveEvent * event) +void TreeWidget::dragLeaveEvent(QDragLeaveEvent* event) { QTreeWidget::dragLeaveEvent(event); } -void TreeWidget::dragMoveEvent(QDragMoveEvent *event) +void TreeWidget::dragMoveEvent(QDragMoveEvent* event) { // Qt5 does not change drag cursor in response to modifier key press, // because QDrag installs a event filter that eats up key event. We install // a filter after Qt and generate fake mouse move event in response to key // press event, which triggers QDrag to update its cursor - if(!_DragEventFilter) { + if (!_DragEventFilter) { _DragEventFilter = true; qApp->installEventFilter(this); } @@ -1560,9 +1578,9 @@ void TreeWidget::dragMoveEvent(QDragMoveEvent *event) } else if (targetItem->type() == TreeWidget::DocumentType) { leaveEvent(0); - if(modifier== Qt::ControlModifier) + if (modifier == Qt::ControlModifier) event->setDropAction(Qt::CopyAction); - else if(modifier== Qt::AltModifier) + else if (modifier == Qt::AltModifier) event->setDropAction(Qt::LinkAction); else event->setDropAction(Qt::MoveAction); @@ -1576,23 +1594,23 @@ void TreeWidget::dragMoveEvent(QDragMoveEvent *event) try { auto items = selectedItems(); - if(modifier == Qt::ControlModifier) + if (modifier == Qt::ControlModifier) event->setDropAction(Qt::CopyAction); - else if(modifier== Qt::AltModifier && items.size()==1) + else if (modifier == Qt::AltModifier && items.size() == 1) event->setDropAction(Qt::LinkAction); else event->setDropAction(Qt::MoveAction); auto da = event->dropAction(); - bool dropOnly = da==Qt::CopyAction || da==Qt::MoveAction; + bool dropOnly = da == Qt::CopyAction || da == Qt::MoveAction; - if (da!=Qt::LinkAction && !vp->canDropObjects()) { - if(!(event->possibleActions() & Qt::LinkAction) || items.size()!=1) { + if (da != Qt::LinkAction && !vp->canDropObjects()) { + if (!(event->possibleActions() & Qt::LinkAction) || items.size() != 1) { TREE_TRACE("cannot drop"); event->ignore(); return; } } - for(auto ti : items) { + for (auto ti : items) { if (ti->type() != TreeWidget::ObjectType) { TREE_TRACE("cannot drop"); event->ignore(); @@ -1602,14 +1620,14 @@ void TreeWidget::dragMoveEvent(QDragMoveEvent *event) auto obj = item->object()->getObject(); - if(!dropOnly && !vp->canDragAndDropObject(obj)) { + if (!dropOnly && !vp->canDragAndDropObject(obj)) { // check if items can be dragged auto parentItem = item->getParentItem(); - if(parentItem - && (!parentItem->object()->canDragObjects() - || !parentItem->object()->canDragObject(item->object()->getObject()))) + if (parentItem + && (!parentItem->object()->canDragObjects() + || !parentItem->object()->canDragObject(item->object()->getObject()))) { - if(!(event->possibleActions() & Qt::CopyAction)) { + if (!(event->possibleActions() & Qt::CopyAction)) { TREE_TRACE("Cannot drag object"); event->ignore(); return; @@ -1619,18 +1637,18 @@ void TreeWidget::dragMoveEvent(QDragMoveEvent *event) } std::ostringstream str; - auto owner = item->getRelativeParent(str,targetItemObj); + auto owner = item->getRelativeParent(str, targetItemObj); auto subname = str.str(); // let the view provider decide to accept the object or ignore it - if (da!=Qt::LinkAction && !vp->canDropObjectEx(obj,owner,subname.c_str(), item->mySubs)) { - if(event->possibleActions() & Qt::LinkAction) { - if(items.size()>1) { + if (da != Qt::LinkAction && !vp->canDropObjectEx(obj, owner, subname.c_str(), item->mySubs)) { + if (event->possibleActions() & Qt::LinkAction) { + if (items.size() > 1) { TREE_TRACE("Cannot replace with more than one object"); event->ignore(); return; } - if(!targetItemObj->getParentItem()) { + if (!targetItemObj->getParentItem()) { TREE_TRACE("Cannot replace without parent"); event->ignore(); return; @@ -1640,18 +1658,21 @@ void TreeWidget::dragMoveEvent(QDragMoveEvent *event) } TREE_TRACE("cannot drop " << obj->getFullName() << ' ' - << (owner?owner->getFullName():"") << '.' << subname); + << (owner ? owner->getFullName() : "") << '.' << subname); event->ignore(); return; } } - } catch (Base::Exception &e){ + } + catch (Base::Exception& e) { e.ReportException(); event->ignore(); - } catch (std::exception &e) { + } + catch (std::exception& e) { FC_ERR("C++ exception: " << e.what()); event->ignore(); - } catch (...) { + } + catch (...) { FC_ERR("Unknown exception"); event->ignore(); } @@ -1686,7 +1707,7 @@ struct ItemInfo2 { std::string topSubname; }; -void TreeWidget::dropEvent(QDropEvent *event) +void TreeWidget::dropEvent(QDropEvent* event) { //FIXME: This should actually be done inside dropMimeData @@ -1699,27 +1720,27 @@ void TreeWidget::dropEvent(QDropEvent *event) if (targetItem->isSelected()) return; - App::Document *thisDoc; + App::Document* thisDoc; Base::EmptySequencer seq; // filter out the selected items we cannot handle - std::vector > > items; + std::vector > > items; auto sels = selectedItems(); items.reserve(sels.size()); - for(auto ti : sels) { + for (auto ti : sels) { if (ti->type() != TreeWidget::ObjectType) continue; // ignore child elements if the parent is selected - if(sels.contains(ti->parent())) + if (sels.contains(ti->parent())) continue; if (ti == targetItem) continue; auto item = static_cast(ti); items.emplace_back(); - auto &info = items.back(); + auto& info = items.back(); info.first = item; - info.second.insert(info.second.end(),item->mySubs.begin(),item->mySubs.end()); + info.second.insert(info.second.end(), item->mySubs.begin(), item->mySubs.end()); } if (items.empty()) @@ -1727,15 +1748,15 @@ void TreeWidget::dropEvent(QDropEvent *event) std::string errMsg; - if(QApplication::keyboardModifiers()== Qt::ControlModifier) + if (QApplication::keyboardModifiers() == Qt::ControlModifier) event->setDropAction(Qt::CopyAction); - else if(QApplication::keyboardModifiers()== Qt::AltModifier - && (items.size()==1||targetItem->type()==TreeWidget::DocumentType)) + else if (QApplication::keyboardModifiers() == Qt::AltModifier + && (items.size() == 1 || targetItem->type() == TreeWidget::DocumentType)) event->setDropAction(Qt::LinkAction); else event->setDropAction(Qt::MoveAction); auto da = event->dropAction(); - bool dropOnly = da==Qt::CopyAction || da==Qt::LinkAction; + bool dropOnly = da == Qt::CopyAction || da == Qt::LinkAction; if (targetItem->type() == TreeWidget::ObjectType) { // add object to group @@ -1743,60 +1764,61 @@ void TreeWidget::dropEvent(QDropEvent *event) thisDoc = targetItemObj->getOwnerDocument()->document()->getDocument(); Gui::ViewProviderDocumentObject* vp = targetItemObj->object(); - if(!vp || !vp->getObject() || !vp->getObject()->getNameInDocument()) { + if (!vp || !vp->getObject() || !vp->getObject()->getNameInDocument()) { TREE_TRACE("invalid object"); return; } - if (da!=Qt::LinkAction && !vp->canDropObjects()) { - if(!(event->possibleActions() & Qt::LinkAction) || items.size()!=1) { + if (da != Qt::LinkAction && !vp->canDropObjects()) { + if (!(event->possibleActions() & Qt::LinkAction) || items.size() != 1) { TREE_TRACE("Cannot drop objects"); return; // no group like object } } std::ostringstream targetSubname; - App::DocumentObject *targetParent = 0; - targetItemObj->getSubName(targetSubname,targetParent); + App::DocumentObject* targetParent = 0; + targetItemObj->getSubName(targetSubname, targetParent); Selection().selStackPush(); Selection().clearCompleteSelection(); - if(targetParent) { + if (targetParent) { targetSubname << vp->getObject()->getNameInDocument() << '.'; Selection().addSelection(targetParent->getDocument()->getName(), - targetParent->getNameInDocument(), targetSubname.str().c_str()); - } else { + targetParent->getNameInDocument(), targetSubname.str().c_str()); + } + else { targetParent = targetItemObj->object()->getObject(); Selection().addSelection(targetParent->getDocument()->getName(), - targetParent->getNameInDocument()); + targetParent->getNameInDocument()); } bool syncPlacement = TreeParams::Instance()->SyncPlacement() && targetItemObj->isGroup(); bool setSelection = true; - std::vector > droppedObjects; + std::vector > droppedObjects; std::vector infos; // Only keep text names here, because you never know when doing drag // and drop some object may delete other objects. infos.reserve(items.size()); - for(auto &v : items) { + for (auto& v : items) { infos.emplace_back(); - auto &info = infos.back(); + auto& info = infos.back(); auto item = v.first; Gui::ViewProviderDocumentObject* vpc = item->object(); App::DocumentObject* obj = vpc->getObject(); std::ostringstream str; - App::DocumentObject *topParent=0; - auto owner = item->getRelativeParent(str,targetItemObj,&topParent,&info.topSubname); - if(syncPlacement && topParent) { + App::DocumentObject* topParent = 0; + auto owner = item->getRelativeParent(str, targetItemObj, &topParent, &info.topSubname); + if (syncPlacement && topParent) { info.topDoc = topParent->getDocument()->getName(); info.topObj = topParent->getNameInDocument(); } info.subname = str.str(); info.doc = obj->getDocument()->getName(); info.obj = obj->getNameInDocument(); - if(owner) { + if (owner) { info.ownerDoc = owner->getDocument()->getName(); info.owner = owner->getNameInDocument(); } @@ -1804,16 +1826,16 @@ void TreeWidget::dropEvent(QDropEvent *event) info.subs.swap(v.second); // check if items can be dragged - if(!dropOnly && - item->myOwner == targetItemObj->myOwner && - vp->canDragAndDropObject(item->object()->getObject())) + if (!dropOnly && + item->myOwner == targetItemObj->myOwner && + vp->canDragAndDropObject(item->object()->getObject())) { // check if items can be dragged auto parentItem = item->getParentItem(); - if(!parentItem) + if (!parentItem) info.dragging = true; - else if(parentItem->object()->canDragObjects() - && parentItem->object()->canDragObject(item->object()->getObject())) + else if (parentItem->object()->canDragObjects() + && parentItem->object()->canDragObject(item->object()->getObject())) { info.dragging = true; auto vpp = parentItem->object(); @@ -1822,16 +1844,16 @@ void TreeWidget::dropEvent(QDropEvent *event) } } - if (da!=Qt::LinkAction - && !vp->canDropObjectEx(obj,owner,info.subname.c_str(),item->mySubs)) + if (da != Qt::LinkAction + && !vp->canDropObjectEx(obj, owner, info.subname.c_str(), item->mySubs)) { - if(event->possibleActions() & Qt::LinkAction) { - if(items.size()>1) { + if (event->possibleActions() & Qt::LinkAction) { + if (items.size() > 1) { TREE_TRACE("Cannot replace with more than one object"); return; } auto ext = vp->getObject()->getExtensionByType(true); - if((!ext || !ext->getLinkedObjectProperty()) && !targetItemObj->getParentItem()) { + if ((!ext || !ext->getLinkedObjectProperty()) && !targetItemObj->getParentItem()) { TREE_TRACE("Cannot replace without parent"); return; } @@ -1847,80 +1869,81 @@ void TreeWidget::dropEvent(QDropEvent *event) std::set inList; auto parentObj = targetObj; - if(da == Qt::LinkAction && targetItemObj->getParentItem()) + if (da == Qt::LinkAction && targetItemObj->getParentItem()) parentObj = targetItemObj->getParentItem()->object()->getObject(); inList = parentObj->getInListEx(true); inList.insert(parentObj); std::string target = targetObj->getNameInDocument(); auto targetDoc = targetObj->getDocument(); - for (auto &info : infos) { - auto &subname = info.subname; + for (auto& info : infos) { + auto& subname = info.subname; targetObj = targetDoc->getObject(target.c_str()); vp = Base::freecad_dynamic_cast( - Application::Instance->getViewProvider(targetObj)); - if(!vp) { + Application::Instance->getViewProvider(targetObj)); + if (!vp) { FC_ERR("Cannot find drop target object " << target); break; } auto doc = App::GetApplication().getDocument(info.doc.c_str()); - if(!doc) { + if (!doc) { FC_WARN("Cannot find document " << info.doc); continue; } auto obj = doc->getObject(info.obj.c_str()); auto vpc = dynamic_cast( - Application::Instance->getViewProvider(obj)); - if(!vpc) { + Application::Instance->getViewProvider(obj)); + if (!vpc) { FC_WARN("Cannot find dragging object " << info.obj); continue; } - ViewProviderDocumentObject *vpp = 0; - if(da!=Qt::LinkAction && info.parentDoc.size()) { + ViewProviderDocumentObject* vpp = 0; + if (da != Qt::LinkAction && info.parentDoc.size()) { auto parentDoc = App::GetApplication().getDocument(info.parentDoc.c_str()); - if(parentDoc) { + if (parentDoc) { auto parent = parentDoc->getObject(info.parent.c_str()); vpp = dynamic_cast( - Application::Instance->getViewProvider(parent)); + Application::Instance->getViewProvider(parent)); } - if(!vpp) { + if (!vpp) { FC_WARN("Cannot find dragging object's parent " << info.parent); continue; } } - App::DocumentObject *owner = 0; - if(info.ownerDoc.size()) { + App::DocumentObject* owner = 0; + if (info.ownerDoc.size()) { auto ownerDoc = App::GetApplication().getDocument(info.ownerDoc.c_str()); - if(ownerDoc) + if (ownerDoc) owner = ownerDoc->getObject(info.owner.c_str()); - if(!owner) { + if (!owner) { FC_WARN("Cannot find dragging object's top parent " << info.owner); continue; } } Base::Matrix4D mat; - App::PropertyPlacement *propPlacement = 0; - if(syncPlacement) { - if(info.topObj.size()) { + App::PropertyPlacement* propPlacement = 0; + if (syncPlacement) { + if (info.topObj.size()) { auto doc = App::GetApplication().getDocument(info.topDoc.c_str()); - if(doc) { + if (doc) { auto topObj = doc->getObject(info.topObj.c_str()); - if(topObj) { - auto sobj = topObj->getSubObject(info.topSubname.c_str(),0,&mat); - if(sobj == obj) { + if (topObj) { + auto sobj = topObj->getSubObject(info.topSubname.c_str(), 0, &mat); + if (sobj == obj) { propPlacement = Base::freecad_dynamic_cast( - obj->getPropertyByName("Placement")); + obj->getPropertyByName("Placement")); } } } - }else{ + } + else { propPlacement = Base::freecad_dynamic_cast( - obj->getPropertyByName("Placement")); - if(propPlacement) + obj->getPropertyByName("Placement")); + if (propPlacement) mat = propPlacement->getValue().toMatrix(); } } @@ -1929,34 +1952,34 @@ void TreeWidget::dropEvent(QDropEvent *event) auto manager = Application::Instance->macroManager(); std::ostringstream ss; - if(vpp) { + if (vpp) { auto lines = manager->getLines(); ss << Command::getObjectCmd(vpp->getObject()) << ".ViewObject.dragObject(" << Command::getObjectCmd(obj) << ')'; vpp->dragObject(obj); - if(manager->getLines() == lines) - manager->addLine(MacroManager::Gui,ss.str().c_str()); + if (manager->getLines() == lines) + manager->addLine(MacroManager::Gui, ss.str().c_str()); owner = 0; subname.clear(); ss.str(""); obj = doc->getObject(info.obj.c_str()); - if(!obj || !obj->getNameInDocument()) { + if (!obj || !obj->getNameInDocument()) { FC_WARN("Dropping object deleted: " << info.doc << '#' << info.obj); continue; } } - if(da == Qt::MoveAction) { + if (da == Qt::MoveAction) { // Try to adjust relative links to avoid cyclic dependency, may // throw exception if failed ss.str(""); ss << Command::getObjectCmd(obj) << ".adjustRelativeLinks(" << Command::getObjectCmd(targetObj) << ")"; - manager->addLine(MacroManager::Gui,ss.str().c_str()); + manager->addLine(MacroManager::Gui, ss.str().c_str()); std::set visited; - if(obj->adjustRelativeLinks(inList,&visited)) { + if (obj->adjustRelativeLinks(inList, &visited)) { inList = parentObj->getInListEx(true); inList.insert(parentObj); @@ -1966,60 +1989,63 @@ void TreeWidget::dropEvent(QDropEvent *event) } } - if(inList.count(obj)) + if (inList.count(obj)) FC_THROWM(Base::RuntimeError, - "Dependency loop detected for " << obj->getFullName()); + "Dependency loop detected for " << obj->getFullName()); std::string dropName; ss.str(""); - if(da == Qt::LinkAction) { + if (da == Qt::LinkAction) { auto parentItem = targetItemObj->getParentItem(); if (parentItem) { ss << Command::getObjectCmd( - parentItem->object()->getObject(),0,".replaceObject(",true) + parentItem->object()->getObject(), 0, ".replaceObject(", true) << Command::getObjectCmd(targetObj) << "," << Command::getObjectCmd(obj) << ")"; std::ostringstream ss; dropParent = 0; - parentItem->getSubName(ss,dropParent); - if(dropParent) + parentItem->getSubName(ss, dropParent); + if (dropParent) ss << parentItem->object()->getObject()->getNameInDocument() << '.'; else dropParent = parentItem->object()->getObject(); ss << obj->getNameInDocument() << '.'; dropName = ss.str(); - } else { + } + else { TREE_WARN("ignore replace operation without parent"); continue; } Gui::Command::runCommand(Gui::Command::App, ss.str().c_str()); - }else{ + } + else { ss << Command::getObjectCmd(vp->getObject()) << ".ViewObject.dropObject(" << Command::getObjectCmd(obj); - if(owner) { + if (owner) { ss << "," << Command::getObjectCmd(owner) << ",'" << subname << "',["; - }else + } + else ss << ",None,'',["; - for(auto &sub : info.subs) + for (auto& sub : info.subs) ss << "'" << sub << "',"; ss << "])"; auto lines = manager->getLines(); - dropName = vp->dropObjectEx(obj,owner,subname.c_str(),info.subs); - if(manager->getLines() == lines) - manager->addLine(MacroManager::Gui,ss.str().c_str()); - if(dropName.size()) + dropName = vp->dropObjectEx(obj, owner, subname.c_str(), info.subs); + if (manager->getLines() == lines) + manager->addLine(MacroManager::Gui, ss.str().c_str()); + if (dropName.size()) dropName = targetSubname.str() + dropName; } touched = true; // Construct the subname pointing to the dropped object - if(dropName.empty()) { + if (dropName.empty()) { auto pos = targetSubname.tellp(); targetSubname << obj->getNameInDocument() << '.' << std::ends; dropName = targetSubname.str(); @@ -2027,55 +2053,58 @@ void TreeWidget::dropEvent(QDropEvent *event) } Base::Matrix4D newMat; - auto sobj = dropParent->getSubObject(dropName.c_str(),0,&newMat); - if(!sobj) { + auto sobj = dropParent->getSubObject(dropName.c_str(), 0, &newMat); + if (!sobj) { FC_LOG("failed to find dropped object " - << dropParent->getFullName() << '.' << dropName); + << dropParent->getFullName() << '.' << dropName); setSelection = false; continue; } - if(da!=Qt::CopyAction && propPlacement) { + if (da != Qt::CopyAction && propPlacement) { // try to adjust placement - if((info.dragging && sobj==obj) || - (!info.dragging && sobj->getLinkedObject(false)==obj)) + if ((info.dragging && sobj == obj) || + (!info.dragging && sobj->getLinkedObject(false) == obj)) { - if(!info.dragging) + if (!info.dragging) propPlacement = Base::freecad_dynamic_cast( - sobj->getPropertyByName("Placement")); - if(propPlacement) { + sobj->getPropertyByName("Placement")); + if (propPlacement) { newMat *= propPlacement->getValue().inverse().toMatrix(); newMat.inverseGauss(); - Base::Placement pla(newMat*mat); + Base::Placement pla(newMat * mat); propPlacement->setValueIfChanged(pla); } } } - droppedObjects.emplace_back(dropParent,dropName); + droppedObjects.emplace_back(dropParent, dropName); } Base::FlagToggler<> guard(_DisableCheckTopParent); - if(setSelection && droppedObjects.size()) { + if (setSelection && droppedObjects.size()) { Selection().selStackPush(); Selection().clearCompleteSelection(); - for(auto &v : droppedObjects) + for (auto& v : droppedObjects) Selection().addSelection(v.first->getDocument()->getName(), v.first->getNameInDocument(), v.second.c_str()); Selection().selStackPush(); } - } catch (const Base::Exception& e) { + } + catch (const Base::Exception& e) { e.ReportException(); errMsg = e.what(); - } catch (std::exception &e) { + } + catch (std::exception& e) { FC_ERR("C++ exception: " << e.what()); errMsg = e.what(); - } catch (...) { + } + catch (...) { FC_ERR("Unknown exception"); errMsg = "Unknown exception"; } - if(errMsg.size()) { + if (errMsg.size()) { committer.close(true); QMessageBox::critical(getMainWindow(), QObject::tr("Drag & drop failed"), - QString::fromUtf8(errMsg.c_str())); + QString::fromUtf8(errMsg.c_str())); return; } } @@ -2088,39 +2117,41 @@ void TreeWidget::dropEvent(QDropEvent *event) bool syncPlacement = TreeParams::Instance()->SyncPlacement(); // check if items can be dragged - for(auto &v : items) { + for (auto& v : items) { auto item = v.first; auto obj = item->object()->getObject(); auto parentItem = item->getParentItem(); - if(!parentItem) { - if(da==Qt::MoveAction && obj->getDocument()==thisDoc) + if (!parentItem) { + if (da == Qt::MoveAction && obj->getDocument() == thisDoc) continue; - }else if(dropOnly || item->myOwner!=targetItem) { + } + else if (dropOnly || item->myOwner != targetItem) { // We will not drag item out of parent if either, 1) the CTRL // key is held, or 2) the dragging item is not inside the // dropping document tree. parentItem = 0; - }else if(!parentItem->object()->canDragObjects() - || !parentItem->object()->canDragObject(obj)) + } + else if (!parentItem->object()->canDragObjects() + || !parentItem->object()->canDragObject(obj)) { TREE_ERR("'" << obj->getFullName() << "' cannot be dragged out of '" << parentItem->object()->getObject()->getFullName() << "'"); return; } infos.emplace_back(); - auto &info = infos.back(); + auto& info = infos.back(); info.doc = obj->getDocument()->getName(); info.obj = obj->getNameInDocument(); - if(parentItem) { + if (parentItem) { auto parent = parentItem->object()->getObject(); info.parentDoc = parent->getDocument()->getName(); info.parent = parent->getNameInDocument(); } - if(syncPlacement) { + if (syncPlacement) { std::ostringstream ss; - App::DocumentObject *topParent=0; - item->getSubName(ss,topParent); - if(topParent) { + App::DocumentObject* topParent = 0; + item->getSubName(ss, topParent); + if (topParent) { info.topDoc = topParent->getDocument()->getName(); info.topObj = topParent->getNameInDocument(); ss << obj->getNameInDocument() << '.'; @@ -2136,66 +2167,68 @@ void TreeWidget::dropEvent(QDropEvent *event) // Open command auto manager = Application::Instance->macroManager(); App::AutoTransaction committer( - da==Qt::LinkAction?"Link object": - da==Qt::CopyAction?"Copy object":"Move object"); + da == Qt::LinkAction ? "Link object" : + da == Qt::CopyAction ? "Copy object" : "Move object"); try { std::vector droppedObjs; - for (auto &info : infos) { + for (auto& info : infos) { auto doc = App::GetApplication().getDocument(info.doc.c_str()); - if(!doc) continue; + if (!doc) continue; auto obj = doc->getObject(info.obj.c_str()); auto vpc = dynamic_cast( - Application::Instance->getViewProvider(obj)); - if(!vpc) { + Application::Instance->getViewProvider(obj)); + if (!vpc) { FC_WARN("Cannot find dragging object " << info.obj); continue; } Base::Matrix4D mat; - App::PropertyPlacement *propPlacement = 0; - if(syncPlacement) { - if(info.topObj.size()) { + App::PropertyPlacement* propPlacement = 0; + if (syncPlacement) { + if (info.topObj.size()) { auto doc = App::GetApplication().getDocument(info.topDoc.c_str()); - if(doc) { + if (doc) { auto topObj = doc->getObject(info.topObj.c_str()); - if(topObj) { - auto sobj = topObj->getSubObject(info.topSubname.c_str(),0,&mat); - if(sobj == obj) { + if (topObj) { + auto sobj = topObj->getSubObject(info.topSubname.c_str(), 0, &mat); + if (sobj == obj) { propPlacement = dynamic_cast( - obj->getPropertyByName("Placement")); + obj->getPropertyByName("Placement")); } } } - }else{ + } + else { propPlacement = dynamic_cast( - obj->getPropertyByName("Placement")); - if(propPlacement) + obj->getPropertyByName("Placement")); + if (propPlacement) mat = propPlacement->getValue().toMatrix(); } } - if(da == Qt::LinkAction) { + if (da == Qt::LinkAction) { std::string name = thisDoc->getUniqueObjectName("Link"); - FCMD_DOC_CMD(thisDoc,"addObject('App::Link','" << name << "').setLink(" - << Command::getObjectCmd(obj) << ")"); + FCMD_DOC_CMD(thisDoc, "addObject('App::Link','" << name << "').setLink(" + << Command::getObjectCmd(obj) << ")"); auto link = thisDoc->getObject(name.c_str()); - if(!link) + if (!link) continue; - FCMD_OBJ_CMD(link,"Label='" << obj->getLinkedObject(true)->Label.getValue() << "'"); + FCMD_OBJ_CMD(link, "Label='" << obj->getLinkedObject(true)->Label.getValue() << "'"); propPlacement = dynamic_cast(link->getPropertyByName("Placement")); - if(propPlacement) + if (propPlacement) propPlacement->setValueIfChanged(Base::Placement(mat)); droppedObjs.push_back(link); - }else if(info.parent.size()) { + } + else if (info.parent.size()) { auto parentDoc = App::GetApplication().getDocument(info.parentDoc.c_str()); - if(!parentDoc) { + if (!parentDoc) { FC_WARN("Canont find document " << info.parentDoc); continue; } auto parent = parentDoc->getObject(info.parent.c_str()); auto vpp = dynamic_cast( - Application::Instance->getViewProvider(parent)); - if(!vpp) { + Application::Instance->getViewProvider(parent)); + if (!vpp) { FC_WARN("Cannot find dragging object's parent " << info.parent); continue; } @@ -2205,79 +2238,84 @@ void TreeWidget::dropEvent(QDropEvent *event) << ".ViewObject.dragObject(" << Command::getObjectCmd(obj) << ')'; auto lines = manager->getLines(); vpp->dragObject(obj); - if(manager->getLines() == lines) - manager->addLine(MacroManager::Gui,ss.str().c_str()); + if (manager->getLines() == lines) + manager->addLine(MacroManager::Gui, ss.str().c_str()); //make sure it is not part of a geofeaturegroup anymore. //When this has happen we need to handle all removed //objects auto grp = App::GeoFeatureGroupExtension::getGroupOfObject(obj); - if(grp) { - FCMD_OBJ_CMD(grp,"removeObject(" << Command::getObjectCmd(obj) << ")"); + if (grp) { + FCMD_OBJ_CMD(grp, "removeObject(" << Command::getObjectCmd(obj) << ")"); } // check if the object has been deleted obj = doc->getObject(info.obj.c_str()); - if(!obj || !obj->getNameInDocument()) + if (!obj || !obj->getNameInDocument()) continue; droppedObjs.push_back(obj); - if(propPlacement) + if (propPlacement) propPlacement->setValueIfChanged(Base::Placement(mat)); - } else { + } + else { std::ostringstream ss; ss << "App.getDocument('" << thisDoc->getName() << "')." - << (da==Qt::CopyAction?"copyObject(":"moveObject(") + << (da == Qt::CopyAction ? "copyObject(" : "moveObject(") << Command::getObjectCmd(obj) << ", True)"; - App::DocumentObject *res = 0; - if(da == Qt::CopyAction) { - auto copied = thisDoc->copyObject({obj},true); - if(copied.size()) + App::DocumentObject* res = 0; + if (da == Qt::CopyAction) { + auto copied = thisDoc->copyObject({ obj }, true); + if (copied.size()) res = copied.back(); - }else - res = thisDoc->moveObject(obj,true); - if(res) { + } + else + res = thisDoc->moveObject(obj, true); + if (res) { propPlacement = dynamic_cast( - res->getPropertyByName("Placement")); - if(propPlacement) + res->getPropertyByName("Placement")); + if (propPlacement) propPlacement->setValueIfChanged(Base::Placement(mat)); droppedObjs.push_back(res); } - manager->addLine(MacroManager::App,ss.str().c_str()); + manager->addLine(MacroManager::App, ss.str().c_str()); } } touched = true; Base::FlagToggler<> guard(_DisableCheckTopParent); - Selection().setSelection(thisDoc->getName(),droppedObjs); + Selection().setSelection(thisDoc->getName(), droppedObjs); - } catch (const Base::Exception& e) { + } + catch (const Base::Exception& e) { e.ReportException(); errMsg = e.what(); - } catch (std::exception &e) { + } + catch (std::exception& e) { FC_ERR("C++ exception: " << e.what()); errMsg = e.what(); - } catch (...) { + } + catch (...) { FC_ERR("Unknown exception"); errMsg = "Unknown exception"; } - if(errMsg.size()) { + if (errMsg.size()) { committer.close(true); QMessageBox::critical(getMainWindow(), QObject::tr("Drag & drop failed"), - QString::fromUtf8(errMsg.c_str())); + QString::fromUtf8(errMsg.c_str())); return; } } - if(touched && TreeParams::Instance()->RecomputeOnDrop()) + if (touched && TreeParams::Instance()->RecomputeOnDrop()) thisDoc->recompute(); - if(touched && TreeParams::Instance()->SyncView()) { + if (touched && TreeParams::Instance()->SyncView()) { auto gdoc = Application::Instance->getDocument(thisDoc); - if(gdoc) + if (gdoc) gdoc->setActiveView(); } } -void TreeWidget::drawRow(QPainter *painter, const QStyleOptionViewItem &options, const QModelIndex &index) const +void TreeWidget::drawRow(QPainter* painter, const QStyleOptionViewItem& options, const QModelIndex& index) const { QTreeWidget::drawRow(painter, options, index); // Set the text and highlighted text color of a hidden object to a dark @@ -2297,14 +2335,14 @@ void TreeWidget::drawRow(QPainter *painter, const QStyleOptionViewItem &options, void TreeWidget::slotNewDocument(const Gui::Document& Doc, bool isMainDoc) { - if(Doc.getDocument()->testStatus(App::Document::TempDoc)) + if (Doc.getDocument()->testStatus(App::Document::TempDoc)) return; DocumentItem* item = new DocumentItem(&Doc, this->rootItem); - if(isMainDoc) + if (isMainDoc) this->expandItem(item); item->setIcon(0, *documentPixmap); item->setText(0, QString::fromUtf8(Doc.getDocument()->Label.getValue())); - DocumentMap[ &Doc ] = item; + DocumentMap[&Doc] = item; } void TreeWidget::slotStartOpenDocument() { @@ -2325,8 +2363,8 @@ void TreeWidget::onReloadDoc() { App::Document* doc = docitem->document()->getDocument(); std::string name = doc->FileName.getValue(); Application::Instance->reopen(doc); - for(auto &v : DocumentMap) { - if(name == v.first->getDocument()->FileName.getValue()) { + for (auto& v : DocumentMap) { + if (name == v.first->getDocument()->FileName.getValue()) { scrollToItem(v.second); App::GetApplication().setActiveDocument(v.first->getDocument()); break; @@ -2344,11 +2382,14 @@ void TreeWidget::onCloseDoc() App::Document* doc = gui->getDocument(); if (gui->canClose(true, true)) Command::doCommand(Command::Doc, "App.closeDocument(\"%s\")", doc->getName()); - } catch (const Base::Exception& e) { + } + catch (const Base::Exception& e) { e.ReportException(); - } catch (std::exception &e) { + } + catch (std::exception& e) { FC_ERR("C++ exception: " << e.what()); - } catch (...) { + } + catch (...) { FC_ERR("Unknown exception"); } } @@ -2359,21 +2400,21 @@ void TreeWidget::slotRenameDocument(const Gui::Document& Doc) Q_UNUSED(Doc); } -void TreeWidget::slotChangedViewObject(const Gui::ViewProvider& vp, const App::Property &prop) +void TreeWidget::slotChangedViewObject(const Gui::ViewProvider& vp, const App::Property& prop) { - if(!App::GetApplication().isRestoring() - && vp.isDerivedFrom(ViewProviderDocumentObject::getClassTypeId())) + if (!App::GetApplication().isRestoring() + && vp.isDerivedFrom(ViewProviderDocumentObject::getClassTypeId())) { - const auto &vpd = static_cast(vp); - if(&prop == &vpd.ShowInTree) { - ChangedObjects.emplace(vpd.getObject(),0); + const auto& vpd = static_cast(vp); + if (&prop == &vpd.ShowInTree) { + ChangedObjects.emplace(vpd.getObject(), 0); _updateStatus(); } } } -void TreeWidget::slotTouchedObject(const App::DocumentObject &obj) { - ChangedObjects.emplace(const_cast(&obj),0); +void TreeWidget::slotTouchedObject(const App::DocumentObject& obj) { + ChangedObjects.emplace(const_cast(&obj), 0); _updateStatus(); } @@ -2381,7 +2422,7 @@ void TreeWidget::slotShowHidden(const Gui::Document& Doc) { auto it = DocumentMap.find(&Doc); if (it != DocumentMap.end()) - it->second->updateItemsVisibility(it->second,it->second->showHidden()); + it->second->updateItemsVisibility(it->second, it->second->showHidden()); } void TreeWidget::slotRelabelDocument(const Gui::Document& Doc) @@ -2399,7 +2440,7 @@ void TreeWidget::slotActiveDocument(const Gui::Document& Doc) return; // signal is emitted before the item gets created int displayMode = TreeParams::Instance()->DocumentMode(); for (auto it = DocumentMap.begin(); - it != DocumentMap.end(); ++it) + it != DocumentMap.end(); ++it) { QFont f = it->second->font(0); f.setBold(it == jt); @@ -2413,21 +2454,21 @@ void TreeWidget::slotActiveDocument(const Gui::Document& Doc) } struct UpdateDisabler { - QWidget &widget; - int &blocked; + QWidget& widget; + int& blocked; bool visible; bool focus; // Note! DO NOT block signal here, or else // QTreeWidgetItem::setChildIndicatorPolicy() does not work - UpdateDisabler(QWidget &w, int &blocked) + UpdateDisabler(QWidget& w, int& blocked) : widget(w), blocked(blocked), visible(false), focus(false) { - if(++blocked > 1) + if (++blocked > 1) return; focus = widget.hasFocus(); visible = widget.isVisible(); - if(visible) { + if (visible) { // setUpdatesEnabled(false) does not seem to speed up anything. // setVisible(false) on the other hand makes QTreeWidget::setData // (i.e. any change to QTreeWidgetItem) faster by 10+ times. @@ -2438,13 +2479,13 @@ struct UpdateDisabler { } } ~UpdateDisabler() { - if(blocked<=0 || --blocked!=0) + if (blocked <= 0 || --blocked != 0) return; - if(visible) { + if (visible) { widget.setVisible(true); // widget.setUpdatesEnabled(true); - if(focus) + if (focus) widget.setFocus(); } } @@ -2452,13 +2493,13 @@ struct UpdateDisabler { void TreeWidget::onUpdateStatus(void) { - if(this->state()==DraggingState || App::GetApplication().isRestoring()) { + if (this->state() == DraggingState || App::GetApplication().isRestoring()) { _updateStatus(); return; } - for(auto &v : DocumentMap) { - if(v.first->isPerformingTransaction()) { + for (auto& v : DocumentMap) { + if (v.first->isPerformingTransaction()) { // We have to delay item creation until undo/redo is done, because the // object re-creation while in transaction may break tree view item // update logic. For example, a parent object re-created before its @@ -2471,56 +2512,56 @@ void TreeWidget::onUpdateStatus(void) FC_LOG("begin update status"); - UpdateDisabler disabler(*this,updateBlocked); + UpdateDisabler disabler(*this, updateBlocked); std::vector errors; // Checking for new objects - for(auto &v : NewObjects) { + for (auto& v : NewObjects) { auto doc = App::GetApplication().getDocument(v.first.c_str()); - if(!doc) + if (!doc) continue; auto gdoc = Application::Instance->getDocument(doc); - if(!gdoc) + if (!gdoc) continue; auto docItem = getDocumentItem(gdoc); - if(!docItem) + if (!docItem) continue; - for(auto id : v.second) { + for (auto id : v.second) { auto obj = doc->getObjectByID(id); - if(!obj) + if (!obj) continue; - if(obj->isError()) + if (obj->isError()) errors.push_back(obj); - if(docItem->ObjectMap.count(obj)) + if (docItem->ObjectMap.count(obj)) continue; auto vpd = Base::freecad_dynamic_cast(gdoc->getViewProvider(obj)); - if(vpd) + if (vpd) docItem->createNewItem(*vpd); } } NewObjects.clear(); // Update children of changed objects - for(auto &v : ChangedObjects) { + for (auto& v : ChangedObjects) { auto obj = v.first; auto iter = ObjectTable.find(obj); - if(iter == ObjectTable.end()) + if (iter == ObjectTable.end()) continue; - if(v.second.test(CS_Error) && obj->isError()) + if (v.second.test(CS_Error) && obj->isError()) errors.push_back(obj); - if(iter->second.size()) { + if (iter->second.size()) { auto data = *iter->second.begin(); bool itemHidden = !data->viewObject->showInTree(); - if(data->itemHidden != itemHidden) { - for(auto &data : iter->second) { + if (data->itemHidden != itemHidden) { + for (auto& data : iter->second) { data->itemHidden = itemHidden; - if(data->docItem->showHidden()) + if (data->docItem->showHidden()) continue; - for(auto item : data->items) + for (auto item : data->items) item->setHidden(itemHidden); } } @@ -2532,45 +2573,45 @@ void TreeWidget::onUpdateStatus(void) FC_LOG("update item status"); TimingInit(); - for (auto pos = DocumentMap.begin();pos!=DocumentMap.end();++pos) { + for (auto pos = DocumentMap.begin(); pos != DocumentMap.end(); ++pos) { pos->second->testStatus(); } TimingPrint(); // Checking for just restored documents - for(auto &v : DocumentMap) { + for (auto& v : DocumentMap) { auto docItem = v.second; - for(auto obj : docItem->PopulateObjects) + for (auto obj : docItem->PopulateObjects) docItem->populateObject(obj); docItem->PopulateObjects.clear(); auto doc = v.first->getDocument(); - if(!docItem->connectChgObject.connected()) { + if (!docItem->connectChgObject.connected()) { docItem->connectChgObject = docItem->document()->signalChangedObject.connect( - boost::bind(&TreeWidget::slotChangeObject, this, bp::_1, bp::_2)); + boost::bind(&TreeWidget::slotChangeObject, this, bp::_1, bp::_2)); docItem->connectTouchedObject = doc->signalTouchedObject.connect( - boost::bind(&TreeWidget::slotTouchedObject, this, bp::_1)); + boost::bind(&TreeWidget::slotTouchedObject, this, bp::_1)); } - if(doc->testStatus(App::Document::PartialDoc)) + if (doc->testStatus(App::Document::PartialDoc)) docItem->setIcon(0, *documentPartialPixmap); - else if(docItem->_ExpandInfo) { - for(auto &entry : *docItem->_ExpandInfo) { - const char *name = entry.first.c_str(); + else if (docItem->_ExpandInfo) { + for (auto& entry : *docItem->_ExpandInfo) { + const char* name = entry.first.c_str(); bool legacy = name[0] == '*'; - if(legacy) + if (legacy) ++name; auto obj = doc->getObject(name); - if(!obj) + if (!obj) continue; auto iter = docItem->ObjectMap.find(obj); - if(iter==docItem->ObjectMap.end()) + if (iter == docItem->ObjectMap.end()) continue; - if(iter->second->rootItem) - docItem->restoreItemExpansion(entry.second,iter->second->rootItem); - else if(legacy && iter->second->items.size()) { + if (iter->second->rootItem) + docItem->restoreItemExpansion(entry.second, iter->second->rootItem); + else if (legacy && iter->second->items.size()) { auto item = *iter->second->items.begin(); item->setExpanded(true); } @@ -2579,10 +2620,10 @@ void TreeWidget::onUpdateStatus(void) docItem->_ExpandInfo.reset(); } - if(Selection().hasSelection() && !selectTimer->isActive() && !this->isConnectionBlocked()) { + if (Selection().hasSelection() && !selectTimer->isActive() && !this->isConnectionBlocked()) { this->blockConnection(true); currentDocItem = 0; - for(auto &v : DocumentMap) { + for (auto& v : DocumentMap) { v.second->setSelected(false); v.second->selectItems(); } @@ -2591,34 +2632,34 @@ void TreeWidget::onUpdateStatus(void) auto activeDocItem = getDocumentItem(Application::Instance->activeDocument()); - QTreeWidgetItem *errItem = 0; - for(auto obj : errors) { + QTreeWidgetItem* errItem = 0; + for (auto obj : errors) { DocumentObjectDataPtr data; - if(activeDocItem) { + if (activeDocItem) { auto it = activeDocItem->ObjectMap.find(obj); - if(it!=activeDocItem->ObjectMap.end()) + if (it != activeDocItem->ObjectMap.end()) data = it->second; } - if(!data) { + if (!data) { auto docItem = getDocumentItem( - Application::Instance->getDocument(obj->getDocument())); - if(docItem) { + Application::Instance->getDocument(obj->getDocument())); + if (docItem) { auto it = docItem->ObjectMap.find(obj); - if(it!=docItem->ObjectMap.end()) + if (it != docItem->ObjectMap.end()) data = it->second; } } - if(data) { + if (data) { auto item = data->rootItem; - if(!item && data->items.size()) { + if (!item && data->items.size()) { item = *data->items.begin(); - data->docItem->showItem(item,false,true); + data->docItem->showItem(item, false, true); } - if(!errItem) + if (!errItem) errItem = item; } } - if(errItem) + if (errItem) scrollToItem(errItem); updateGeometries(); @@ -2627,43 +2668,44 @@ void TreeWidget::onUpdateStatus(void) FC_LOG("done update status"); } -void TreeWidget::onItemEntered(QTreeWidgetItem * item) +void TreeWidget::onItemEntered(QTreeWidgetItem* item) { // object item selected if (item && item->type() == TreeWidget::ObjectType) { DocumentObjectItem* objItem = static_cast(item); objItem->displayStatusInfo(); - if(TreeParams::Instance()->PreSelection()) { + if (TreeParams::Instance()->PreSelection()) { int timeout = TreeParams::Instance()->PreSelectionDelay(); - if(timeout < 0) + if (timeout < 0) timeout = 1; - if(preselectTime.elapsed() < timeout) + if (preselectTime.elapsed() < timeout) onPreSelectTimer(); - else{ + else { timeout = TreeParams::Instance()->PreSelectionTimeout(); - if(timeout < 0) + if (timeout < 0) timeout = 1; preselectTimer->start(timeout); Selection().rmvPreselect(); } } - } else if(TreeParams::Instance()->PreSelection()) + } + else if (TreeParams::Instance()->PreSelection()) Selection().rmvPreselect(); } -void TreeWidget::leaveEvent(QEvent *) { - if(!updateBlocked && TreeParams::Instance()->PreSelection()) { +void TreeWidget::leaveEvent(QEvent*) { + if (!updateBlocked && TreeParams::Instance()->PreSelection()) { preselectTimer->stop(); Selection().rmvPreselect(); } } void TreeWidget::onPreSelectTimer() { - if(!TreeParams::Instance()->PreSelection()) + if (!TreeParams::Instance()->PreSelection()) return; auto item = itemAt(viewport()->mapFromGlobal(QCursor::pos())); - if(!item || item->type()!=TreeWidget::ObjectType) + if (!item || item->type() != TreeWidget::ObjectType) return; preselectTime.restart(); @@ -2671,17 +2713,17 @@ void TreeWidget::onPreSelectTimer() { auto vp = objItem->object(); auto obj = vp->getObject(); std::ostringstream ss; - App::DocumentObject *parent = 0; - objItem->getSubName(ss,parent); - if(!parent) + App::DocumentObject* parent = 0; + objItem->getSubName(ss, parent); + if (!parent) parent = obj; - else if(!obj->redirectSubName(ss,parent,0)) + else if (!obj->redirectSubName(ss, parent, 0)) ss << obj->getNameInDocument() << '.'; - Selection().setPreselect(parent->getDocument()->getName(),parent->getNameInDocument(), - ss.str().c_str(),0,0,0,2); + Selection().setPreselect(parent->getDocument()->getName(), parent->getNameInDocument(), + ss.str().c_str(), 0, 0, 0, 2); } -void TreeWidget::onItemCollapsed(QTreeWidgetItem * item) +void TreeWidget::onItemCollapsed(QTreeWidgetItem* item) { // object item collapsed if (item && item->type() == TreeWidget::ObjectType) { @@ -2689,40 +2731,41 @@ void TreeWidget::onItemCollapsed(QTreeWidgetItem * item) } } -void TreeWidget::onItemExpanded(QTreeWidgetItem * item) +void TreeWidget::onItemExpanded(QTreeWidgetItem* item) { // object item expanded if (item && item->type() == TreeWidget::ObjectType) { DocumentObjectItem* objItem = static_cast(item); objItem->setExpandedStatus(true); - objItem->getOwnerDocument()->populateItem(objItem,false,false); + objItem->getOwnerDocument()->populateItem(objItem, false, false); } } void TreeWidget::scrollItemToTop() { auto doc = Application::Instance->activeDocument(); - for(auto tree : Instances) { - if(!tree->isConnectionAttached() || tree->isConnectionBlocked()) + for (auto tree : Instances) { + if (!tree->isConnectionAttached() || tree->isConnectionBlocked()) continue; tree->_updateStatus(false); - if(doc && Gui::Selection().hasSelection(doc->getDocument()->getName(),false)) { + if (doc && Gui::Selection().hasSelection(doc->getDocument()->getName(), false)) { auto it = tree->DocumentMap.find(doc); if (it != tree->DocumentMap.end()) { bool lock = tree->blockConnection(true); it->second->selectItems(DocumentItem::SR_FORCE_EXPAND); tree->blockConnection(lock); } - } else { + } + else { tree->blockConnection(true); - for (int i=0; irootItem->childCount(); i++) { + for (int i = 0; i < tree->rootItem->childCount(); i++) { auto docItem = dynamic_cast(tree->rootItem->child(i)); - if(!docItem) + if (!docItem) continue; auto doc = docItem->document()->getDocument(); - if(Gui::Selection().hasSelection(doc->getName())) { + if (Gui::Selection().hasSelection(doc->getName())) { tree->currentDocItem = docItem; docItem->selectItems(DocumentItem::SR_FORCE_EXPAND); tree->currentDocItem = 0; @@ -2738,10 +2781,10 @@ void TreeWidget::scrollItemToTop() void TreeWidget::expandSelectedItems(TreeItemMode mode) { - if(!isConnectionAttached()) + if (!isConnectionAttached()) return; - for(auto item : selectedItems()) { + for (auto item : selectedItems()) { switch (mode) { case TreeItemMode::ExpandPath: { QTreeWidgetItem* parentItem = item->parent(); @@ -2791,7 +2834,7 @@ void TreeWidget::setupText() this->selectDependentsAction->setText(tr("Add dependent objects to selection")); this->selectDependentsAction->setStatusTip(tr("Adds all dependent objects to the selection")); - + this->closeDocAction->setText(tr("Close document")); this->closeDocAction->setStatusTip(tr("Close the document")); @@ -2803,7 +2846,7 @@ void TreeWidget::setupText() this->allowPartialRecomputeAction->setText(tr("Allow partial recomputes")); this->allowPartialRecomputeAction->setStatusTip( - tr("Enable or disable recomputating editing object when 'skip recomputation' is enabled")); + tr("Enable or disable recomputating editing object when 'skip recomputation' is enabled")); this->markRecomputeAction->setText(tr("Mark to recompute")); this->markRecomputeAction->setStatusTip(tr("Mark this object to be recomputed")); @@ -2814,12 +2857,12 @@ void TreeWidget::setupText() this->recomputeObjectAction->setIcon(BitmapFactory().iconFromTheme("view-refresh")); } -void TreeWidget::syncView(ViewProviderDocumentObject *vp) +void TreeWidget::syncView(ViewProviderDocumentObject* vp) { - if(currentDocItem && TreeParams::Instance()->SyncView()) { + if (currentDocItem && TreeParams::Instance()->SyncView()) { bool focus = hasFocus(); currentDocItem->document()->setActiveView(vp); - if(focus) + if (focus) setFocus(); } } @@ -2827,12 +2870,12 @@ void TreeWidget::syncView(ViewProviderDocumentObject *vp) void TreeWidget::onShowHidden() { if (!this->contextItem) return; - DocumentItem *docItem = nullptr; - if(this->contextItem->type() == DocumentType) + DocumentItem* docItem = nullptr; + if (this->contextItem->type() == DocumentType) docItem = static_cast(contextItem); - else if(this->contextItem->type() == ObjectType) + else if (this->contextItem->type() == ObjectType) docItem = static_cast(contextItem)->getOwnerDocument(); - if(docItem) + if (docItem) docItem->setShowHidden(showHiddenAction->isChecked()); } @@ -2844,7 +2887,7 @@ void TreeWidget::onHideInTree() } } -void TreeWidget::changeEvent(QEvent *e) +void TreeWidget::changeEvent(QEvent* e) { if (e->type() == QEvent::LanguageChange) setupText(); @@ -2852,11 +2895,11 @@ void TreeWidget::changeEvent(QEvent *e) QTreeWidget::changeEvent(e); } -void TreeWidget::onItemSelectionChanged () +void TreeWidget::onItemSelectionChanged() { if (!this->isConnectionAttached() - || this->isConnectionBlocked() - || updateBlocked) + || this->isConnectionBlocked() + || updateBlocked) return; _LastSelectedTreeWidget = this; @@ -2864,7 +2907,7 @@ void TreeWidget::onItemSelectionChanged () // block tmp. the connection to avoid to notify us ourself bool lock = this->blockConnection(true); - if(selectTimer->isActive()) + if (selectTimer->isActive()) onSelectTimer(); else _updateStatus(false); @@ -2872,59 +2915,61 @@ void TreeWidget::onItemSelectionChanged () auto selItems = selectedItems(); // do not allow document item multi-selection - if(selItems.size()) { + if (selItems.size()) { auto firstType = selItems.back()->type(); - for(auto it=selItems.begin();it!=selItems.end();) { + for (auto it = selItems.begin(); it != selItems.end();) { auto item = *it; - if((firstType==ObjectType && item->type()!=ObjectType) - || (firstType==DocumentType && item!=selItems.back())) + if ((firstType == ObjectType && item->type() != ObjectType) + || (firstType == DocumentType && item != selItems.back())) { item->setSelected(false); it = selItems.erase(it); - } else + } + else ++it; } } - if(selItems.size()<=1) { - if(TreeParams::Instance()->RecordSelection()) + if (selItems.size() <= 1) { + if (TreeParams::Instance()->RecordSelection()) Gui::Selection().selStackPush(); // This special handling to deal with possible discrepancy of // Gui.Selection and Tree view selection because of newly added // DocumentObject::redirectSubName() Selection().clearCompleteSelection(); - DocumentObjectItem *item=0; - if(selItems.size()) { - if(selItems.front()->type() == ObjectType) + DocumentObjectItem* item = 0; + if (selItems.size()) { + if (selItems.front()->type() == ObjectType) item = static_cast(selItems.front()); - else if(selItems.front()->type() == DocumentType) { + else if (selItems.front()->type() == DocumentType) { auto ditem = static_cast(selItems.front()); - if(TreeParams::Instance()->SyncView()) { + if (TreeParams::Instance()->SyncView()) { bool focus = hasFocus(); ditem->document()->setActiveView(); - if(focus) + if (focus) setFocus(); } // For triggering property editor refresh Gui::Selection().signalSelectionChanged(SelectionChanges()); } } - for(auto &v : DocumentMap) { + for (auto& v : DocumentMap) { currentDocItem = v.second; v.second->clearSelection(item); currentDocItem = 0; } - if(TreeParams::Instance()->RecordSelection()) + if (TreeParams::Instance()->RecordSelection()) Gui::Selection().selStackPush(); - }else{ - for (auto pos = DocumentMap.begin();pos!=DocumentMap.end();++pos) { + } + else { + for (auto pos = DocumentMap.begin(); pos != DocumentMap.end(); ++pos) { currentDocItem = pos->second; pos->second->updateSelection(pos->second); currentDocItem = 0; } - if(TreeParams::Instance()->RecordSelection()) - Gui::Selection().selStackPush(true,true); + if (TreeParams::Instance()->RecordSelection()) + Gui::Selection().selStackPush(true, true); } this->blockConnection(lock); @@ -2947,19 +2992,20 @@ void TreeWidget::synchronizeSelectionCheckBoxes() { resizeColumnToContents(0); } -QList TreeWidget::childrenOfItem(const QTreeWidgetItem &item) const{ - QList children = QList(); +QList TreeWidget::childrenOfItem(const QTreeWidgetItem& item) const { + QList children = QList(); // check item is in this tree - if (!this->indexFromItem(&item).isValid()) return children; + if (!this->indexFromItem(&item).isValid()) + return children; - for (int i=0 ; i < item.childCount() ; i++) { + for (int i = 0; i < item.childCount(); i++) { children.append(item.child(i)); } return children; } -void TreeWidget::onItemChanged(QTreeWidgetItem *item, int column) { +void TreeWidget::onItemChanged(QTreeWidgetItem* item, int column) { if (column == 0 && isSelectionCheckBoxesEnabled()) { bool selected = item->isSelected(); bool checked = item->checkState(0) == Qt::Checked; @@ -2975,15 +3021,16 @@ void TreeWidget::onSelectTimer() { bool syncSelect = TreeParams::Instance()->SyncSelection(); bool locked = this->blockConnection(true); - if(Selection().hasSelection()) { - for(auto &v : DocumentMap) { + if (Selection().hasSelection()) { + for (auto& v : DocumentMap) { v.second->setSelected(false); currentDocItem = v.second; - v.second->selectItems(syncSelect?DocumentItem::SR_EXPAND:DocumentItem::SR_SELECT); + v.second->selectItems(syncSelect ? DocumentItem::SR_EXPAND : DocumentItem::SR_SELECT); currentDocItem = 0; } - }else{ - for(auto &v : DocumentMap) + } + else { + for (auto& v : DocumentMap) v.second->clearSelection(); } this->blockConnection(locked); @@ -3000,7 +3047,7 @@ void TreeWidget::onSelectionChanged(const SelectionChanges& msg) case SelectionChanges::SetSelection: case SelectionChanges::ClrSelection: { int timeout = TreeParams::Instance()->SelectionTimeout(); - if(timeout<=0) + if (timeout <= 0) timeout = 1; selectTimer->start(timeout); break; @@ -3014,31 +3061,31 @@ void TreeWidget::onSelectionChanged(const SelectionChanges& msg) /* TRANSLATOR Gui::TreePanel */ -TreePanel::TreePanel(const char *name, QWidget* parent) - : QWidget(parent) +TreePanel::TreePanel(const char* name, QWidget* parent) + : QWidget(parent) { this->treeWidget = new TreeWidget(name, this); int indent = TreeParams::Instance()->Indentation(); - if(indent) + if (indent) this->treeWidget->setIndentation(indent); QVBoxLayout* pLayout = new QVBoxLayout(this); pLayout->setSpacing(0); - pLayout->setMargin (0); + pLayout->setMargin(0); pLayout->addWidget(this->treeWidget); connect(this->treeWidget, SIGNAL(emitSearchObjects()), - this, SLOT(showEditor())); + this, SLOT(showEditor())); - this->searchBox = new Gui::ExpressionLineEdit(this,true); + this->searchBox = new Gui::ExpressionLineEdit(this, true); static_cast(this->searchBox)->setExactMatch(Gui::ExpressionParameter::instance()->isExactMatch()); pLayout->addWidget(this->searchBox); this->searchBox->hide(); this->searchBox->installEventFilter(this); this->searchBox->setPlaceholderText(tr("Search")); connect(this->searchBox, SIGNAL(returnPressed()), - this, SLOT(accept())); + this, SLOT(accept())); connect(this->searchBox, SIGNAL(textChanged(QString)), - this, SLOT(itemSearch(QString))); + this, SLOT(itemSearch(QString))); } TreePanel::~TreePanel() @@ -3050,10 +3097,10 @@ void TreePanel::accept() QString text = this->searchBox->text(); hideEditor(); this->treeWidget->setFocus(); - this->treeWidget->itemSearch(text,true); + this->treeWidget->itemSearch(text, true); } -bool TreePanel::eventFilter(QObject *obj, QEvent *ev) +bool TreePanel::eventFilter(QObject* obj, QEvent* ev) { if (obj != this->searchBox) return false; @@ -3092,103 +3139,103 @@ void TreePanel::hideEditor() this->searchBox->hide(); this->treeWidget->resetItemSearch(); auto sels = this->treeWidget->selectedItems(); - if(sels.size()) + if (sels.size()) this->treeWidget->scrollToItem(sels.front()); } -void TreePanel::itemSearch(const QString &text) +void TreePanel::itemSearch(const QString& text) { - this->treeWidget->itemSearch(text,false); + this->treeWidget->itemSearch(text, false); } // ---------------------------------------------------------------------------- /* TRANSLATOR Gui::TreeDockWidget */ -TreeDockWidget::TreeDockWidget(Gui::Document* pcDocument,QWidget *parent) - : DockWindow(pcDocument,parent) +TreeDockWidget::TreeDockWidget(Gui::Document* pcDocument, QWidget* parent) + : DockWindow(pcDocument, parent) { setWindowTitle(tr("Tree view")); auto panel = new TreePanel("TreeView", this); QGridLayout* pLayout = new QGridLayout(this); pLayout->setSpacing(0); - pLayout->setMargin (0); - pLayout->addWidget(panel, 0, 0 ); + pLayout->setMargin(0); + pLayout->addWidget(panel, 0, 0); } TreeDockWidget::~TreeDockWidget() { } -void TreeWidget::selectLinkedObject(App::DocumentObject *linked) { - if(!isConnectionAttached() || isConnectionBlocked()) +void TreeWidget::selectLinkedObject(App::DocumentObject* linked) { + if (!isConnectionAttached() || isConnectionBlocked()) return; auto linkedVp = Base::freecad_dynamic_cast( - Application::Instance->getViewProvider(linked)); - if(!linkedVp) { + Application::Instance->getViewProvider(linked)); + if (!linkedVp) { TREE_ERR("invalid linked view provider"); return; } auto linkedDoc = getDocumentItem(linkedVp->getDocument()); - if(!linkedDoc) { + if (!linkedDoc) { TREE_ERR("cannot find document of linked object"); return; } - if(selectTimer->isActive()) + if (selectTimer->isActive()) onSelectTimer(); else _updateStatus(false); auto it = linkedDoc->ObjectMap.find(linked); - if(it == linkedDoc->ObjectMap.end()) { + if (it == linkedDoc->ObjectMap.end()) { TREE_ERR("cannot find tree item of linked object"); return; } auto linkedItem = it->second->rootItem; - if(!linkedItem) + if (!linkedItem) linkedItem = *it->second->items.begin(); - if(linkedDoc->showItem(linkedItem,true)) + if (linkedDoc->showItem(linkedItem, true)) scrollToItem(linkedItem); - if(linkedDoc->document()->getDocument() != App::GetApplication().getActiveDocument()) { + if (linkedDoc->document()->getDocument() != App::GetApplication().getActiveDocument()) { bool focus = hasFocus(); linkedDoc->document()->setActiveView(linkedItem->object()); - if(focus) + if (focus) setFocus(); } } // ---------------------------------------------------------------------------- -DocumentItem::DocumentItem(const Gui::Document* doc, QTreeWidgetItem * parent) +DocumentItem::DocumentItem(const Gui::Document* doc, QTreeWidgetItem* parent) : QTreeWidgetItem(parent, TreeWidget::DocumentType), pDocument(const_cast(doc)) { // Setup connections connectNewObject = doc->signalNewObject.connect(boost::bind(&DocumentItem::slotNewObject, this, bp::_1)); connectDelObject = doc->signalDeletedObject.connect( - boost::bind(&TreeWidget::slotDeleteObject, getTree(), bp::_1)); - if(!App::GetApplication().isRestoring()) { + boost::bind(&TreeWidget::slotDeleteObject, getTree(), bp::_1)); + if (!App::GetApplication().isRestoring()) { connectChgObject = doc->signalChangedObject.connect( - boost::bind(&TreeWidget::slotChangeObject, getTree(), bp::_1, bp::_2)); + boost::bind(&TreeWidget::slotChangeObject, getTree(), bp::_1, bp::_2)); connectTouchedObject = doc->getDocument()->signalTouchedObject.connect( - boost::bind(&TreeWidget::slotTouchedObject, getTree(), bp::_1)); + boost::bind(&TreeWidget::slotTouchedObject, getTree(), bp::_1)); } connectEdtObject = doc->signalInEdit.connect(boost::bind(&DocumentItem::slotInEdit, this, bp::_1)); connectResObject = doc->signalResetEdit.connect(boost::bind(&DocumentItem::slotResetEdit, this, bp::_1)); connectHltObject = doc->signalHighlightObject.connect( - boost::bind(&DocumentItem::slotHighlightObject, this, bp::_1, bp::_2, bp::_3, bp::_4, bp::_5)); + boost::bind(&DocumentItem::slotHighlightObject, this, bp::_1, bp::_2, bp::_3, bp::_4, bp::_5)); connectExpObject = doc->signalExpandObject.connect( - boost::bind(&DocumentItem::slotExpandObject, this, bp::_1, bp::_2, bp::_3, bp::_4)); + boost::bind(&DocumentItem::slotExpandObject, this, bp::_1, bp::_2, bp::_3, bp::_4)); connectScrObject = doc->signalScrollToObject.connect(boost::bind(&DocumentItem::slotScrollToObject, this, bp::_1)); auto adoc = doc->getDocument(); connectRecomputed = adoc->signalRecomputed.connect(boost::bind(&DocumentItem::slotRecomputed, this, bp::_1, bp::_2)); connectRecomputedObj = adoc->signalRecomputedObject.connect( - boost::bind(&DocumentItem::slotRecomputedObject, this, bp::_1)); + boost::bind(&DocumentItem::slotRecomputedObject, this, bp::_1)); - setFlags(Qt::ItemIsEnabled|Qt::ItemIsSelectable/*|Qt::ItemIsEditable*/); + setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable/*|Qt::ItemIsEditable*/); treeName = getTree()->getTreeName(); } @@ -3208,11 +3255,11 @@ DocumentItem::~DocumentItem() connectRecomputedObj.disconnect(); } -TreeWidget *DocumentItem::getTree() const{ +TreeWidget* DocumentItem::getTree() const { return static_cast(treeWidget()); } -const char *DocumentItem::getTreeName() const { +const char* DocumentItem::getTreeName() const { return treeName; } @@ -3235,27 +3282,27 @@ void DocumentItem::slotInEdit(const Gui::ViewProviderDocumentObject& v) (void)v; ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/TreeView"); - unsigned long col = hGrp->GetUnsigned("TreeEditColor",4294902015); - QColor color((col >> 24) & 0xff,(col >> 16) & 0xff,(col >> 8) & 0xff); + unsigned long col = hGrp->GetUnsigned("TreeEditColor", 4294902015); + QColor color((col >> 24) & 0xff, (col >> 16) & 0xff, (col >> 8) & 0xff); - if(!getTree()->editingItem) { + if (!getTree()->editingItem) { auto doc = Application::Instance->editDocument(); - if(!doc) + if (!doc) return; - ViewProviderDocumentObject *parentVp=0; + ViewProviderDocumentObject* parentVp = 0; std::string subname; - auto vp = doc->getInEdit(&parentVp,&subname); - if(!parentVp) + auto vp = doc->getInEdit(&parentVp, &subname); + if (!parentVp) parentVp = dynamic_cast(vp); - if(parentVp) - getTree()->editingItem = findItemByObject(true,parentVp->getObject(),subname.c_str()); + if (parentVp) + getTree()->editingItem = findItemByObject(true, parentVp->getObject(), subname.c_str()); } - if(getTree()->editingItem) - getTree()->editingItem->setBackground(0,color); - else{ - FOREACH_ITEM(item,v) - item->setBackground(0,color); + if (getTree()->editingItem) + getTree()->editingItem->setBackground(0, color); + else { + FOREACH_ITEM(item, v) + item->setBackground(0, color); END_FOREACH_ITEM } } @@ -3264,19 +3311,20 @@ void DocumentItem::slotResetEdit(const Gui::ViewProviderDocumentObject& v) { auto tree = getTree(); FOREACH_ITEM_ALL(item) - if(tree->editingItem) { - if(item == tree->editingItem) { - item->setData(0, Qt::BackgroundRole,QVariant()); + if (tree->editingItem) { + if (item == tree->editingItem) { + item->setData(0, Qt::BackgroundRole, QVariant()); break; } - }else if(item->object() == &v) - item->setData(0, Qt::BackgroundRole,QVariant()); + } + else if (item->object() == &v) + item->setData(0, Qt::BackgroundRole, QVariant()); END_FOREACH_ITEM - tree->editingItem = 0; + tree->editingItem = 0; } void DocumentItem::slotNewObject(const Gui::ViewProviderDocumentObject& obj) { - if(!obj.getObject() || !obj.getObject()->getNameInDocument()) { + if (!obj.getObject() || !obj.getObject()->getNameInDocument()) { FC_ERR("view provider not attached"); return; } @@ -3285,48 +3333,49 @@ void DocumentItem::slotNewObject(const Gui::ViewProviderDocumentObject& obj) { } bool DocumentItem::createNewItem(const Gui::ViewProviderDocumentObject& obj, - QTreeWidgetItem *parent, int index, DocumentObjectDataPtr data) + QTreeWidgetItem* parent, int index, DocumentObjectDataPtr data) { - const char *name; + const char* name; if (!obj.getObject() || - !(name=obj.getObject()->getNameInDocument()) || + !(name = obj.getObject()->getNameInDocument()) || obj.getObject()->testStatus(App::PartialObject)) return false; - if(!data) { - auto &pdata = ObjectMap[obj.getObject()]; - if(!pdata) { + if (!data) { + auto& pdata = ObjectMap[obj.getObject()]; + if (!pdata) { pdata = std::make_shared( - this, const_cast(&obj)); - auto &entry = getTree()->ObjectTable[obj.getObject()]; - if(entry.size()) + this, const_cast(&obj)); + auto& entry = getTree()->ObjectTable[obj.getObject()]; + if (entry.size()) pdata->updateChildren(*entry.begin()); else pdata->updateChildren(true); entry.insert(pdata); - }else if(pdata->rootItem && parent==NULL) { + } + else if (pdata->rootItem && parent == NULL) { Base::Console().Warning("DocumentItem::slotNewObject: Cannot add view provider twice.\n"); return false; } data = pdata; } - DocumentObjectItem* item = new DocumentObjectItem(this,data); - if(!parent || parent==this) { + DocumentObjectItem* item = new DocumentObjectItem(this, data); + if (!parent || parent == this) { parent = this; data->rootItem = item; - if(index<0) + if (index < 0) index = findRootIndex(obj.getObject()); } - if(index<0) + if (index < 0) parent->addChild(item); else - parent->insertChild(index,item); + parent->insertChild(index, item); assert(item->parent() == parent); item->setText(0, QString::fromUtf8(data->label.c_str())); - if(data->label2.size()) + if (data->label2.size()) item->setText(1, QString::fromUtf8(data->label2.c_str())); - if(!obj.showInTree() && !showHidden()) + if (!obj.showInTree() && !showHidden()) item->setHidden(true); item->testStatus(true); @@ -3334,7 +3383,7 @@ bool DocumentItem::createNewItem(const Gui::ViewProviderDocumentObject& obj, return true; } -ViewProviderDocumentObject *DocumentItem::getViewProvider(App::DocumentObject *obj) { +ViewProviderDocumentObject* DocumentItem::getViewProvider(App::DocumentObject* obj) { // 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 @@ -3351,14 +3400,14 @@ ViewProviderDocumentObject *DocumentItem::getViewProvider(App::DocumentObject *o // getNameInDocument() check be sufficient? - if(!obj || !obj->getNameInDocument()) return 0; + if (!obj || !obj->getNameInDocument()) return 0; - ViewProvider *vp; - if(obj->getDocument() == pDocument->getDocument()) + ViewProvider* vp; + if (obj->getDocument() == pDocument->getDocument()) vp = pDocument->getViewProvider(obj); else vp = Application::Instance->getViewProvider(obj); - if(!vp || !vp->isDerivedFrom(ViewProviderDocumentObject::getClassTypeId())) + if (!vp || !vp->isDerivedFrom(ViewProviderDocumentObject::getClassTypeId())) return 0; return static_cast(vp); } @@ -3368,19 +3417,19 @@ void TreeWidget::slotDeleteDocument(const Gui::Document& Doc) NewObjects.erase(Doc.getDocument()->getName()); auto it = DocumentMap.find(&Doc); if (it != DocumentMap.end()) { - UpdateDisabler disabler(*this,updateBlocked); + UpdateDisabler disabler(*this, updateBlocked); auto docItem = it->second; - for(auto &v : docItem->ObjectMap) { - for(auto item : v.second->items) + for (auto& v : docItem->ObjectMap) { + for (auto item : v.second->items) item->myOwner = 0; auto obj = v.second->viewObject->getObject(); - if(obj->getDocument() == Doc.getDocument()) { + if (obj->getDocument() == Doc.getDocument()) { _slotDeleteObject(*v.second->viewObject, docItem); continue; } auto it = ObjectTable.find(obj); - assert(it!=ObjectTable.end()); - assert(it->second.size()>1); + assert(it != ObjectTable.end()); + assert(it->second.size() > 1); it->second.erase(v.second); } this->rootItem->takeChild(this->rootItem->indexOfChild(docItem)); @@ -3393,14 +3442,14 @@ void TreeWidget::slotDeleteObject(const Gui::ViewProviderDocumentObject& view) { _slotDeleteObject(view, 0); } -void TreeWidget::_slotDeleteObject(const Gui::ViewProviderDocumentObject& view, DocumentItem *deletingDoc) +void TreeWidget::_slotDeleteObject(const Gui::ViewProviderDocumentObject& view, DocumentItem* deletingDoc) { auto obj = view.getObject(); auto itEntry = ObjectTable.find(obj); - if(itEntry == ObjectTable.end()) + if (itEntry == ObjectTable.end()) return; - if(itEntry->second.empty()) { + if (itEntry->second.empty()) { ObjectTable.erase(itEntry); return; } @@ -3409,41 +3458,41 @@ void TreeWidget::_slotDeleteObject(const Gui::ViewProviderDocumentObject& view, bool needUpdate = false; - for(auto data : itEntry->second) { - DocumentItem *docItem = data->docItem; - if(docItem == deletingDoc) + for (auto data : itEntry->second) { + DocumentItem* docItem = data->docItem; + if (docItem == deletingDoc) continue; auto doc = docItem->document()->getDocument(); - auto &items = data->items; + auto& items = data->items; - if(obj->getDocument() == doc) + if (obj->getDocument() == doc) docItem->_ParentMap.erase(obj); bool lock = blockConnection(true); - 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; (*cit)->myOwner = 0; - delete *cit; + delete* cit; } blockConnection(lock); // Check for any child of the deleted object that is not in the tree, and put it // under document item. - for(auto child : data->children) { + for (auto child : data->children) { auto childVp = docItem->getViewProvider(child); if (!childVp || child->getDocument() != doc) continue; docItem->_ParentMap[child].erase(obj); auto cit = docItem->ObjectMap.find(child); - if (cit==docItem->ObjectMap.end() || cit->second->items.empty()) { + if (cit == docItem->ObjectMap.end() || cit->second->items.empty()) { if (docItem->createNewItem(*childVp)) needUpdate = true; } else { auto childItem = *cit->second->items.begin(); if (childItem->requiredAtRoot(false)) { - if (docItem->createNewItem(*childItem->object(),docItem,-1,childItem->myData)) + if (docItem->createNewItem(*childItem->object(), docItem, -1, childItem->myData)) needUpdate = true; } } @@ -3453,30 +3502,30 @@ void TreeWidget::_slotDeleteObject(const Gui::ViewProviderDocumentObject& view, } ObjectTable.erase(itEntry); - if(needUpdate) + if (needUpdate) _updateStatus(); } -bool DocumentItem::populateObject(App::DocumentObject *obj) { +bool DocumentItem::populateObject(App::DocumentObject* obj) { // make sure at least one of the item corresponding to obj is populated auto it = ObjectMap.find(obj); - if(it == ObjectMap.end()) + if (it == ObjectMap.end()) return false; - auto &items = it->second->items; - if(items.empty()) + auto& items = it->second->items; + if (items.empty()) return false; - for(auto item : items) { - if(item->populated) + for (auto item : items) { + if (item->populated) return true; } TREE_LOG("force populate object " << obj->getFullName()); auto item = *items.begin(); item->populated = true; - populateItem(item,true); + populateItem(item, true); return true; } -void DocumentItem::populateItem(DocumentObjectItem *item, bool refresh, bool delay) +void DocumentItem::populateItem(DocumentObjectItem* item, bool refresh, bool delay) { (void)delay; @@ -3487,29 +3536,29 @@ void DocumentItem::populateItem(DocumentObjectItem *item, bool refresh, bool del // a) the item is expanded, or b) there is at least one free child, i.e. // child originally located at root. - item->setChildIndicatorPolicy(item->myData->children.empty()? - QTreeWidgetItem::DontShowIndicator:QTreeWidgetItem::ShowIndicator); + item->setChildIndicatorPolicy(item->myData->children.empty() ? + QTreeWidgetItem::DontShowIndicator : QTreeWidgetItem::ShowIndicator); if (!item->populated && !item->isExpanded()) { bool doPopulate = false; - bool external = item->object()->getDocument()!=item->getOwnerDocument()->document(); - if(external) + bool external = item->object()->getDocument() != item->getOwnerDocument()->document(); + if (external) return; auto obj = item->object()->getObject(); auto linked = obj->getLinkedObject(true); - if (linked && linked->getDocument()!=obj->getDocument()) + if (linked && linked->getDocument() != obj->getDocument()) return; - for(auto child : item->myData->children) { + for (auto child : item->myData->children) { auto it = ObjectMap.find(child); - if(it == ObjectMap.end() || it->second->items.empty()) { + if (it == ObjectMap.end() || it->second->items.empty()) { auto vp = getViewProvider(child); - if(!vp) continue; + if (!vp) continue; doPopulate = true; break; } - if(item->myData->removeChildrenFromRoot) { - if(it->second->rootItem) { + if (item->myData->removeChildrenFromRoot) { + if (it->second->rootItem) { doPopulate = true; break; } @@ -3524,45 +3573,46 @@ void DocumentItem::populateItem(DocumentObjectItem *item, bool refresh, bool del bool checkHidden = !showHidden(); bool updated = false; - int i=-1; + int i = -1; // iterate through the claimed children, and try to synchronize them with the // children tree item with the same order of appearance. int childCount = item->childCount(); - for(auto child : item->myData->children) { + for (auto child : item->myData->children) { ++i; // the current index of the claimed child bool found = false; - for (int j=i;jchild(j); + for (int j = i; j < childCount; ++j) { + QTreeWidgetItem* ci = item->child(j); if (ci->type() != TreeWidget::ObjectType) continue; - DocumentObjectItem *childItem = static_cast(ci); + DocumentObjectItem* childItem = static_cast(ci); 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 childItem->setHighlight(false); item->removeChild(ci); - item->insertChild(i,ci); - assert(ci->parent()==item); - if(checkHidden) - updateItemsVisibility(ci,false); + item->insertChild(i, ci); + assert(ci->parent() == item); + if (checkHidden) + updateItemsVisibility(ci, false); } // Check if the item just changed its policy of whether to remove // children item from the root. - if(item->myData->removeChildrenFromRoot) { - if(childItem->myData->rootItem) { + if (item->myData->removeChildrenFromRoot) { + if (childItem->myData->rootItem) { assert(childItem != childItem->myData->rootItem); bool lock = getTree()->blockConnection(true); delete childItem->myData->rootItem; getTree()->blockConnection(lock); } - }else if(childItem->requiredAtRoot()) { - createNewItem(*childItem->object(),this,-1,childItem->myData); + } + else if (childItem->requiredAtRoot()) { + createNewItem(*childItem->object(), this, -1, childItem->myData); updated = true; } break; @@ -3575,24 +3625,25 @@ void DocumentItem::populateItem(DocumentObjectItem *item, bool refresh, bool del // through slotNewObject -> populateItem auto it = ObjectMap.find(child); - if(it==ObjectMap.end() || it->second->items.empty()) { + if (it == ObjectMap.end() || it->second->items.empty()) { auto vp = getViewProvider(child); - if(!vp || !createNewItem(*vp,item,i,it==ObjectMap.end()?DocumentObjectDataPtr():it->second)) + if (!vp || !createNewItem(*vp, item, i, it == ObjectMap.end() ? DocumentObjectDataPtr() : it->second)) --i; else updated = true; continue; } - if(!item->myData->removeChildrenFromRoot || !it->second->rootItem) { - DocumentObjectItem *childItem = *it->second->items.begin(); - if(!createNewItem(*childItem->object(),item,i,it->second)) + if (!item->myData->removeChildrenFromRoot || !it->second->rootItem) { + DocumentObjectItem* childItem = *it->second->items.begin(); + if (!createNewItem(*childItem->object(), item, i, it->second)) --i; else updated = true; - }else { - DocumentObjectItem *childItem = it->second->rootItem; - if(item==childItem || item->isChildOfItem(childItem)) { + } + else { + DocumentObjectItem* childItem = it->second->rootItem; + if (item == childItem || item->isChildOfItem(childItem)) { TREE_ERR("Cyclic dependency in " << item->object()->getObject()->getFullName() << '.' << childItem->object()->getObject()->getFullName()); @@ -3602,27 +3653,27 @@ void DocumentItem::populateItem(DocumentObjectItem *item, bool refresh, bool del it->second->rootItem = 0; childItem->setHighlight(false); this->removeChild(childItem); - item->insertChild(i,childItem); - assert(childItem->parent()==item); - if(checkHidden) - updateItemsVisibility(childItem,false); + item->insertChild(i, childItem); + assert(childItem->parent() == item); + if (checkHidden) + updateItemsVisibility(childItem, false); } } - for (++i;item->childCount()>i;) { - QTreeWidgetItem *ci = item->child(i); + for (++i; item->childCount() > i;) { + QTreeWidgetItem* ci = item->child(i); if (ci->type() == TreeWidget::ObjectType) { DocumentObjectItem* childItem = static_cast(ci); - if(childItem->requiredAtRoot()) { + if (childItem->requiredAtRoot()) { item->removeChild(childItem); auto index = findRootIndex(childItem->object()->getObject()); - if(index>=0) - this->insertChild(index,childItem); + if (index >= 0) + this->insertChild(index, childItem); else this->addChild(childItem); - assert(childItem->parent()==this); - if(checkHidden) - updateItemsVisibility(childItem,false); + assert(childItem->parent() == this); + if (checkHidden) + updateItemsVisibility(childItem, false); childItem->myData->rootItem = childItem; continue; } @@ -3632,40 +3683,40 @@ void DocumentItem::populateItem(DocumentObjectItem *item, bool refresh, bool del delete ci; getTree()->blockConnection(lock); } - if(updated) + if (updated) getTree()->_updateStatus(); } -int DocumentItem::findRootIndex(App::DocumentObject *childObj) { - if(!TreeParams::Instance()->KeepRootOrder() || !childObj || !childObj->getNameInDocument()) +int DocumentItem::findRootIndex(App::DocumentObject* childObj) { + if (!TreeParams::Instance()->KeepRootOrder() || !childObj || !childObj->getNameInDocument()) return -1; // object id is monotonically increasing, so use this as a hint to insert // object back so that we can have a stable order in root level. int count = this->childCount(); - if(!count) + if (!count) return -1; - int first,last; + int first, last; // find the last item - for(last=count-1;last>=0;--last) { + for (last = count - 1; last >= 0; --last) { auto citem = this->child(last); - if(citem->type() == TreeWidget::ObjectType) { + if (citem->type() == TreeWidget::ObjectType) { auto obj = static_cast(citem)->object()->getObject(); - if(obj->getID()<=childObj->getID()) - return last+1; + if (obj->getID() <= childObj->getID()) + return last + 1; break; } } // find the first item - for(first=0;firstchild(first); - if(citem->type() == TreeWidget::ObjectType) { + if (citem->type() == TreeWidget::ObjectType) { auto obj = static_cast(citem)->object()->getObject(); - if(obj->getID()>=childObj->getID()) + if (obj->getID() >= childObj->getID()) return first; break; } @@ -3673,186 +3724,188 @@ int DocumentItem::findRootIndex(App::DocumentObject *childObj) { // now do a binary search to find the lower bound, assuming the root level // object is already in order - count = last-first; + count = last - first; int pos; while (count > 0) { int step = count / 2; pos = first + step; - for(;pos<=last;++pos) { + for (; pos <= last; ++pos) { auto citem = this->child(pos); - if(citem->type() != TreeWidget::ObjectType) + if (citem->type() != TreeWidget::ObjectType) continue; auto obj = static_cast(citem)->object()->getObject(); - if(obj->getID()getID()) { + if (obj->getID() < childObj->getID()) { first = ++pos; - count -= step+1; - } else + count -= step + 1; + } + else count = step; break; } - if(pos>last) + if (pos > last) return -1; } - if(first>last) + if (first > last) return -1; return first; } void TreeWidget::slotChangeObject( - const Gui::ViewProviderDocumentObject& view, const App::Property &prop) { + const Gui::ViewProviderDocumentObject& view, const App::Property& prop) { auto obj = view.getObject(); - if(!obj || !obj->getNameInDocument()) + if (!obj || !obj->getNameInDocument()) return; auto itEntry = ObjectTable.find(obj); - if(itEntry == ObjectTable.end() || itEntry->second.empty()) + if (itEntry == ObjectTable.end() || itEntry->second.empty()) return; _updateStatus(); // Let's not waste time on the newly added Visibility property in // DocumentObject. - if(&prop == &obj->Visibility) + if (&prop == &obj->Visibility) return; - if(&prop == &obj->Label) { - const char *label = obj->Label.getValue(); + if (&prop == &obj->Label) { + const char* label = obj->Label.getValue(); auto firstData = *itEntry->second.begin(); - if(firstData->label != label) { - for(auto data : itEntry->second) { + if (firstData->label != label) { + for (auto data : itEntry->second) { data->label = label; auto displayName = QString::fromUtf8(label); - for(auto item : data->items) + for (auto item : data->items) item->setText(0, displayName); } } return; } - if(&prop == &obj->Label2) { - const char *label = obj->Label2.getValue(); + if (&prop == &obj->Label2) { + const char* label = obj->Label2.getValue(); auto firstData = *itEntry->second.begin(); - if(firstData->label2 != label) { - for(auto data : itEntry->second) { + if (firstData->label2 != label) { + for (auto data : itEntry->second) { data->label2 = label; auto displayName = QString::fromUtf8(label); - for(auto item : data->items) + for (auto item : data->items) item->setText(1, displayName); } } return; } - auto &s = ChangedObjects[obj]; - if(prop.testStatus(App::Property::Output) - || prop.testStatus(App::Property::NoRecompute)) + auto& s = ChangedObjects[obj]; + if (prop.testStatus(App::Property::Output) + || prop.testStatus(App::Property::NoRecompute)) { s.set(CS_Output); } } -void TreeWidget::updateChildren(App::DocumentObject *obj, - const std::set &dataSet, bool propOutput, bool force) +void TreeWidget::updateChildren(App::DocumentObject* obj, + const std::set& dataSet, bool propOutput, bool force) { bool childrenChanged = false; std::vector children; bool removeChildrenFromRoot = true; DocumentObjectDataPtr found; - for(auto data : dataSet) { - if(!found) { + for (auto data : dataSet) { + if (!found) { found = data; childrenChanged = found->updateChildren(force); removeChildrenFromRoot = found->viewObject->canRemoveChildrenFromRoot(); - if(!childrenChanged && found->removeChildrenFromRoot==removeChildrenFromRoot) + if (!childrenChanged && found->removeChildrenFromRoot == removeChildrenFromRoot) return; - }else if(childrenChanged) + } + else if (childrenChanged) data->updateChildren(found); data->removeChildrenFromRoot = removeChildrenFromRoot; DocumentItem* docItem = data->docItem; - for(auto item : data->items) - docItem->populateItem(item,true); + for (auto item : data->items) + docItem->populateItem(item, true); } - if(force) + if (force) return; - if(childrenChanged && propOutput) { + if (childrenChanged && propOutput) { // When a property is marked as output, it will not touch its object, // and thus, its property change will not be propagated through // recomputation. So we have to manually check for each links here. - for(auto link : App::GetApplication().getLinksTo(obj,App::GetLinkRecursive)) { - if(ChangedObjects.count(link)) + for (auto link : App::GetApplication().getLinksTo(obj, App::GetLinkRecursive)) { + if (ChangedObjects.count(link)) continue; std::vector linkedChildren; DocumentObjectDataPtr found; auto it = ObjectTable.find(link); - if(it == ObjectTable.end()) + if (it == ObjectTable.end()) continue; - for(auto data : it->second) { - if(!found) { + for (auto data : it->second) { + if (!found) { found = data; - if(!found->updateChildren(false)) + if (!found->updateChildren(false)) break; } data->updateChildren(found); DocumentItem* docItem = data->docItem; - for(auto item : data->items) - docItem->populateItem(item,true); + for (auto item : data->items) + docItem->populateItem(item, true); } } } - if(childrenChanged) { - if(!selectTimer->isActive()) + if (childrenChanged) { + if (!selectTimer->isActive()) onSelectionChanged(SelectionChanges()); //if the item is in a GeoFeatureGroup we may need to update that too, as the claim children //of the geofeaturegroup depends on what the childs claim auto grp = App::GeoFeatureGroupExtension::getGroupOfObject(obj); - if(grp && !ChangedObjects.count(grp)) { + if (grp && !ChangedObjects.count(grp)) { auto iter = ObjectTable.find(grp); - if(iter!=ObjectTable.end()) - updateChildren(grp,iter->second,true,false); + if (iter != ObjectTable.end()) + updateChildren(grp, iter->second, true, false); } } } -void DocumentItem::slotHighlightObject (const Gui::ViewProviderDocumentObject& obj, - const Gui::HighlightMode& high, bool set, const App::DocumentObject *parent, const char *subname) +void DocumentItem::slotHighlightObject(const Gui::ViewProviderDocumentObject& obj, + const Gui::HighlightMode& high, bool set, const App::DocumentObject* parent, const char* subname) { getTree()->_updateStatus(false); - if(parent && parent->getDocument()!=document()->getDocument()) { + if (parent && parent->getDocument() != document()->getDocument()) { auto it = getTree()->DocumentMap.find(Application::Instance->getDocument(parent->getDocument())); - if(it!=getTree()->DocumentMap.end()) - it->second->slotHighlightObject(obj,high,set,parent,subname); + if (it != getTree()->DocumentMap.end()) + it->second->slotHighlightObject(obj, high, set, parent, subname); return; } - FOREACH_ITEM(item,obj) - if(parent) { - App::DocumentObject *topParent = 0; + FOREACH_ITEM(item, obj) + if (parent) { + App::DocumentObject* topParent = 0; std::ostringstream ss; - item->getSubName(ss,topParent); - if(!topParent) { - if(parent!=obj.getObject()) + item->getSubName(ss, topParent); + if (!topParent) { + if (parent != obj.getObject()) continue; } } - item->setHighlight(set,high); - if(parent) - return; + item->setHighlight(set, high); + if (parent) + return; END_FOREACH_ITEM } -static unsigned int countExpandedItem(const QTreeWidgetItem *item) { +static unsigned int countExpandedItem(const QTreeWidgetItem* item) { unsigned int size = 0; - for(int i=0,count=item->childCount();ichildCount(); i < count; ++i) { auto citem = item->child(i); - if(citem->type()!=TreeWidget::ObjectType || !citem->isExpanded()) + if (citem->type() != TreeWidget::ObjectType || !citem->isExpanded()) continue; auto obj = static_cast(citem)->object()->getObject(); - if(obj->getNameInDocument()) + if (obj->getNameInDocument()) size += strlen(obj->getNameInDocument()) + countExpandedItem(citem); } return size; @@ -3862,179 +3915,181 @@ unsigned int DocumentItem::getMemSize(void) const { return countExpandedItem(this); } -static void saveExpandedItem(Base::Writer &writer, const QTreeWidgetItem *item) { +static void saveExpandedItem(Base::Writer& writer, const QTreeWidgetItem* item) { int itemCount = 0; - for(int i=0,count=item->childCount();ichildCount(); i < count; ++i) { auto citem = item->child(i); - if(citem->type()!=TreeWidget::ObjectType || !citem->isExpanded()) + if (citem->type() != TreeWidget::ObjectType || !citem->isExpanded()) continue; auto obj = static_cast(citem)->object()->getObject(); - if(obj->getNameInDocument()) + if (obj->getNameInDocument()) ++itemCount; } - if(!itemCount) { + if (!itemCount) { writer.Stream() << "/>" << std::endl; return; } - writer.Stream() << " count=\"" << itemCount << "\">" <" << std::endl; writer.incInd(); - for(int i=0,count=item->childCount();ichildCount(); i < count; ++i) { auto citem = item->child(i); - if(citem->type()!=TreeWidget::ObjectType || !citem->isExpanded()) + if (citem->type() != TreeWidget::ObjectType || !citem->isExpanded()) continue; auto obj = static_cast(citem)->object()->getObject(); - if(obj->getNameInDocument()) { + if (obj->getNameInDocument()) { writer.Stream() << writer.ind() << "getNameInDocument() << "\""; - saveExpandedItem(writer,static_cast(citem)); + saveExpandedItem(writer, static_cast(citem)); } } writer.decInd(); writer.Stream() << writer.ind() << "" << std::endl; } -void DocumentItem::Save (Base::Writer &writer) const { +void DocumentItem::Save(Base::Writer& writer) const { writer.Stream() << writer.ind() << "restore(reader); - for(auto inst : TreeWidget::Instances) { - if(inst!=getTree()) { + for (auto inst : TreeWidget::Instances) { + if (inst != getTree()) { auto docItem = inst->getDocumentItem(document()); - if(docItem) + if (docItem) docItem->_ExpandInfo = _ExpandInfo; } } } -void DocumentItem::restoreItemExpansion(const ExpandInfoPtr &info, DocumentObjectItem *item) { +void DocumentItem::restoreItemExpansion(const ExpandInfoPtr& info, DocumentObjectItem* item) { item->setExpanded(true); - if(!info) + if (!info) return; - for(int i=0,count=item->childCount();ichildCount(); i < count; ++i) { auto citem = item->child(i); - if(citem->type() != TreeWidget::ObjectType) + if (citem->type() != TreeWidget::ObjectType) continue; auto obj = static_cast(citem)->object()->getObject(); - if(!obj->getNameInDocument()) + if (!obj->getNameInDocument()) continue; auto it = info->find(obj->getNameInDocument()); - if(it != info->end()) - restoreItemExpansion(it->second,static_cast(citem)); + if (it != info->end()) + restoreItemExpansion(it->second, static_cast(citem)); } } -void DocumentItem::slotExpandObject (const Gui::ViewProviderDocumentObject& obj, - const Gui::TreeItemMode& mode, const App::DocumentObject *parent, const char *subname) +void DocumentItem::slotExpandObject(const Gui::ViewProviderDocumentObject& obj, + const Gui::TreeItemMode& mode, const App::DocumentObject* parent, const char* subname) { getTree()->_updateStatus(false); if ((mode == TreeItemMode::ExpandItem || - mode == TreeItemMode::ExpandPath) && + mode == TreeItemMode::ExpandPath) && obj.getDocument()->getDocument()->testStatus(App::Document::Restoring)) { if (!_ExpandInfo) _ExpandInfo.reset(new ExpandInfo); - _ExpandInfo->emplace(std::string("*") + obj.getObject()->getNameInDocument(),ExpandInfoPtr()); + _ExpandInfo->emplace(std::string("*") + obj.getObject()->getNameInDocument(), ExpandInfoPtr()); return; } - if (parent && parent->getDocument()!=document()->getDocument()) { + if (parent && parent->getDocument() != document()->getDocument()) { auto it = getTree()->DocumentMap.find(Application::Instance->getDocument(parent->getDocument())); - if (it!=getTree()->DocumentMap.end()) - it->second->slotExpandObject(obj,mode,parent,subname); + if (it != getTree()->DocumentMap.end()) + it->second->slotExpandObject(obj, mode, parent, subname); return; } - FOREACH_ITEM(item,obj) + FOREACH_ITEM(item, obj) // All document object items must always have a parent, either another // object item or document item. If not, then there is a bug somewhere // else. assert(item->parent()); - switch (mode) { - case TreeItemMode::ExpandPath: - if(!parent) { - QTreeWidgetItem* parentItem = item->parent(); - while (parentItem) { - parentItem->setExpanded(true); - parentItem = parentItem->parent(); - } - item->setExpanded(true); - break; + switch (mode) { + case TreeItemMode::ExpandPath: + if (!parent) { + QTreeWidgetItem* parentItem = item->parent(); + while (parentItem) { + parentItem->setExpanded(true); + parentItem = parentItem->parent(); } - // fall through - case TreeItemMode::ExpandItem: - if(!parent) { - if(item->parent()->isExpanded()) - item->setExpanded(true); - }else{ - App::DocumentObject *topParent = 0; - std::ostringstream ss; - item->getSubName(ss,topParent); - if(!topParent) { - if(parent!=obj.getObject()) - continue; - }else if(topParent!=parent) - continue; - showItem(item,false,true); - item->setExpanded(true); - } - break; - case TreeItemMode::CollapseItem: - item->setExpanded(false); - break; - case TreeItemMode::ToggleItem: - if (item->isExpanded()) - item->setExpanded(false); - else - item->setExpanded(true); - break; - - default: + item->setExpanded(true); break; } - if(item->isExpanded()) - populateItem(item); - if(parent) - return; + // fall through + case TreeItemMode::ExpandItem: + if (!parent) { + if (item->parent()->isExpanded()) + item->setExpanded(true); + } + else { + App::DocumentObject* topParent = 0; + std::ostringstream ss; + item->getSubName(ss, topParent); + if (!topParent) { + if (parent != obj.getObject()) + continue; + } + else if (topParent != parent) + continue; + showItem(item, false, true); + item->setExpanded(true); + } + break; + case TreeItemMode::CollapseItem: + item->setExpanded(false); + break; + case TreeItemMode::ToggleItem: + if (item->isExpanded()) + item->setExpanded(false); + else + item->setExpanded(true); + break; + + default: + break; + } + if (item->isExpanded()) + populateItem(item); + if (parent) + return; END_FOREACH_ITEM } void DocumentItem::slotScrollToObject(const Gui::ViewProviderDocumentObject& obj) { - if(!obj.getObject() || !obj.getObject()->getNameInDocument()) + if (!obj.getObject() || !obj.getObject()->getNameInDocument()) return; auto it = ObjectMap.find(obj.getObject()); - if(it == ObjectMap.end() || it->second->items.empty()) + if (it == ObjectMap.end() || it->second->items.empty()) return; auto item = it->second->rootItem; - if(!item) + if (!item) item = *it->second->items.begin(); getTree()->_updateStatus(false); getTree()->scrollToItem(item); } -void DocumentItem::slotRecomputedObject(const App::DocumentObject &obj) { - if(obj.isValid()) +void DocumentItem::slotRecomputedObject(const App::DocumentObject& obj) { + if (obj.isValid()) return; - slotRecomputed(*obj.getDocument(), {const_cast(&obj)}); + slotRecomputed(*obj.getDocument(), { const_cast(&obj) }); } -void DocumentItem::slotRecomputed(const App::Document &, const std::vector &objs) { +void DocumentItem::slotRecomputed(const App::Document&, const std::vector& objs) { auto tree = getTree(); - for(auto obj : objs) { - if(!obj->isValid()) + for (auto obj : objs) { + if (!obj->isValid()) tree->ChangedObjects[obj].set(TreeWidget::CS_Error); } - if(tree->ChangedObjects.size()) + if (tree->ChangedObjects.size()) tree->_updateStatus(); } @@ -4060,11 +4115,11 @@ Gui::Document* DocumentItem::document() const void DocumentItem::testStatus(void) { - for(const auto &v : ObjectMap) + for (const auto& v : ObjectMap) v.second->testStatus(); } -void DocumentItem::setData (int column, int role, const QVariant & value) +void DocumentItem::setData(int column, int role, const QVariant& value) { if (role == Qt::EditRole) { QString label = value.toString(); @@ -4074,93 +4129,94 @@ void DocumentItem::setData (int column, int role, const QVariant & value) QTreeWidgetItem::setData(column, role, value); } -void DocumentItem::clearSelection(DocumentObjectItem *exclude) +void DocumentItem::clearSelection(DocumentObjectItem* exclude) { // Block signals here otherwise we get a recursion and quadratic runtime bool ok = treeWidget()->blockSignals(true); FOREACH_ITEM_ALL(item); - if(item==exclude) { - if(item->selected>0) - item->selected = -1; - else - item->selected = 0; - updateItemSelection(item); - }else{ + if (item == exclude) { + if (item->selected > 0) + item->selected = -1; + else item->selected = 0; - item->mySubs.clear(); - item->setSelected(false); - item->setCheckState(false); - } + updateItemSelection(item); + } + else { + item->selected = 0; + item->mySubs.clear(); + item->setSelected(false); + item->setCheckState(false); + } END_FOREACH_ITEM; treeWidget()->blockSignals(ok); } -void DocumentItem::updateSelection(QTreeWidgetItem *ti, bool unselect) { - for(int i=0,count=ti->childCount();ichildCount(); i < count; ++i) { auto child = ti->child(i); - if(child && child->type()==TreeWidget::ObjectType) { + if (child && child->type() == TreeWidget::ObjectType) { auto childItem = static_cast(child); if (unselect) { childItem->setSelected(false); childItem->setCheckState(false); } updateItemSelection(childItem); - if(unselect && childItem->isGroup()) { + if (unselect && childItem->isGroup()) { // If the child item being force unselected by its group parent // is itself a group, propagate the unselection to its own // children - updateSelection(childItem,true); + updateSelection(childItem, true); } } } - if(unselect) return; - for(int i=0,count=ti->childCount();ichildCount(); i < count; ++i) updateSelection(ti->child(i)); } -void DocumentItem::updateItemSelection(DocumentObjectItem *item) { +void DocumentItem::updateItemSelection(DocumentObjectItem* item) { bool selected = item->isSelected(); bool checked = item->checkState(0) == Qt::Checked; - if(selected && !checked) + if (selected && !checked) item->setCheckState(true); - if(!selected && checked) + if (!selected && checked) item->setCheckState(false); - if((selected && item->selected>0) || (!selected && !item->selected)) { + if ((selected && item->selected > 0) || (!selected && !item->selected)) { return; } - if(item->selected != -1) + if (item->selected != -1) item->mySubs.clear(); item->selected = selected; auto obj = item->object()->getObject(); - if(!obj || !obj->getNameInDocument()) + if (!obj || !obj->getNameInDocument()) return; std::ostringstream str; - App::DocumentObject *topParent = 0; - item->getSubName(str,topParent); - if(topParent) { - if(topParent->hasExtension(App::GeoFeatureGroupExtension::getExtensionClassTypeId())) { + App::DocumentObject* topParent = 0; + item->getSubName(str, topParent); + if (topParent) { + if (topParent->hasExtension(App::GeoFeatureGroupExtension::getExtensionClassTypeId())) { // remove legacy selection, i.e. those without subname Gui::Selection().rmvSelection(obj->getDocument()->getName(), - obj->getNameInDocument(),0); + obj->getNameInDocument(), 0); } - if(!obj->redirectSubName(str,topParent,0)) + if (!obj->redirectSubName(str, topParent, 0)) str << obj->getNameInDocument() << '.'; obj = topParent; } - const char *objname = obj->getNameInDocument(); - const char *docname = obj->getDocument()->getName(); - const auto &subname = str.str(); + const char* objname = obj->getNameInDocument(); + const char* docname = obj->getDocument()->getName(); + const auto& subname = str.str(); - if(subname.size()) { + if (subname.size()) { auto parentItem = item->getParentItem(); assert(parentItem); - if(selected && parentItem->selected) { + if (selected && parentItem->selected) { // When a group item is selected, all its children objects are // highlighted in the 3D view. So, when an item of some group is // newly selected, we must force unselect its parent in order to @@ -4177,7 +4233,7 @@ void DocumentItem::updateItemSelection(DocumentObjectItem *item) { } } - if(selected && item->isGroup()) { + if (selected && item->isGroup()) { // Same reasoning as above. When a group item is newly selected, We // choose to force unselect all its children to void messing up the // selection highlight @@ -4188,20 +4244,20 @@ void DocumentItem::updateItemSelection(DocumentObjectItem *item) { // updateSelection(item,true); } - if(!selected) { - Gui::Selection().rmvSelection(docname,objname,subname.c_str()); + if (!selected) { + Gui::Selection().rmvSelection(docname, objname, subname.c_str()); return; } selected = false; - if(item->mySubs.size()) { - for(auto &sub : item->mySubs) { - if(Gui::Selection().addSelection(docname,objname,(subname+sub).c_str())) + if (item->mySubs.size()) { + for (auto& sub : item->mySubs) { + if (Gui::Selection().addSelection(docname, objname, (subname + sub).c_str())) selected = true; } } - if(!selected) { + if (!selected) { item->mySubs.clear(); - if(!Gui::Selection().addSelection(docname,objname,subname.c_str())) { + if (!Gui::Selection().addSelection(docname, objname, subname.c_str())) { item->selected = 0; item->setSelected(false); item->setCheckState(false); @@ -4211,97 +4267,97 @@ void DocumentItem::updateItemSelection(DocumentObjectItem *item) { getTree()->syncView(item->object()); } -App::DocumentObject *DocumentItem::getTopParent(App::DocumentObject *obj, std::string &subname) { +App::DocumentObject* DocumentItem::getTopParent(App::DocumentObject* obj, std::string& subname) { auto it = ObjectMap.find(obj); - if(it == ObjectMap.end() || it->second->items.empty()) + if (it == ObjectMap.end() || it->second->items.empty()) return 0; // already a top parent - if(it->second->rootItem) + if (it->second->rootItem) return obj; - for(auto item : it->second->items) { + for (auto item : it->second->items) { // non group object do not provide a coordinate system, hence its // claimed child is still in the global coordinate space, so the // child can still be considered a top level object - if(!item->isParentGroup()) + if (!item->isParentGroup()) return obj; } // If no top level item, find an item that is closest to the top level - std::multimap items; - for(auto item : it->second->items) { - int i=0; - for(auto parent=item->parent();parent;++i,parent=parent->parent()) { - if(parent->isHidden()) + std::multimap items; + for (auto item : it->second->items) { + int i = 0; + for (auto parent = item->parent(); parent; ++i, parent = parent->parent()) { + if (parent->isHidden()) i += 1000; ++i; } - items.emplace(i,item); + items.emplace(i, item); } - App::DocumentObject *topParent = 0; + App::DocumentObject* topParent = 0; std::ostringstream ss; - items.begin()->second->getSubName(ss,topParent); - if(!topParent) { + items.begin()->second->getSubName(ss, topParent); + if (!topParent) { // this shouldn't happen FC_WARN("No top parent for " << obj->getFullName() << '.' << subname); return obj; } ss << obj->getNameInDocument() << '.' << subname; FC_LOG("Subname correction " << obj->getFullName() << '.' << subname - << " -> " << topParent->getFullName() << '.' << ss.str()); + << " -> " << topParent->getFullName() << '.' << ss.str()); subname = ss.str(); return topParent; } -DocumentObjectItem *DocumentItem::findItemByObject( - bool sync, App::DocumentObject *obj, const char *subname, bool select) +DocumentObjectItem* DocumentItem::findItemByObject( + bool sync, App::DocumentObject* obj, const char* subname, bool select) { - if(!subname) + if (!subname) subname = ""; auto it = ObjectMap.find(obj); - if(it == ObjectMap.end() || it->second->items.empty()) + if (it == ObjectMap.end() || it->second->items.empty()) return 0; // prefer top level item of this object - if(it->second->rootItem) - return findItem(sync,it->second->rootItem,subname,select); + if (it->second->rootItem) + return findItem(sync, it->second->rootItem, subname, select); - for(auto item : it->second->items) { + for (auto item : it->second->items) { // non group object do not provide a coordinate system, hence its // claimed child is still in the global coordinate space, so the // child can still be considered a top level object - if(!item->isParentGroup()) - return findItem(sync,item,subname,select); + if (!item->isParentGroup()) + return findItem(sync, item, subname, select); } // If no top level item, find an item that is closest to the top level - std::multimap items; - for(auto item : it->second->items) { - int i=0; - for(auto parent=item->parent();parent;++i,parent=parent->parent()) + std::multimap items; + for (auto item : it->second->items) { + int i = 0; + for (auto parent = item->parent(); parent; ++i, parent = parent->parent()) ++i; - items.emplace(i,item); + items.emplace(i, item); } - for(auto &v : items) { - auto item = findItem(sync,v.second,subname,select); - if(item) + for (auto& v : items) { + auto item = findItem(sync, v.second, subname, select); + if (item) return item; } return 0; } -DocumentObjectItem *DocumentItem::findItem( - bool sync, DocumentObjectItem *item, const char *subname, bool select) +DocumentObjectItem* DocumentItem::findItem( + bool sync, DocumentObjectItem* item, const char* subname, bool select) { - if(item->isHidden()) + if (item->isHidden()) item->setHidden(false); - if(!subname || *subname==0) { - if(select) { - item->selected+=2; + if (!subname || *subname == 0) { + if (select) { + item->selected += 2; item->mySubs.clear(); } return item; @@ -4310,113 +4366,114 @@ DocumentObjectItem *DocumentItem::findItem( TREE_TRACE("find next " << subname); // try to find the next level object name - const char *nextsub = 0; - const char *dot = 0; - if((dot=strchr(subname,'.'))) - nextsub = dot+1; + const char* nextsub = 0; + const char* dot = 0; + if ((dot = strchr(subname, '.'))) + nextsub = dot + 1; else { - if(select) { - item->selected+=2; - if(std::find(item->mySubs.begin(),item->mySubs.end(),subname)==item->mySubs.end()) + if (select) { + item->selected += 2; + if (std::find(item->mySubs.begin(), item->mySubs.end(), subname) == item->mySubs.end()) item->mySubs.push_back(subname); } return item; } - std::string name(subname,nextsub-subname); + std::string name(subname, nextsub - subname); auto obj = item->object()->getObject(); auto subObj = obj->getSubObject(name.c_str()); - if(!subObj || subObj==obj) { - if(!subObj && !getTree()->searchDoc) + if (!subObj || subObj == obj) { + if (!subObj && !getTree()->searchDoc) TREE_LOG("sub object not found " << item->getName() << '.' << name.c_str()); - if(select) { + if (select) { item->selected += 2; - if(std::find(item->mySubs.begin(),item->mySubs.end(),subname)==item->mySubs.end()) + if (std::find(item->mySubs.begin(), item->mySubs.end(), subname) == item->mySubs.end()) item->mySubs.push_back(subname); } return item; } - if(select) + if (select) item->mySubs.clear(); - if(!item->populated && sync) { + if (!item->populated && sync) { //force populate the item item->populated = true; - populateItem(item,true); + populateItem(item, true); } - for(int i=0,count=item->childCount();ichildCount(); i < count; ++i) { auto ti = item->child(i); - if(!ti || ti->type()!=TreeWidget::ObjectType) continue; + if (!ti || ti->type() != TreeWidget::ObjectType) continue; auto child = static_cast(ti); - if(child->object()->getObject() == subObj) - return findItem(sync,child,nextsub,select); + if (child->object()->getObject() == subObj) + return findItem(sync, child, nextsub, select); } // The sub object is not found. This could happen for geo group, since its // children may be in more than one hierarchy down. bool found = false; - DocumentObjectItem *res=0; + DocumentObjectItem* res = 0; auto it = ObjectMap.find(subObj); - if(it != ObjectMap.end()) { - for(auto child : it->second->items) { - if(child->isChildOfItem(item)) { + if (it != ObjectMap.end()) { + for (auto child : it->second->items) { + if (child->isChildOfItem(item)) { found = true; - res = findItem(sync,child,nextsub,select); - if(!select) + res = findItem(sync, child, nextsub, select); + if (!select) return res; } } } - if(select && !found) { + if (select && !found) { // The sub object is still not found. Maybe it is a non-object sub-element. // Select the current object instead. TREE_TRACE("element " << subname << " not found"); - item->selected+=2; - if(std::find(item->mySubs.begin(),item->mySubs.end(),subname)==item->mySubs.end()) + item->selected += 2; + if (std::find(item->mySubs.begin(), item->mySubs.end(), subname) == item->mySubs.end()) item->mySubs.push_back(subname); } return res; } void DocumentItem::selectItems(SelectionReason reason) { - const auto &sels = Selection().getSelection(pDocument->getDocument()->getName(),false); + const auto& sels = Selection().getSelection(pDocument->getDocument()->getName(), false); - bool sync = (sels.size()>50 || reason==SR_SELECT)?false:true; + bool sync = (sels.size() > 50 || reason == SR_SELECT) ? false : true; - for(const auto &sel : sels) - findItemByObject(sync,sel.pObject,sel.SubName,true); + for (const auto& sel : sels) + findItemByObject(sync, sel.pObject, sel.SubName, true); - DocumentObjectItem *newSelect = 0; - DocumentObjectItem *oldSelect = 0; + DocumentObjectItem* newSelect = 0; + DocumentObjectItem* oldSelect = 0; FOREACH_ITEM_ALL(item) - if(item->selected == 1) { + if (item->selected == 1) { // this means it is the old selection and is not in the current // selection item->selected = 0; item->mySubs.clear(); item->setSelected(false); item->setCheckState(false); - }else if(item->selected) { - if(sync) { - if(item->selected==2 && showItem(item,false,reason==SR_FORCE_EXPAND)) { + } + else if (item->selected) { + if (sync) { + if (item->selected == 2 && showItem(item, false, reason == SR_FORCE_EXPAND)) { // This means newly selected and can auto expand - if(!newSelect) + if (!newSelect) newSelect = item; } - if(!newSelect && !oldSelect && !item->isHidden()) { + if (!newSelect && !oldSelect && !item->isHidden()) { bool visible = true; - for(auto parent=item->parent();parent;parent=parent->parent()) { - if(!parent->isExpanded() || parent->isHidden()) { + for (auto parent = item->parent(); parent; parent = parent->parent()) { + if (!parent->isExpanded() || parent->isHidden()) { visible = false; break; } } - if(visible) + if (visible) oldSelect = item; } } @@ -4426,38 +4483,38 @@ void DocumentItem::selectItems(SelectionReason reason) { } END_FOREACH_ITEM; - if(sync) { - if(!newSelect) + if (sync) { + if (!newSelect) newSelect = oldSelect; else getTree()->syncView(newSelect->object()); - if(newSelect) + if (newSelect) getTree()->scrollToItem(newSelect); } } -void DocumentItem::populateParents(const ViewProvider *vp, ViewParentMap &parentMap) { +void DocumentItem::populateParents(const ViewProvider* vp, ViewParentMap& parentMap) { auto it = parentMap.find(vp); - if(it == parentMap.end()) return; - for(auto parent : it->second) { + if (it == parentMap.end()) return; + for (auto parent : it->second) { auto it = ObjectMap.find(parent->getObject()); - if(it==ObjectMap.end()) + if (it == ObjectMap.end()) continue; - populateParents(parent,parentMap); - for(auto item : it->second->items) { - if(!item->isHidden() && !item->populated) { + populateParents(parent, parentMap); + for (auto item : it->second->items) { + if (!item->isHidden() && !item->populated) { item->populated = true; - populateItem(item,true); + populateItem(item, true); } } } } -void DocumentItem::selectAllInstances(const ViewProviderDocumentObject &vpd) { +void DocumentItem::selectAllInstances(const ViewProviderDocumentObject& vpd) { ViewParentMap parentMap; auto pObject = vpd.getObject(); - if(ObjectMap.find(pObject) == ObjectMap.end()) + if (ObjectMap.find(pObject) == ObjectMap.end()) return; bool lock = getTree()->blockConnection(true); @@ -4466,27 +4523,27 @@ void DocumentItem::selectAllInstances(const ViewProviderDocumentObject &vpd) { // provider, i.e. all appearance of the object inside all its parent items // // Build a map of object to all its parent - for(auto &v : ObjectMap) { - if(v.second->viewObject == &vpd) continue; - for(auto child : v.second->viewObject->claimChildren()) { + for (auto& v : ObjectMap) { + if (v.second->viewObject == &vpd) continue; + for (auto child : v.second->viewObject->claimChildren()) { auto vp = getViewProvider(child); - if(!vp) continue; + if (!vp) continue; parentMap[vp].push_back(v.second->viewObject); } } // now make sure all parent items are populated. In order to do that, we // need to populate the oldest parent first - populateParents(&vpd,parentMap); + populateParents(&vpd, parentMap); - DocumentObjectItem *first = 0; - FOREACH_ITEM(item,vpd); - if(showItem(item,true) && !first) - first = item; + DocumentObjectItem* first = 0; + FOREACH_ITEM(item, vpd); + if (showItem(item, true) && !first) + first = item; END_FOREACH_ITEM; getTree()->blockConnection(lock); - if(first) { + if (first) { treeWidget()->scrollToItem(first); updateSelection(); } @@ -4500,44 +4557,45 @@ void DocumentItem::setShowHidden(bool show) { pDocument->getDocument()->ShowHidden.setValue(show); } -bool DocumentItem::showItem(DocumentObjectItem *item, bool select, bool force) { +bool DocumentItem::showItem(DocumentObjectItem* item, bool select, bool force) { auto parent = item->parent(); - if(item->isHidden()) { - if(!force) + if (item->isHidden()) { + if (!force) return false; item->setHidden(false); } - if(parent->type()==TreeWidget::ObjectType) { - if(!showItem(static_cast(parent),false)) + if (parent->type() == TreeWidget::ObjectType) { + if (!showItem(static_cast(parent), false)) return false; auto pitem = static_cast(parent); - if(force || !pitem->object()->getObject()->testStatus(App::NoAutoExpand)) + if (force || !pitem->object()->getObject()->testStatus(App::NoAutoExpand)) parent->setExpanded(true); - else if(!select) + else if (!select) return false; - }else + } + else parent->setExpanded(true); - if(select) { + if (select) { item->setSelected(true); item->setCheckState(true); } return true; } -void DocumentItem::updateItemsVisibility(QTreeWidgetItem *item, bool show) { - if(item->type() == TreeWidget::ObjectType) { +void DocumentItem::updateItemsVisibility(QTreeWidgetItem* item, bool show) { + if (item->type() == TreeWidget::ObjectType) { auto objitem = static_cast(item); objitem->setHidden(!show && !objitem->object()->showInTree()); } - for(int i=0;ichildCount();++i) - updateItemsVisibility(item->child(i),show); + for (int i = 0; i < item->childCount(); ++i) + updateItemsVisibility(item->child(i), show); } void DocumentItem::updateSelection() { bool lock = getTree()->blockConnection(true); - updateSelection(this,false); + updateSelection(this, false); getTree()->blockConnection(lock); } @@ -4545,9 +4603,9 @@ void DocumentItem::updateSelection() { static int countItems; -DocumentObjectItem::DocumentObjectItem(DocumentItem *ownerDocItem, DocumentObjectDataPtr data) +DocumentObjectItem::DocumentObjectItem(DocumentItem* ownerDocItem, DocumentObjectDataPtr data) : QTreeWidgetItem(TreeWidget::ObjectType) - , myOwner(ownerDocItem), myData(data), previousStatus(-1),selected(0),populated(false) + , myOwner(ownerDocItem), myData(data), previousStatus(-1), selected(0), populated(false) { setFlags(flags() | Qt::ItemIsEditable | Qt::ItemIsUserCheckable); setCheckState(false); @@ -4562,17 +4620,17 @@ DocumentObjectItem::~DocumentObjectItem() --countItems; TREE_LOG("Delete item: " << countItems << ", " << object()->getObject()->getFullName()); auto it = myData->items.find(this); - if(it == myData->items.end()) + if (it == myData->items.end()) assert(0); else myData->items.erase(it); - if(myData->rootItem == this) + if (myData->rootItem == this) myData->rootItem = 0; - if(myOwner && myData->items.empty()) { + if (myOwner && myData->items.empty()) { auto it = myOwner->_ParentMap.find(object()->getObject()); - if(it!=myOwner->_ParentMap.end() && it->second.size()) { + if (it != myOwner->_ParentMap.end() && it->second.size()) { myOwner->PopulateObjects.push_back(*it->second.begin()); myOwner->getTree()->_updateStatus(); } @@ -4580,12 +4638,12 @@ DocumentObjectItem::~DocumentObjectItem() } void DocumentObjectItem::restoreBackground() { - this->setBackground(0,this->bgBrush); + this->setBackground(0, this->bgBrush); } void DocumentObjectItem::setHighlight(bool set, Gui::HighlightMode high) { QFont f = this->font(0); - auto highlight = [=](const QColor& col){ + auto highlight = [=](const QColor& col) { if (set) this->setBackground(0, col); else @@ -4607,27 +4665,27 @@ void DocumentObjectItem::setHighlight(bool set, Gui::HighlightMode high) { f.setOverline(set); break; case HighlightMode::Blue: - highlight(QColor(200,200,255)); + highlight(QColor(200, 200, 255)); break; case HighlightMode::LightBlue: - highlight(QColor(230,230,255)); + highlight(QColor(230, 230, 255)); break; case HighlightMode::UserDefined: { - QColor color(230,230,255); + QColor color(230, 230, 255); if (set) { ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/TreeView"); - bool bold = hGrp->GetBool("TreeActiveBold",true); - bool italic = hGrp->GetBool("TreeActiveItalic",false); - bool underlined = hGrp->GetBool("TreeActiveUnderlined",false); - bool overlined = hGrp->GetBool("TreeActiveOverlined",false); + bool bold = hGrp->GetBool("TreeActiveBold", true); + bool italic = hGrp->GetBool("TreeActiveItalic", false); + bool underlined = hGrp->GetBool("TreeActiveUnderlined", false); + bool overlined = hGrp->GetBool("TreeActiveOverlined", false); f.setBold(bold); f.setItalic(italic); f.setUnderline(underlined); f.setOverline(overlined); - unsigned long col = hGrp->GetUnsigned("TreeActiveColor",3873898495); - color = QColor((col >> 24) & 0xff,(col >> 16) & 0xff,(col >> 8) & 0xff); + unsigned long col = hGrp->GetUnsigned("TreeActiveColor", 3873898495); + color = QColor((col >> 24) & 0xff, (col >> 16) & 0xff, (col >> 8) & 0xff); } else { f.setBold(false); @@ -4640,10 +4698,10 @@ void DocumentObjectItem::setHighlight(bool set, Gui::HighlightMode high) { default: break; } - this->setFont(0,f); + this->setFont(0, f); } -const char *DocumentObjectItem::getTreeName() const +const char* DocumentObjectItem::getTreeName() const { return myData->getTreeName(); } @@ -4655,30 +4713,30 @@ Gui::ViewProviderDocumentObject* DocumentObjectItem::object() const void DocumentObjectItem::testStatus(bool resetStatus) { - QIcon icon,icon2; - testStatus(resetStatus,icon,icon2); + QIcon icon, icon2; + testStatus(resetStatus, icon, icon2); } -void DocumentObjectItem::testStatus(bool resetStatus, QIcon &icon1, QIcon &icon2) +void DocumentObjectItem::testStatus(bool resetStatus, QIcon& icon1, QIcon& icon2) { App::DocumentObject* pObject = object()->getObject(); int visible = -1; auto parentItem = getParentItem(); - if(parentItem) { + if (parentItem) { Timing(testStatus1); auto parent = parentItem->object()->getObject(); - auto ext = parent->getExtensionByType(true,false); - if(!ext) + auto ext = parent->getExtensionByType(true, false); + if (!ext) visible = parent->isElementVisible(pObject->getNameInDocument()); else { // We are dealing with a plain group. It has special handling when // linked, which allows it to have indpenedent visibility control. // We need to go up the hierarchy and see if there is any link to // it. - for(auto pp=parentItem->getParentItem();pp;pp=pp->getParentItem()) { + for (auto pp = parentItem->getParentItem(); pp; pp = pp->getParentItem()) { auto obj = pp->object()->getObject(); - if(!obj->hasExtension(App::GroupExtension::getExtensionClassTypeId(),false)) { + if (!obj->hasExtension(App::GroupExtension::getExtensionClassTypeId(), false)) { visible = pp->object()->getObject()->isElementVisible(pObject->getNameInDocument()); break; } @@ -4688,27 +4746,27 @@ void DocumentObjectItem::testStatus(bool resetStatus, QIcon &icon1, QIcon &icon2 Timing(testStatus2); - if(visible<0) - visible = object()->isShow()?1:0; + if (visible < 0) + visible = object()->isShow() ? 1 : 0; auto obj = object()->getObject(); auto linked = obj->getLinkedObject(false); - bool external = object()->getDocument()!=getOwnerDocument()->document() || - (linked && linked->getDocument()!=obj->getDocument()); + bool external = object()->getDocument() != getOwnerDocument()->document() || + (linked && linked->getDocument() != obj->getDocument()); int currentStatus = - ((external?0:1)<<4) | + ((external ? 0 : 1) << 4) | ((object()->showInTree() ? 0 : 1) << 3) | - ((pObject->isError() ? 1 : 0) << 2) | - ((pObject->isTouched()||pObject->mustExecute()== 1 ? 1 : 0) << 1) | - (visible ? 1 : 0); + ((pObject->isError() ? 1 : 0) << 2) | + ((pObject->isTouched() || pObject->mustExecute() == 1 ? 1 : 0) << 1) | + (visible ? 1 : 0); TimingStop(testStatus2); - if (!resetStatus && previousStatus==currentStatus) + if (!resetStatus && previousStatus == currentStatus) return; - _Timing(1,testStatus3); + _Timing(1, testStatus3); previousStatus = currentStatus; @@ -4722,29 +4780,29 @@ void DocumentObjectItem::testStatus(bool resetStatus, QIcon &icon1, QIcon &icon2 // to black which will lead to unreadable text if the system background // hss already a dark color. // However, it works if we set the appropriate role to an empty QVariant(). - this->setData(0, Qt::ForegroundRole,QVariant()); + this->setData(0, Qt::ForegroundRole, QVariant()); } else { // invisible QStyleOptionViewItem opt; // it can happen that a tree item is not attached to the tree widget (#0003025) if (this->treeWidget()) opt.initFrom(this->treeWidget()); - this->setForeground(0, opt.palette.color(QPalette::Disabled,QPalette::Text)); + this->setForeground(0, opt.palette.color(QPalette::Disabled, QPalette::Text)); mode = QIcon::Disabled; } - _TimingStop(1,testStatus3); + _TimingStop(1, testStatus3); - QIcon &icon = mode==QIcon::Normal?icon1:icon2; + QIcon& icon = mode == QIcon::Normal ? icon1 : icon2; - if(icon.isNull()) { + if (icon.isNull()) { Timing(getIcon); QPixmap px; if (currentStatus & 4) { static QPixmap pxError; - if(pxError.isNull()) { - // object is in error state - const char * const feature_error_xpm[]={ + if (pxError.isNull()) { + // object is in error state + const char* const feature_error_xpm[] = { "9 9 3 1", ". c None", "# c #ff0000", @@ -4757,16 +4815,16 @@ void DocumentObjectItem::testStatus(bool resetStatus, QIcon &icon1, QIcon &icon2 "#########", ".##aaa##.", ".##aaa##.", - "...###..."}; + "...###..." }; pxError = QPixmap(feature_error_xpm); } px = pxError; } else if (currentStatus & 2) { static QPixmap pxRecompute; - if(pxRecompute.isNull()) { + if (pxRecompute.isNull()) { // object must be recomputed - const char * const feature_recompute_xpm[]={ + const char* const feature_recompute_xpm[] = { "9 9 3 1", ". c None", "# c #0000ff", @@ -4779,7 +4837,7 @@ void DocumentObjectItem::testStatus(bool resetStatus, QIcon &icon1, QIcon &icon2 "#aaaa####", ".#aa####.", ".#######.", - "...###..."}; + "...###..." }; pxRecompute = QPixmap(feature_recompute_xpm); } px = pxRecompute; @@ -4790,23 +4848,24 @@ void DocumentObjectItem::testStatus(bool resetStatus, QIcon &icon1, QIcon &icon2 int w = getTree()->viewOptions().decorationSize.width(); - QPixmap pxOn,pxOff; + QPixmap pxOn, pxOff; // if needed show small pixmap inside if (!px.isNull()) { pxOff = BitmapFactory().merge(icon_org.pixmap(w, w, mode, QIcon::Off), - px,BitmapFactoryInst::TopRight); - pxOn = BitmapFactory().merge(icon_org.pixmap(w, w, mode, QIcon::On ), - px,BitmapFactoryInst::TopRight); - } else { + px, BitmapFactoryInst::TopRight); + pxOn = BitmapFactory().merge(icon_org.pixmap(w, w, mode, QIcon::On), + px, BitmapFactoryInst::TopRight); + } + else { pxOff = icon_org.pixmap(w, w, mode, QIcon::Off); pxOn = icon_org.pixmap(w, w, mode, QIcon::On); } - if(currentStatus & 8) {// hidden item + if (currentStatus & 8) {// hidden item static QPixmap pxHidden; - if(pxHidden.isNull()) { - const char * const feature_hidden_xpm[]={ + if (pxHidden.isNull()) { + const char* const feature_hidden_xpm[] = { "9 7 3 1", ". c None", "# c #000000", @@ -4817,17 +4876,17 @@ void DocumentObjectItem::testStatus(bool resetStatus, QIcon &icon1, QIcon &icon2 "#aa###aa#", ".#a###a#.", "..#aaa#..", - "...###..."}; + "...###..." }; pxHidden = QPixmap(feature_hidden_xpm); } pxOff = BitmapFactory().merge(pxOff, pxHidden, BitmapFactoryInst::TopLeft); pxOn = BitmapFactory().merge(pxOn, pxHidden, BitmapFactoryInst::TopLeft); } - if(external) {// external item + if (external) {// external item static QPixmap pxExternal; - if(pxExternal.isNull()) { - const char * const feature_external_xpm[]={ + if (pxExternal.isNull()) { + const char* const feature_external_xpm[] = { "7 7 3 1", ". c None", "# c #000000", @@ -4838,7 +4897,7 @@ void DocumentObjectItem::testStatus(bool resetStatus, QIcon &icon1, QIcon &icon2 "..##aa#", "..#aa##", ".#aa##.", - "..###.."}; + "..###.." }; pxExternal = QPixmap(feature_external_xpm); } pxOff = BitmapFactory().merge(pxOff, pxExternal, BitmapFactoryInst::BottomRight); @@ -4852,7 +4911,7 @@ void DocumentObjectItem::testStatus(bool resetStatus, QIcon &icon1, QIcon &icon2 } - _Timing(2,setIcon); + _Timing(2, setIcon); this->setIcon(0, icon); } @@ -4866,12 +4925,12 @@ void DocumentObjectItem::displayStatusInfo() info += TreeWidget::tr(" (but must be executed)"); QString status = TreeWidget::tr("%1, Internal name: %2") - .arg(info, QString::fromLatin1(Obj->getNameInDocument())); + .arg(info, QString::fromLatin1(Obj->getNameInDocument())); if (!Obj->isError()) getMainWindow()->showMessage(status); else { - getMainWindow()->showStatus(MainWindow::Err,status); + getMainWindow()->showStatus(MainWindow::Err, status); QTreeWidget* tree = this->treeWidget(); QPoint pos = tree->visualItemRect(this).topRight(); QToolTip::showText(tree->mapToGlobal(pos), info); @@ -4880,20 +4939,20 @@ void DocumentObjectItem::displayStatusInfo() void DocumentObjectItem::setExpandedStatus(bool on) { - if(getOwnerDocument()->document() == object()->getDocument()) + if (getOwnerDocument()->document() == object()->getDocument()) object()->getObject()->setStatus(App::Expand, on); } -void DocumentObjectItem::setData (int column, int role, const QVariant & value) +void DocumentObjectItem::setData(int column, int role, const QVariant& value) { QVariant myValue(value); - if (role == Qt::EditRole && column<=1) { + if (role == Qt::EditRole && column <= 1) { auto obj = object()->getObject(); - auto &label = column?obj->Label2:obj->Label; + auto& label = column ? obj->Label2 : obj->Label; std::ostringstream ss; ss << "Change " << getName() << '.' << label.getName(); App::AutoTransaction committer(ss.str().c_str()); - label.setValue((const char *)value.toString().toUtf8()); + label.setValue((const char*)value.toString().toUtf8()); myValue = QString::fromUtf8(label.getValue()); } QTreeWidgetItem::setData(column, role, myValue); @@ -4901,26 +4960,26 @@ void DocumentObjectItem::setData (int column, int role, const QVariant & value) bool DocumentObjectItem::isChildOfItem(DocumentObjectItem* item) { - for(auto pitem=parent();pitem;pitem=pitem->parent()) - if(pitem == item) + for (auto pitem = parent(); pitem; pitem = pitem->parent()) + if (pitem == item) return true; return false; } -bool DocumentObjectItem::requiredAtRoot(bool excludeSelf) const{ - if(myData->rootItem || object()->getDocument()!=getOwnerDocument()->document()) +bool DocumentObjectItem::requiredAtRoot(bool excludeSelf) const { + if (myData->rootItem || object()->getDocument() != getOwnerDocument()->document()) return false; bool checkMap = true; - for(auto item : myData->items) { - if(excludeSelf && item == this) continue; + for (auto item : myData->items) { + if (excludeSelf && item == this) continue; auto pi = item->getParentItem(); - if(!pi || pi->myData->removeChildrenFromRoot) + if (!pi || pi->myData->removeChildrenFromRoot) return false; checkMap = false; } - if(checkMap && myOwner) { + if (checkMap && myOwner) { auto it = myOwner->_ParentMap.find(object()->getObject()); - if(it!=myOwner->_ParentMap.end()) { + if (it != myOwner->_ParentMap.end()) { // Reaching here means all items of this corresponding object is // going to be deleted, but the object itself is not deleted and // still being referred to by some parent item that is not expanded @@ -4933,8 +4992,8 @@ bool DocumentObjectItem::requiredAtRoot(bool excludeSelf) const{ // expand its parent item. It only causes minor problems, such as, // tree scroll to object command won't work properly. - for(auto parent : it->second) { - if(getOwnerDocument()->populateObject(parent)) + for (auto parent : it->second) { + if (getOwnerDocument()->populateObject(parent)) return false; } } @@ -4945,7 +5004,7 @@ bool DocumentObjectItem::requiredAtRoot(bool excludeSelf) const{ bool DocumentObjectItem::isLink() const { auto obj = object()->getObject(); auto linked = obj->getLinkedObject(false); - return linked && obj!=linked; + return linked && obj != linked; } bool DocumentObjectItem::isLinkFinal() const { @@ -4970,33 +5029,33 @@ enum GroupType { int DocumentObjectItem::isGroup() const { auto obj = object()->getObject(); auto linked = obj->getLinkedObject(true); - if(linked && linked->hasExtension( - App::GeoFeatureGroupExtension::getExtensionClassTypeId())) + if (linked && linked->hasExtension( + App::GeoFeatureGroupExtension::getExtensionClassTypeId())) return PartGroup; - if(obj->hasChildElement()) + if (obj->hasChildElement()) return LinkGroup; - if(obj->hasExtension(App::GroupExtension::getExtensionClassTypeId(),false)) { - for(auto parent=getParentItem();parent;parent=parent->getParentItem()) { + if (obj->hasExtension(App::GroupExtension::getExtensionClassTypeId(), false)) { + for (auto parent = getParentItem(); parent; parent = parent->getParentItem()) { auto pobj = parent->object()->getObject(); - if(pobj->hasExtension(App::GroupExtension::getExtensionClassTypeId(),false)) + if (pobj->hasExtension(App::GroupExtension::getExtensionClassTypeId(), false)) continue; - if(pobj->isElementVisible(obj->getNameInDocument())>=0) + if (pobj->isElementVisible(obj->getNameInDocument()) >= 0) return LinkGroup; } } return NotGroup; } -bool DocumentItem::isObjectShowable(App::DocumentObject *obj) { +bool DocumentItem::isObjectShowable(App::DocumentObject* obj) { auto itParents = _ParentMap.find(obj); - if(itParents == _ParentMap.end() || itParents->second.empty()) + if (itParents == _ParentMap.end() || itParents->second.empty()) return true; bool showable = true; - for(auto parent : itParents->second) { - if(parent->getDocument() != obj->getDocument()) + for (auto parent : itParents->second) { + if (parent->getDocument() != obj->getDocument()) continue; - if(!parent->hasChildElement() - && parent->getLinkedObject(false)==parent) + if (!parent->hasChildElement() + && parent->getLinkedObject(false) == parent) return true; showable = false; } @@ -5005,30 +5064,30 @@ bool DocumentItem::isObjectShowable(App::DocumentObject *obj) { int DocumentObjectItem::isParentGroup() const { auto pi = getParentItem(); - return pi?pi->isGroup():0; + return pi ? pi->isGroup() : 0; } -DocumentObjectItem *DocumentObjectItem::getParentItem() const{ - if(parent()->type()!=TreeWidget::ObjectType) +DocumentObjectItem* DocumentObjectItem::getParentItem() const { + if (parent()->type() != TreeWidget::ObjectType) return 0; return static_cast(parent()); } -const char *DocumentObjectItem::getName() const { - const char *name = object()->getObject()->getNameInDocument(); - return name?name:""; +const char* DocumentObjectItem::getName() const { + const char* name = object()->getObject()->getNameInDocument(); + return name ? name : ""; } -int DocumentObjectItem::getSubName(std::ostringstream &str, App::DocumentObject *&topParent) const +int DocumentObjectItem::getSubName(std::ostringstream& str, App::DocumentObject*& topParent) const { auto parent = getParentItem(); - if(!parent) + if (!parent) return NotGroup; - int ret = parent->getSubName(str,topParent); - if(ret != SuperGroup) { + int ret = parent->getSubName(str, topParent); + if (ret != SuperGroup) { int group = parent->isGroup(); - if(group == NotGroup) { - if(ret!=PartGroup) { + if (group == NotGroup) { + if (ret != PartGroup) { // Handle this situation, // // LinkGroup @@ -5048,74 +5107,74 @@ int DocumentObjectItem::getSubName(std::ostringstream &str, App::DocumentObject } auto obj = parent->object()->getObject(); - if(!obj || !obj->getNameInDocument()) { + if (!obj || !obj->getNameInDocument()) { topParent = 0; str.str(""); return NotGroup; } - if(!topParent) + if (!topParent) topParent = obj; - else if(!obj->redirectSubName(str,topParent,object()->getObject())) + else if (!obj->redirectSubName(str, topParent, object()->getObject())) str << obj->getNameInDocument() << '.'; return ret; } -App::DocumentObject *DocumentObjectItem::getFullSubName( - std::ostringstream &str, DocumentObjectItem *parent) const +App::DocumentObject* DocumentObjectItem::getFullSubName( + std::ostringstream& str, DocumentObjectItem* parent) const { auto pi = getParentItem(); - if(this==parent || !pi || (!parent && !pi->isGroup())) + if (this == parent || !pi || (!parent && !pi->isGroup())) return object()->getObject(); - auto ret = pi->getFullSubName(str,parent); + auto ret = pi->getFullSubName(str, parent); str << getName() << '.'; return ret; } -App::DocumentObject *DocumentObjectItem::getRelativeParent( - std::ostringstream &str, DocumentObjectItem *cousin, - App::DocumentObject **topParent, std::string *topSubname) const +App::DocumentObject* DocumentObjectItem::getRelativeParent( + std::ostringstream& str, DocumentObjectItem* cousin, + App::DocumentObject** topParent, std::string* topSubname) const { std::ostringstream str2; - App::DocumentObject *top=0,*top2=0; - getSubName(str,top); - if(topParent) + App::DocumentObject* top = 0, * top2 = 0; + getSubName(str, top); + if (topParent) *topParent = top; - if(!top) + if (!top) return 0; - if(topSubname) + if (topSubname) *topSubname = str.str() + getName() + '.'; - cousin->getSubName(str2,top2); - if(top!=top2) { + cousin->getSubName(str2, top2); + if (top != top2) { str << getName() << '.'; return top; } auto subname = str.str(); auto subname2 = str2.str(); - const char *sub = subname.c_str(); - const char *sub2 = subname2.c_str(); - while(1) { - const char *dot = strchr(sub,'.'); - if(!dot) { + const char* sub = subname.c_str(); + const char* sub2 = subname2.c_str(); + while (1) { + const char* dot = strchr(sub, '.'); + if (!dot) { str.str(""); return 0; } - const char *dot2 = strchr(sub2,'.'); - if(!dot2 || dot-sub!=dot2-sub2 || strncmp(sub,sub2,dot-sub)!=0) { - auto substr = subname.substr(0,dot-subname.c_str()+1); + const char* dot2 = strchr(sub2, '.'); + if (!dot2 || dot - sub != dot2 - sub2 || strncmp(sub, sub2, dot - sub) != 0) { + auto substr = subname.substr(0, dot - subname.c_str() + 1); auto ret = top->getSubObject(substr.c_str()); - if(!top) { + if (!top) { FC_ERR("invalid subname " << top->getFullName() << '.' << substr); str.str(""); return 0; } str.str(""); - str << dot+1 << getName() << '.'; + str << dot + 1 << getName() << '.'; return ret; } - sub = dot+1; - sub2 = dot2+1; + sub = dot + 1; + sub2 = dot2 + 1; } str.str(""); return 0; @@ -5128,15 +5187,15 @@ void DocumentObjectItem::setCheckState(bool checked) { setData(0, Qt::CheckStateRole, QVariant()); } -DocumentItem *DocumentObjectItem::getParentDocument() const { +DocumentItem* DocumentObjectItem::getParentDocument() const { return getTree()->getDocumentItem(object()->getDocument()); } -DocumentItem *DocumentObjectItem::getOwnerDocument() const { +DocumentItem* DocumentObjectItem::getOwnerDocument() const { return myOwner; } -TreeWidget *DocumentObjectItem::getTree() const{ +TreeWidget* DocumentObjectItem::getTree() const { return static_cast(treeWidget()); }