changeset 116:807c79350bf1

* Pull history tab out into its own widget
author Chris Cannam
date Fri, 26 Nov 2010 22:06:52 +0000
parents 78374cefa10f
children d5db15bf250c
files easyhg.pro hgtabwidget.cpp hgtabwidget.h historywidget.cpp historywidget.h mainwindow.cpp
diffstat 6 files changed, 188 insertions(+), 92 deletions(-) [+]
line wrap: on
line diff
--- a/easyhg.pro	Fri Nov 26 21:48:25 2010 +0000
+++ b/easyhg.pro	Fri Nov 26 22:06:52 2010 +0000
@@ -33,7 +33,8 @@
     filestates.h \
     filestatuswidget.h \
     confirmcommentdialog.h \
-    hgaction.h
+    hgaction.h \
+    historywidget.h
 SOURCES = main.cpp \
     mainwindow.cpp \
     hgtabwidget.cpp \
@@ -57,7 +58,8 @@
     selectablelabel.cpp \
     filestates.cpp \
     filestatuswidget.cpp \
-    confirmcommentdialog.cpp
+    confirmcommentdialog.cpp \
+    historywidget.cpp
 
 macx-* {
     SOURCES += common_osx.mm
--- a/hgtabwidget.cpp	Fri Nov 26 21:48:25 2010 +0000
+++ b/hgtabwidget.cpp	Fri Nov 26 22:06:52 2010 +0000
@@ -17,13 +17,8 @@
 
 #include "hgtabwidget.h"
 #include "common.h"
-#include "logparser.h"
-#include "changeset.h"
-#include "changesetitem.h"
-#include "grapher.h"
-#include "panner.h"
-#include "panned.h"
 #include "filestatuswidget.h"
+#include "historywidget.h"
 
 #include <QClipboard>
 #include <QContextMenuEvent>
@@ -37,57 +32,47 @@
 QTabWidget(parent)
 {
     // Work page
-    fileStatusWidget = new FileStatusWidget;
-    fileStatusWidget->setLocalPath(workFolderPath);
-    fileStatusWidget->setRemoteURL(remoteRepo);
-    connect(fileStatusWidget, SIGNAL(selectionChanged()),
+    m_fileStatusWidget = new FileStatusWidget;
+    m_fileStatusWidget->setLocalPath(workFolderPath);
+    m_fileStatusWidget->setRemoteURL(remoteRepo);
+    connect(m_fileStatusWidget, SIGNAL(selectionChanged()),
             this, SIGNAL(selectionChanged()));
-    addTab(fileStatusWidget, tr("My work"));
+    addTab(m_fileStatusWidget, tr("My work"));
 
     // History graph page
-    historyGraphPageWidget = new QWidget;
-    Panned *panned = new Panned;
-    Panner *panner = new Panner;
-    historyGraphWidget = panned;
-    historyGraphPanner = panner;
-    QGridLayout *layout = new QGridLayout;
-    layout->addWidget(historyGraphWidget, 0, 0);
-    layout->addWidget(historyGraphPanner, 0, 1);
-    panner->setMaximumWidth(80);
-    panner->connectToPanned(panned);
-    historyGraphPageWidget->setLayout(layout);
-    addTab(historyGraphPageWidget, tr("History"));
+    m_historyWidget = new HistoryWidget;
+    addTab(m_historyWidget, tr("History"));
 }
 
 void HgTabWidget::clearSelections()
 {
-    fileStatusWidget->clearSelections();
+    m_fileStatusWidget->clearSelections();
 }
 
 bool HgTabWidget::canCommit() const
 {
-    if (!fileStatusWidget->getSelectedAddableFiles().empty()) return false;
-    return fileStatusWidget->haveChangesToCommit();
+    if (!m_fileStatusWidget->getSelectedAddableFiles().empty()) return false;
+    return m_fileStatusWidget->haveChangesToCommit();
 }
 
 bool HgTabWidget::canRevert() const
 {
-    return fileStatusWidget->haveChangesToCommit() ||
-        !fileStatusWidget->getSelectedRevertableFiles().empty();
+    return m_fileStatusWidget->haveChangesToCommit() ||
+        !m_fileStatusWidget->getSelectedRevertableFiles().empty();
 }
 
 bool HgTabWidget::canAdd() const
 {
-    if (fileStatusWidget->getSelectedAddableFiles().empty()) return false;
-    if (!fileStatusWidget->getSelectedCommittableFiles().empty()) return false;
-    if (!fileStatusWidget->getSelectedRemovableFiles().empty()) return false;
+    if (m_fileStatusWidget->getSelectedAddableFiles().empty()) return false;
+    if (!m_fileStatusWidget->getSelectedCommittableFiles().empty()) return false;
+    if (!m_fileStatusWidget->getSelectedRemovableFiles().empty()) return false;
     return true;
 }
 
 bool HgTabWidget::canRemove() const
 {
-    if (fileStatusWidget->getSelectedRemovableFiles().empty()) return false;
-    if (!fileStatusWidget->getSelectedAddableFiles().empty()) return false;
+    if (m_fileStatusWidget->getSelectedRemovableFiles().empty()) return false;
+    if (!m_fileStatusWidget->getSelectedAddableFiles().empty()) return false;
     return true;
 }
 
@@ -98,94 +83,62 @@
 
 QStringList HgTabWidget::getAllSelectedFiles() const
 {
-    return fileStatusWidget->getAllSelectedFiles();
+    return m_fileStatusWidget->getAllSelectedFiles();
 }
 
 QStringList HgTabWidget::getAllCommittableFiles() const
 {
-    return fileStatusWidget->getAllCommittableFiles();
+    return m_fileStatusWidget->getAllCommittableFiles();
 }
 
 QStringList HgTabWidget::getSelectedCommittableFiles() const
 {
-    return fileStatusWidget->getSelectedCommittableFiles();
+    return m_fileStatusWidget->getSelectedCommittableFiles();
 }
 
 QStringList HgTabWidget::getAllRevertableFiles() const
 {
-    return fileStatusWidget->getAllRevertableFiles();
+    return m_fileStatusWidget->getAllRevertableFiles();
 }
 
 QStringList HgTabWidget::getSelectedRevertableFiles() const
 {
-    return fileStatusWidget->getSelectedRevertableFiles();
+    return m_fileStatusWidget->getSelectedRevertableFiles();
 }
 
 QStringList HgTabWidget::getSelectedAddableFiles() const
 {
-    return fileStatusWidget->getSelectedAddableFiles();
+    return m_fileStatusWidget->getSelectedAddableFiles();
 }
 
 QStringList HgTabWidget::getAllRemovableFiles() const
 {
-    return fileStatusWidget->getAllRemovableFiles();
+    return m_fileStatusWidget->getAllRemovableFiles();
 }
 
 QStringList HgTabWidget::getSelectedRemovableFiles() const
 {
-    return fileStatusWidget->getSelectedRemovableFiles();
+    return m_fileStatusWidget->getSelectedRemovableFiles();
 }
 
 void HgTabWidget::updateWorkFolderFileList(QString fileList)
 {
-    fileStates.parseStates(fileList);
-    fileStatusWidget->setFileStates(fileStates);
+    m_fileStates.parseStates(fileList);
+    m_fileStatusWidget->setFileStates(m_fileStates);
 }
 
 void HgTabWidget::updateLocalRepoHgLogList(QString hgLogList)
 {
-    //!!!
-    Panned *panned = static_cast<Panned *>(historyGraphWidget);
-    Panner *panner = static_cast<Panner *>(historyGraphPanner);
-    QGraphicsScene *scene = new QGraphicsScene();
-    Changesets csets = parseChangeSets(hgLogList);
-    if (csets.empty()) return;
-    Grapher g(scene);
-    try {
-        g.layout(csets);
-    } catch (std::string s) {
-        std::cerr << "Internal error: Layout failed: " << s << std::endl;
-    }
-    QGraphicsScene *oldScene = panned->scene();
-    panned->setScene(scene);
-    panner->setScene(scene);
-    if (oldScene) delete oldScene;
-    ChangesetItem *tipItem = g.getItemFor(csets[0]);
-    if (tipItem) tipItem->ensureVisible();
-    //!!! track lifecycle of those Changesets
-}
-
-Changesets HgTabWidget::parseChangeSets(QString changeSetsStr)
-{
-    Changesets csets = Changeset::parseChangesets(changeSetsStr);
-    for (int i = 0; i+1 < csets.size(); ++i) {
-        Changeset *cs = csets[i];
-        if (cs->parents().empty()) {
-            QStringList list;
-            list.push_back(csets[i+1]->id());
-            cs->setParents(list);
-        }
-    }
-    return csets;
+    m_historyWidget->parseLog(hgLogList);
 }
 
 void HgTabWidget::setWorkFolderAndRepoNames(QString workFolderPath, QString remoteRepoPath)
 {
-    fileStatusWidget->setLocalPath(workFolderPath);
-    fileStatusWidget->setRemoteURL(remoteRepoPath);
+    m_fileStatusWidget->setLocalPath(workFolderPath);
+    m_fileStatusWidget->setRemoteURL(remoteRepoPath);
 }
 
 void HgTabWidget::setState(QString state)
 {
-    fileStatusWidget->setState(state);
+    m_fileStatusWidget->setState(state);
 }
--- a/hgtabwidget.h	Fri Nov 26 21:48:25 2010 +0000
+++ b/hgtabwidget.h	Fri Nov 26 22:06:52 2010 +0000
@@ -31,7 +31,7 @@
 #include <QTabWidget>
 
 class FileStatusWidget;
-
+class HistoryWidget;
 
 class HgTabWidget: public QTabWidget
 {
@@ -45,7 +45,7 @@
     void setWorkFolderAndRepoNames(QString workFolderPath, QString remoteRepoPath);
     void setState(QString state);
 
-    FileStates getFileStates() { return fileStates; }
+    FileStates getFileStates() { return m_fileStates; }
 
     bool canCommit() const;
     bool canRevert() const;
@@ -74,14 +74,9 @@
     void clearSelections();
 
 private:
-    FileStatusWidget *fileStatusWidget;
-
-    QWidget *historyGraphPageWidget;
-    QWidget *historyGraphWidget;
-    QWidget *historyGraphPanner;
-    QWidget *historyPageWidget;
-
-    FileStates fileStates;
+    FileStatusWidget *m_fileStatusWidget;
+    HistoryWidget *m_historyWidget;
+    FileStates m_fileStates;
 
     Changesets parseChangeSets(QString changeSetsStr);
 };
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/historywidget.cpp	Fri Nov 26 22:06:52 2010 +0000
@@ -0,0 +1,94 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
+
+/*
+    EasyMercurial
+
+    Based on HgExplorer by Jari Korhonen
+    Copyright (c) 2010 Jari Korhonen
+    Copyright (c) 2010 Chris Cannam
+    Copyright (c) 2010 Queen Mary, University of London
+    
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.  See the file
+    COPYING included with this distribution for more information.
+*/
+
+#include "historywidget.h"
+
+#include "panned.h"
+#include "panner.h"
+#include "grapher.h"
+#include "debug.h"
+
+#include <iostream>
+
+#include <QGridLayout>
+
+HistoryWidget::HistoryWidget()
+{
+    m_panned = new Panned;
+    m_panner = new Panner;
+
+    QGridLayout *layout = new QGridLayout;
+    layout->addWidget(m_panned, 0, 0);
+    layout->addWidget(m_panner, 0, 1);
+    m_panner->setMaximumWidth(80);
+    m_panner->connectToPanned(m_panned);
+
+    setLayout(layout);
+}
+
+HistoryWidget::~HistoryWidget()
+{
+    clearChangesets();
+}
+
+void HistoryWidget::clearChangesets()
+{
+    foreach (Changeset *cs, m_changesets) delete cs;
+    m_changesets.clear();
+}
+    
+void HistoryWidget::parseLog(QString log)
+{
+    QGraphicsScene *scene = new QGraphicsScene();
+    Changesets csets = parseChangeSets(log);
+    ChangesetItem *tipItem = 0;
+
+    if (!csets.empty()) {
+	Grapher g(scene);
+	try {
+	    g.layout(csets);
+	} catch (std::string s) {
+	    std::cerr << "Internal error: Layout failed: " << s << std::endl;
+	}
+	tipItem = g.getItemFor(csets[0]);
+    }
+
+    QGraphicsScene *oldScene = m_panned->scene();
+    m_panned->setScene(scene);
+    m_panner->setScene(scene);
+
+    if (oldScene) delete oldScene;
+    clearChangesets();
+
+    m_changesets = csets;
+
+    if (tipItem) tipItem->ensureVisible();
+}
+
+Changesets HistoryWidget::parseChangeSets(QString changeSetsStr)
+{
+    Changesets csets = Changeset::parseChangesets(changeSetsStr);
+    for (int i = 0; i+1 < csets.size(); ++i) {
+        Changeset *cs = csets[i];
+        if (cs->parents().empty()) {
+            QStringList list;
+            list.push_back(csets[i+1]->id());
+            cs->setParents(list);
+        }
+    }
+    return csets;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/historywidget.h	Fri Nov 26 22:06:52 2010 +0000
@@ -0,0 +1,48 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
+
+/*
+    EasyMercurial
+
+    Based on HgExplorer by Jari Korhonen
+    Copyright (c) 2010 Jari Korhonen
+    Copyright (c) 2010 Chris Cannam
+    Copyright (c) 2010 Queen Mary, University of London
+    
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.  See the file
+    COPYING included with this distribution for more information.
+*/
+
+#ifndef HISTORYWIDGET_H
+#define HISTORYWIDGET_H
+
+#include "changeset.h"
+
+#include <QWidget>
+
+class Panned;
+class Panner;
+
+class HistoryWidget : public QWidget
+{
+    Q_OBJECT
+
+public:
+    HistoryWidget();
+    virtual ~HistoryWidget();
+
+    void parseLog(QString log);
+    
+private:
+    Changesets m_changesets;
+
+    Panned *m_panned;
+    Panner *m_panner;
+
+    void clearChangesets();
+    Changesets parseChangeSets(QString);
+};
+
+#endif
--- a/mainwindow.cpp	Fri Nov 26 21:48:25 2010 +0000
+++ b/mainwindow.cpp	Fri Nov 26 22:06:52 2010 +0000
@@ -1140,10 +1140,14 @@
     case ACT_REMOVE:
     case ACT_ADD:
     case ACT_COMMIT:
+    case ACT_REVERT:
+        hgTabs->clearSelections();
+        shouldHgStat = true;
+        break;
+
     case ACT_FILEDIFF:
     case ACT_FOLDERDIFF:
     case ACT_CHGSETDIFF:
-    case ACT_REVERT:
     case ACT_SERVE:
     case ACT_TAG:
     case ACT_HG_IGNORE: