Mercurial > hg > easyhg
comparison grapher.cpp @ 47:24efab584ee5
* More graph layout refinements
author | Chris Cannam |
---|---|
date | Wed, 10 Nov 2010 17:30:46 +0000 |
parents | bd3accba9b3f |
children | f9b53c10a3f6 |
comparison
equal
deleted
inserted
replaced
46:bd3accba9b3f | 47:24efab584ee5 |
---|---|
97 if (!m_handled.contains(parentId)) { | 97 if (!m_handled.contains(parentId)) { |
98 layoutCol(parentId); | 98 layoutCol(parentId); |
99 } | 99 } |
100 } | 100 } |
101 | 101 |
102 // Parent may have layed out child in the recursive call | |
103 if (m_handled.contains(id)) { | |
104 std::cerr << "Looks like we've dealt with " << id.toStdString() << std::endl; | |
105 return; | |
106 } | |
107 | |
102 int col = 0; | 108 int col = 0; |
103 int row = item->row(); | 109 int row = item->row(); |
104 QString branch = cs->branch(); | 110 QString branch = cs->branch(); |
111 | |
105 int nparents = cs->parents().size(); | 112 int nparents = cs->parents().size(); |
106 QString parentId; | 113 QString parentId; |
107 int parentsOnSameBranch = 0; | 114 int parentsOnSameBranch = 0; |
108 | 115 |
109 switch (nparents) { | 116 switch (nparents) { |
154 std::cerr << "putting " << cs->id().toStdString() << " at col " << col << std::endl; | 161 std::cerr << "putting " << cs->id().toStdString() << " at col " << col << std::endl; |
155 | 162 |
156 m_alloc[row].insert(col); | 163 m_alloc[row].insert(col); |
157 item->setColumn(col); | 164 item->setColumn(col); |
158 m_handled.insert(id); | 165 m_handled.insert(id); |
166 | |
167 int nchildren = cs->children().size(); | |
168 if (nchildren > 1) { | |
169 // Normally the children will lay out themselves. We just | |
170 // want to handle the case where exactly two children have the | |
171 // same branch as us, because we can handle that neatly | |
172 QList<QString> special; | |
173 foreach (QString childId, cs->children()) { | |
174 if (!m_changesets.contains(childId)) continue; | |
175 Changeset *child = m_changesets[childId]; | |
176 if (child->branch() == branch && | |
177 child->parents().size() == 1) { | |
178 special.push_back(childId); | |
179 } | |
180 } | |
181 if (special.size() == 2) { | |
182 m_items[special[0]]->setColumn | |
183 (findAvailableColumn(item->row() - 1, col - 1, true)); | |
184 m_items[special[1]]->setColumn | |
185 (findAvailableColumn(item->row() - 1, col + 1, true)); | |
186 m_handled.insert(special[0]); | |
187 m_handled.insert(special[1]); | |
188 } | |
189 } | |
159 } | 190 } |
160 | 191 |
161 bool | 192 bool |
162 Grapher::rangesConflict(const Range &r1, const Range &r2) | 193 Grapher::rangesConflict(const Range &r1, const Range &r2) |
163 { | 194 { |
203 if (m_branchHomes.contains(other)) { | 234 if (m_branchHomes.contains(other)) { |
204 taken.insert(m_branchHomes[other]); | 235 taken.insert(m_branchHomes[other]); |
205 } | 236 } |
206 } | 237 } |
207 } | 238 } |
208 int home = 2; | 239 int home = 3; |
209 while (taken.contains(home)) { | 240 while (taken.contains(home)) { |
210 if (home > 0) home = -home; | 241 if (home > 0) home = -home; |
211 else home = -(home-2); | 242 else home = -(home-3); |
212 } | 243 } |
213 m_branchHomes[branch] = home; | 244 m_branchHomes[branch] = home; |
214 } | 245 } |
215 | 246 |
216 foreach (QString branch, m_branchRanges.keys()) { | 247 foreach (QString branch, m_branchRanges.keys()) { |
249 | 280 |
250 foreach (Changeset *cs, csets) { | 281 foreach (Changeset *cs, csets) { |
251 QString id = cs->id(); | 282 QString id = cs->id(); |
252 ChangesetItem *item = m_items[id]; | 283 ChangesetItem *item = m_items[id]; |
253 foreach (QString parentId, cs->parents()) { | 284 foreach (QString parentId, cs->parents()) { |
254 if (!m_items.contains(parentId)) continue; | 285 if (!m_changesets.contains(parentId)) continue; |
286 Changeset *parent = m_changesets[parentId]; | |
287 parent->addChild(id); | |
255 ConnectionItem *conn = new ConnectionItem(); | 288 ConnectionItem *conn = new ConnectionItem(); |
256 conn->setChild(item); | 289 conn->setChild(item); |
257 conn->setParent(m_items[parentId]); | 290 conn->setParent(m_items[parentId]); |
258 m_scene->addItem(conn); | 291 m_scene->addItem(conn); |
259 } | 292 } |
272 | 305 |
273 m_handled.clear(); | 306 m_handled.clear(); |
274 for (int i = csets.size() - 1; i >= 0; --i) { | 307 for (int i = csets.size() - 1; i >= 0; --i) { |
275 layoutCol(csets[i]->id()); | 308 layoutCol(csets[i]->id()); |
276 } | 309 } |
277 /* | 310 } |
278 foreach (Changeset *cs, csets) { | 311 |
279 QString id = cs->id(); | |
280 if (!m_items.contains(id)) continue; | |
281 ChangesetItem *me = m_items[id]; | |
282 foreach (QString parentId, cs->parents()) { | |
283 if (!m_items.contains(parentId)) continue; | |
284 ChangesetItem *parent = m_items[parentId]; | |
285 QGraphicsLineItem *line = new QGraphicsLineItem; | |
286 line->setLine(me->x() + 25, me->y() + 50, | |
287 parent->x() + 25, parent->y()); | |
288 m_scene->addItem(line); | |
289 } | |
290 } | |
291 */ | |
292 } | |
293 |