comparison historywidget.cpp @ 133:aaeab914f2a3

* Better attempt at retaining current visible area when history scene changes; first cut at highlighting new items
author Chris Cannam
date Tue, 30 Nov 2010 12:45:34 +0000
parents 4986642800f0
children 1208d9688a8f
comparison
equal deleted inserted replaced
132:16ceeee30e2a 133:aaeab914f2a3
58 58
59 void HistoryWidget::setCurrent(QStringList ids) 59 void HistoryWidget::setCurrent(QStringList ids)
60 { 60 {
61 if (m_currentIds == ids) return; 61 if (m_currentIds == ids) return;
62 DEBUG << "HistoryWidget::setCurrent: " << ids.size() << " ids" << endl; 62 DEBUG << "HistoryWidget::setCurrent: " << ids.size() << " ids" << endl;
63 m_currentIds = ids; 63 m_currentIds.clear();
64 updateCurrentItems(); 64 foreach (QString id, ids) {
65 m_currentIds.push_back(id);
66 }
67 updateNewAndCurrentItems();
65 } 68 }
66 69
67 void HistoryWidget::showUncommittedChanges(bool show) 70 void HistoryWidget::showUncommittedChanges(bool show)
68 { 71 {
69 QGraphicsScene *scene = m_panned->scene(); 72 QGraphicsScene *scene = m_panned->scene();
82 void HistoryWidget::parseNewLog(QString log) 85 void HistoryWidget::parseNewLog(QString log)
83 { 86 {
84 DEBUG << "HistoryWidget::parseNewLog: log has " << log.length() << " chars" << endl; 87 DEBUG << "HistoryWidget::parseNewLog: log has " << log.length() << " chars" << endl;
85 Changesets csets = Changeset::parseChangesets(log); 88 Changesets csets = Changeset::parseChangesets(log);
86 DEBUG << "HistoryWidget::parseNewLog: log has " << csets.size() << " changesets" << endl; 89 DEBUG << "HistoryWidget::parseNewLog: log has " << csets.size() << " changesets" << endl;
87 clearChangesets(); 90 replaceChangesets(csets);
88 m_changesets = csets;
89 layoutAll(); 91 layoutAll();
90 } 92 }
91 93
92 void HistoryWidget::parseIncrementalLog(QString log) 94 void HistoryWidget::parseIncrementalLog(QString log)
93 { 95 {
94 DEBUG << "HistoryWidget::parseIncrementalLog: log has " << log.length() << " chars" << endl; 96 DEBUG << "HistoryWidget::parseIncrementalLog: log has " << log.length() << " chars" << endl;
95 Changesets csets = Changeset::parseChangesets(log); 97 Changesets csets = Changeset::parseChangesets(log);
96 DEBUG << "HistoryWidget::parseIncrementalLog: log has " << csets.size() << " changesets" << endl; 98 DEBUG << "HistoryWidget::parseIncrementalLog: log has " << csets.size() << " changesets" << endl;
97 if (!csets.empty()) { 99 if (!csets.empty()) {
98 csets << m_changesets; 100 addChangesets(csets);
99 m_changesets = csets;
100 layoutAll(); 101 layoutAll();
101 } 102 }
103 }
104
105 void HistoryWidget::replaceChangesets(Changesets csets)
106 {
107 QSet<QString> oldIds;
108 foreach (Changeset *cs, m_changesets) {
109 oldIds.insert(cs->id());
110 }
111
112 QSet<QString> newIds;
113 foreach (Changeset *cs, csets) {
114 if (!oldIds.contains(cs->id())) {
115 newIds.insert(cs->id());
116 }
117 }
118
119 if (newIds.size() == csets.size()) {
120 // completely new set, unrelated to the old: don't mark new
121 m_newIds.clear();
122 } else {
123 m_newIds = newIds;
124 }
125
126 clearChangesets();
127 m_changesets = csets;
128 }
129
130 void HistoryWidget::addChangesets(Changesets csets)
131 {
132 m_newIds.clear();
133 foreach (Changeset *cs, csets) {
134 m_newIds.insert(cs->id());
135 }
136
137 csets << m_changesets;
138 m_changesets = csets;
102 } 139 }
103 140
104 void HistoryWidget::layoutAll() 141 void HistoryWidget::layoutAll()
105 { 142 {
106 setChangesetParents(); 143 setChangesetParents();
126 m_panner->setScene(scene); 163 m_panner->setScene(scene);
127 164
128 if (oldScene) delete oldScene; 165 if (oldScene) delete oldScene;
129 if (tipItem) tipItem->ensureVisible(); 166 if (tipItem) tipItem->ensureVisible();
130 167
131 updateCurrentItems(); 168 updateNewAndCurrentItems();
132 } 169 }
133 170
134 void HistoryWidget::setChangesetParents() 171 void HistoryWidget::setChangesetParents()
135 { 172 {
136 for (int i = 0; i+1 < m_changesets.size(); ++i) { 173 for (int i = 0; i+1 < m_changesets.size(); ++i) {
145 cs->setParents(list); 182 cs->setParents(list);
146 } 183 }
147 } 184 }
148 } 185 }
149 186
150 void HistoryWidget::updateCurrentItems() 187 void HistoryWidget::updateNewAndCurrentItems()
151 { 188 {
152 QGraphicsScene *scene = m_panned->scene(); 189 QGraphicsScene *scene = m_panned->scene();
153 if (!scene) return; 190 if (!scene) return;
191
154 QList<QGraphicsItem *> items = scene->items(); 192 QList<QGraphicsItem *> items = scene->items();
155 foreach (QGraphicsItem *it, items) { 193 foreach (QGraphicsItem *it, items) {
194
156 ChangesetItem *csit = dynamic_cast<ChangesetItem *>(it); 195 ChangesetItem *csit = dynamic_cast<ChangesetItem *>(it);
157 if (csit) { 196 if (!csit) continue;
158 QString id = csit->getChangeset()->id(); 197
159 bool current = m_currentIds.contains(id); 198 QString id = csit->getChangeset()->id();
160 if (current) { 199
161 DEBUG << "id " << id << " is current" << endl; 200 bool current = m_currentIds.contains(id);
162 } 201 if (current) {
163 csit->setCurrent(current); 202 DEBUG << "id " << id << " is current" << endl;
203 }
204 bool newid = m_newIds.contains(id);
205 if (newid) {
206 DEBUG << "id " << id << " is new" << endl;
207 }
208
209 csit->setCurrent(current);
210 csit->setNew(newid);
211
212 if (current) {
164 m_uncommitted->setRow(csit->row() - 1); 213 m_uncommitted->setRow(csit->row() - 1);
165 m_uncommitted->setColumn(csit->column()); 214 m_uncommitted->setColumn(csit->column());
166 m_uncommitted->setWide(csit->isWide()); 215 m_uncommitted->setWide(csit->isWide());
167 m_uncommitted->setBranch(csit->getChangeset()->branch()); 216 m_uncommitted->setBranch(csit->getChangeset()->branch());
168 } 217 }
169 } 218 }
170 } 219 }
171