comparison src/grapher.cpp @ 509:6f371814509d

Refactor: sort out changeset structure and parent-child relationships before anything else in grapher. Also stop marking changesets as closed when we reach a change of branch name
author Chris Cannam
date Tue, 18 Oct 2011 11:21:20 +0100
parents c43880dfdb78
children c623ce6b3104
comparison
equal deleted inserted replaced
508:c43880dfdb78 509:6f371814509d
389 389
390 DEBUG << "Grapher::layout: Have " << csets.size() << " changesets" << endl; 390 DEBUG << "Grapher::layout: Have " << csets.size() << " changesets" << endl;
391 391
392 if (csets.empty()) return; 392 if (csets.empty()) return;
393 393
394 // Create (but don't yet position) the changeset items 394 // Initialise changesets hash
395 395
396 foreach (Changeset *cs, csets) { 396 foreach (Changeset *cs, csets) {
397 397
398 QString id = cs->id(); 398 QString id = cs->id();
399 399
405 << " in Grapher::layout()" << endl; 405 << " in Grapher::layout()" << endl;
406 throw LayoutException(QString("Duplicate changeset ID %1").arg(id)); 406 throw LayoutException(QString("Duplicate changeset ID %1").arg(id));
407 } 407 }
408 408
409 m_changesets[id] = cs; 409 m_changesets[id] = cs;
410 410 }
411
412 // Set the children for each changeset
413
414 foreach (Changeset *cs, csets) {
415 QString id = cs->id();
416 foreach (QString parentId, cs->parents()) {
417 if (!m_changesets.contains(parentId)) continue;
418 Changeset *parent = m_changesets[parentId];
419 parent->addChild(id);
420 }
421 }
422
423 // Create (but don't yet position) the changeset items
424
425 foreach (Changeset *cs, csets) {
426 QString id = cs->id();
411 ChangesetItem *item = new ChangesetItem(cs); 427 ChangesetItem *item = new ChangesetItem(cs);
412 item->setX(0); 428 item->setX(0);
413 item->setY(0); 429 item->setY(0);
414 item->setZValue(0); 430 item->setZValue(0);
415 m_items[id] = item; 431 m_items[id] = item;
416 m_scene->addChangesetItem(item); 432 m_scene->addChangesetItem(item);
417 } 433 }
418
419 // Add the connecting lines
420
421 foreach (Changeset *cs, csets) {
422 QString id = cs->id();
423 ChangesetItem *item = m_items[id];
424 bool merge = (cs->parents().size() > 1);
425 foreach (QString parentId, cs->parents()) {
426 if (!m_changesets.contains(parentId)) continue;
427 Changeset *parent = m_changesets[parentId];
428 parent->addChild(id);
429 ConnectionItem *conn = new ConnectionItem();
430 if (merge) conn->setConnectionType(ConnectionItem::Merge);
431 conn->setChild(item);
432 conn->setParent(m_items[parentId]);
433 conn->setZValue(-1);
434 m_scene->addItem(conn);
435 }
436 }
437 434
438 // Ensure the closed branches are all marked as closed 435 // Ensure the closed branches are all marked as closed
439 436
440 foreach (QString closedId, m_closedIds) { 437 foreach (QString closedId, m_closedIds) {
441 438
442 if (!m_items.contains(closedId)) continue; 439 if (!m_items.contains(closedId)) continue;
443 440
444 Changeset *cs = m_changesets[closedId]; 441 Changeset *cs = m_changesets[closedId];
445 ChangesetItem *item = m_items[closedId]; 442 ChangesetItem *item = m_items[closedId];
446 443
444 QString branch = cs->branch();
445
447 item->setClosingCommit(true); 446 item->setClosingCommit(true);
448 447
449 while (cs && item) { 448 while (cs && item) {
450 449
451 if (cs->children().size() > 1) { 450 if (cs->children().size() > 1 || !cs->isOnBranch(branch)) {
452 break; 451 break;
453 } 452 }
454 453
455 item->setClosed(true); 454 item->setClosed(true);
456 455
461 cs = m_changesets[pid]; 460 cs = m_changesets[pid];
462 item = m_items[pid]; 461 item = m_items[pid];
463 } else { 462 } else {
464 item = 0; 463 item = 0;
465 } 464 }
465 }
466 }
467
468 // Add the connecting lines
469
470 foreach (Changeset *cs, csets) {
471 QString id = cs->id();
472 ChangesetItem *item = m_items[id];
473 bool merge = (cs->parents().size() > 1);
474 foreach (QString parentId, cs->parents()) {
475 if (!m_changesets.contains(parentId)) continue;
476 ConnectionItem *conn = new ConnectionItem();
477 if (merge) conn->setConnectionType(ConnectionItem::Merge);
478 conn->setChild(item);
479 conn->setParent(m_items[parentId]);
480 conn->setZValue(-1);
481 m_scene->addItem(conn);
466 } 482 }
467 } 483 }
468 484
469 // Add uncommitted item and connecting line as necessary 485 // Add uncommitted item and connecting line as necessary
470 486