Mercurial > hg > svcore
comparison data/model/SparseModel.h @ 425:f5e8f12d2e58
* Add audio device selection to preferences
* Add (not yet functional) insert, delete, edit buttons to data edit window
* Add proper set methods for time fields in data edit window (using general
sparse model base class)
author | Chris Cannam |
---|---|
date | Fri, 13 Jun 2008 21:09:43 +0000 |
parents | 4caa28a0a8a2 |
children | 72ec275e458b |
comparison
equal
deleted
inserted
replaced
424:eafef13bb0b3 | 425:f5e8f12d2e58 |
---|---|
17 #define _SPARSE_MODEL_H_ | 17 #define _SPARSE_MODEL_H_ |
18 | 18 |
19 #include "Model.h" | 19 #include "Model.h" |
20 #include "TabularModel.h" | 20 #include "TabularModel.h" |
21 #include "base/Command.h" | 21 #include "base/Command.h" |
22 #include "base/RealTime.h" | |
22 | 23 |
23 #include <iostream> | 24 #include <iostream> |
24 | 25 |
25 #include <set> | 26 #include <set> |
26 #include <vector> | 27 #include <vector> |
27 #include <algorithm> | 28 #include <algorithm> |
29 | |
30 #include <cmath> | |
28 | 31 |
29 #include <QMutex> | 32 #include <QMutex> |
30 #include <QTextStream> | 33 #include <QTextStream> |
31 | 34 |
32 /** | 35 /** |
284 std::vector<long>::iterator i = | 287 std::vector<long>::iterator i = |
285 std::lower_bound(m_rows.begin(), m_rows.end(), frame); | 288 std::lower_bound(m_rows.begin(), m_rows.end(), frame); |
286 return std::distance(m_rows.begin(), i); | 289 return std::distance(m_rows.begin(), i); |
287 } | 290 } |
288 | 291 |
289 //!!! just for now | |
290 virtual int getColumnCount() const { return 1; } | 292 virtual int getColumnCount() const { return 1; } |
291 virtual QString getHeading(int column) const { return tr("Unknown"); } | 293 virtual QVariant getData(int row, int column, int role) const |
292 virtual QVariant getData(int row, int column, int role) const { | 294 { |
295 PointListIterator i = getPointListIteratorForRow(row); | |
296 if (i == m_points.end()) return QVariant(); | |
297 | |
298 switch (column) { | |
299 case 0: { | |
300 if (role == SortRole) return int(i->frame); | |
301 RealTime rt = RealTime::frame2RealTime(i->frame, getSampleRate()); | |
302 if (role == Qt::EditRole) return rt.toString().c_str(); | |
303 else return rt.toText().c_str(); | |
304 } | |
305 case 1: return int(i->frame); | |
306 } | |
307 | |
293 return QVariant(); | 308 return QVariant(); |
294 } | 309 } |
295 virtual bool isColumnTimeValue(int column) const { return true; } | 310 virtual Command *getSetDataCommand(int row, int column, |
296 virtual SortType getSortType(int column) const { return SortNumeric; } | 311 const QVariant &value, int role) |
297 | 312 { |
313 if (role != Qt::EditRole) return false; | |
314 PointListIterator i = getPointListIteratorForRow(row); | |
315 if (i == m_points.end()) return false; | |
316 EditCommand *command = new EditCommand(this, tr("Edit Data")); | |
317 | |
318 Point point(*i); | |
319 command->deletePoint(point); | |
320 | |
321 switch (column) { | |
322 case 0: point.frame = lrint(value.toDouble() * getSampleRate()); break; | |
323 case 1: point.frame = value.toInt(); break; | |
324 } | |
325 | |
326 command->addPoint(point); | |
327 return command->finish(); | |
328 } | |
329 | |
298 protected: | 330 protected: |
299 size_t m_sampleRate; | 331 size_t m_sampleRate; |
300 size_t m_resolution; | 332 size_t m_resolution; |
301 bool m_notifyOnAdd; | 333 bool m_notifyOnAdd; |
302 long m_sinceLastNotifyMin; | 334 long m_sinceLastNotifyMin; |
324 } | 356 } |
325 | 357 |
326 PointListIterator getPointListIteratorForRow(int row) const | 358 PointListIterator getPointListIteratorForRow(int row) const |
327 { | 359 { |
328 if (m_rows.empty()) rebuildRowVector(); | 360 if (m_rows.empty()) rebuildRowVector(); |
329 if (row < 0 || row + 1 > m_rows.size()) return m_points.end(); | 361 if (row < 0 || row + 1 > int(m_rows.size())) return m_points.end(); |
330 | 362 |
331 size_t frame = m_rows[row]; | 363 size_t frame = m_rows[row]; |
332 int indexAtFrame = 0; | 364 int indexAtFrame = 0; |
333 int ri = row; | 365 int ri = row; |
334 while (ri > 0 && m_rows[ri-1] == m_rows[row]) { --ri; ++indexAtFrame; } | 366 while (ri > 0 && m_rows[ri-1] == m_rows[row]) { --ri; ++indexAtFrame; } |
393 | 425 |
394 template <typename PointType> | 426 template <typename PointType> |
395 Model * | 427 Model * |
396 SparseModel<PointType>::clone() const | 428 SparseModel<PointType>::clone() const |
397 { | 429 { |
430 return 0; //!!! is this ever used? | |
431 /* | |
398 SparseModel<PointType> *model = | 432 SparseModel<PointType> *model = |
399 new SparseModel<PointType>(m_sampleRate, m_resolution, m_notifyOnAdd); | 433 new SparseModel<PointType>(m_sampleRate, m_resolution, m_notifyOnAdd); |
400 model->m_points = m_points; | 434 model->m_points = m_points; |
401 model->m_pointCount = m_pointCount; | 435 model->m_pointCount = m_pointCount; |
402 return model; | 436 return model; |
437 */ | |
403 } | 438 } |
404 | 439 |
405 template <typename PointType> | 440 template <typename PointType> |
406 bool | 441 bool |
407 SparseModel<PointType>::isEmpty() const | 442 SparseModel<PointType>::isEmpty() const |