changeset 134:1208d9688a8f

* Have a go at switching to new items in history widget when something happens in repo
author Chris Cannam
date Tue, 30 Nov 2010 13:07:53 +0000
parents aaeab914f2a3
children 908a1fdeed6a
files hgtabwidget.cpp historywidget.cpp historywidget.h
diffstat 3 files changed, 29 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/hgtabwidget.cpp	Tue Nov 30 12:45:34 2010 +0000
+++ b/hgtabwidget.cpp	Tue Nov 30 13:07:53 2010 +0000
@@ -140,11 +140,17 @@
 void HgTabWidget::setNewLog(QString hgLogList)
 {
     m_historyWidget->parseNewLog(hgLogList);
+    if (m_historyWidget->haveNewItems()) {
+        setCurrentWidget(m_historyWidget);
+    }
 }
 
 void HgTabWidget::addIncrementalLog(QString hgLogList)
 {
     m_historyWidget->parseIncrementalLog(hgLogList);
+    if (m_historyWidget->haveNewItems()) {
+        setCurrentWidget(m_historyWidget);
+    }
 }
 
 void HgTabWidget::setWorkFolderAndRepoNames(QString workFolderPath, QString remoteRepoPath)
--- a/historywidget.cpp	Tue Nov 30 12:45:34 2010 +0000
+++ b/historywidget.cpp	Tue Nov 30 13:07:53 2010 +0000
@@ -34,6 +34,7 @@
     m_panner = new Panner;
     m_uncommitted = new UncommittedItem();
     m_uncommitted->setRow(-1);
+    m_uncommittedVisible = false;
 
     QGridLayout *layout = new QGridLayout;
     layout->addWidget(m_panned, 0, 0);
@@ -47,7 +48,7 @@
 HistoryWidget::~HistoryWidget()
 {
     clearChangesets();
-    delete m_uncommitted;
+    if (!m_uncommittedVisible) delete m_uncommitted;
 }
 
 void HistoryWidget::clearChangesets()
@@ -69,17 +70,8 @@
 
 void HistoryWidget::showUncommittedChanges(bool show)
 {
-    QGraphicsScene *scene = m_panned->scene();
-    if (!scene) return;
-
-    if (show) {
-        if (m_uncommitted->scene() == scene) return;
-        scene->addItem(m_uncommitted);
-        m_uncommitted->ensureVisible();
-    } else {
-        if (m_uncommitted->scene() != scene) return;
-        scene->removeItem(m_uncommitted);
-    }
+    m_uncommittedVisible = show;
+    layoutAll();
 }
     
 void HistoryWidget::parseNewLog(QString log)
@@ -141,7 +133,6 @@
 void HistoryWidget::layoutAll()
 {
     setChangesetParents();
-    showUncommittedChanges(false); // detach the item from our scene
 
     ChangesetScene *scene = new ChangesetScene();
     ChangesetItem *tipItem = 0;
@@ -159,13 +150,28 @@
     }
 
     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);
+    }
+
     m_panned->setScene(scene);
     m_panner->setScene(scene);
 
     if (oldScene) delete oldScene;
-    if (tipItem) tipItem->ensureVisible();
 
     updateNewAndCurrentItems();
+
+    if (m_uncommittedVisible) {
+        m_uncommitted->ensureVisible();
+    } else if (tipItem) {
+        DEBUG << "asking tip item to be visible" << endl;
+        tipItem->ensureVisible();
+    }
 }
 
 void HistoryWidget::setChangesetParents()
--- a/historywidget.h	Tue Nov 30 12:45:34 2010 +0000
+++ b/historywidget.h	Tue Nov 30 13:07:53 2010 +0000
@@ -40,12 +40,15 @@
 
     void parseNewLog(QString log);
     void parseIncrementalLog(QString log);
+
+    bool haveNewItems() const { return !m_newIds.empty(); }
     
 private:
     Changesets m_changesets;
     QStringList m_currentIds;
     QSet<QString> m_newIds;
     UncommittedItem *m_uncommitted;
+    bool m_uncommittedVisible;
 
     Panned *m_panned;
     Panner *m_panner;