comparison data/model/ModelDataTableModel.cpp @ 618:b1dc68507e46 sv-v1.7.1

* Layer data editor window: fix sorting for columns in region model, add Find feature * RDF import: assign names to layers based on event types, if no suitable labels are found in the RDF * Add label to status bar showing the last text that was passed in current layer (so e.g. counting 1, 2, 3, 4 if that's what beats are labelled) * Better layout of text labels for region layers in segmentation mode when they are close together * Give text layer the same method for finding "nearest point" as region and note layers, should improve its editability
author Chris Cannam
date Thu, 22 Oct 2009 15:54:21 +0000
parents ba7aaacb7211
children b4a8d8221eaf
comparison
equal deleted inserted replaced
617:24f06d34ac99 618:b1dc68507e46
167 { 167 {
168 if (!m_model) return 0; 168 if (!m_model) return 0;
169 return m_model->getFrameForRow(getUnsorted(index.row())); 169 return m_model->getFrameForRow(getUnsorted(index.row()));
170 } 170 }
171 171
172 QModelIndex
173 ModelDataTableModel::findText(QString text) const
174 {
175 if (text == "") return QModelIndex();
176 int rows = rowCount();
177 int cols = columnCount();
178 int current = getCurrentRow();
179 for (int row = 1; row <= rows; ++row) {
180 int wrapped = (row + current) % rows;
181 for (int col = 0; col < cols; ++col) {
182 if (m_model->getSortType(col) != TabularModel::SortAlphabetical) {
183 continue;
184 }
185 QString cell = m_model->getData(getUnsorted(wrapped), col,
186 Qt::DisplayRole).toString();
187 if (cell.contains(text, Qt::CaseInsensitive)) {
188 return createIndex(wrapped, col);
189 }
190 }
191 }
192 return QModelIndex();
193 }
194
172 void 195 void
173 ModelDataTableModel::sort(int column, Qt::SortOrder sortOrder) 196 ModelDataTableModel::sort(int column, Qt::SortOrder sortOrder)
174 { 197 {
175 // std::cerr << "ModelDataTableModel::sort(" << column << ", " << sortOrder 198 // std::cerr << "ModelDataTableModel::sort(" << column << ", " << sortOrder
176 // << ")" << std::endl; 199 // << ")" << std::endl;
272 if (!m_model) return; 295 if (!m_model) return;
273 296
274 bool numeric = (m_model->getSortType(m_sortColumn) == 297 bool numeric = (m_model->getSortType(m_sortColumn) ==
275 TabularModel::SortNumeric); 298 TabularModel::SortNumeric);
276 299
300 // std::cerr << "resort: numeric == " << numeric << std::endl;
301
277 m_sort.clear(); 302 m_sort.clear();
278 m_rsort.clear(); 303 m_rsort.clear();
279 304
280 if (numeric) resortNumeric(); 305 if (numeric) resortNumeric();
281 else resortAlphabetical(); 306 else resortAlphabetical();
311 QVariant value = m_model->getData(i, m_sortColumn, TabularModel::SortRole); 336 QVariant value = m_model->getData(i, m_sortColumn, TabularModel::SortRole);
312 rowMap.insert(MapType::value_type(value.toDouble(), i)); 337 rowMap.insert(MapType::value_type(value.toDouble(), i));
313 } 338 }
314 339
315 for (MapType::iterator i = rowMap.begin(); i != rowMap.end(); ++i) { 340 for (MapType::iterator i = rowMap.begin(); i != rowMap.end(); ++i) {
341 // std::cerr << "resortNumeric: " << i->second << ": " << i->first << std::endl;
316 m_rsort.push_back(i->second); 342 m_rsort.push_back(i->second);
317 } 343 }
318 344
319 // rsort now maps from sorted row number to original row number 345 // rsort now maps from sorted row number to original row number
320 } 346 }
334 m_model->getData(i, m_sortColumn, TabularModel::SortRole); 360 m_model->getData(i, m_sortColumn, TabularModel::SortRole);
335 rowMap.insert(MapType::value_type(value.toString(), i)); 361 rowMap.insert(MapType::value_type(value.toString(), i));
336 } 362 }
337 363
338 for (MapType::iterator i = rowMap.begin(); i != rowMap.end(); ++i) { 364 for (MapType::iterator i = rowMap.begin(); i != rowMap.end(); ++i) {
365 // std::cerr << "resortAlphabetical: " << i->second << ": " << i->first.toStdString() << std::endl;
339 m_rsort.push_back(i->second); 366 m_rsort.push_back(i->second);
340 } 367 }
341 368
342 // rsort now maps from sorted row number to original row number 369 // rsort now maps from sorted row number to original row number
343 } 370 }
344 371
345 int 372 int
346 ModelDataTableModel::getCurrentRow() 373 ModelDataTableModel::getCurrentRow() const
347 { 374 {
348 return getSorted(m_currentRow); 375 return getSorted(m_currentRow);
349 } 376 }
350 377
351 void 378 void