def pasteSibling(self, treeStruct, insertBefore=True): """Paste a sibling at the these spots. Return True on success. Arguments: treeStruct -- a ref to the existing tree structure insertBefore -- if True, insert before these nodes, o/w after """ mimeData = QApplication.clipboard().mimeData() parentNodes = [spot.parentSpot.nodeRef for spot in self] undoObj = undo.ChildListUndo(treeStruct.undoList, parentNodes, treeFormats=treeStruct.treeFormats) for spot in self: newStruct = treestructure.structFromMimeData(mimeData) if not newStruct: treeStruct.undoList.removeLastUndo(undoObj) return False newStruct.replaceDuplicateIds(treeStruct.nodeDict) parent = spot.parentSpot.nodeRef pos = parent.childList.index(spot.nodeRef) if not insertBefore: pos += 1 treeStruct.addNodesFromStruct(newStruct, parent, pos) return True
def pasteChild(self, treeStruct, treeView): """Paste child nodes from the clipbaord. Return True on success. Arguments: treeStruct -- a ref to the existing tree structure treeView -- a ref to the tree view for expanding nodes """ mimeData = QApplication.clipboard().mimeData() parentNodes = self.relatedNodes() if not parentNodes: parentNodes = [treeStruct] undoObj = undo.ChildListUndo(treeStruct.undoList, parentNodes, treeFormats=treeStruct.treeFormats) for parent in parentNodes: newStruct = treestructure.structFromMimeData(mimeData) if not newStruct: treeStruct.undoList.removeLastUndo(undoObj) return False newStruct.replaceDuplicateIds(treeStruct.nodeDict) treeStruct.addNodesFromStruct(newStruct, parent) for spot in self: treeView.expandSpot(spot) return True
def dropMimeData(self, mimeData, dropAction, row, column, index): """Decode mime data and add as a child node to the given index. Return True if successful. Arguments: mimeData -- data for the node branch to be added dropAction -- a drop type enum value row -- a row number for the drop location column -- the column number for the drop location (normally 0) index -- the index of the parent node for the drop """ parent = (index.internalPointer().nodeRef if index.internalPointer() else self.treeStructure) isMove = (dropAction == Qt.MoveAction and TreeModel.storedDragModel == self) undoParents = [parent] if isMove: moveParents = { spot.parentSpot.nodeRef for spot in TreeModel.storedDragSpots } undoParents.extend(list(moveParents)) newStruct = treestructure.structFromMimeData(mimeData) # check for valid structure and no circular clone ref and not siblings: if newStruct and ( not isMove or (not parent.uId in newStruct.nodeDict and (row >= 0 or {node.uId for node in parent.childList}.isdisjoint( {node.uId for node in newStruct.childList})))): undo.ChildListUndo(self.treeStructure.undoList, undoParents, treeFormats=self.treeStructure.treeFormats) if isMove: for spot in TreeModel.storedDragSpots: self.treeStructure.deleteNodeSpot(spot) newStruct.replaceClonedBranches(self.treeStructure) else: newStruct.replaceDuplicateIds(self.treeStructure.nodeDict) self.treeStructure.addNodesFromStruct(newStruct, parent, row) return True return False
def pasteCloneSibling(self, treeStruct, insertBefore=True): """Paste sibling clones at the these spots. Return True on success. Arguments: treeStruct -- a ref to the existing tree structure insertBefore -- if True, insert before these nodes, o/w after """ mimeData = QApplication.clipboard().mimeData() newStruct = treestructure.structFromMimeData(mimeData) if not newStruct: return False try: existNodes = [ treeStruct.nodeDict[node.uId] for node in newStruct.childList ] except KeyError: return False # nodes copied from other file parentNodes = [spot.parentSpot.nodeRef for spot in self] for parent in parentNodes: if not parent.ancestors().isdisjoint(set(existNodes)): return False # circular ref for node in existNodes: if parent in node.parents(): return False # identical siblings undoObj = undo.ChildListUndo(treeStruct.undoList, parentNodes, treeFormats=treeStruct.treeFormats) for spot in self: parent = spot.parentSpot.nodeRef pos = parent.childList.index(spot.nodeRef) if not insertBefore: pos += 1 for node in existNodes: parent.childList.insert(pos, node) node.addSpotRef(parent) return True
def pasteCloneChild(self, treeStruct, treeView): """Paste child clones from the clipbaord. Return True on success. Arguments: treeStruct -- a ref to the existing tree structure treeView -- a ref to the tree view for expanding nodes """ mimeData = QApplication.clipboard().mimeData() newStruct = treestructure.structFromMimeData(mimeData) if not newStruct: return False try: existNodes = [ treeStruct.nodeDict[node.uId] for node in newStruct.childList ] except KeyError: return False # nodes copied from other file parentNodes = self.relatedNodes() if not parentNodes: parentNodes = [treeStruct] for parent in parentNodes: if not parent.ancestors().isdisjoint(set(existNodes)): return False # circular ref for node in existNodes: if parent in node.parents(): return False # identical siblings undoObj = undo.ChildListUndo(treeStruct.undoList, parentNodes, treeFormats=treeStruct.treeFormats) for parent in parentNodes: for node in existNodes: parent.childList.append(node) node.addSpotRef(parent) for spot in self: treeView.expandSpot(spot) return True