comparison changesetitem.cpp @ 288:ca6edd303c9d

Add "Summarise changes" options to changeset item right-button menu (already existed for uncommitted item)
author Chris Cannam
date Mon, 21 Feb 2011 11:37:58 +0000
parents 9162f14c5ab7
children 37f67999b661
comparison
equal deleted inserted replaced
285:769ab0fa125d 288:ca6edd303c9d
106 106
107 void 107 void
108 ChangesetItem::activateMenu() 108 ChangesetItem::activateMenu()
109 { 109 {
110 m_parentDiffActions.clear(); 110 m_parentDiffActions.clear();
111 m_summaryActions.clear();
111 112
112 QMenu *menu = new QMenu; 113 QMenu *menu = new QMenu;
113 QLabel *label = new QLabel(tr("<qt><b>&nbsp;Revision: </b>%1</qt>") 114 QLabel *label = new QLabel(tr("<qt><b>&nbsp;Revision: </b>%1</qt>")
114 .arg(Changeset::hashOf(m_changeset->id()))); 115 .arg(Changeset::hashOf(m_changeset->id())));
115 QWidgetAction *wa = new QWidgetAction(menu); 116 QWidgetAction *wa = new QWidgetAction(menu);
118 menu->addSeparator(); 119 menu->addSeparator();
119 120
120 QAction *copyId = menu->addAction(tr("Copy identifier to clipboard")); 121 QAction *copyId = menu->addAction(tr("Copy identifier to clipboard"));
121 connect(copyId, SIGNAL(triggered()), this, SLOT(copyIdActivated())); 122 connect(copyId, SIGNAL(triggered()), this, SLOT(copyIdActivated()));
122 123
123 menu->addSeparator();
124
125 QStringList parents = m_changeset->parents(); 124 QStringList parents = m_changeset->parents();
126 125
126 QString leftId, rightId;
127 bool havePositions = false;
128
127 if (parents.size() > 1) { 129 if (parents.size() > 1) {
128
129 QString leftId, rightId;
130 ChangesetScene *cs = dynamic_cast<ChangesetScene *>(scene()); 130 ChangesetScene *cs = dynamic_cast<ChangesetScene *>(scene());
131 bool havePositions = false;
132
133 if (cs && parents.size() == 2) { 131 if (cs && parents.size() == 2) {
134 ChangesetItem *i0 = cs->getItemById(parents[0]); 132 ChangesetItem *i0 = cs->getItemById(parents[0]);
135 ChangesetItem *i1 = cs->getItemById(parents[1]); 133 ChangesetItem *i1 = cs->getItemById(parents[1]);
136 if (i0 && i1) { 134 if (i0 && i1) {
137 if (i0->x() < i1->x()) { 135 if (i0->x() < i1->x()) {
142 rightId = parents[0]; 140 rightId = parents[0];
143 } 141 }
144 havePositions = true; 142 havePositions = true;
145 } 143 }
146 } 144 }
147 145 }
146
147 if (parents.size() > 1) {
148 if (havePositions) {
149 QAction *stat = menu->addAction(tr("Summarise changes from left parent"));
150 connect(stat, SIGNAL(triggered()), this, SLOT(showSummaryToParentActivated()));
151 m_summaryActions[stat] = leftId;
152
153 stat = menu->addAction(tr("Summarise changes from right parent"));
154 connect(stat, SIGNAL(triggered()), this, SLOT(showSummaryToParentActivated()));
155 m_summaryActions[stat] = rightId;
156 } else {
157
158 foreach (QString parentId, parents) {
159 QString text = tr("Summarise changes from parent %1").arg(Changeset::hashOf(parentId));
160 QAction *stat = menu->addAction(text);
161 connect(stat, SIGNAL(triggered()), this, SLOT(showSummaryToParentActivated()));
162 m_summaryActions[stat] = parentId;
163 }
164
165 }
166 } else {
167 QAction *stat = menu->addAction(tr("Summarise changes"));
168 connect(stat, SIGNAL(triggered()), this, SLOT(showSummaryToParentActivated()));
169 }
170
171 menu->addSeparator();
172
173 if (parents.size() > 1) {
148 if (havePositions) { 174 if (havePositions) {
149 175
150 QAction *diffParent = menu->addAction(tr("Diff to left parent")); 176 QAction *diff = menu->addAction(tr("Diff to left parent"));
151 connect(diffParent, SIGNAL(triggered()), 177 connect(diff, SIGNAL(triggered()), this, SLOT(diffToParentActivated()));
152 this, SLOT(diffToParentActivated())); 178 m_parentDiffActions[diff] = leftId;
153 m_parentDiffActions[diffParent] = leftId;
154 179
155 diffParent = menu->addAction(tr("Diff to right parent")); 180 diff = menu->addAction(tr("Diff to right parent"));
156 connect(diffParent, SIGNAL(triggered()), 181 connect(diff, SIGNAL(triggered()), this, SLOT(diffToParentActivated()));
157 this, SLOT(diffToParentActivated())); 182 m_parentDiffActions[diff] = rightId;
158 m_parentDiffActions[diffParent] = rightId;
159 183
160 } else { 184 } else {
161 185
162 foreach (QString parentId, parents) { 186 foreach (QString parentId, parents) {
163 QString text = tr("Diff to parent %1") 187 QString text = tr("Diff to parent %1").arg(Changeset::hashOf(parentId));
164 .arg(Changeset::hashOf(parentId)); 188 QAction *diff = menu->addAction(text);
165 QAction *diffParent = menu->addAction(text); 189 connect(diff, SIGNAL(triggered()), this, SLOT(diffToParentActivated()));
166 connect(diffParent, SIGNAL(triggered()), 190 m_parentDiffActions[diff] = parentId;
167 this, SLOT(diffToParentActivated()));
168 m_parentDiffActions[diffParent] = parentId;
169 } 191 }
170 } 192 }
171 193
172 } else { 194 } else {
173 195
174 QAction *diffParent = 196 QAction *diff = menu->addAction(tr("Diff to parent"));
175 menu->addAction(tr("Diff to parent")); 197 connect(diff, SIGNAL(triggered()), this, SLOT(diffToParentActivated()));
176 connect(diffParent, SIGNAL(triggered()),
177 this, SLOT(diffToParentActivated()));
178 } 198 }
179 199
180 QAction *diffCurrent = menu->addAction(tr("Diff to current working folder")); 200 QAction *diffCurrent = menu->addAction(tr("Diff to current working folder"));
181 connect(diffCurrent, SIGNAL(triggered()), this, SLOT(diffToCurrentActivated())); 201 connect(diffCurrent, SIGNAL(triggered()), this, SLOT(diffToCurrentActivated()));
182 202
221 } 241 }
222 242
223 emit diffToParent(getId(), parentId); 243 emit diffToParent(getId(), parentId);
224 } 244 }
225 245
246 void ChangesetItem::showSummaryToParentActivated()
247 {
248 QAction *a = qobject_cast<QAction *>(sender());
249 QString parentId;
250 if (m_summaryActions.contains(a)) {
251 parentId = m_summaryActions[a];
252 DEBUG << "ChangesetItem::showSummaryToParentActivated: specific parent "
253 << parentId << " selected" << endl;
254 } else {
255 parentId = m_changeset->parents()[0];
256 DEBUG << "ChangesetItem::showSummaryToParentActivated: "
257 << "no specific parent selected, using first parent "
258 << parentId << endl;
259 }
260
261 emit showSummaryToParent(getId(), parentId);
262 }
263
226 void ChangesetItem::updateActivated() { emit updateTo(getId()); } 264 void ChangesetItem::updateActivated() { emit updateTo(getId()); }
227 void ChangesetItem::diffToCurrentActivated() { emit diffToCurrent(getId()); } 265 void ChangesetItem::diffToCurrentActivated() { emit diffToCurrent(getId()); }
228 void ChangesetItem::mergeActivated() { emit mergeFrom(getId()); } 266 void ChangesetItem::mergeActivated() { emit mergeFrom(getId()); }
229 void ChangesetItem::tagActivated() { emit tag(getId()); } 267 void ChangesetItem::tagActivated() { emit tag(getId()); }
230 268
231 void 269 void
232 ChangesetItem::paint(QPainter *paint, const QStyleOptionGraphicsItem *option, 270 ChangesetItem::paint(QPainter *paint, const QStyleOptionGraphicsItem *, QWidget *)
233 QWidget *w)
234 { 271 {
235 paint->save(); 272 paint->save();
236 273
237 ColourSet *colourSet = ColourSet::instance(); 274 ColourSet *colourSet = ColourSet::instance();
238 QColor branchColour = colourSet->getColourFor(m_changeset->branch()); 275 QColor branchColour = colourSet->getColourFor(m_changeset->branch());