comparison src/grapher.cpp @ 512:67d18eaca830

Hide closed branches by default (contingent on settings). Note that it's now permitted for a changeset id not to be present in m_items in the grapher
author Chris Cannam
date Tue, 18 Oct 2011 11:49:40 +0100
parents f1fe20ff3c07
children fc35aa6d433e
comparison
equal deleted inserted replaced
511:f1fe20ff3c07 512:67d18eaca830
28 m_scene(scene) 28 m_scene(scene)
29 { 29 {
30 QSettings settings; 30 QSettings settings;
31 settings.beginGroup("Presentation"); 31 settings.beginGroup("Presentation");
32 m_showDates = (settings.value("dateformat", 0) == 1); 32 m_showDates = (settings.value("dateformat", 0) == 1);
33 m_showClosedBranches = (settings.value("showclosedbranches", false).toBool());
33 } 34 }
34 35
35 int Grapher::findAvailableColumn(int row, int parent, bool preferParentCol) 36 int Grapher::findAvailableColumn(int row, int parent, bool preferParentCol)
36 { 37 {
37 int col = parent; 38 int col = parent;
67 } 68 }
68 if (!m_changesets.contains(id)) { 69 if (!m_changesets.contains(id)) {
69 throw LayoutException(QString("Changeset %1 not in ID map").arg(id)); 70 throw LayoutException(QString("Changeset %1 not in ID map").arg(id));
70 } 71 }
71 if (!m_items.contains(id)) { 72 if (!m_items.contains(id)) {
72 throw LayoutException(QString("Changeset %1 not in item map").arg(id)); 73 return;
73 } 74 }
74 Changeset *cs = m_changesets[id]; 75 Changeset *cs = m_changesets[id];
75 ChangesetItem *item = m_items[id]; 76 ChangesetItem *item = m_items[id];
76 DEBUG << "layoutRow: Looking at " << id.toStdString() << endl; 77 DEBUG << "layoutRow: Looking at " << id.toStdString() << endl;
77 78
143 } 144 }
144 if (!m_changesets.contains(id)) { 145 if (!m_changesets.contains(id)) {
145 throw LayoutException(QString("Changeset %1 not in ID map").arg(id)); 146 throw LayoutException(QString("Changeset %1 not in ID map").arg(id));
146 } 147 }
147 if (!m_items.contains(id)) { 148 if (!m_items.contains(id)) {
148 throw LayoutException(QString("Changeset %1 not in item map").arg(id)); 149 return;
149 } 150 }
150 151
151 Changeset *cs = m_changesets[id]; 152 Changeset *cs = m_changesets[id];
152 DEBUG << "layoutCol: Looking at " << id.toStdString() << endl; 153 DEBUG << "layoutCol: Looking at " << id.toStdString() << endl;
153 154
173 174
174 if (!m_changesets.contains(parentId) || 175 if (!m_changesets.contains(parentId) ||
175 !m_changesets[parentId]->isOnBranch(branch)) { 176 !m_changesets[parentId]->isOnBranch(branch)) {
176 // new branch 177 // new branch
177 col = m_branchHomes[branch]; 178 col = m_branchHomes[branch];
178 } else { 179 } else if (m_items.contains(parentId)) {
179 col = m_items[parentId]->column(); 180 col = m_items[parentId]->column();
180 } 181 }
181 182
182 col = findAvailableColumn(row, col, true); 183 col = findAvailableColumn(row, col, true);
183 break; 184 break;
189 // out rather than having affinity to a specific branch) 190 // out rather than having affinity to a specific branch)
190 191
191 foreach (QString parentId, cs->parents()) { 192 foreach (QString parentId, cs->parents()) {
192 if (!m_changesets.contains(parentId)) continue; 193 if (!m_changesets.contains(parentId)) continue;
193 if (m_changesets[parentId]->isOnBranch(branch)) { 194 if (m_changesets[parentId]->isOnBranch(branch)) {
194 ChangesetItem *parentItem = m_items[parentId]; 195 if (m_items.contains(parentId)) {
195 col += parentItem->column(); 196 ChangesetItem *parentItem = m_items[parentId];
196 parentsOnSameBranch++; 197 col += parentItem->column();
198 parentsOnSameBranch++;
199 }
197 } 200 }
198 } 201 }
199 202
200 if (parentsOnSameBranch > 0) { 203 if (parentsOnSameBranch > 0) {
201 col /= parentsOnSameBranch; 204 col /= parentsOnSameBranch;
242 // straight line, and make sure nobody is going to overwrite their 245 // straight line, and make sure nobody is going to overwrite their
243 // connection lines 246 // connection lines
244 247
245 foreach (QString childId, cs->children()) { 248 foreach (QString childId, cs->children()) {
246 DEBUG << "reserving connection line space" << endl; 249 DEBUG << "reserving connection line space" << endl;
247 if (!m_changesets.contains(childId)) continue; 250 if (!m_items.contains(childId)) continue;
248 Changeset *child = m_changesets[childId]; 251 Changeset *child = m_changesets[childId];
249 int childRow = m_items[childId]->row(); 252 int childRow = m_items[childId]->row();
250 if (child->parents().size() > 1 || 253 if (child->parents().size() > 1 ||
251 child->isOnBranch(cs->branch())) { 254 child->isOnBranch(cs->branch())) {
252 for (int r = row-1; r > childRow; --r) { 255 for (int r = row-1; r > childRow; --r) {
259 // branch as us: split them to a little either side of our position 262 // branch as us: split them to a little either side of our position
260 263
261 if (nchildren > 1) { 264 if (nchildren > 1) {
262 QList<QString> special; 265 QList<QString> special;
263 foreach (QString childId, cs->children()) { 266 foreach (QString childId, cs->children()) {
264 if (!m_changesets.contains(childId)) continue; 267 if (!m_items.contains(childId)) continue;
265 Changeset *child = m_changesets[childId]; 268 Changeset *child = m_changesets[childId];
266 if (child->isOnBranch(branch) && 269 if (child->isOnBranch(branch) &&
267 child->parents().size() == 1) { 270 child->parents().size() == 1) {
268 special.push_back(childId); 271 special.push_back(childId);
269 } 272 }
296 } 299 }
297 300
298 void Grapher::allocateBranchHomes(Changesets csets) 301 void Grapher::allocateBranchHomes(Changesets csets)
299 { 302 {
300 foreach (Changeset *cs, csets) { 303 foreach (Changeset *cs, csets) {
304 QString id = cs->id();
305 if (!m_items.contains(id)) continue;
306 ChangesetItem *item = m_items[id];
301 QString branch = cs->branch(); 307 QString branch = cs->branch();
302 ChangesetItem *item = m_items[cs->id()];
303 if (!item) continue;
304 int row = item->row(); 308 int row = item->row();
305 if (!m_branchRanges.contains(branch)) { 309 if (!m_branchRanges.contains(branch)) {
306 m_branchRanges[branch] = Range(row, row); 310 m_branchRanges[branch] = Range(row, row);
307 } else { 311 } else {
308 Range p = m_branchRanges[branch]; 312 Range p = m_branchRanges[branch];
449 } 453 }
450 454
451 // Create (but don't yet position) the changeset items 455 // Create (but don't yet position) the changeset items
452 456
453 foreach (Changeset *cs, csets) { 457 foreach (Changeset *cs, csets) {
458 if (cs->closed() && !m_showClosedBranches) continue;
454 QString id = cs->id(); 459 QString id = cs->id();
455 ChangesetItem *item = new ChangesetItem(cs); 460 ChangesetItem *item = new ChangesetItem(cs);
456 item->setX(0); 461 item->setX(0);
457 item->setY(0); 462 item->setY(0);
458 item->setZValue(0); 463 item->setZValue(0);
469 474
470 // Add the connecting lines 475 // Add the connecting lines
471 476
472 foreach (Changeset *cs, csets) { 477 foreach (Changeset *cs, csets) {
473 QString id = cs->id(); 478 QString id = cs->id();
479 if (!m_items.contains(id)) continue;
474 ChangesetItem *item = m_items[id]; 480 ChangesetItem *item = m_items[id];
475 bool merge = (cs->parents().size() > 1); 481 bool merge = (cs->parents().size() > 1);
476 foreach (QString parentId, cs->parents()) { 482 foreach (QString parentId, cs->parents()) {
477 if (!m_changesets.contains(parentId)) continue; 483 if (!m_items.contains(parentId)) continue;
478 ConnectionItem *conn = new ConnectionItem(); 484 ConnectionItem *conn = new ConnectionItem();
479 if (merge) conn->setConnectionType(ConnectionItem::Merge); 485 if (merge) conn->setConnectionType(ConnectionItem::Merge);
480 conn->setChild(item); 486 conn->setChild(item);
481 conn->setParent(m_items[parentId]); 487 conn->setParent(m_items[parentId]);
482 conn->setZValue(-1); 488 conn->setZValue(-1);
493 m_uncommitted->setZValue(10); 499 m_uncommitted->setZValue(10);
494 m_scene->addUncommittedItem(m_uncommitted); 500 m_scene->addUncommittedItem(m_uncommitted);
495 501
496 bool haveParentOnBranch = false; 502 bool haveParentOnBranch = false;
497 foreach (QString p, m_uncommittedParents) { 503 foreach (QString p, m_uncommittedParents) {
504 if (!m_items.contains(p)) continue;
498 ConnectionItem *conn = new ConnectionItem(); 505 ConnectionItem *conn = new ConnectionItem();
499 conn->setConnectionType(ConnectionItem::Merge); 506 conn->setConnectionType(ConnectionItem::Merge);
500 ChangesetItem *pitem = m_items[p]; 507 ChangesetItem *pitem = m_items[p];
501 conn->setParent(pitem); 508 conn->setParent(pitem);
502 conn->setChild(m_uncommitted); 509 conn->setChild(m_uncommitted);
520 527
521 // Add the branch labels 528 // Add the branch labels
522 529
523 foreach (Changeset *cs, csets) { 530 foreach (Changeset *cs, csets) {
524 QString id = cs->id(); 531 QString id = cs->id();
532 if (!m_items.contains(id)) continue;
525 ChangesetItem *item = m_items[id]; 533 ChangesetItem *item = m_items[id];
526 bool haveChildOnSameBranch = false; 534 bool haveChildOnSameBranch = false;
527 foreach (QString childId, cs->children()) { 535 foreach (QString childId, cs->children()) {
528 Changeset *child = m_changesets[childId]; 536 Changeset *child = m_changesets[childId];
529 if (child->branch() == cs->branch()) { 537 if (child->branch() == cs->branch()) {
603 611
604 // Changeset items that have nothing to either side of them can be 612 // Changeset items that have nothing to either side of them can be
605 // made double-width 613 // made double-width
606 614
607 foreach (Changeset *cs, csets) { 615 foreach (Changeset *cs, csets) {
608 ChangesetItem *item = m_items[cs->id()]; 616 QString id = cs->id();
617 if (!m_items.contains(id)) continue;
618 ChangesetItem *item = m_items[id];
609 if (isAvailable(item->row(), item->column()-1) && 619 if (isAvailable(item->row(), item->column()-1) &&
610 isAvailable(item->row(), item->column()+1)) { 620 isAvailable(item->row(), item->column()+1)) {
611 item->setWide(true); 621 item->setWide(true);
612 } 622 }
613 } 623 }