# HG changeset patch # User Chris Cannam # Date 1213391383 0 # Node ID f5e8f12d2e58f1a8a39c76c2eaeb5ab88c25ce2a # Parent eafef13bb0b3699580c2c8038139a856fd7432bb * 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) diff -r eafef13bb0b3 -r f5e8f12d2e58 data/model/ImageModel.h --- a/data/model/ImageModel.h Thu Jun 12 14:33:45 2008 +0000 +++ b/data/model/ImageModel.h Fri Jun 13 21:09:43 2008 +0000 @@ -159,16 +159,15 @@ virtual QVariant getData(int row, int column, int role) const { + if (column < 2) { + return SparseModel::getData + (row, column, role); + } + 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(); @@ -177,6 +176,11 @@ virtual Command *getSetDataCommand(int row, int column, const QVariant &value, int role) { + if (column < 2) { + return SparseModel::getSetDataCommand + (row, column, value, role); + } + if (role != Qt::EditRole) return false; PointListIterator i = getPointListIteratorForRow(row); if (i == m_points.end()) return false; @@ -186,7 +190,6 @@ 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; } diff -r eafef13bb0b3 -r f5e8f12d2e58 data/model/ModelDataTableModel.cpp --- a/data/model/ModelDataTableModel.cpp Thu Jun 12 14:33:45 2008 +0000 +++ b/data/model/ModelDataTableModel.cpp Fri Jun 13 21:09:43 2008 +0000 @@ -74,9 +74,12 @@ QVariant ModelDataTableModel::headerData(int section, Qt::Orientation orientation, int role) const { + if (orientation == Qt::Vertical && role == Qt::DisplayRole) { + return section + 1; + } if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { return m_model->getHeading(section); - } + } return QVariant(); } diff -r eafef13bb0b3 -r f5e8f12d2e58 data/model/NoteModel.h --- a/data/model/NoteModel.h Thu Jun 12 14:33:45 2008 +0000 +++ b/data/model/NoteModel.h Fri Jun 13 21:09:43 2008 +0000 @@ -186,16 +186,15 @@ virtual QVariant getData(int row, int column, int role) const { + if (column < 2) { + return SparseValueModel::getData + (row, column, role); + } + 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: if (role == Qt::EditRole || role == SortRole) return i->value; else return QString("%1 %2").arg(i->value).arg(getScaleUnits()); @@ -208,6 +207,11 @@ virtual Command *getSetDataCommand(int row, int column, const QVariant &value, int role) { + if (column < 2) { + return SparseValueModel::getSetDataCommand + (row, column, value, role); + } + if (role != Qt::EditRole) return false; PointListIterator i = getPointListIteratorForRow(row); if (i == m_points.end()) return false; diff -r eafef13bb0b3 -r f5e8f12d2e58 data/model/PathModel.h --- a/data/model/PathModel.h Thu Jun 12 14:33:45 2008 +0000 +++ b/data/model/PathModel.h Fri Jun 13 21:09:43 2008 +0000 @@ -80,6 +80,14 @@ QString("%1 subtype=\"path\"") .arg(extraAttributes)); } + + /** + * TabularModel is inherited via SparseModel, but we don't need it here. + */ + virtual QString getHeading(int) const { return ""; } + virtual bool isColumnTimeValue(int) const { return false; } + virtual SortType getSortType(int) const { return SortNumeric; } + }; diff -r eafef13bb0b3 -r f5e8f12d2e58 data/model/SparseModel.h --- a/data/model/SparseModel.h Thu Jun 12 14:33:45 2008 +0000 +++ b/data/model/SparseModel.h Fri Jun 13 21:09:43 2008 +0000 @@ -19,6 +19,7 @@ #include "Model.h" #include "TabularModel.h" #include "base/Command.h" +#include "base/RealTime.h" #include @@ -26,6 +27,8 @@ #include #include +#include + #include #include @@ -286,15 +289,44 @@ return std::distance(m_rows.begin(), i); } - //!!! just for now virtual int getColumnCount() const { return 1; } - virtual QString getHeading(int column) const { return tr("Unknown"); } - virtual QVariant getData(int row, int column, int role) const { + 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()); + if (role == Qt::EditRole) return rt.toString().c_str(); + else return rt.toText().c_str(); + } + case 1: return int(i->frame); + } + return QVariant(); } - virtual bool isColumnTimeValue(int column) const { return true; } - virtual SortType getSortType(int column) const { return SortNumeric; } - + 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: point.frame = lrint(value.toDouble() * getSampleRate()); break; + case 1: point.frame = value.toInt(); break; + } + + command->addPoint(point); + return command->finish(); + } + protected: size_t m_sampleRate; size_t m_resolution; @@ -326,7 +358,7 @@ PointListIterator getPointListIteratorForRow(int row) const { if (m_rows.empty()) rebuildRowVector(); - if (row < 0 || row + 1 > m_rows.size()) return m_points.end(); + if (row < 0 || row + 1 > int(m_rows.size())) return m_points.end(); size_t frame = m_rows[row]; int indexAtFrame = 0; @@ -395,11 +427,14 @@ Model * SparseModel::clone() const { + return 0; //!!! is this ever used? +/* SparseModel *model = new SparseModel(m_sampleRate, m_resolution, m_notifyOnAdd); model->m_points = m_points; model->m_pointCount = m_pointCount; return model; +*/ } template diff -r eafef13bb0b3 -r f5e8f12d2e58 data/model/SparseOneDimensionalModel.h --- a/data/model/SparseOneDimensionalModel.h Thu Jun 12 14:33:45 2008 +0000 +++ b/data/model/SparseOneDimensionalModel.h Fri Jun 13 21:09:43 2008 +0000 @@ -132,16 +132,15 @@ virtual QVariant getData(int row, int column, int role) const { + if (column < 2) { + return SparseModel::getData + (row, column, role); + } + 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 QVariant(rt.toText().c_str()); - } - case 1: return int(i->frame); case 2: return i->label; default: return QVariant(); } @@ -149,6 +148,11 @@ virtual Command *getSetDataCommand(int row, int column, const QVariant &value, int role) { + if (column < 2) { + return SparseModel::getSetDataCommand + (row, column, value, role); + } + if (role != Qt::EditRole) return false; PointListIterator i = getPointListIteratorForRow(row); if (i == m_points.end()) return false; @@ -158,7 +162,6 @@ command->deletePoint(point); switch (column) { - case 0: case 1: point.frame = value.toInt(); break; case 2: point.label = value.toString(); break; } diff -r eafef13bb0b3 -r f5e8f12d2e58 data/model/SparseTimeValueModel.h --- a/data/model/SparseTimeValueModel.h Thu Jun 12 14:33:45 2008 +0000 +++ b/data/model/SparseTimeValueModel.h Fri Jun 13 21:09:43 2008 +0000 @@ -122,16 +122,15 @@ virtual QVariant getData(int row, int column, int role) const { + if (column < 2) { + return SparseValueModel::getData + (row, column, role); + } + 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: if (role == Qt::EditRole || role == SortRole) return i->value; else return QString("%1 %2").arg(i->value).arg(getScaleUnits()); @@ -142,6 +141,11 @@ virtual Command *getSetDataCommand(int row, int column, const QVariant &value, int role) { + if (column < 2) { + return SparseValueModel::getSetDataCommand + (row, column, value, role); + } + if (role != Qt::EditRole) return false; PointListIterator i = getPointListIteratorForRow(row); if (i == m_points.end()) return false; @@ -151,7 +155,6 @@ command->deletePoint(point); switch (column) { - case 0: case 1: point.frame = value.toInt(); break; case 2: point.value = value.toDouble(); break; case 3: point.label = value.toString(); break; } diff -r eafef13bb0b3 -r f5e8f12d2e58 data/model/TabularModel.h --- a/data/model/TabularModel.h Thu Jun 12 14:33:45 2008 +0000 +++ b/data/model/TabularModel.h Fri Jun 13 21:09:43 2008 +0000 @@ -50,7 +50,7 @@ virtual int getRowForFrame(long frame) const = 0; virtual bool isEditable() const { return false; } - virtual Command *getSetDataCommand(int row, int column, const QVariant &, int role) { return 0; } + virtual Command *getSetDataCommand(int /* row */, int /* column */, const QVariant &, int /* role */) { return 0; } }; #endif diff -r eafef13bb0b3 -r f5e8f12d2e58 data/model/TextModel.h --- a/data/model/TextModel.h Thu Jun 12 14:33:45 2008 +0000 +++ b/data/model/TextModel.h Fri Jun 13 21:09:43 2008 +0000 @@ -124,16 +124,15 @@ virtual QVariant getData(int row, int column, int role) const { + if (column < 2) { + return SparseModel::getData + (row, column, role); + } + 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->height; case 3: return i->label; default: return QVariant(); @@ -142,6 +141,11 @@ virtual Command *getSetDataCommand(int row, int column, const QVariant &value, int role) { + if (column < 2) { + return SparseModel::getSetDataCommand + (row, column, value, role); + } + if (role != Qt::EditRole) return false; PointListIterator i = getPointListIteratorForRow(row); if (i == m_points.end()) return false; @@ -151,7 +155,6 @@ command->deletePoint(point); switch (column) { - case 0: case 1: point.frame = value.toInt(); break; case 2: point.height = value.toDouble(); break; case 3: point.label = value.toString(); break; }