forked from qt-creator/qt-creator
Git: Make tree layout consistent on add branch
Change-Id: I3b49d76ef0e3da9ab60d6859a8b8e18092794bbb Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
This commit is contained in:
committed by
Orgad Shaneh
parent
4babcabf20
commit
11e7c706be
@@ -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
|
|||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
|
|||||||
Reference in New Issue
Block a user