Mercurial > hg > easyhg
comparison historywidget.cpp @ 116:807c79350bf1
* Pull history tab out into its own widget
author | Chris Cannam |
---|---|
date | Fri, 26 Nov 2010 22:06:52 +0000 |
parents | |
children | 005a54380502 |
comparison
equal
deleted
inserted
replaced
115:78374cefa10f | 116:807c79350bf1 |
---|---|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ | |
2 | |
3 /* | |
4 EasyMercurial | |
5 | |
6 Based on HgExplorer by Jari Korhonen | |
7 Copyright (c) 2010 Jari Korhonen | |
8 Copyright (c) 2010 Chris Cannam | |
9 Copyright (c) 2010 Queen Mary, University of London | |
10 | |
11 This program is free software; you can redistribute it and/or | |
12 modify it under the terms of the GNU General Public License as | |
13 published by the Free Software Foundation; either version 2 of the | |
14 License, or (at your option) any later version. See the file | |
15 COPYING included with this distribution for more information. | |
16 */ | |
17 | |
18 #include "historywidget.h" | |
19 | |
20 #include "panned.h" | |
21 #include "panner.h" | |
22 #include "grapher.h" | |
23 #include "debug.h" | |
24 | |
25 #include <iostream> | |
26 | |
27 #include <QGridLayout> | |
28 | |
29 HistoryWidget::HistoryWidget() | |
30 { | |
31 m_panned = new Panned; | |
32 m_panner = new Panner; | |
33 | |
34 QGridLayout *layout = new QGridLayout; | |
35 layout->addWidget(m_panned, 0, 0); | |
36 layout->addWidget(m_panner, 0, 1); | |
37 m_panner->setMaximumWidth(80); | |
38 m_panner->connectToPanned(m_panned); | |
39 | |
40 setLayout(layout); | |
41 } | |
42 | |
43 HistoryWidget::~HistoryWidget() | |
44 { | |
45 clearChangesets(); | |
46 } | |
47 | |
48 void HistoryWidget::clearChangesets() | |
49 { | |
50 foreach (Changeset *cs, m_changesets) delete cs; | |
51 m_changesets.clear(); | |
52 } | |
53 | |
54 void HistoryWidget::parseLog(QString log) | |
55 { | |
56 QGraphicsScene *scene = new QGraphicsScene(); | |
57 Changesets csets = parseChangeSets(log); | |
58 ChangesetItem *tipItem = 0; | |
59 | |
60 if (!csets.empty()) { | |
61 Grapher g(scene); | |
62 try { | |
63 g.layout(csets); | |
64 } catch (std::string s) { | |
65 std::cerr << "Internal error: Layout failed: " << s << std::endl; | |
66 } | |
67 tipItem = g.getItemFor(csets[0]); | |
68 } | |
69 | |
70 QGraphicsScene *oldScene = m_panned->scene(); | |
71 m_panned->setScene(scene); | |
72 m_panner->setScene(scene); | |
73 | |
74 if (oldScene) delete oldScene; | |
75 clearChangesets(); | |
76 | |
77 m_changesets = csets; | |
78 | |
79 if (tipItem) tipItem->ensureVisible(); | |
80 } | |
81 | |
82 Changesets HistoryWidget::parseChangeSets(QString changeSetsStr) | |
83 { | |
84 Changesets csets = Changeset::parseChangesets(changeSetsStr); | |
85 for (int i = 0; i+1 < csets.size(); ++i) { | |
86 Changeset *cs = csets[i]; | |
87 if (cs->parents().empty()) { | |
88 QStringList list; | |
89 list.push_back(csets[i+1]->id()); | |
90 cs->setParents(list); | |
91 } | |
92 } | |
93 return csets; | |
94 } |