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@244
|
8 Copyright (c) 2011 Chris Cannam
|
Chris@244
|
9 Copyright (c) 2011 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@397
|
21 #include "changesetview.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@513
|
30 #include <QSettings>
|
Chris@116
|
31
|
Chris@154
|
32 HistoryWidget::HistoryWidget() :
|
Chris@154
|
33 m_showUncommitted(false),
|
Chris@154
|
34 m_refreshNeeded(false)
|
Chris@116
|
35 {
|
Chris@397
|
36 m_panned = new ChangesetView;
|
Chris@116
|
37 m_panner = new Panner;
|
Chris@116
|
38
|
Chris@168
|
39 m_panned->setDragMode(QGraphicsView::ScrollHandDrag);
|
Chris@250
|
40 m_panned->setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
|
Chris@397
|
41 m_panned->setCacheMode(QGraphicsView::CacheNone);
|
Chris@168
|
42
|
Chris@513
|
43 int row = 0;
|
Chris@513
|
44
|
Chris@116
|
45 QGridLayout *layout = new QGridLayout;
|
Chris@513
|
46 layout->setMargin(10);
|
Chris@513
|
47 layout->addWidget(m_panned, row, 0);
|
Chris@513
|
48 layout->addWidget(m_panner, row, 1);
|
Chris@116
|
49 m_panner->setMaximumWidth(80);
|
Chris@116
|
50 m_panner->connectToPanned(m_panned);
|
Chris@116
|
51
|
Chris@513
|
52 layout->setRowStretch(row, 20);
|
Chris@513
|
53
|
Chris@513
|
54 QSettings settings;
|
Chris@513
|
55 settings.beginGroup("Presentation");
|
Chris@513
|
56 bool showClosed = (settings.value("showclosedbranches", false).toBool());
|
Chris@513
|
57
|
Chris@513
|
58 m_showClosedBranches = new QCheckBox(tr("Show closed branches"), this);
|
Chris@513
|
59 m_showClosedBranches->setChecked(showClosed);
|
Chris@513
|
60 connect(m_showClosedBranches, SIGNAL(toggled(bool)),
|
Chris@513
|
61 this, SLOT(showClosedChanged(bool)));
|
Chris@513
|
62 layout->addWidget(m_showClosedBranches, ++row, 0, Qt::AlignLeft);
|
Chris@513
|
63 m_showClosedBranches->hide();
|
Chris@513
|
64
|
Chris@116
|
65 setLayout(layout);
|
Chris@116
|
66 }
|
Chris@116
|
67
|
Chris@116
|
68 HistoryWidget::~HistoryWidget()
|
Chris@116
|
69 {
|
Chris@116
|
70 clearChangesets();
|
Chris@145
|
71 }
|
Chris@145
|
72
|
Chris@145
|
73 QGraphicsScene *HistoryWidget::scene()
|
Chris@145
|
74 {
|
Chris@145
|
75 return m_panned->scene();
|
Chris@116
|
76 }
|
Chris@116
|
77
|
Chris@116
|
78 void HistoryWidget::clearChangesets()
|
Chris@116
|
79 {
|
Chris@116
|
80 foreach (Changeset *cs, m_changesets) delete cs;
|
Chris@116
|
81 m_changesets.clear();
|
Chris@116
|
82 }
|
Chris@128
|
83
|
Chris@153
|
84 void HistoryWidget::setCurrent(QStringList ids, QString branch,
|
Chris@153
|
85 bool showUncommitted)
|
Chris@128
|
86 {
|
Chris@153
|
87 if (m_currentIds == ids &&
|
Chris@153
|
88 m_currentBranch == branch &&
|
Chris@153
|
89 m_showUncommitted == showUncommitted) return;
|
Chris@145
|
90
|
Chris@145
|
91 DEBUG << "HistoryWidget::setCurrent: " << ids.size() << " ids, "
|
Chris@145
|
92 << "showUncommitted: " << showUncommitted << endl;
|
Chris@145
|
93
|
Chris@133
|
94 m_currentIds.clear();
|
Chris@153
|
95 m_currentBranch = branch;
|
Chris@145
|
96 m_showUncommitted = showUncommitted;
|
Chris@145
|
97
|
Chris@145
|
98 if (ids.empty()) return;
|
Chris@145
|
99
|
Chris@133
|
100 foreach (QString id, ids) {
|
Chris@133
|
101 m_currentIds.push_back(id);
|
Chris@133
|
102 }
|
Chris@128
|
103
|
Chris@154
|
104 m_refreshNeeded = true;
|
Chris@128
|
105 }
|
Chris@505
|
106
|
Chris@506
|
107 void HistoryWidget::setClosedHeadIds(QSet<QString> closed)
|
Chris@506
|
108 {
|
Chris@506
|
109 if (closed == m_closedIds) return;
|
Chris@506
|
110 m_closedIds = closed;
|
Chris@513
|
111 m_showClosedBranches->setVisible(!closed.empty());
|
Chris@506
|
112 m_refreshNeeded = true;
|
Chris@506
|
113 }
|
Chris@506
|
114
|
Chris@505
|
115 void HistoryWidget::setShowUncommitted(bool showUncommitted)
|
Chris@505
|
116 {
|
Chris@505
|
117 setCurrent(m_currentIds, m_currentBranch, showUncommitted);
|
Chris@505
|
118 }
|
Chris@513
|
119
|
Chris@513
|
120 void HistoryWidget::showClosedChanged(bool show)
|
Chris@513
|
121 {
|
Chris@513
|
122 QSettings settings;
|
Chris@513
|
123 settings.beginGroup("Presentation");
|
Chris@513
|
124 settings.setValue("showclosedbranches", show);
|
Chris@513
|
125 layoutAll();
|
Chris@513
|
126 }
|
Chris@116
|
127
|
Chris@120
|
128 void HistoryWidget::parseNewLog(QString log)
|
Chris@120
|
129 {
|
Chris@120
|
130 DEBUG << "HistoryWidget::parseNewLog: log has " << log.length() << " chars" << endl;
|
Chris@122
|
131 Changesets csets = Changeset::parseChangesets(log);
|
Chris@120
|
132 DEBUG << "HistoryWidget::parseNewLog: log has " << csets.size() << " changesets" << endl;
|
Chris@133
|
133 replaceChangesets(csets);
|
Chris@154
|
134 m_refreshNeeded = true;
|
Chris@120
|
135 }
|
Chris@120
|
136
|
Chris@120
|
137 void HistoryWidget::parseIncrementalLog(QString log)
|
Chris@120
|
138 {
|
Chris@120
|
139 DEBUG << "HistoryWidget::parseIncrementalLog: log has " << log.length() << " chars" << endl;
|
Chris@122
|
140 Changesets csets = Changeset::parseChangesets(log);
|
Chris@120
|
141 DEBUG << "HistoryWidget::parseIncrementalLog: log has " << csets.size() << " changesets" << endl;
|
Chris@120
|
142 if (!csets.empty()) {
|
Chris@133
|
143 addChangesets(csets);
|
Chris@120
|
144 }
|
Chris@154
|
145 m_refreshNeeded = true;
|
Chris@120
|
146 }
|
Chris@120
|
147
|
Chris@133
|
148 void HistoryWidget::replaceChangesets(Changesets csets)
|
Chris@133
|
149 {
|
Chris@133
|
150 QSet<QString> oldIds;
|
Chris@133
|
151 foreach (Changeset *cs, m_changesets) {
|
Chris@133
|
152 oldIds.insert(cs->id());
|
Chris@133
|
153 }
|
Chris@133
|
154
|
Chris@133
|
155 QSet<QString> newIds;
|
Chris@133
|
156 foreach (Changeset *cs, csets) {
|
Chris@133
|
157 if (!oldIds.contains(cs->id())) {
|
Chris@133
|
158 newIds.insert(cs->id());
|
Chris@133
|
159 }
|
Chris@133
|
160 }
|
Chris@133
|
161
|
Chris@133
|
162 if (newIds.size() == csets.size()) {
|
Chris@133
|
163 // completely new set, unrelated to the old: don't mark new
|
Chris@133
|
164 m_newIds.clear();
|
Chris@133
|
165 } else {
|
Chris@133
|
166 m_newIds = newIds;
|
Chris@133
|
167 }
|
Chris@133
|
168
|
Chris@133
|
169 clearChangesets();
|
Chris@133
|
170 m_changesets = csets;
|
Chris@133
|
171 }
|
Chris@133
|
172
|
Chris@133
|
173 void HistoryWidget::addChangesets(Changesets csets)
|
Chris@133
|
174 {
|
Chris@133
|
175 m_newIds.clear();
|
Chris@138
|
176
|
Chris@138
|
177 if (csets.empty()) return;
|
Chris@138
|
178
|
Chris@133
|
179 foreach (Changeset *cs, csets) {
|
Chris@133
|
180 m_newIds.insert(cs->id());
|
Chris@133
|
181 }
|
Chris@133
|
182
|
Chris@305
|
183 DEBUG << "addChangesets: " << csets.size() << " new changesets have ("
|
Chris@305
|
184 << m_changesets.size() << " already)" << endl;
|
Chris@138
|
185
|
Chris@133
|
186 csets << m_changesets;
|
Chris@133
|
187 m_changesets = csets;
|
Chris@133
|
188 }
|
Chris@133
|
189
|
Chris@154
|
190 void HistoryWidget::update()
|
Chris@154
|
191 {
|
Chris@154
|
192 if (m_refreshNeeded) {
|
Chris@154
|
193 layoutAll();
|
Chris@154
|
194 }
|
Chris@154
|
195 }
|
Chris@154
|
196
|
Chris@120
|
197 void HistoryWidget::layoutAll()
|
Chris@116
|
198 {
|
Chris@154
|
199 m_refreshNeeded = false;
|
Chris@154
|
200
|
Chris@122
|
201 setChangesetParents();
|
Chris@122
|
202
|
Chris@119
|
203 ChangesetScene *scene = new ChangesetScene();
|
Chris@116
|
204 ChangesetItem *tipItem = 0;
|
Chris@116
|
205
|
Chris@138
|
206 QGraphicsScene *oldScene = m_panned->scene();
|
Chris@138
|
207
|
Chris@138
|
208 m_panned->setScene(0);
|
Chris@138
|
209 m_panner->setScene(0);
|
Chris@138
|
210
|
Chris@138
|
211 delete oldScene;
|
Chris@138
|
212
|
Chris@145
|
213 QGraphicsItem *toFocus = 0;
|
Chris@145
|
214
|
Chris@120
|
215 if (!m_changesets.empty()) {
|
Chris@116
|
216 Grapher g(scene);
|
Chris@506
|
217 g.setClosedHeadIds(m_closedIds);
|
Chris@116
|
218 try {
|
Chris@153
|
219 g.layout(m_changesets,
|
Chris@153
|
220 m_showUncommitted ? m_currentIds : QStringList(),
|
Chris@153
|
221 m_currentBranch);
|
Chris@116
|
222 } catch (std::string s) {
|
Chris@116
|
223 std::cerr << "Internal error: Layout failed: " << s << std::endl;
|
Chris@116
|
224 }
|
Chris@145
|
225 toFocus = g.getUncommittedItem();
|
Chris@145
|
226 if (!toFocus) {
|
Chris@371
|
227 if (!m_currentIds.empty()) {
|
Chris@371
|
228 toFocus = g.getItemFor(m_currentIds[0]);
|
Chris@371
|
229 } else {
|
Chris@371
|
230 toFocus = g.getItemFor(m_changesets[0]);
|
Chris@371
|
231 }
|
Chris@145
|
232 }
|
Chris@134
|
233 }
|
Chris@134
|
234
|
Chris@116
|
235 m_panned->setScene(scene);
|
Chris@116
|
236 m_panner->setScene(scene);
|
Chris@116
|
237
|
Chris@133
|
238 updateNewAndCurrentItems();
|
Chris@134
|
239
|
Chris@145
|
240 if (toFocus) {
|
Chris@145
|
241 toFocus->ensureVisible();
|
Chris@134
|
242 }
|
Chris@141
|
243
|
Chris@141
|
244 connectSceneSignals();
|
Chris@116
|
245 }
|
Chris@116
|
246
|
Chris@122
|
247 void HistoryWidget::setChangesetParents()
|
Chris@116
|
248 {
|
Chris@139
|
249 for (int i = 0; i < m_changesets.size(); ++i) {
|
Chris@122
|
250 Changeset *cs = m_changesets[i];
|
Chris@123
|
251 // Need to reset this, as Grapher::layout will recalculate it
|
Chris@123
|
252 // and we don't want to end up with twice the children for
|
Chris@123
|
253 // each parent...
|
Chris@123
|
254 cs->setChildren(QStringList());
|
Chris@139
|
255 }
|
Chris@139
|
256 for (int i = 0; i+1 < m_changesets.size(); ++i) {
|
Chris@139
|
257 Changeset *cs = m_changesets[i];
|
Chris@116
|
258 if (cs->parents().empty()) {
|
Chris@116
|
259 QStringList list;
|
Chris@122
|
260 list.push_back(m_changesets[i+1]->id());
|
Chris@116
|
261 cs->setParents(list);
|
Chris@116
|
262 }
|
Chris@116
|
263 }
|
Chris@116
|
264 }
|
Chris@128
|
265
|
Chris@133
|
266 void HistoryWidget::updateNewAndCurrentItems()
|
Chris@128
|
267 {
|
Chris@128
|
268 QGraphicsScene *scene = m_panned->scene();
|
Chris@128
|
269 if (!scene) return;
|
Chris@133
|
270
|
Chris@128
|
271 QList<QGraphicsItem *> items = scene->items();
|
Chris@128
|
272 foreach (QGraphicsItem *it, items) {
|
Chris@133
|
273
|
Chris@128
|
274 ChangesetItem *csit = dynamic_cast<ChangesetItem *>(it);
|
Chris@133
|
275 if (!csit) continue;
|
Chris@133
|
276
|
Chris@133
|
277 QString id = csit->getChangeset()->id();
|
Chris@133
|
278
|
Chris@133
|
279 bool current = m_currentIds.contains(id);
|
Chris@133
|
280 if (current) {
|
Chris@133
|
281 DEBUG << "id " << id << " is current" << endl;
|
Chris@133
|
282 }
|
Chris@133
|
283 bool newid = m_newIds.contains(id);
|
Chris@133
|
284 if (newid) {
|
Chris@133
|
285 DEBUG << "id " << id << " is new" << endl;
|
Chris@133
|
286 }
|
Chris@147
|
287
|
Chris@506
|
288 if (csit->isCurrent() != current ||
|
Chris@506
|
289 csit->isNew() != newid) {
|
Chris@147
|
290 csit->setCurrent(current);
|
Chris@147
|
291 csit->setNew(newid);
|
Chris@147
|
292 csit->update();
|
Chris@147
|
293 }
|
Chris@128
|
294 }
|
Chris@128
|
295 }
|
Chris@141
|
296
|
Chris@141
|
297 void HistoryWidget::connectSceneSignals()
|
Chris@141
|
298 {
|
Chris@141
|
299 ChangesetScene *scene = qobject_cast<ChangesetScene *>(m_panned->scene());
|
Chris@141
|
300 if (!scene) return;
|
Chris@141
|
301
|
Chris@141
|
302 connect(scene, SIGNAL(commit()),
|
Chris@141
|
303 this, SIGNAL(commit()));
|
Chris@141
|
304
|
Chris@141
|
305 connect(scene, SIGNAL(revert()),
|
Chris@141
|
306 this, SIGNAL(revert()));
|
Chris@141
|
307
|
Chris@141
|
308 connect(scene, SIGNAL(diffWorkingFolder()),
|
Chris@141
|
309 this, SIGNAL(diffWorkingFolder()));
|
Chris@141
|
310
|
Chris@168
|
311 connect(scene, SIGNAL(showSummary()),
|
Chris@168
|
312 this, SIGNAL(showSummary()));
|
Chris@168
|
313
|
Chris@153
|
314 connect(scene, SIGNAL(showWork()),
|
Chris@153
|
315 this, SIGNAL(showWork()));
|
Chris@311
|
316
|
Chris@311
|
317 connect(scene, SIGNAL(newBranch()),
|
Chris@311
|
318 this, SIGNAL(newBranch()));
|
Chris@311
|
319
|
Chris@311
|
320 connect(scene, SIGNAL(noBranch()),
|
Chris@311
|
321 this, SIGNAL(noBranch()));
|
Chris@153
|
322
|
Chris@141
|
323 connect(scene, SIGNAL(updateTo(QString)),
|
Chris@141
|
324 this, SIGNAL(updateTo(QString)));
|
Chris@141
|
325
|
Chris@141
|
326 connect(scene, SIGNAL(diffToCurrent(QString)),
|
Chris@141
|
327 this, SIGNAL(diffToCurrent(QString)));
|
Chris@141
|
328
|
Chris@148
|
329 connect(scene, SIGNAL(diffToParent(QString, QString)),
|
Chris@148
|
330 this, SIGNAL(diffToParent(QString, QString)));
|
Chris@141
|
331
|
Chris@289
|
332 connect(scene, SIGNAL(showSummary(Changeset *)),
|
Chris@289
|
333 this, SIGNAL(showSummary(Changeset *)));
|
Chris@288
|
334
|
Chris@141
|
335 connect(scene, SIGNAL(mergeFrom(QString)),
|
Chris@141
|
336 this, SIGNAL(mergeFrom(QString)));
|
Chris@141
|
337
|
Chris@278
|
338 connect(scene, SIGNAL(newBranch(QString)),
|
Chris@278
|
339 this, SIGNAL(newBranch(QString)));
|
Chris@278
|
340
|
Chris@141
|
341 connect(scene, SIGNAL(tag(QString)),
|
Chris@141
|
342 this, SIGNAL(tag(QString)));
|
Chris@141
|
343 }
|