From 5a9c65e4fc276f4047f53a76bfd31824ecfea64e Mon Sep 17 00:00:00 2001 From: wmayer Date: Fri, 16 Nov 2018 11:24:25 +0100 Subject: [PATCH] use more speaking variable names --- src/Gui/Tree.cpp | 234 ++++++++++++++++++++++++----------------------- 1 file changed, 121 insertions(+), 113 deletions(-) diff --git a/src/Gui/Tree.cpp b/src/Gui/Tree.cpp index 4fbea298a8..7e7c0df87b 100644 --- a/src/Gui/Tree.cpp +++ b/src/Gui/Tree.cpp @@ -498,86 +498,89 @@ void TreeWidget::dragMoveEvent(QDragMoveEvent *event) if (!event->isAccepted()) return; - QTreeWidgetItem* targetitem = itemAt(event->pos()); - if (!targetitem || this->isItemSelected(targetitem)) { + QTreeWidgetItem* targetItem = itemAt(event->pos()); + if (!targetItem || this->isItemSelected(targetItem)) { event->ignore(); } - else if (targetitem->type() == TreeWidget::DocumentType) { - QList idxs = selectedIndexes(); - App::Document* doc = static_cast(targetitem)-> - document()->getDocument(); - for (QList::Iterator it = idxs.begin(); it != idxs.end(); ++it) { - QTreeWidgetItem* item = itemFromIndex(*it); - if (item->type() != TreeWidget::ObjectType) { - event->ignore(); - return; - } - App::DocumentObject* obj = static_cast(item)-> - object()->getObject(); - if (doc != obj->getDocument()) { - event->ignore(); - return; - } - } - } - else if (targetitem->type() == TreeWidget::ObjectType) { - - DocumentObjectItem* targetItemObj = static_cast(targetitem); - Gui::ViewProviderDocumentObject* vp = targetItemObj->object(); - - if (!vp->canDropObjects()) { - event->ignore(); - } - - QList children; - for (int i=0; ichildCount(); i++) - children << targetitem->child(i); - - App::DocumentObject* grp = vp->getObject(); - App::Document* doc = grp->getDocument(); - QList idxs = selectedIndexes(); - - std::vector dropObjects; - dropObjects.reserve(idxs.size()); - - for (QList::Iterator it = idxs.begin(); it != idxs.end(); ++it) { - QTreeWidgetItem* item = itemFromIndex(*it); - if (item->type() != TreeWidget::ObjectType) { - event->ignore(); - return; - } - App::DocumentObject* obj = static_cast(item)-> - object()->getObject(); - if (doc != obj->getDocument()) { - event->ignore(); - return; - } - - dropObjects.push_back(obj); - - // To avoid a cylic dependency it must be made sure to not allow to - // drag'n'drop a tree item onto a child or grandchild item of it. - if (static_cast(targetitem)->isChildOfItem( - static_cast(item))) { - event->ignore(); - return; - } - - // if the item is already a child of the target item there is nothing to do - if (children.contains(item)) { - event->ignore(); - return; - } - - // let the view provider decide to accept the object or ignore it - if (!vp->canDropObject(obj)) { - event->ignore(); - return; - } - } - } else { - event->ignore(); + if (targetItem->type() == TreeWidget::DocumentType) { + QList idxs = selectedIndexes(); + App::Document* doc = static_cast(targetItem)-> + document()->getDocument(); + for (QList::Iterator it = idxs.begin(); it != idxs.end(); ++it) { + QTreeWidgetItem* item = itemFromIndex(*it); + if (item->type() != TreeWidget::ObjectType) { + event->ignore(); + return; + } + App::DocumentObject* obj = static_cast(item)-> + object()->getObject(); + if (doc != obj->getDocument()) { + event->ignore(); + return; + } + } + } + else if (targetItem->type() == TreeWidget::ObjectType) { + DocumentObjectItem* targetItemObj = static_cast(targetItem); + Gui::ViewProviderDocumentObject* vpTarget = targetItemObj->object(); + + if (!vpTarget->canDropObjects()) { + event->ignore(); + } + + QList children; + for (int i=0; ichildCount(); i++) + children << targetItem->child(i); + + App::DocumentObject* targetObj = vpTarget->getObject(); + App::Document* docTarget = targetObj->getDocument(); + + QList idxsSelected = selectedIndexes(); + + std::vector dropObjects; + dropObjects.reserve(idxsSelected.size()); + + for (QList::Iterator it = idxsSelected.begin(); it != idxsSelected.end(); ++it) { + QTreeWidgetItem* item = itemFromIndex(*it); + if (item->type() != TreeWidget::ObjectType) { + event->ignore(); + return; + } + + Gui::ViewProviderDocumentObject* vpDropped = static_cast(item)->object(); + App::DocumentObject* objDropped = vpDropped->getObject(); + if (docTarget != objDropped->getDocument()) { + event->ignore(); + return; + } + + dropObjects.push_back(objDropped); + + // To avoid a cylic dependency it must be made sure to not allow to + // drag'n'drop a tree item onto a child or grandchild item of it. + if (static_cast(targetItem)->isChildOfItem( + static_cast(item))) { + event->ignore(); + return; + } + + // if the item is already a child of the target item there is nothing to do + if (children.contains(item)) { + event->ignore(); + return; + } + + // let the view provider decide to accept the object or ignore it + if (!vpTarget->canDropObject(objDropped)) { + event->ignore(); + return; + } + } + } + else { + event->ignore(); + } } } @@ -585,12 +588,12 @@ void TreeWidget::dropEvent(QDropEvent *event) { //FIXME: This should actually be done inside dropMimeData - QTreeWidgetItem* targetitem = itemAt(event->pos()); + QTreeWidgetItem* targetItem = itemAt(event->pos()); // not dropped onto an item - if (!targetitem) + if (!targetItem) return; // one of the source items is also the destination item, that's not allowed - if (this->isItemSelected(targetitem)) + if (this->isItemSelected(targetItem)) return; // filter out the selected items we cannot handle @@ -602,9 +605,9 @@ void TreeWidget::dropEvent(QDropEvent *event) if (idxs.contains(parent)) continue; QTreeWidgetItem* item = itemFromIndex(*it); - if (item == targetitem) + if (item == targetItem) continue; - if (item->parent() == targetitem) + if (item->parent() == targetItem) continue; items.push_back(item); } @@ -612,51 +615,56 @@ void TreeWidget::dropEvent(QDropEvent *event) if (items.isEmpty()) return; // nothing needs to be done - if (targetitem->type() == TreeWidget::ObjectType) { + if (targetItem->type() == TreeWidget::ObjectType) { // add object to group - DocumentObjectItem* targetItemObj = static_cast(targetitem); - Gui::ViewProviderDocumentObject* vp = targetItemObj->object(); - if (!vp->canDropObjects()) { - return; // no group like object + DocumentObjectItem* targetItemObj = static_cast(targetItem); + Gui::ViewProviderDocumentObject* vpTarget = targetItemObj->object(); + Gui::Document* gui = vpTarget->getDocument(); + + if (false) { } - - bool dropOnly = QApplication::keyboardModifiers()== Qt::ControlModifier; - - // Open command - Gui::Document* gui = vp->getDocument(); - gui->openCommand("Drag object"); - for (QList::Iterator it = items.begin(); it != items.end(); ++it) { - Gui::ViewProviderDocumentObject* vpc = static_cast(*it)->object(); - App::DocumentObject* obj = vpc->getObject(); - - if(!dropOnly) { - // does this have a parent object - QTreeWidgetItem* parent = (*it)->parent(); - if (parent && parent->type() == TreeWidget::ObjectType) { - Gui::ViewProvider* vpp = static_cast(parent)->object(); - vpp->dragObject(obj); - } + else { + if (!vpTarget->canDropObjects()) { + return; // no group like object } - // now add the object to the target object - vp->dropObject(obj); + bool dropOnly = QApplication::keyboardModifiers()== Qt::ControlModifier; + + // Open command + gui->openCommand("Drag object"); + for (QList::Iterator it = items.begin(); it != items.end(); ++it) { + Gui::ViewProviderDocumentObject* vpDropped = static_cast(*it)->object(); + App::DocumentObject* objDropped = vpDropped->getObject(); + + if (!dropOnly) { + // does this have a parent object + QTreeWidgetItem* parent = (*it)->parent(); + if (parent && parent->type() == TreeWidget::ObjectType) { + Gui::ViewProvider* vpParent = static_cast(parent)->object(); + vpParent->dragObject(objDropped); + } + } + + // now add the object to the target object + vpTarget->dropObject(objDropped); + } + gui->commitCommand(); } - gui->commitCommand(); } - else if (targetitem->type() == TreeWidget::DocumentType) { + else if (targetItem->type() == TreeWidget::DocumentType) { // Open command - App::Document* doc = static_cast(targetitem)->document()->getDocument(); + App::Document* doc = static_cast(targetItem)->document()->getDocument(); Gui::Document* gui = Gui::Application::Instance->getDocument(doc); gui->openCommand("Move object"); for (QList::Iterator it = items.begin(); it != items.end(); ++it) { - Gui::ViewProviderDocumentObject* vpc = static_cast(*it)->object(); - App::DocumentObject* obj = vpc->getObject(); + Gui::ViewProviderDocumentObject* vpDropped = static_cast(*it)->object(); + App::DocumentObject* objDropped = vpDropped->getObject(); // does this have a parent object QTreeWidgetItem* parent = (*it)->parent(); if (parent && parent->type() == TreeWidget::ObjectType) { - Gui::ViewProvider* vpp = static_cast(parent)->object(); - vpp->dragObject(obj); + Gui::ViewProvider* vpParent = static_cast(parent)->object(); + vpParent->dragObject(objDropped); } } gui->commitCommand();