Mercurial > hg > svcore
diff data/model/ImageModel.h @ 424:eafef13bb0b3
* Add more data-editor support to various models
author | Chris Cannam |
---|---|
date | Thu, 12 Jun 2008 14:33:45 +0000 |
parents | 6a96bff0bd59 |
children | f5e8f12d2e58 |
line wrap: on
line diff
--- a/data/model/ImageModel.h Thu Jun 12 10:47:11 2008 +0000 +++ b/data/model/ImageModel.h Thu Jun 12 14:33:45 2008 +0000 @@ -136,6 +136,75 @@ ImagePoint m_oldPoint; ImagePoint m_newPoint; }; + + /** + * TabularModel methods. + */ + + virtual int getColumnCount() const + { + return 4; + } + + virtual QString getHeading(int column) const + { + switch (column) { + case 0: return tr("Time"); + case 1: return tr("Frame"); + case 2: return tr("Image"); + case 3: return tr("Label"); + default: return tr("Unknown"); + } + } + + virtual QVariant getData(int row, int column, int role) const + { + PointListIterator i = getPointListIteratorForRow(row); + if (i == m_points.end()) return QVariant(); + + switch (column) { + case 0: { + if (role == SortRole) return int(i->frame); + RealTime rt = RealTime::frame2RealTime(i->frame, getSampleRate()); + return rt.toText().c_str(); + } + case 1: return int(i->frame); + case 2: return i->image; + case 3: return i->label; + default: return QVariant(); + } + } + + virtual Command *getSetDataCommand(int row, int column, const QVariant &value, int role) + { + if (role != Qt::EditRole) return false; + PointListIterator i = getPointListIteratorForRow(row); + if (i == m_points.end()) return false; + EditCommand *command = new EditCommand(this, tr("Edit Data")); + + Point point(*i); + command->deletePoint(point); + + switch (column) { + case 0: case 1: point.frame = value.toInt(); break; + case 2: point.image = value.toString(); break; + case 3: point.label = value.toString(); break; + } + + command->addPoint(point); + return command->finish(); + } + + virtual bool isColumnTimeValue(int column) const + { + return (column < 2); + } + + virtual SortType getSortType(int column) const + { + if (column > 2) return SortAlphabetical; + return SortNumeric; + } };