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@119
|
20 #include "changesetscene.h"
|
Chris@116
|
21 #include "panned.h"
|
Chris@116
|
22 #include "panner.h"
|
Chris@116
|
23 #include "grapher.h"
|
Chris@116
|
24 #include "debug.h"
|
Chris@129
|
25 #include "uncommitteditem.h"
|
Chris@116
|
26
|
Chris@116
|
27 #include <iostream>
|
Chris@116
|
28
|
Chris@116
|
29 #include <QGridLayout>
|
Chris@116
|
30
|
Chris@116
|
31 HistoryWidget::HistoryWidget()
|
Chris@116
|
32 {
|
Chris@116
|
33 m_panned = new Panned;
|
Chris@116
|
34 m_panner = new Panner;
|
Chris@129
|
35 m_uncommitted = new UncommittedItem();
|
Chris@129
|
36 m_uncommitted->setRow(-1);
|
Chris@134
|
37 m_uncommittedVisible = false;
|
Chris@116
|
38
|
Chris@116
|
39 QGridLayout *layout = new QGridLayout;
|
Chris@116
|
40 layout->addWidget(m_panned, 0, 0);
|
Chris@116
|
41 layout->addWidget(m_panner, 0, 1);
|
Chris@116
|
42 m_panner->setMaximumWidth(80);
|
Chris@116
|
43 m_panner->connectToPanned(m_panned);
|
Chris@116
|
44
|
Chris@116
|
45 setLayout(layout);
|
Chris@116
|
46 }
|
Chris@116
|
47
|
Chris@116
|
48 HistoryWidget::~HistoryWidget()
|
Chris@116
|
49 {
|
Chris@116
|
50 clearChangesets();
|
Chris@134
|
51 if (!m_uncommittedVisible) delete m_uncommitted;
|
Chris@116
|
52 }
|
Chris@116
|
53
|
Chris@116
|
54 void HistoryWidget::clearChangesets()
|
Chris@116
|
55 {
|
Chris@116
|
56 foreach (Changeset *cs, m_changesets) delete cs;
|
Chris@116
|
57 m_changesets.clear();
|
Chris@116
|
58 }
|
Chris@128
|
59
|
Chris@128
|
60 void HistoryWidget::setCurrent(QStringList ids)
|
Chris@128
|
61 {
|
Chris@128
|
62 if (m_currentIds == ids) return;
|
Chris@128
|
63 DEBUG << "HistoryWidget::setCurrent: " << ids.size() << " ids" << endl;
|
Chris@133
|
64 m_currentIds.clear();
|
Chris@133
|
65 foreach (QString id, ids) {
|
Chris@133
|
66 m_currentIds.push_back(id);
|
Chris@133
|
67 }
|
Chris@133
|
68 updateNewAndCurrentItems();
|
Chris@128
|
69 }
|
Chris@128
|
70
|
Chris@128
|
71 void HistoryWidget::showUncommittedChanges(bool show)
|
Chris@128
|
72 {
|
Chris@134
|
73 m_uncommittedVisible = show;
|
Chris@134
|
74 layoutAll();
|
Chris@128
|
75 }
|
Chris@116
|
76
|
Chris@120
|
77 void HistoryWidget::parseNewLog(QString log)
|
Chris@120
|
78 {
|
Chris@120
|
79 DEBUG << "HistoryWidget::parseNewLog: log has " << log.length() << " chars" << endl;
|
Chris@122
|
80 Changesets csets = Changeset::parseChangesets(log);
|
Chris@120
|
81 DEBUG << "HistoryWidget::parseNewLog: log has " << csets.size() << " changesets" << endl;
|
Chris@133
|
82 replaceChangesets(csets);
|
Chris@120
|
83 layoutAll();
|
Chris@120
|
84 }
|
Chris@120
|
85
|
Chris@120
|
86 void HistoryWidget::parseIncrementalLog(QString log)
|
Chris@120
|
87 {
|
Chris@120
|
88 DEBUG << "HistoryWidget::parseIncrementalLog: log has " << log.length() << " chars" << endl;
|
Chris@122
|
89 Changesets csets = Changeset::parseChangesets(log);
|
Chris@120
|
90 DEBUG << "HistoryWidget::parseIncrementalLog: log has " << csets.size() << " changesets" << endl;
|
Chris@120
|
91 if (!csets.empty()) {
|
Chris@133
|
92 addChangesets(csets);
|
Chris@120
|
93 layoutAll();
|
Chris@120
|
94 }
|
Chris@120
|
95 }
|
Chris@120
|
96
|
Chris@133
|
97 void HistoryWidget::replaceChangesets(Changesets csets)
|
Chris@133
|
98 {
|
Chris@133
|
99 QSet<QString> oldIds;
|
Chris@133
|
100 foreach (Changeset *cs, m_changesets) {
|
Chris@133
|
101 oldIds.insert(cs->id());
|
Chris@133
|
102 }
|
Chris@133
|
103
|
Chris@133
|
104 QSet<QString> newIds;
|
Chris@133
|
105 foreach (Changeset *cs, csets) {
|
Chris@133
|
106 if (!oldIds.contains(cs->id())) {
|
Chris@133
|
107 newIds.insert(cs->id());
|
Chris@133
|
108 }
|
Chris@133
|
109 }
|
Chris@133
|
110
|
Chris@133
|
111 if (newIds.size() == csets.size()) {
|
Chris@133
|
112 // completely new set, unrelated to the old: don't mark new
|
Chris@133
|
113 m_newIds.clear();
|
Chris@133
|
114 } else {
|
Chris@133
|
115 m_newIds = newIds;
|
Chris@133
|
116 }
|
Chris@133
|
117
|
Chris@133
|
118 clearChangesets();
|
Chris@133
|
119 m_changesets = csets;
|
Chris@133
|
120 }
|
Chris@133
|
121
|
Chris@133
|
122 void HistoryWidget::addChangesets(Changesets csets)
|
Chris@133
|
123 {
|
Chris@133
|
124 m_newIds.clear();
|
Chris@138
|
125
|
Chris@138
|
126 if (csets.empty()) return;
|
Chris@138
|
127
|
Chris@133
|
128 foreach (Changeset *cs, csets) {
|
Chris@133
|
129 m_newIds.insert(cs->id());
|
Chris@133
|
130 }
|
Chris@133
|
131
|
Chris@138
|
132 DEBUG << "addChangesets: " << csets.size() << " new changesets" << endl;
|
Chris@138
|
133
|
Chris@133
|
134 csets << m_changesets;
|
Chris@133
|
135 m_changesets = csets;
|
Chris@133
|
136 }
|
Chris@133
|
137
|
Chris@120
|
138 void HistoryWidget::layoutAll()
|
Chris@116
|
139 {
|
Chris@122
|
140 setChangesetParents();
|
Chris@122
|
141
|
Chris@119
|
142 ChangesetScene *scene = new ChangesetScene();
|
Chris@116
|
143 ChangesetItem *tipItem = 0;
|
Chris@116
|
144
|
Chris@138
|
145 QGraphicsScene *oldScene = m_panned->scene();
|
Chris@138
|
146
|
Chris@138
|
147 // detach m_uncommitted from old scene so it doesn't get deleted
|
Chris@138
|
148 if (oldScene && (m_uncommitted->scene() == oldScene)) {
|
Chris@138
|
149 oldScene->removeItem(m_uncommitted);
|
Chris@138
|
150 }
|
Chris@138
|
151
|
Chris@138
|
152 m_panned->setScene(0);
|
Chris@138
|
153 m_panner->setScene(0);
|
Chris@138
|
154
|
Chris@138
|
155 delete oldScene;
|
Chris@138
|
156
|
Chris@120
|
157 if (!m_changesets.empty()) {
|
Chris@116
|
158 Grapher g(scene);
|
Chris@116
|
159 try {
|
Chris@120
|
160 g.layout(m_changesets);
|
Chris@116
|
161 } catch (std::string s) {
|
Chris@116
|
162 std::cerr << "Internal error: Layout failed: " << s << std::endl;
|
Chris@116
|
163 }
|
Chris@120
|
164 tipItem = g.getItemFor(m_changesets[0]);
|
Chris@120
|
165 DEBUG << "tipItem is " << tipItem << " for tip changeset "
|
Chris@120
|
166 << m_changesets[0]->id() << endl;
|
Chris@116
|
167 }
|
Chris@116
|
168
|
Chris@134
|
169 if (m_uncommittedVisible) {
|
Chris@134
|
170 scene->addItem(m_uncommitted);
|
Chris@134
|
171 }
|
Chris@134
|
172
|
Chris@116
|
173 m_panned->setScene(scene);
|
Chris@116
|
174 m_panner->setScene(scene);
|
Chris@116
|
175
|
Chris@133
|
176 updateNewAndCurrentItems();
|
Chris@134
|
177
|
Chris@134
|
178 if (m_uncommittedVisible) {
|
Chris@134
|
179 m_uncommitted->ensureVisible();
|
Chris@134
|
180 } else if (tipItem) {
|
Chris@134
|
181 DEBUG << "asking tip item to be visible" << endl;
|
Chris@134
|
182 tipItem->ensureVisible();
|
Chris@134
|
183 }
|
Chris@116
|
184 }
|
Chris@116
|
185
|
Chris@122
|
186 void HistoryWidget::setChangesetParents()
|
Chris@116
|
187 {
|
Chris@122
|
188 for (int i = 0; i+1 < m_changesets.size(); ++i) {
|
Chris@122
|
189 Changeset *cs = m_changesets[i];
|
Chris@123
|
190 // Need to reset this, as Grapher::layout will recalculate it
|
Chris@123
|
191 // and we don't want to end up with twice the children for
|
Chris@123
|
192 // each parent...
|
Chris@123
|
193 cs->setChildren(QStringList());
|
Chris@116
|
194 if (cs->parents().empty()) {
|
Chris@116
|
195 QStringList list;
|
Chris@122
|
196 list.push_back(m_changesets[i+1]->id());
|
Chris@116
|
197 cs->setParents(list);
|
Chris@116
|
198 }
|
Chris@116
|
199 }
|
Chris@116
|
200 }
|
Chris@128
|
201
|
Chris@133
|
202 void HistoryWidget::updateNewAndCurrentItems()
|
Chris@128
|
203 {
|
Chris@128
|
204 QGraphicsScene *scene = m_panned->scene();
|
Chris@128
|
205 if (!scene) return;
|
Chris@133
|
206
|
Chris@128
|
207 QList<QGraphicsItem *> items = scene->items();
|
Chris@128
|
208 foreach (QGraphicsItem *it, items) {
|
Chris@133
|
209
|
Chris@128
|
210 ChangesetItem *csit = dynamic_cast<ChangesetItem *>(it);
|
Chris@133
|
211 if (!csit) continue;
|
Chris@133
|
212
|
Chris@133
|
213 QString id = csit->getChangeset()->id();
|
Chris@133
|
214
|
Chris@133
|
215 bool current = m_currentIds.contains(id);
|
Chris@133
|
216 if (current) {
|
Chris@133
|
217 DEBUG << "id " << id << " is current" << endl;
|
Chris@133
|
218 }
|
Chris@133
|
219 bool newid = m_newIds.contains(id);
|
Chris@133
|
220 if (newid) {
|
Chris@133
|
221 DEBUG << "id " << id << " is new" << endl;
|
Chris@133
|
222 }
|
Chris@133
|
223
|
Chris@133
|
224 csit->setCurrent(current);
|
Chris@133
|
225 csit->setNew(newid);
|
Chris@133
|
226
|
Chris@133
|
227 if (current) {
|
Chris@129
|
228 m_uncommitted->setRow(csit->row() - 1);
|
Chris@129
|
229 m_uncommitted->setColumn(csit->column());
|
Chris@129
|
230 m_uncommitted->setWide(csit->isWide());
|
Chris@129
|
231 m_uncommitted->setBranch(csit->getChangeset()->branch());
|
Chris@128
|
232 }
|
Chris@128
|
233 }
|
Chris@128
|
234 }
|