void HierarchyTreeControl::HandleDropHierarchyMimeData(QDropEvent *event, const HierarchyTreeControlMimeData* mimeData) { HierarchyTreeNode::HIERARCHYTREENODEID insertInTo = HierarchyTreeNode::HIERARCHYTREENODEID_EMPTY; HierarchyTreeNode::HIERARCHYTREENODEID insertAfter = HierarchyTreeNode::HIERARCHYTREENODEID_EMPTY; if (!GetMoveItemID(event, insertInTo, insertAfter)) return; HierarchyTreeNode* parentNode = HierarchyTreeController::Instance()->GetTree().GetNode(insertInTo); if (!parentNode) { parentNode = (HierarchyTreeNode*) HierarchyTreeController::Instance()->GetTree().GetRootNode(); insertInTo = parentNode->GetId(); } if (!mimeData->IsDropEnable(parentNode)) { return; } //Copy current selected item(s) if ctrl key is pressed during drag if (event->keyboardModifiers() == Qt::ControlModifier) { CopyPasteController::Instance()->CopyControls(HierarchyTreeController::Instance()->GetActiveControlNodes()); CopyPasteController::Instance()->Paste(parentNode); } else //Otherwise move item(s) { HierarchyTreeNode::HIERARCHYTREENODESIDLIST items = mimeData->GetItems(); ChangeNodeHeirarchy* cmd = new ChangeNodeHeirarchy(insertInTo, insertAfter, items); CommandsController::Instance()->ExecuteCommand(cmd); SafeRelease(cmd); } }
void ChangeNodeHeirarchy::StorePreviousParents() { for (HierarchyTreeNode::HIERARCHYTREENODESIDLIST::iterator iter = items.begin(); iter != items.end(); ++iter) { HierarchyTreeNode* node = HierarchyTreeController::Instance()->GetTree().GetNode((*iter)); if (!node) { continue; } HierarchyTreeNode* parentNode = node->GetParent(); if (!parentNode) { continue; } HierarchyTreeNode::HIERARCHYTREENODEID addAfter = HierarchyTreeNode::HIERARCHYTREENODEID_EMPTY; HierarchyTreeNode::HIERARCHYTREENODEID lastId = HierarchyTreeNode::HIERARCHYTREENODEID_EMPTY; const HierarchyTreeNode::HIERARCHYTREENODESLIST& childs = parentNode->GetChildNodes(); for (HierarchyTreeNode::HIERARCHYTREENODESLIST::const_iterator citer = childs.begin(); citer != childs.end(); ++citer) { if (node == (*citer)) addAfter = lastId; lastId = (*citer)->GetId(); } // The Previous Parents are stored in the "item ID - parent ID" map. this->previousParents.insert(std::make_pair(*iter, PreviousState(parentNode->GetId(), addAfter))); } }