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