SourceElementDiffOperation *CompareSideBySideView::getSource(DiffSingleNodeResult *node, const bool isReference) { SourceElementDiffOperation *source ; bool isEmpty = isNodeEmpty(node, isReference) ; if((isEmpty && isReference) || (!isEmpty && !isReference)) { source = node->compareElement(); } else { source = node->referenceElement(); } return source ; }
/* Finds where to added to the binary tree */ BinNode * addToBinaryTree(BinTree * theTree, BinNode * root, void * dataToAdd) { if (isNodeEmpty(root) == true) { /* Allocate enough memory and insert to root when the node is empty */ root = insertNode(dataToAdd); } else { if (theTree->compareFunction(dataToAdd, root->binVPtr) < 0) { root->leftNode = addToBinaryTree(theTree, root->leftNode, dataToAdd); /* Traverse left */ } else if (theTree->compareFunction(dataToAdd, root->binVPtr) >= 0) { root->rightNode = addToBinaryTree(theTree, root->rightNode, dataToAdd); /* Traverse right */ } else { printf("Error: Node could not be added to the tree \n"); } } return root; }
void CompareSideBySideView::setupItem(DiffSingleNodeResult *node, QTreeWidgetItem *currentNodeItem, const bool isReference, QList<QTreeWidgetItem*> &itemsList, QList<DiffInfo*> &diffList, const bool isChildrenBlocked) { SourceElementDiffOperation *sourceRef = node->referenceElement(); SourceElementDiffOperation *compareRef = node->compareElement(); SourceElementDiffOperation *source = getSource(node, isReference); bool isEmpty = isNodeEmpty(node, isReference); QString text = getText(source, node->type(), isEmpty); setGraphic(currentNodeItem, node->type(), isEmpty) ; currentNodeItem->setText(0, text); if(node->hasAttributes()) { QTreeWidgetItem *attributeTextItem = newTreeItem(itemsList); if(isReference) { DiffInfo *info = NULL ; // if blocked, use the last item if(isChildrenBlocked) { info = diffList.at(diffList.size() - 1); } setLastItemDiff(isReference, itemsList, diffList, info); } if(!isEmpty) { //attributeTextItem->setBackgroundColor(0, colo);aaa attributeTextItem->setBackgroundColor(0, currentNodeItem->backgroundColor(0)); attributeTextItem->setText(0, tr("Attributes:")); } else { attributeTextItem->setBackgroundColor(0, _chrome.emptyColor()); } currentNodeItem->addChild(attributeTextItem); // added only if it is the reference bool emptyAddedAttributes = !isReference || isEmpty ; bool emptyDeletedAttributes = isReference || isEmpty ; if(NULL != sourceRef) { appendAttributes(node, attributeTextItem, EDiff::ED_ADDED, isReference, emptyAddedAttributes, sourceRef->addedAttributes(), itemsList, diffList, isChildrenBlocked); } appendAttributes(node, attributeTextItem, EDiff::ED_MODIFIED, isReference, isEmpty, source->modifiedAttributes(), itemsList, diffList, isChildrenBlocked); appendAttributes(node, attributeTextItem, EDiff::ED_EQUAL, isReference, isEmpty, node->equalsAttributes(), itemsList, diffList, isChildrenBlocked); if(NULL != compareRef) { appendAttributes(node, attributeTextItem, EDiff::ED_DELETED, isReference, emptyDeletedAttributes, compareRef->addedAttributes(), itemsList, diffList, isChildrenBlocked); } } }
/*Searches the tree and returns a matching node if found, if not found, returns null*/ BinNode * searchBinTree(BinTree * toSearch, BinNode * nodeInTree, void * ptrToFind) { BinNode * nodePtr = NULL; if (isNodeEmpty(nodeInTree) == false) { if (toSearch->compareFunction(ptrToFind, nodeInTree->binVPtr) == 0) { if (toSearch->equalsFunction(nodeInTree->binVPtr, ptrToFind) == 1) { /*Check equals*/ nodePtr = nodeInTree; return nodePtr; /*Return the pointer to end the recursive calls*/ } } if (toSearch->compareFunction(ptrToFind, nodeInTree->binVPtr) >= 0) { nodePtr = searchBinTree(toSearch, nodeInTree->rightNode, ptrToFind); /*Traverse right*/ } else if (toSearch->compareFunction(ptrToFind, nodeInTree->binVPtr) < 0) { nodePtr = searchBinTree(toSearch, nodeInTree->leftNode, ptrToFind); /*Traverse left*/ } } else { nodePtr = nodeInTree; } return nodePtr; }