changeset 138:a7dbc8e5b69d

* Minor adjustment to scene lifecycle, delete old scene before creating new one to use less memory &c
author Chris Cannam
date Tue, 30 Nov 2010 13:51:50 +0000
parents a4044b4b3e35
children e8a481789607
files historywidget.cpp
diffstat 1 files changed, 17 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/historywidget.cpp	Tue Nov 30 13:51:27 2010 +0000
+++ b/historywidget.cpp	Tue Nov 30 13:51:50 2010 +0000
@@ -122,10 +122,15 @@
 void HistoryWidget::addChangesets(Changesets csets)
 {
     m_newIds.clear();
+
+    if (csets.empty()) return;
+
     foreach (Changeset *cs, csets) {
         m_newIds.insert(cs->id());
     }
 
+    DEBUG << "addChangesets: " << csets.size() << " new changesets" << endl;
+
     csets << m_changesets;
     m_changesets = csets;
 }
@@ -137,6 +142,18 @@
     ChangesetScene *scene = new ChangesetScene();
     ChangesetItem *tipItem = 0;
 
+    QGraphicsScene *oldScene = m_panned->scene();
+
+    // detach m_uncommitted from old scene so it doesn't get deleted
+    if (oldScene && (m_uncommitted->scene() == oldScene)) {
+        oldScene->removeItem(m_uncommitted);
+    }
+
+    m_panned->setScene(0);
+    m_panner->setScene(0);
+
+    delete oldScene;
+
     if (!m_changesets.empty()) {
 	Grapher g(scene);
 	try {
@@ -149,12 +166,6 @@
               << m_changesets[0]->id() << endl;
     }
 
-    QGraphicsScene *oldScene = m_panned->scene();
-
-    // detach m_uncommitted from old scene so it doesn't get deleted
-    if (oldScene && (m_uncommitted->scene() == oldScene)) {
-        oldScene->removeItem(m_uncommitted);
-    }
     if (m_uncommittedVisible) {
         scene->addItem(m_uncommitted);
     }
@@ -162,8 +173,6 @@
     m_panned->setScene(scene);
     m_panner->setScene(scene);
 
-    if (oldScene) delete oldScene;
-
     updateNewAndCurrentItems();
 
     if (m_uncommittedVisible) {