diff options
author | Orgad Shaneh <orgad.shaneh@audiocodes.com> | 2013-07-19 15:28:26 +0300 |
---|---|---|
committer | Orgad Shaneh <orgads@gmail.com> | 2013-07-22 12:38:54 +0200 |
commit | 39755c09b9cf03e64723ffcbef100c0d52fffb7c (patch) | |
tree | 9a4b39dac3e81dd63b70556b207ba565ef9b2f2c /src/plugins/git/branchmodel.cpp | |
parent | 8f05239b924327b45d1e39960732403cae91a25b (diff) | |
download | qt-creator-39755c09b9cf03e64723ffcbef100c0d52fffb7c.tar.gz |
Git: Only show Tags root node when tags are enabled and exist
Create it on demand. Remove on clear
Change-Id: Ic29e82a859f99b5d739c25be83aa6c40a1ee2cc8
Reviewed-by: Nikita Baryshnikov <nib952051@gmail.com>
Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
Diffstat (limited to 'src/plugins/git/branchmodel.cpp')
-rw-r--r-- | src/plugins/git/branchmodel.cpp | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/src/plugins/git/branchmodel.cpp b/src/plugins/git/branchmodel.cpp index ea7d64795c..ee961b6371 100644 --- a/src/plugins/git/branchmodel.cpp +++ b/src/plugins/git/branchmodel.cpp @@ -202,8 +202,6 @@ BranchModel::BranchModel(GitClient *client, QObject *parent) : // Abuse the sha field for ref prefix m_rootNode->append(new BranchNode(tr("Local Branches"), QLatin1String("refs/heads"))); m_rootNode->append(new BranchNode(tr("Remote Branches"), QLatin1String("refs/remotes"))); - if (m_client->settings()->boolValue(GitSettings::showTagsKey)) - m_rootNode->append(new BranchNode(tr("Tags"), QLatin1String("refs/tags"))); } BranchModel::~BranchModel() @@ -335,6 +333,8 @@ void BranchModel::clear() foreach (BranchNode *root, m_rootNode->children) while (root->count()) delete root->children.takeLast(); + if (hasTags()) + m_rootNode->children.takeLast(); m_currentBranch = 0; } @@ -457,6 +457,11 @@ QString BranchModel::sha(const QModelIndex &idx) const return node->sha; } +bool BranchModel::hasTags() const +{ + return m_rootNode->children.count() > Tags; +} + bool BranchModel::isLocal(const QModelIndex &idx) const { if (!idx.isValid()) @@ -475,7 +480,7 @@ bool BranchModel::isLeaf(const QModelIndex &idx) const bool BranchModel::isTag(const QModelIndex &idx) const { - if (!idx.isValid()) + if (!idx.isValid() || !hasTags()) return false; return indexToNode(idx)->isTag(); } @@ -640,14 +645,17 @@ void BranchModel::parseOutputLine(const QString &line) nameParts.removeFirst(); // remove refs... BranchNode *root = 0; - if (nameParts.first() == QLatin1String("heads")) + if (nameParts.first() == QLatin1String("heads")) { root = m_rootNode->children.at(LocalBranches); - else if (nameParts.first() == QLatin1String("remotes")) + } else if (nameParts.first() == QLatin1String("remotes")) { root = m_rootNode->children.at(RemoteBranches); - else if (showTags && nameParts.first() == QLatin1String("tags")) + } else if (showTags && nameParts.first() == QLatin1String("tags")) { + if (!hasTags()) // Tags is missing, add it + m_rootNode->append(new BranchNode(tr("Tags"), QLatin1String("refs/tags"))); root = m_rootNode->children.at(Tags); - else + } else { return; + } nameParts.removeFirst(); |