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