forked from qt-creator/qt-creator
Git: Show date and time in branches dialog
This helps discovering recently active branches. Change-Id: Ic82e1257c2a3407149e62768ddf2fc25c1a54b6b Reviewed-by: André Hartmann <aha_1980@gmx.de> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
committed by
Orgad Shaneh
parent
a06e04c88a
commit
04eb012267
@@ -109,6 +109,8 @@ void BranchDialog::refresh(const QString &repository, bool force)
|
|||||||
VcsOutputWindow::appendError(errorMessage);
|
VcsOutputWindow::appendError(errorMessage);
|
||||||
|
|
||||||
m_ui->branchView->expandAll();
|
m_ui->branchView->expandAll();
|
||||||
|
m_ui->branchView->resizeColumnToContents(0);
|
||||||
|
m_ui->branchView->resizeColumnToContents(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BranchDialog::refreshIfSame(const QString &repository)
|
void BranchDialog::refreshIfSame(const QString &repository)
|
||||||
|
|||||||
@@ -57,8 +57,9 @@ public:
|
|||||||
name(QLatin1String("<ROOT>"))
|
name(QLatin1String("<ROOT>"))
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
BranchNode(const QString &n, const QString &s = QString(), const QString &t = QString()) :
|
BranchNode(const QString &n, const QString &s = QString(), const QString &t = QString(),
|
||||||
parent(0), name(n), sha(s), tracking(t)
|
const QDateTime &dt = QDateTime()) :
|
||||||
|
parent(0), name(n), sha(s), tracking(t), dateTime(dt)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
~BranchNode()
|
~BranchNode()
|
||||||
@@ -185,6 +186,7 @@ public:
|
|||||||
QString name;
|
QString name;
|
||||||
QString sha;
|
QString sha;
|
||||||
QString tracking;
|
QString tracking;
|
||||||
|
QDateTime dateTime;
|
||||||
mutable QString toolTip;
|
mutable QString toolTip;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -211,13 +213,13 @@ BranchModel::~BranchModel()
|
|||||||
|
|
||||||
QModelIndex BranchModel::index(int row, int column, const QModelIndex &parentIdx) const
|
QModelIndex BranchModel::index(int row, int column, const QModelIndex &parentIdx) const
|
||||||
{
|
{
|
||||||
if (column != 0)
|
if (column > 1)
|
||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
BranchNode *parentNode = indexToNode(parentIdx);
|
BranchNode *parentNode = indexToNode(parentIdx);
|
||||||
|
|
||||||
if (row >= parentNode->count())
|
if (row >= parentNode->count())
|
||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
return nodeToIndex(parentNode->children.at(row));
|
return nodeToIndex(parentNode->children.at(row), column);
|
||||||
}
|
}
|
||||||
|
|
||||||
QModelIndex BranchModel::parent(const QModelIndex &index) const
|
QModelIndex BranchModel::parent(const QModelIndex &index) const
|
||||||
@@ -228,7 +230,7 @@ QModelIndex BranchModel::parent(const QModelIndex &index) const
|
|||||||
BranchNode *node = indexToNode(index);
|
BranchNode *node = indexToNode(index);
|
||||||
if (node->parent == m_rootNode)
|
if (node->parent == m_rootNode)
|
||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
return nodeToIndex(node->parent);
|
return nodeToIndex(node->parent, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int BranchModel::rowCount(const QModelIndex &parentIdx) const
|
int BranchModel::rowCount(const QModelIndex &parentIdx) const
|
||||||
@@ -242,7 +244,7 @@ int BranchModel::rowCount(const QModelIndex &parentIdx) const
|
|||||||
int BranchModel::columnCount(const QModelIndex &parent) const
|
int BranchModel::columnCount(const QModelIndex &parent) const
|
||||||
{
|
{
|
||||||
Q_UNUSED(parent);
|
Q_UNUSED(parent);
|
||||||
return 1;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant BranchModel::data(const QModelIndex &index, int role) const
|
QVariant BranchModel::data(const QModelIndex &index, int role) const
|
||||||
@@ -253,13 +255,23 @@ QVariant BranchModel::data(const QModelIndex &index, int role) const
|
|||||||
|
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case Qt::DisplayRole: {
|
case Qt::DisplayRole: {
|
||||||
QString res = node->name;
|
QString res;
|
||||||
|
switch (index.column()) {
|
||||||
|
case 0: {
|
||||||
|
res = node->name;
|
||||||
if (!node->tracking.isEmpty())
|
if (!node->tracking.isEmpty())
|
||||||
res += QLatin1String(" [") + node->tracking + QLatin1Char(']');
|
res += QLatin1String(" [") + node->tracking + QLatin1Char(']');
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 1:
|
||||||
|
if (node->isLeaf() && node->dateTime.isValid())
|
||||||
|
res = node->dateTime.toString("yyyy-MM-dd HH:mm");
|
||||||
|
break;
|
||||||
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
case Qt::EditRole:
|
case Qt::EditRole:
|
||||||
return node->name;
|
return index.column() == 0 ? node->name : QVariant();
|
||||||
case Qt::ToolTipRole:
|
case Qt::ToolTipRole:
|
||||||
if (!node->isLeaf())
|
if (!node->isLeaf())
|
||||||
return QVariant();
|
return QVariant();
|
||||||
@@ -284,7 +296,7 @@ QVariant BranchModel::data(const QModelIndex &index, int role) const
|
|||||||
|
|
||||||
bool BranchModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
bool BranchModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||||
{
|
{
|
||||||
if (role != Qt::EditRole)
|
if (index.column() != 0 || role != Qt::EditRole)
|
||||||
return false;
|
return false;
|
||||||
BranchNode *node = indexToNode(index);
|
BranchNode *node = indexToNode(index);
|
||||||
if (!node)
|
if (!node)
|
||||||
@@ -322,7 +334,7 @@ Qt::ItemFlags BranchModel::flags(const QModelIndex &index) const
|
|||||||
BranchNode *node = indexToNode(index);
|
BranchNode *node = indexToNode(index);
|
||||||
if (!node)
|
if (!node)
|
||||||
return Qt::NoItemFlags;
|
return Qt::NoItemFlags;
|
||||||
if (node->isLeaf() && node->isLocal())
|
if (index.column() == 0 && node->isLeaf() && node->isLocal())
|
||||||
return Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled;
|
return Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled;
|
||||||
else
|
else
|
||||||
return Qt::ItemIsSelectable | Qt::ItemIsEnabled;
|
return Qt::ItemIsSelectable | Qt::ItemIsEnabled;
|
||||||
@@ -428,7 +440,7 @@ QModelIndex BranchModel::currentBranch() const
|
|||||||
{
|
{
|
||||||
if (!m_currentBranch)
|
if (!m_currentBranch)
|
||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
return nodeToIndex(m_currentBranch);
|
return nodeToIndex(m_currentBranch, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString BranchModel::fullName(const QModelIndex &idx, bool includePrefix) const
|
QString BranchModel::fullName(const QModelIndex &idx, bool includePrefix) const
|
||||||
@@ -604,7 +616,7 @@ QModelIndex BranchModel::addBranch(const QString &name, bool track, const QModel
|
|||||||
BranchNode *child = (pos == local->count()) ? 0 : local->children.at(pos);
|
BranchNode *child = (pos == local->count()) ? 0 : local->children.at(pos);
|
||||||
if (!child || child->name != nodeName) {
|
if (!child || child->name != nodeName) {
|
||||||
child = new BranchNode(nodeName);
|
child = new BranchNode(nodeName);
|
||||||
beginInsertRows(nodeToIndex(local), pos, pos);
|
beginInsertRows(nodeToIndex(local, 0), pos, pos);
|
||||||
added = true;
|
added = true;
|
||||||
child->parent = local;
|
child->parent = local;
|
||||||
local->children.insert(pos, child);
|
local->children.insert(pos, child);
|
||||||
@@ -614,11 +626,11 @@ QModelIndex BranchModel::addBranch(const QString &name, bool track, const QModel
|
|||||||
int pos = positionForName(local, leafName);
|
int pos = positionForName(local, leafName);
|
||||||
auto newNode = new BranchNode(leafName, startSha, track ? trackedBranch : QString());
|
auto newNode = new BranchNode(leafName, startSha, track ? trackedBranch : QString());
|
||||||
if (!added)
|
if (!added)
|
||||||
beginInsertRows(nodeToIndex(local), pos, pos);
|
beginInsertRows(nodeToIndex(local, 0), pos, pos);
|
||||||
newNode->parent = local;
|
newNode->parent = local;
|
||||||
local->children.insert(pos, newNode);
|
local->children.insert(pos, newNode);
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
return nodeToIndex(newNode);
|
return nodeToIndex(newNode, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BranchModel::setRemoteTracking(const QModelIndex &trackingIndex)
|
void BranchModel::setRemoteTracking(const QModelIndex &trackingIndex)
|
||||||
@@ -649,23 +661,21 @@ void BranchModel::parseOutputLine(const QString &line)
|
|||||||
const QString sha = shaDeref.isEmpty() ? lineParts.at(0) : shaDeref;
|
const QString sha = shaDeref.isEmpty() ? lineParts.at(0) : shaDeref;
|
||||||
const QString fullName = lineParts.at(1);
|
const QString fullName = lineParts.at(1);
|
||||||
const QString upstream = lineParts.at(2);
|
const QString upstream = lineParts.at(2);
|
||||||
|
QDateTime dateTime;
|
||||||
const bool current = (sha == m_currentSha);
|
const bool current = (sha == m_currentSha);
|
||||||
if (!m_oldBranchesIncluded && !current) {
|
|
||||||
QString strDateTime = lineParts.at(5);
|
QString strDateTime = lineParts.at(5);
|
||||||
if (strDateTime.isEmpty())
|
if (strDateTime.isEmpty())
|
||||||
strDateTime = lineParts.at(4);
|
strDateTime = lineParts.at(4);
|
||||||
if (!strDateTime.isEmpty()) {
|
if (!strDateTime.isEmpty()) {
|
||||||
const uint timeT = strDateTime.leftRef(strDateTime.indexOf(QLatin1Char(' '))).toUInt();
|
const uint timeT = strDateTime.leftRef(strDateTime.indexOf(QLatin1Char(' '))).toUInt();
|
||||||
const int age = QDateTime::fromTime_t(timeT).daysTo(QDateTime::currentDateTime());
|
dateTime = QDateTime::fromTime_t(timeT);
|
||||||
if (age > Constants::OBSOLETE_COMMIT_AGE_IN_DAYS) {
|
}
|
||||||
const QString heads = "refs/heads/";
|
|
||||||
if (fullName.startsWith(heads))
|
if (!m_oldBranchesIncluded && !current && dateTime.isValid()) {
|
||||||
m_obsoleteLocalBranches.append(fullName.mid(heads.size()));
|
const int age = dateTime.daysTo(QDateTime::currentDateTime());
|
||||||
|
if (age > Constants::OBSOLETE_COMMIT_AGE_IN_DAYS)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
bool showTags = m_client->settings().boolValue(GitSettings::showTagsKey);
|
bool showTags = m_client->settings().boolValue(GitSettings::showTagsKey);
|
||||||
|
|
||||||
// insert node into tree:
|
// insert node into tree:
|
||||||
@@ -697,7 +707,7 @@ void BranchModel::parseOutputLine(const QString &line)
|
|||||||
const QString name = nameParts.last();
|
const QString name = nameParts.last();
|
||||||
nameParts.removeLast();
|
nameParts.removeLast();
|
||||||
|
|
||||||
auto newNode = new BranchNode(name, sha, upstream);
|
auto newNode = new BranchNode(name, sha, upstream, dateTime);
|
||||||
root->insert(nameParts, newNode);
|
root->insert(nameParts, newNode);
|
||||||
if (current)
|
if (current)
|
||||||
m_currentBranch = newNode;
|
m_currentBranch = newNode;
|
||||||
@@ -705,18 +715,18 @@ void BranchModel::parseOutputLine(const QString &line)
|
|||||||
|
|
||||||
BranchNode *BranchModel::indexToNode(const QModelIndex &index) const
|
BranchNode *BranchModel::indexToNode(const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
if (index.column() > 0)
|
if (index.column() > 1)
|
||||||
return 0;
|
return 0;
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
return m_rootNode;
|
return m_rootNode;
|
||||||
return static_cast<BranchNode *>(index.internalPointer());
|
return static_cast<BranchNode *>(index.internalPointer());
|
||||||
}
|
}
|
||||||
|
|
||||||
QModelIndex BranchModel::nodeToIndex(BranchNode *node) const
|
QModelIndex BranchModel::nodeToIndex(BranchNode *node, int column) const
|
||||||
{
|
{
|
||||||
if (node == m_rootNode)
|
if (node == m_rootNode)
|
||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
return createIndex(node->parent->rowOf(node), 0, static_cast<void *>(node));
|
return createIndex(node->parent->rowOf(node), column, static_cast<void *>(node));
|
||||||
}
|
}
|
||||||
|
|
||||||
void BranchModel::removeNode(const QModelIndex &idx)
|
void BranchModel::removeNode(const QModelIndex &idx)
|
||||||
@@ -725,7 +735,7 @@ void BranchModel::removeNode(const QModelIndex &idx)
|
|||||||
BranchNode *node = indexToNode(nodeIndex);
|
BranchNode *node = indexToNode(nodeIndex);
|
||||||
while (node->count() == 0 && node->parent != m_rootNode) {
|
while (node->count() == 0 && node->parent != m_rootNode) {
|
||||||
BranchNode *parentNode = node->parent;
|
BranchNode *parentNode = node->parent;
|
||||||
const QModelIndex parentIndex = nodeToIndex(parentNode);
|
const QModelIndex parentIndex = nodeToIndex(parentNode, 0);
|
||||||
const int nodeRow = nodeIndex.row();
|
const int nodeRow = nodeIndex.row();
|
||||||
beginRemoveRows(parentIndex, nodeRow, nodeRow);
|
beginRemoveRows(parentIndex, nodeRow, nodeRow);
|
||||||
parentNode->children.removeAt(nodeRow);
|
parentNode->children.removeAt(nodeRow);
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ private:
|
|||||||
void parseOutputLine(const QString &line);
|
void parseOutputLine(const QString &line);
|
||||||
void setCurrentBranch();
|
void setCurrentBranch();
|
||||||
BranchNode *indexToNode(const QModelIndex &index) const;
|
BranchNode *indexToNode(const QModelIndex &index) const;
|
||||||
QModelIndex nodeToIndex(BranchNode *node) const;
|
QModelIndex nodeToIndex(BranchNode *node, int column) const;
|
||||||
void removeNode(const QModelIndex &idx);
|
void removeNode(const QModelIndex &idx);
|
||||||
|
|
||||||
QString toolTip(const QString &sha) const;
|
QString toolTip(const QString &sha) const;
|
||||||
|
|||||||
Reference in New Issue
Block a user