changeset 516:2981d2defa61

Introduce a graphical representation for merge from a closed to an open branch (half a connection item)
author Chris Cannam
date Thu, 20 Oct 2011 12:04:47 +0100
parents fc35aa6d433e
children fb196c016a9f
files src/connectionitem.cpp src/connectionitem.h src/grapher.cpp
diffstat 3 files changed, 60 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/connectionitem.cpp	Thu Oct 20 11:36:49 2011 +0100
+++ b/src/connectionitem.cpp	Thu Oct 20 12:04:47 2011 +0100
@@ -21,18 +21,19 @@
 #include "changesetitem.h"
 #include "changeset.h"
 #include "colourset.h"
+#include "textabbrev.h"
 
 #include <QPainter>
+#include <QFont>
 
 QRectF
 ConnectionItem::boundingRect() const
 {
-    if (!m_parent || !(m_child || m_uncommitted)) return QRectF();
+    if (!(m_child || m_uncommitted)) return QRectF();
     float xscale = 100;
     float yscale = 90;
     float size = 50;
 
-    int p_col = m_parent->column(), p_row = m_parent->row();
     int c_col, c_row;
     if (m_child) {
         c_col = m_child->column(); c_row = m_child->row();
@@ -40,6 +41,13 @@
         c_col = m_uncommitted->column(); c_row = m_uncommitted->row();
     }
 
+    int p_col, p_row;
+    if (m_parent) {
+        p_col = m_parent->column(); p_row = m_parent->row();
+    } else {
+        p_col = c_col - 1; p_row = c_row + 1;
+    }
+
     return QRectF(xscale * c_col + size/2 - 2,
 		  yscale * c_row + size - 22,
 		  xscale * p_col - xscale * c_col + 6,
@@ -50,7 +58,7 @@
 void
 ConnectionItem::paint(QPainter *paint, const QStyleOptionGraphicsItem *, QWidget *)
 {
-    if (!m_parent || !(m_child || m_uncommitted)) return;
+    if (!(m_child || m_uncommitted)) return;
     QPainterPath p;
 
     paint->save();
@@ -83,7 +91,6 @@
     float size = 50;
     float ygap = yscale - size - 2;
 
-    int p_col = m_parent->column(), p_row = m_parent->row();
     int c_col, c_row;
     if (m_child) {
         c_col = m_child->column(); c_row = m_child->row();
@@ -91,6 +98,13 @@
         c_col = m_uncommitted->column(); c_row = m_uncommitted->row();
     }
 
+    int p_col, p_row;
+    if (m_parent) {
+        p_col = m_parent->column(); p_row = m_parent->row();
+    } else {
+        p_col = c_col - 1; p_row = c_row + 1;
+    }
+
     float c_x = xscale * c_col + size/2;
     float p_x = xscale * p_col + size/2;
 
@@ -130,11 +144,42 @@
 	}
     }
 
-    // ensure line reaches the node -- again doesn't matter if we
-    // overshoot
-    p.lineTo(p_x, yscale * p_row + 20);
+    if (m_parent) {
 
+        // ensure line reaches the node -- again doesn't matter if we
+        // overshoot
+        p.lineTo(p_x, yscale * p_row + 20);
+
+    } else {
+
+        // no parent: merge from closed branch: draw only half the line
+        paint->setClipRect(QRectF((c_x + p_x)/2, yscale * c_row + size - 22,
+                                  xscale, yscale));
+    }
+    
     paint->drawPath(p);
+
+    if (!m_parent) {
+
+        // merge from closed branch: draw branch name
+
+        paint->setClipping(false);
+
+        QFont f;
+        f.setPixelSize(11);
+        f.setBold(true);
+        f.setItalic(false);
+	paint->setFont(f);
+
+	QString branch = m_mergedBranch;
+        if (branch == "") branch = "default";
+	int wid = xscale;
+	branch = TextAbbrev::abbreviate(branch, QFontMetrics(f), wid);
+	paint->drawText((c_x + p_x)/2 - wid - 2,
+                        yscale * c_row + size + ygap/2 + 2,
+                        branch);
+    }
+    
     paint->restore();
 }
 
--- a/src/connectionitem.h	Thu Oct 20 11:36:49 2011 +0100
+++ b/src/connectionitem.h	Thu Oct 20 12:04:47 2011 +0100
@@ -50,12 +50,14 @@
     void setParent(ChangesetItem *p) { m_parent = p; }
     void setChild(ChangesetItem *c) { m_child = c; }
     void setChild(UncommittedItem *u) { m_uncommitted = u; }
+    void setMergedBranch(QString mb) { m_mergedBranch = mb; }
 
 private:
     Type m_type;
     ChangesetItem *m_parent;
     ChangesetItem *m_child;
     UncommittedItem *m_uncommitted;
+    QString m_mergedBranch;
 };
 
 #endif // CONNECTIONITEM_H
--- a/src/grapher.cpp	Thu Oct 20 11:36:49 2011 +0100
+++ b/src/grapher.cpp	Thu Oct 20 12:04:47 2011 +0100
@@ -515,12 +515,16 @@
         ChangesetItem *item = m_items[id];
         bool merge = (cs->parents().size() > 1);
         foreach (QString parentId, cs->parents()) {
-            if (!m_items.contains(parentId)) continue;
+            if (!m_changesets.contains(parentId)) continue;
             ConnectionItem *conn = new ConnectionItem();
             if (merge) conn->setConnectionType(ConnectionItem::Merge);
             conn->setChild(item);
-            conn->setParent(m_items[parentId]);
             conn->setZValue(-1);
+            if (m_items.contains(parentId)) {
+                conn->setParent(m_items[parentId]);
+            } else {
+                conn->setMergedBranch(m_changesets[parentId]->branch());
+            }
             m_scene->addItem(conn);
         }
     }