Commit 11e7c706 authored by Orgad Shaneh's avatar Orgad Shaneh Committed by Orgad Shaneh

Git: Make tree layout consistent on add branch

Change-Id: I3b49d76ef0e3da9ab60d6859a8b8e18092794bbb
Reviewed-by: default avatarTobias Hunger <tobias.hunger@digia.com>
parent 4babcabf
...@@ -513,6 +513,16 @@ bool BranchModel::branchIsMerged(const QModelIndex &idx) ...@@ -513,6 +513,16 @@ bool BranchModel::branchIsMerged(const QModelIndex &idx)
return false; return false;
} }
static int positionForName(BranchNode *node, const QString &name)
{
int pos = 0;
for (pos = 0; pos < node->count(); ++pos) {
if (node->children.at(pos)->name >= name)
break;
}
return pos;
}
QModelIndex BranchModel::addBranch(const QString &name, bool track, const QModelIndex &startPoint) QModelIndex BranchModel::addBranch(const QString &name, bool track, const QModelIndex &startPoint)
{ {
if (!m_rootNode || !m_rootNode->count()) if (!m_rootNode || !m_rootNode->count())
...@@ -534,18 +544,30 @@ QModelIndex BranchModel::addBranch(const QString &name, bool track, const QModel ...@@ -534,18 +544,30 @@ QModelIndex BranchModel::addBranch(const QString &name, bool track, const QModel
} }
BranchNode *local = m_rootNode->children.at(0); BranchNode *local = m_rootNode->children.at(0);
int pos = 0; const int slash = name.indexOf(QLatin1Char('/'));
for (pos = 0; pos < local->count(); ++pos) { const QString leafName = slash == -1 ? name : name.mid(slash + 1);
if (local->children.at(pos)->name > name) bool added = false;
break; if (slash != -1) {
const QString nodeName = name.left(slash);
int pos = positionForName(local, nodeName);
BranchNode *child = (pos == local->count()) ? 0 : local->children.at(pos);
if (!child || child->name != nodeName) {
child = new BranchNode(nodeName);
beginInsertRows(nodeToIndex(local), pos, pos);
added = true;
child->parent = local;
local->children.insert(pos, child);
}
local = child;
} }
BranchNode *newNode = new BranchNode(name, sha(startPoint), track ? trackedBranch : QString()); int pos = positionForName(local, leafName);
beginInsertRows(index(0, 0), pos, pos); BranchNode *newNode = new BranchNode(leafName, sha(startPoint), track ? trackedBranch : QString());
if (!added)
beginInsertRows(nodeToIndex(local), pos, pos);
newNode->parent = local; newNode->parent = local;
local->children.insert(pos, newNode); local->children.insert(pos, newNode);
endInsertRows(); endInsertRows();
return nodeToIndex(newNode);
return index(pos, 0, index(0, 0));
} }
void BranchModel::parseOutputLine(const QString &line) void BranchModel::parseOutputLine(const QString &line)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment