Mercurial > hg > svcore
comparison data/model/ModelDataTableModel.cpp @ 428:3e1d190048f4
* a bit of progress on retaining current row when sorting changes &c
author | Chris Cannam |
---|---|
date | Tue, 17 Jun 2008 16:07:56 +0000 |
parents | 72ec275e458b |
children | 304fd0223fa6 |
comparison
equal
deleted
inserted
replaced
427:72ec275e458b | 428:3e1d190048f4 |
---|---|
23 #include <iostream> | 23 #include <iostream> |
24 | 24 |
25 ModelDataTableModel::ModelDataTableModel(TabularModel *m) : | 25 ModelDataTableModel::ModelDataTableModel(TabularModel *m) : |
26 m_model(m), | 26 m_model(m), |
27 m_sortColumn(0), | 27 m_sortColumn(0), |
28 m_sortOrdering(Qt::AscendingOrder) | 28 m_sortOrdering(Qt::AscendingOrder), |
29 m_currentRow(0) | |
29 { | 30 { |
30 Model *baseModel = dynamic_cast<Model *>(m); | 31 Model *baseModel = dynamic_cast<Model *>(m); |
31 | 32 |
32 connect(baseModel, SIGNAL(modelChanged()), this, SLOT(modelChanged())); | 33 connect(baseModel, SIGNAL(modelChanged()), this, SLOT(modelChanged())); |
33 connect(baseModel, SIGNAL(modelChanged(size_t, size_t)), | 34 connect(baseModel, SIGNAL(modelChanged(size_t, size_t)), |
154 ModelDataTableModel::getFrameForModelIndex(const QModelIndex &index) const | 155 ModelDataTableModel::getFrameForModelIndex(const QModelIndex &index) const |
155 { | 156 { |
156 return m_model->getFrameForRow(getUnsorted(index.row())); | 157 return m_model->getFrameForRow(getUnsorted(index.row())); |
157 } | 158 } |
158 | 159 |
160 QModelIndex | |
161 ModelDataTableModel::getModelIndexForRow(int row) const | |
162 { | |
163 return createIndex(row, 0, 0); | |
164 } | |
165 | |
159 void | 166 void |
160 ModelDataTableModel::sort(int column, Qt::SortOrder sortOrder) | 167 ModelDataTableModel::sort(int column, Qt::SortOrder sortOrder) |
161 { | 168 { |
162 std::cerr << "ModelDataTableModel::sort(" << column << ", " << sortOrder | 169 std::cerr << "ModelDataTableModel::sort(" << column << ", " << sortOrder |
163 << ")" << std::endl; | 170 << ")" << std::endl; |
171 int prevCurrent = getCurrentRow(); | |
164 if (m_sortColumn != column) { | 172 if (m_sortColumn != column) { |
165 m_sort.clear(); | 173 clearSort(); |
166 } | 174 } |
167 m_sortColumn = column; | 175 m_sortColumn = column; |
168 m_sortOrdering = sortOrder; | 176 m_sortOrdering = sortOrder; |
177 int current = getCurrentRow(); | |
178 if (current != prevCurrent) { | |
179 std::cerr << "Current row changed from " << prevCurrent << " to " << current << " for underlying row " << m_currentRow << std::endl; | |
180 emit currentChanged(createIndex(current, 0, 0)); | |
181 } | |
169 emit layoutChanged(); | 182 emit layoutChanged(); |
170 } | 183 } |
171 | 184 |
172 void | 185 void |
173 ModelDataTableModel::modelChanged() | 186 ModelDataTableModel::modelChanged() |
174 { | 187 { |
175 m_sort.clear(); | 188 clearSort(); |
176 emit layoutChanged(); | 189 emit layoutChanged(); |
177 } | 190 } |
178 | 191 |
179 void | 192 void |
180 ModelDataTableModel::modelChanged(size_t f0, size_t f1) | 193 ModelDataTableModel::modelChanged(size_t f0, size_t f1) |
181 { | 194 { |
182 //!!! inefficient | 195 //!!! inefficient |
183 m_sort.clear(); | 196 clearSort(); |
184 emit layoutChanged(); | 197 emit layoutChanged(); |
185 } | 198 } |
186 | 199 |
187 int | 200 int |
188 ModelDataTableModel::getSorted(int row) const | 201 ModelDataTableModel::getSorted(int row) const |
304 } | 317 } |
305 | 318 |
306 // rsort now maps from sorted row number to original row number | 319 // rsort now maps from sorted row number to original row number |
307 } | 320 } |
308 | 321 |
322 int | |
323 ModelDataTableModel::getCurrentRow() | |
324 { | |
325 return getSorted(m_currentRow); | |
326 } | |
327 | |
328 void | |
329 ModelDataTableModel::setCurrentRow(int row) | |
330 { | |
331 m_currentRow = getUnsorted(row); | |
332 } | |
333 | |
334 void | |
335 ModelDataTableModel::clearSort() | |
336 { | |
337 // int prevCurrent = getCurrentRow(); | |
338 m_sort.clear(); | |
339 // int current = getCurrentRow(); //!!! no -- not until the sort criteria have changed | |
340 // if (current != prevCurrent) { | |
341 // std::cerr << "Current row changed from " << prevCurrent << " to " << current << " for underlying row " << m_currentRow << std::endl; | |
342 // emit currentRowChanged(createIndex(current, 0, 0)); | |
343 // } | |
344 } | |
345 | |
346 |