changeset 47:24efab584ee5

* More graph layout refinements
author Chris Cannam
date Wed, 10 Nov 2010 17:30:46 +0000
parents bd3accba9b3f
children 996b3c4037ef
files changeset.h grapher.cpp
diffstat 2 files changed, 42 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/changeset.h	Wed Nov 10 17:11:41 2010 +0000
+++ b/changeset.h	Wed Nov 10 17:30:46 2010 +0000
@@ -17,6 +17,7 @@
     Q_PROPERTY(QString date READ date WRITE setDate NOTIFY dateChanged STORED true);
     Q_PROPERTY(QString age READ age WRITE setAge NOTIFY ageChanged STORED true);
     Q_PROPERTY(QStringList parents READ parents WRITE setParents NOTIFY parentsChanged STORED true);
+    Q_PROPERTY(QStringList children READ children WRITE setChildren NOTIFY childrenChanged STORED true);
     Q_PROPERTY(QString comment READ comment WRITE setComment NOTIFY commentChanged STORED true);
 
 public:
@@ -29,6 +30,7 @@
     QString date() const { return m_date; }
     QString age() const { return m_age; }
     QStringList parents() const { return m_parents; }
+    QStringList children() const { return m_children; }
     QString comment() const { return m_comment; }
 
     int number() const {
@@ -48,6 +50,7 @@
     void dateChanged(QString date);
     void ageChanged(QString age);
     void parentsChanged(QStringList parents);
+    void childrenChanged(QStringList children);
     void commentChanged(QString comment);
 
 public slots:
@@ -58,6 +61,8 @@
     void setDate(QString date) { m_date = date; emit dateChanged(date); }
     void setAge(QString age) { m_age = age; emit ageChanged(age); }
     void setParents(QStringList parents) { m_parents = parents; emit parentsChanged(parents); }
+    void setChildren(QStringList children) { m_children = children; emit childrenChanged(m_children); }
+    void addChild(QString child) { m_children.push_back(child); emit childrenChanged(m_children); }
     void setComment(QString comment) { m_comment = comment; emit commentChanged(comment); }
 
 private:
@@ -68,6 +73,7 @@
     QString m_date;
     QString m_age;
     QStringList m_parents;
+    QStringList m_children;
     QString m_comment;
 };
 
--- a/grapher.cpp	Wed Nov 10 17:11:41 2010 +0000
+++ b/grapher.cpp	Wed Nov 10 17:30:46 2010 +0000
@@ -99,9 +99,16 @@
 	}
     }
 
+    // Parent may have layed out child in the recursive call
+    if (m_handled.contains(id)) {
+	std::cerr << "Looks like we've dealt with " << id.toStdString() << std::endl;
+	return;
+    }
+
     int col = 0;
     int row = item->row();
     QString branch = cs->branch();
+
     int nparents = cs->parents().size();
     QString parentId;
     int parentsOnSameBranch = 0;
@@ -156,6 +163,30 @@
     m_alloc[row].insert(col);
     item->setColumn(col);
     m_handled.insert(id);
+
+    int nchildren = cs->children().size();
+    if (nchildren > 1) {
+	// Normally the children will lay out themselves.  We just
+	// want to handle the case where exactly two children have the
+	// same branch as us, because we can handle that neatly
+	QList<QString> special;
+	foreach (QString childId, cs->children()) {
+	    if (!m_changesets.contains(childId)) continue;
+	    Changeset *child = m_changesets[childId];
+	    if (child->branch() == branch &&
+		child->parents().size() == 1) {
+		special.push_back(childId);
+	    }
+	}
+	if (special.size() == 2) {
+	    m_items[special[0]]->setColumn
+		(findAvailableColumn(item->row() - 1, col - 1, true));
+	    m_items[special[1]]->setColumn
+		(findAvailableColumn(item->row() - 1, col + 1, true));
+	    m_handled.insert(special[0]);
+	    m_handled.insert(special[1]);
+	}
+    }
 }
 
 bool
@@ -205,10 +236,10 @@
 		}
 	    }
 	}
-	int home = 2;
+	int home = 3;
 	while (taken.contains(home)) {
 	    if (home > 0) home = -home;
-	    else home = -(home-2);
+	    else home = -(home-3);
 	}
 	m_branchHomes[branch] = home;
     }
@@ -251,7 +282,9 @@
 	QString id = cs->id();
 	ChangesetItem *item = m_items[id];
 	foreach (QString parentId, cs->parents()) {
-	    if (!m_items.contains(parentId)) continue;
+	    if (!m_changesets.contains(parentId)) continue;
+	    Changeset *parent = m_changesets[parentId];
+	    parent->addChild(id);
 	    ConnectionItem *conn = new ConnectionItem();
 	    conn->setChild(item);
 	    conn->setParent(m_items[parentId]);
@@ -274,20 +307,5 @@
     for (int i = csets.size() - 1; i >= 0; --i) {
 	layoutCol(csets[i]->id());
     }
-/*
-    foreach (Changeset *cs, csets) {
-	QString id = cs->id();
-	if (!m_items.contains(id)) continue;
-	ChangesetItem *me = m_items[id];
-	foreach (QString parentId, cs->parents()) {
-	    if (!m_items.contains(parentId)) continue;
-	    ChangesetItem *parent = m_items[parentId];
-	    QGraphicsLineItem *line = new QGraphicsLineItem;
-	    line->setLine(me->x() + 25, me->y() + 50,
-			  parent->x() + 25, parent->y());
-	    m_scene->addItem(line);
-	}
-    }
-*/
 }