changeset 128:fcaf09ee825d

* Show tags and current working copy parents in history graph
author Chris Cannam
date Mon, 29 Nov 2010 20:09:58 +0000
parents 758471b71721
children 4986642800f0
files changeset.cpp changeset.h changesetdetailitem.cpp changesetitem.cpp changesetitem.h hgrunner.cpp hgtabwidget.cpp hgtabwidget.h historywidget.cpp historywidget.h mainwindow.cpp
diffstat 11 files changed, 102 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/changeset.cpp	Mon Nov 29 17:48:43 2010 +0000
+++ b/changeset.cpp	Mon Nov 29 20:09:58 2010 +0000
@@ -27,6 +27,10 @@
             QStringList parents = e.value(key).split
                 (" ", QString::SkipEmptyParts);
             setParents(parents);
+        } else if (key == "tag") {
+            QStringList tags = e.value(key).split
+                (" ", QString::SkipEmptyParts);
+            setTags(tags);
         } else if (key == "timestamp") {
             setTimestamp(e.value(key).split(" ")[0].toULongLong());
         } else if (key == "changeset") {
@@ -39,7 +43,7 @@
 
 QString Changeset::getLogTemplate()
 {
-    return "id: {rev}:{node|short}\\nuser: {author}\\nbranch: {branches}\\ntag: {tag}\\ndatetime: {date|isodate}\\ntimestamp: {date|hgdate}\\nage: {date|age}\\nparents: {parents}\\ncomment: {desc|json}\\n\\n";
+    return "id: {rev}:{node|short}\\nauthor: {author}\\nbranch: {branches}\\ntag: {tags}\\ndatetime: {date|isodate}\\ntimestamp: {date|hgdate}\\nage: {date|age}\\nparents: {parents}\\ncomment: {desc|json}\\n\\n";
 }
 
 QString Changeset::formatHtml()
@@ -59,10 +63,10 @@
     QStringList propNames, propTexts;
     
     propNames << "id"
-	      << "user"
+	      << "author"
 	      << "datetime"
 	      << "branch"
-	      << "tag"
+	      << "tags"
 	      << "comment";
 
     propTexts << QObject::tr("Identifier")
@@ -75,8 +79,11 @@
     for (int i = 0; i < propNames.size(); ++i) {
 	QString prop = propNames[i];
 	QString value;
-	if (prop == "comment") value = c;
-	else {
+	if (prop == "comment") {
+            value = c;
+        } else if (prop == "tags") {
+            value = tags().join(" ");
+        } else {
 	    value = xmlEncode(property(prop.toLocal8Bit().data()).toString());
 	}
 	if (value != "") {
--- a/changeset.h	Mon Nov 29 17:48:43 2010 +0000
+++ b/changeset.h	Mon Nov 29 20:09:58 2010 +0000
@@ -35,9 +35,9 @@
     Q_OBJECT
 
     Q_PROPERTY(QString id READ id WRITE setId NOTIFY idChanged STORED true);
-    Q_PROPERTY(QString user READ user WRITE setUser NOTIFY userChanged STORED true);
+    Q_PROPERTY(QString author READ author WRITE setAuthor NOTIFY authorChanged STORED true);
     Q_PROPERTY(QString branch READ branch WRITE setBranch NOTIFY branchChanged STORED true);
-    Q_PROPERTY(QString tag READ tag WRITE setTag NOTIFY tagChanged STORED true);
+    Q_PROPERTY(QStringList tags READ tags WRITE setTags NOTIFY tagsChanged STORED true);
     Q_PROPERTY(QString datetime READ datetime WRITE setDatetime NOTIFY datetimeChanged STORED true);
     Q_PROPERTY(qulonglong timestamp READ timestamp WRITE setTimestamp NOTIFY timestampChanged STORED true);
     Q_PROPERTY(QString age READ age WRITE setAge NOTIFY ageChanged STORED true);
@@ -50,9 +50,9 @@
     explicit Changeset(const LogEntry &e);
 
     QString id() const { return m_id; }
-    QString user() const { return m_user; }
+    QString author() const { return m_author; }
     QString branch() const { return m_branch; }
-    QString tag() const { return m_tag; }
+    QStringList tags() const { return m_tags; }
     QString datetime() const { return m_datetime; }
     qulonglong timestamp() const { return m_timestamp; }
     QString age() const { return m_age; }
@@ -69,8 +69,8 @@
         return id().split(':')[0].toInt();
     }
 
-    QString userName() const {
-	QString a = user();
+    QString authorName() const {
+	QString a = author();
 	return a.replace(QRegExp("\\s*<[^>]*>"), "");
     }
 
@@ -101,9 +101,9 @@
     
 signals:
     void idChanged(QString id);
-    void userChanged(QString user);
+    void authorChanged(QString author);
     void branchChanged(QString branch);
-    void tagChanged(QString tag);
+    void tagsChanged(QStringList tags);
     void datetimeChanged(QString datetime);
     void timestampChanged(qulonglong timestamp);
     void ageChanged(QString age);
@@ -113,9 +113,10 @@
 
 public slots:
     void setId(QString id) { m_id = id; emit idChanged(id); }
-    void setUser(QString user) { m_user = user; emit userChanged(user); }
+    void setAuthor(QString author) { m_author = author; emit authorChanged(author); }
     void setBranch(QString branch) { m_branch = branch; emit branchChanged(branch); }
-    void setTag(QString tag) { m_tag = tag; emit tagChanged(tag); }
+    void setTags(QStringList tags) { m_tags = tags; emit tagsChanged(tags); }
+    void addTag(QString tag) { m_tags.push_back(tag); emit tagsChanged(m_tags); }
     void setDatetime(QString datetime) { m_datetime = datetime; emit datetimeChanged(datetime); }
     void setTimestamp(qulonglong timestamp) { m_timestamp = timestamp; emit timestampChanged(timestamp); }
     void setAge(QString age) { m_age = age; emit ageChanged(age); }
@@ -126,9 +127,9 @@
 
 private:
     QString m_id;
-    QString m_user;
+    QString m_author;
     QString m_branch;
-    QString m_tag;
+    QStringList m_tags;
     QString m_datetime;
     qulonglong m_timestamp;
     QString m_age;
--- a/changesetdetailitem.cpp	Mon Nov 29 17:48:43 2010 +0000
+++ b/changesetdetailitem.cpp	Mon Nov 29 20:09:58 2010 +0000
@@ -58,7 +58,7 @@
     
     ColourSet *colourSet = ColourSet::instance();
     QColor branchColour = colourSet->getColourFor(m_changeset->branch());
-    QColor userColour = colourSet->getColourFor(m_changeset->user());
+    QColor userColour = colourSet->getColourFor(m_changeset->author());
 
     QFont f(m_font);
 
--- a/changesetitem.cpp	Mon Nov 29 17:48:43 2010 +0000
+++ b/changesetitem.cpp	Mon Nov 29 20:09:58 2010 +0000
@@ -27,7 +27,7 @@
 
 ChangesetItem::ChangesetItem(Changeset *cs) :
     m_changeset(cs), m_detail(0),
-    m_showBranch(false), m_column(0), m_row(0), m_wide(false)
+    m_showBranch(false), m_column(0), m_row(0), m_wide(false), m_current(false)
 {
     m_font = QFont();
     m_font.setPixelSize(11);
@@ -89,7 +89,7 @@
     
     ColourSet *colourSet = ColourSet::instance();
     QColor branchColour = colourSet->getColourFor(m_changeset->branch());
-    QColor userColour = colourSet->getColourFor(m_changeset->user());
+    QColor userColour = colourSet->getColourFor(m_changeset->author());
 
     QFont f(m_font);
 
@@ -119,6 +119,10 @@
     QRectF r(x0, 0, width - 3, height);
     paint->drawRect(r);
 
+    if (m_current) {
+        paint->drawRect(QRectF(x0 - 4, -4, width + 5, height + 8));
+    }
+
     if (scale < 0.1) {
 	paint->restore();
 	return;
@@ -130,11 +134,19 @@
     paint->setPen(QPen(Qt::white));
 
     int wid = width - 5;
-    QString person = TextAbbrev::abbreviate(m_changeset->userName(), fm, wid);
+    QString person = TextAbbrev::abbreviate(m_changeset->authorName(), fm, wid);
     paint->drawText(x0 + 3, fm.ascent(), person);
 
     paint->setPen(QPen(Qt::black));
 
+    QString tags = m_changeset->tags().join(" ").trimmed();
+    if (tags != "") {
+        int tw = fm.width(tags);
+        paint->fillRect(QRectF(x0 + width - 8 - tw, 1, tw + 4, fh - 1),
+                        QBrush(Qt::yellow));
+        paint->drawText(x0 + width - 6 - tw, fm.ascent(), tags);
+    }
+
     if (m_showBranch) {
 	// write branch name
 	f.setBold(true);
--- a/changesetitem.h	Mon Nov 29 17:48:43 2010 +0000
+++ b/changesetitem.h	Mon Nov 29 20:09:58 2010 +0000
@@ -45,6 +45,9 @@
     bool isWide() const { return m_wide; }
     void setWide(bool w) { m_wide = w; }
 
+    bool isCurrent() const { return m_current; }
+    void setCurrent(bool c) { m_current = c; }
+
     bool shouldShowBranch() const { return m_showBranch; }
     void setShowBranch(bool s) { m_showBranch = s; }
 
@@ -67,6 +70,7 @@
     int m_column;
     int m_row;
     bool m_wide;
+    bool m_current;
 };
 
 #endif // CHANGESETITEM_H
--- a/hgrunner.cpp	Mon Nov 29 17:48:43 2010 +0000
+++ b/hgrunner.cpp	Mon Nov 29 20:09:58 2010 +0000
@@ -176,19 +176,21 @@
 {
     //DEBUG << "checkPrompts: " << chunk << endl;
 
+    if (!m_currentAction.mayBeInteractive()) return false;
+
     QString text = chunk.trimmed();
     QString lower = text.toLower();
     if (lower.endsWith("password:")) {
         getPassword();
         return true;
     }
-    if (lower.endsWith("user:")) {
+    if (lower.endsWith("user:") || lower.endsWith("username:")) {
         getUsername();
         return true;
     }
-    QRegExp userRe("\\buser:\\s*([^\\s]+)");
+    QRegExp userRe("\\buser(name)?:\\s*([^\\s]+)");
     if (userRe.indexIn(text) >= 0) {
-        noteUsername(userRe.cap(1));
+        noteUsername(userRe.cap(2));
     }
     QRegExp realmRe("\\brealmr:\\s*([^\\s]+)");
     if (realmRe.indexIn(text) >= 0) {
--- a/hgtabwidget.cpp	Mon Nov 29 17:48:43 2010 +0000
+++ b/hgtabwidget.cpp	Mon Nov 29 20:09:58 2010 +0000
@@ -49,6 +49,11 @@
     m_fileStatusWidget->clearSelections();
 }
 
+void HgTabWidget::setCurrent(QStringList ids)
+{
+    m_historyWidget->setCurrent(ids);
+}
+
 bool HgTabWidget::canCommit() const
 {
     if (!m_fileStatusWidget->getSelectedAddableFiles().empty()) return false;
--- a/hgtabwidget.h	Mon Nov 29 17:48:43 2010 +0000
+++ b/hgtabwidget.h	Mon Nov 29 20:09:58 2010 +0000
@@ -48,6 +48,8 @@
     void setWorkFolderAndRepoNames(QString workFolderPath, QString remoteRepoPath);
     void setState(QString state);
 
+    void setCurrent(QStringList ids);
+
     FileStates getFileStates() { return m_fileStates; }
 
     bool canCommit() const;
--- a/historywidget.cpp	Mon Nov 29 17:48:43 2010 +0000
+++ b/historywidget.cpp	Mon Nov 29 20:09:58 2010 +0000
@@ -51,6 +51,19 @@
     foreach (Changeset *cs, m_changesets) delete cs;
     m_changesets.clear();
 }
+
+void HistoryWidget::setCurrent(QStringList ids)
+{
+    if (m_currentIds == ids) return;
+    DEBUG << "HistoryWidget::setCurrent: " << ids.size() << " ids" << endl;
+    m_currentIds = ids;
+    updateCurrentItems();
+}
+
+void HistoryWidget::showUncommittedChanges(bool show)
+{
+    //!!! implement!
+}
     
 void HistoryWidget::parseNewLog(QString log)
 {
@@ -99,6 +112,8 @@
 
     if (oldScene) delete oldScene;
     if (tipItem) tipItem->ensureVisible();
+
+    updateCurrentItems();
 }
 
 void HistoryWidget::setChangesetParents()
@@ -116,3 +131,22 @@
         }
     }
 }
+
+void HistoryWidget::updateCurrentItems()
+{
+    QGraphicsScene *scene = m_panned->scene();
+    if (!scene) return;
+    QList<QGraphicsItem *> items = scene->items();
+    foreach (QGraphicsItem *it, items) {
+        ChangesetItem *csit = dynamic_cast<ChangesetItem *>(it);
+        if (csit) {
+            QString id = csit->getChangeset()->id();
+            bool current = m_currentIds.contains(id);
+            if (current) {
+                DEBUG << "id " << id << " is current" << endl;
+            }
+            csit->setCurrent(current);
+        }
+    }
+}
+
--- a/historywidget.h	Mon Nov 29 17:48:43 2010 +0000
+++ b/historywidget.h	Mon Nov 29 20:09:58 2010 +0000
@@ -33,11 +33,15 @@
     HistoryWidget();
     virtual ~HistoryWidget();
 
+    void setCurrent(QStringList ids);
+    void showUncommittedChanges(bool);
+
     void parseNewLog(QString log);
     void parseIncrementalLog(QString log);
     
 private:
     Changesets m_changesets;
+    QStringList m_currentIds;
 
     Panned *m_panned;
     Panner *m_panner;
@@ -45,6 +49,7 @@
     void clearChangesets();
     void layoutAll();
     void setChangesetParents();
+    void updateCurrentItems();
 };
 
 #endif
--- a/mainwindow.cpp	Mon Nov 29 17:48:43 2010 +0000
+++ b/mainwindow.cpp	Mon Nov 29 20:09:58 2010 +0000
@@ -1246,8 +1246,13 @@
         break;
         
     case ACT_QUERY_PARENTS:
+    {
         foreach (Changeset *cs, currentParents) delete cs;
         currentParents = Changeset::parseChangesets(output);
+        QStringList ids;
+        foreach (Changeset *cs, currentParents) ids.push_back(cs->id());
+        hgTabs->setCurrent(ids);
+    }
         break;
         
     case ACT_QUERY_HEADS:
@@ -1648,7 +1653,7 @@
 
     helpMenu = menuBar()->addMenu(tr("Help"));
     helpMenu->addAction(aboutAct);
-    helpMenu->addAction(aboutQtAct);
+//!!!    helpMenu->addAction(aboutQtAct);
 }
 
 void MainWindow::createToolBars()