forked from qt-creator/qt-creator
Git: Protect against removal of the "Local Branches" node
... When a single local branch is being removed Change-Id: I4321d045ebb6faaf5f864ff33cb4f34c15d2264b Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
This commit is contained in:
committed by
Orgad Shaneh
parent
d2cad7d1a6
commit
18906fac4f
@@ -692,14 +692,18 @@ QModelIndex BranchModel::nodeToIndex(BranchNode *node) const
|
||||
|
||||
void BranchModel::removeNode(const QModelIndex &idx)
|
||||
{
|
||||
QModelIndex tmp = idx; // tmp is a leaf, so count must be 0.
|
||||
while (indexToNode(tmp)->count() == 0) {
|
||||
QModelIndex tmpParent = parent(tmp);
|
||||
beginRemoveRows(tmpParent, tmp.row(), tmp.row());
|
||||
indexToNode(tmpParent)->children.removeAt(tmp.row());
|
||||
delete indexToNode(tmp);
|
||||
QModelIndex nodeIndex = idx; // idx is a leaf, so count must be 0.
|
||||
BranchNode *node = indexToNode(nodeIndex);
|
||||
while (node->count() == 0 && node->parent != m_rootNode) {
|
||||
BranchNode *parentNode = node->parent;
|
||||
const QModelIndex parentIndex = nodeToIndex(parentNode);
|
||||
const int nodeRow = nodeIndex.row();
|
||||
beginRemoveRows(parentIndex, nodeRow, nodeRow);
|
||||
parentNode->children.removeAt(nodeRow);
|
||||
delete node;
|
||||
endRemoveRows();
|
||||
tmp = tmpParent;
|
||||
node = parentNode;
|
||||
nodeIndex = parentIndex;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user