annotate hgexpwidget.cpp @ 92:06f4fffd5287

* Rename StatParser to FileStates; start thinking about selections
author Chris Cannam
date Wed, 24 Nov 2010 13:23:30 +0000
parents 879af4608c5e
children 44ed7766d55a
rev   line source
Chris@57 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@57 2
Chris@57 3 /*
Chris@57 4 EasyMercurial
Chris@57 5
Chris@57 6 Based on HgExplorer by Jari Korhonen
Chris@57 7 Copyright (c) 2010 Jari Korhonen
Chris@57 8 Copyright (c) 2010 Chris Cannam
Chris@57 9 Copyright (c) 2010 Queen Mary, University of London
Chris@57 10
Chris@57 11 This program is free software; you can redistribute it and/or
Chris@57 12 modify it under the terms of the GNU General Public License as
Chris@57 13 published by the Free Software Foundation; either version 2 of the
Chris@57 14 License, or (at your option) any later version. See the file
Chris@57 15 COPYING included with this distribution for more information.
Chris@57 16 */
jtkorhonen@0 17
jtkorhonen@0 18 #include "hgexpwidget.h"
jtkorhonen@0 19 #include "common.h"
Chris@43 20 #include "logparser.h"
Chris@43 21 #include "changeset.h"
Chris@43 22 #include "changesetitem.h"
Chris@44 23 #include "grapher.h"
cannam@45 24 #include "panner.h"
cannam@45 25 #include "panned.h"
Chris@88 26 #include "filestatuswidget.h"
Chris@44 27
Chris@50 28 #include <QClipboard>
Chris@50 29 #include <QContextMenuEvent>
Chris@50 30 #include <QApplication>
Chris@50 31
Chris@44 32 #include <iostream>
jtkorhonen@0 33
Chris@88 34 HgExpWidget::HgExpWidget(QWidget *parent, QString remoteRepo,
Chris@88 35 QString workFolderPath,
Chris@88 36 unsigned char viewFileTypesBits) :
Chris@88 37 QTabWidget(parent)
jtkorhonen@0 38 {
Chris@91 39 // Work page
Chris@88 40 fileStatusWidget = new FileStatusWidget;
Chris@89 41 fileStatusWidget->setLocalPath(workFolderPath);
Chris@89 42 fileStatusWidget->setRemoteURL(remoteRepo);
Chris@89 43 addTab(fileStatusWidget, tr("My work"));
Chris@88 44
Chris@43 45 // History graph page
cannam@45 46 historyGraphPageWidget = new QWidget;
cannam@45 47 Panned *panned = new Panned;
cannam@45 48 Panner *panner = new Panner;
cannam@45 49 historyGraphWidget = panned;
cannam@45 50 historyGraphPanner = panner;
cannam@45 51 QGridLayout *layout = new QGridLayout;
cannam@45 52 layout->addWidget(historyGraphWidget, 0, 0);
cannam@45 53 layout->addWidget(historyGraphPanner, 0, 1);
cannam@45 54 panner->setMaximumWidth(80);
cannam@45 55 panner->connectToPanned(panned);
cannam@45 56 historyGraphPageWidget->setLayout(layout);
Chris@58 57 addTab(historyGraphPageWidget, tr("History"));
jtkorhonen@32 58 }
jtkorhonen@32 59
Chris@90 60 bool HgExpWidget::canCommit() const
Chris@90 61 {
Chris@90 62 return fileStatusWidget->haveChangesToCommit();
Chris@90 63 }
jtkorhonen@0 64
jtkorhonen@0 65 void HgExpWidget::updateWorkFolderFileList(QString fileList)
jtkorhonen@0 66 {
Chris@92 67 fileStates = FileStates(fileList);
Chris@92 68 fileStatusWidget->setFileStates(fileStates);
jtkorhonen@0 69 }
jtkorhonen@0 70
jtkorhonen@0 71 void HgExpWidget::updateLocalRepoHgLogList(QString hgLogList)
jtkorhonen@0 72 {
Chris@43 73 //!!!
cannam@45 74 Panned *panned = static_cast<Panned *>(historyGraphWidget);
cannam@45 75 Panner *panner = static_cast<Panner *>(historyGraphPanner);
Chris@43 76 QGraphicsScene *scene = new QGraphicsScene();
Chris@43 77 Changesets csets = parseChangeSets(hgLogList);
Chris@44 78 if (csets.empty()) return;
Chris@53 79 Grapher g(scene);
Chris@44 80 try {
Chris@53 81 g.layout(csets);
Chris@44 82 } catch (std::string s) {
Chris@44 83 std::cerr << "Internal error: Layout failed: " << s << std::endl;
Chris@44 84 }
Chris@87 85 QGraphicsScene *oldScene = panned->scene();
cannam@45 86 panned->setScene(scene);
cannam@45 87 panner->setScene(scene);
Chris@87 88 if (oldScene) delete oldScene;
Chris@53 89 ChangesetItem *tipItem = g.getItemFor(csets[0]);
Chris@53 90 if (tipItem) tipItem->ensureVisible();
jtkorhonen@0 91 }
jtkorhonen@0 92
Chris@43 93 Changesets HgExpWidget::parseChangeSets(QString changeSetsStr)
Chris@43 94 {
Chris@43 95 Changesets csets;
Chris@43 96 LogList log = LogParser(changeSetsStr).parse();
Chris@43 97 foreach (LogEntry e, log) {
Chris@43 98 Changeset *cs = new Changeset();
Chris@43 99 foreach (QString key, e.keys()) {
Chris@44 100 if (key == "parents") {
Chris@44 101 QStringList parents = e.value(key).split
Chris@44 102 (" ", QString::SkipEmptyParts);
Chris@44 103 cs->setParents(parents);
Chris@52 104 } else if (key == "timestamp") {
Chris@52 105 cs->setTimestamp(e.value(key).split(" ")[0].toULongLong());
Chris@44 106 } else {
Chris@44 107 cs->setProperty(key.toLocal8Bit().data(), e.value(key));
Chris@44 108 }
Chris@43 109 }
Chris@43 110 csets.push_back(cs);
Chris@43 111 }
Chris@44 112 for (int i = 0; i+1 < csets.size(); ++i) {
Chris@44 113 Changeset *cs = csets[i];
Chris@44 114 if (cs->parents().empty()) {
Chris@44 115 QStringList list;
Chris@44 116 list.push_back(csets[i+1]->id());
Chris@44 117 cs->setParents(list);
Chris@44 118 }
Chris@44 119 }
Chris@43 120 return csets;
jtkorhonen@0 121 }
jtkorhonen@0 122
jtkorhonen@0 123 void HgExpWidget::setWorkFolderAndRepoNames(QString workFolderPath, QString remoteRepoPath)
jtkorhonen@0 124 {
Chris@89 125 fileStatusWidget->setLocalPath(workFolderPath);
Chris@89 126 fileStatusWidget->setRemoteURL(remoteRepoPath);
jtkorhonen@0 127 }