changeset 510:c623ce6b3104

Refactor: make closed a changeset property (not a changeset item one)
author Chris Cannam
date Tue, 18 Oct 2011 11:30:00 +0100
parents 6f371814509d
children f1fe20ff3c07
files src/changeset.cpp src/changeset.h src/changesetitem.cpp src/changesetitem.h src/grapher.cpp
diffstat 5 files changed, 22 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/changeset.cpp	Tue Oct 18 11:21:20 2011 +0100
+++ b/src/changeset.cpp	Tue Oct 18 11:30:00 2011 +0100
@@ -21,7 +21,8 @@
 
 #include <QVariant>
 
-Changeset::Changeset(const LogEntry &e)
+Changeset::Changeset(const LogEntry &e) :
+    m_closed(false)
 {
     foreach (QString key, e.keys()) {
         if (key == "parents") {
--- a/src/changeset.h	Tue Oct 18 11:21:20 2011 +0100
+++ b/src/changeset.h	Tue Oct 18 11:30:00 2011 +0100
@@ -65,6 +65,12 @@
      */
     QStringList children() const { return m_children; }
 
+    /**
+     * The closed property is not obtained from Hg, but set in
+     * Grapher::layout() based on traversing closed branch graphs
+     */
+    bool closed() const { return m_closed; }
+
     int number() const {
         return id().split(':')[0].toInt();
     }
@@ -119,6 +125,7 @@
     void ageChanged(QString age);
     void parentsChanged(QStringList parents);
     void childrenChanged(QStringList children);
+    void closedChanged(bool closed);
     void commentChanged(QString comment);
 
 public slots:
@@ -133,6 +140,7 @@
     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 setClosed(bool closed) { m_closed = closed; emit closedChanged(closed); }
     void setComment(QString comment) { m_comment = comment; emit commentChanged(comment); }
 
 private:
@@ -145,6 +153,7 @@
     QString m_age;
     QStringList m_parents;
     QStringList m_children;
+    bool m_closed;
     QString m_comment;
 };
 
--- a/src/changesetitem.cpp	Tue Oct 18 11:21:20 2011 +0100
+++ b/src/changesetitem.cpp	Tue Oct 18 11:30:00 2011 +0100
@@ -38,7 +38,7 @@
 ChangesetItem::ChangesetItem(Changeset *cs) :
     m_changeset(cs), m_detail(0),
     m_showBranch(false), m_column(0), m_row(0), m_wide(false),
-    m_current(false), m_closed(false), m_closing(false), m_new(false)
+    m_current(false), m_closing(false), m_new(false)
 {
     m_font = QFont();
     m_font.setPixelSize(11);
@@ -257,13 +257,19 @@
     return (m_changeset && m_changeset->parents().size() > 1);
 }
 
+bool
+ChangesetItem::isClosed() const
+{
+    return (m_changeset && m_changeset->closed());
+}
+
 void
 ChangesetItem::paintNormal(QPainter *paint)
 {
     paint->save();
     
     int alpha = 255;
-    if (m_closed) alpha = 90;
+    if (isClosed()) alpha = 90;
 
     ColourSet *colourSet = ColourSet::instance();
     QColor branchColour = colourSet->getColourFor(m_changeset->branch());
@@ -438,7 +444,7 @@
     paint->save();
 
     int alpha = 255;
-    if (m_closed) alpha = 90;
+    if (isClosed()) alpha = 90;
     
     ColourSet *colourSet = ColourSet::instance();
     QColor branchColour = colourSet->getColourFor(m_changeset->branch());
--- a/src/changesetitem.h	Tue Oct 18 11:21:20 2011 +0100
+++ b/src/changesetitem.h	Tue Oct 18 11:30:00 2011 +0100
@@ -52,8 +52,7 @@
     void setCurrent(bool c) { m_current = c; }
 
     // Closed is true if this changeset is on a closed branch
-    bool isClosed() const { return m_closed; }
-    void setClosed(bool c) { m_closed = c; }
+    bool isClosed() const;
 
     // Closing is true if this changeset is the commit that closed its
     // branch (i.e. is at the end of a closed branch)
@@ -107,7 +106,6 @@
     int m_row;
     bool m_wide;
     bool m_current;
-    bool m_closed;
     bool m_closing;
     bool m_new;
 
--- a/src/grapher.cpp	Tue Oct 18 11:21:20 2011 +0100
+++ b/src/grapher.cpp	Tue Oct 18 11:30:00 2011 +0100
@@ -451,7 +451,7 @@
                 break;
             }
 
-            item->setClosed(true);
+            cs->setClosed(true);
 
             int pcount = cs->parents().size();
             if (pcount >= 1) {