# HG changeset patch # User Chris Cannam # Date 1298036356 0 # Node ID 1ec306df738e767cffe386d82565463540fda551 # Parent 9162f14c5ab7f5580abc24d8a5ac220662451789# Parent a98e76fa58f2f9142b0d38206da24b44e57add60 Merge diff -r a98e76fa58f2 -r 1ec306df738e changesetitem.cpp --- a/changesetitem.cpp Thu Feb 17 12:10:09 2011 +0000 +++ b/changesetitem.cpp Fri Feb 18 13:39:16 2011 +0000 @@ -16,6 +16,7 @@ */ #include "changesetitem.h" +#include "changesetscene.h" #include "changesetdetailitem.h" #include "changeset.h" #include "textabbrev.h" @@ -121,15 +122,51 @@ menu->addSeparator(); - if (m_changeset->parents().size() > 1) { + QStringList parents = m_changeset->parents(); - foreach (QString parentId, m_changeset->parents()) { - QAction *diffParent = - menu->addAction(tr("Diff to parent %1") - .arg(Changeset::hashOf(parentId))); + if (parents.size() > 1) { + + QString leftId, rightId; + ChangesetScene *cs = dynamic_cast(scene()); + bool havePositions = false; + + if (cs && parents.size() == 2) { + ChangesetItem *i0 = cs->getItemById(parents[0]); + ChangesetItem *i1 = cs->getItemById(parents[1]); + if (i0 && i1) { + if (i0->x() < i1->x()) { + leftId = parents[0]; + rightId = parents[1]; + } else { + leftId = parents[1]; + rightId = parents[0]; + } + havePositions = true; + } + } + + if (havePositions) { + + QAction *diffParent = menu->addAction(tr("Diff to left parent")); connect(diffParent, SIGNAL(triggered()), this, SLOT(diffToParentActivated())); - m_parentDiffActions[diffParent] = parentId; + m_parentDiffActions[diffParent] = leftId; + + diffParent = menu->addAction(tr("Diff to right parent")); + connect(diffParent, SIGNAL(triggered()), + this, SLOT(diffToParentActivated())); + m_parentDiffActions[diffParent] = rightId; + + } else { + + foreach (QString parentId, parents) { + QString text = tr("Diff to parent %1") + .arg(Changeset::hashOf(parentId)); + QAction *diffParent = menu->addAction(text); + connect(diffParent, SIGNAL(triggered()), + this, SLOT(diffToParentActivated())); + m_parentDiffActions[diffParent] = parentId; + } } } else { diff -r a98e76fa58f2 -r 1ec306df738e changesetscene.cpp --- a/changesetscene.cpp Thu Feb 17 12:10:09 2011 +0000 +++ b/changesetscene.cpp Fri Feb 18 13:39:16 2011 +0000 @@ -108,3 +108,13 @@ } } +ChangesetItem * +ChangesetScene::getItemById(QString id) +{ + foreach (QGraphicsItem *it, items()) { + ChangesetItem *csit = dynamic_cast(it); + if (csit && csit->getId() == id) return csit; + } +} + + diff -r a98e76fa58f2 -r 1ec306df738e changesetscene.h --- a/changesetscene.h Thu Feb 17 12:10:09 2011 +0000 +++ b/changesetscene.h Fri Feb 18 13:39:16 2011 +0000 @@ -35,6 +35,8 @@ void addUncommittedItem(UncommittedItem *item); void addDateItem(DateItem *item); + ChangesetItem *getItemById(QString id); // Slow: traversal required + signals: void commit(); void revert(); diff -r a98e76fa58f2 -r 1ec306df738e mainwindow.cpp --- a/mainwindow.cpp Thu Feb 17 12:10:09 2011 +0000 +++ b/mainwindow.cpp Fri Feb 18 13:39:16 2011 +0000 @@ -590,7 +590,7 @@ QStringList params; - // Diff given revision against working folder + // Diff given revision against parent revision params << "--config" << "extensions.extdiff=" << "extdiff"; params << "--program" << diff;