comparison data/model/SparseOneDimensionalModel.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 eafef13bb0b3
children 72ec275e458b
comparison
equal deleted inserted replaced
424:eafef13bb0b3 425:f5e8f12d2e58
130 } 130 }
131 } 131 }
132 132
133 virtual QVariant getData(int row, int column, int role) const 133 virtual QVariant getData(int row, int column, int role) const
134 { 134 {
135 if (column < 2) {
136 return SparseModel<OneDimensionalPoint>::getData
137 (row, column, role);
138 }
139
135 PointListIterator i = getPointListIteratorForRow(row); 140 PointListIterator i = getPointListIteratorForRow(row);
136 if (i == m_points.end()) return QVariant(); 141 if (i == m_points.end()) return QVariant();
137 142
138 switch (column) { 143 switch (column) {
139 case 0: {
140 if (role == SortRole) return int(i->frame);
141 RealTime rt = RealTime::frame2RealTime(i->frame, getSampleRate());
142 return QVariant(rt.toText().c_str());
143 }
144 case 1: return int(i->frame);
145 case 2: return i->label; 144 case 2: return i->label;
146 default: return QVariant(); 145 default: return QVariant();
147 } 146 }
148 } 147 }
149 148
150 virtual Command *getSetDataCommand(int row, int column, const QVariant &value, int role) 149 virtual Command *getSetDataCommand(int row, int column, const QVariant &value, int role)
151 { 150 {
151 if (column < 2) {
152 return SparseModel<OneDimensionalPoint>::getSetDataCommand
153 (row, column, value, role);
154 }
155
152 if (role != Qt::EditRole) return false; 156 if (role != Qt::EditRole) return false;
153 PointListIterator i = getPointListIteratorForRow(row); 157 PointListIterator i = getPointListIteratorForRow(row);
154 if (i == m_points.end()) return false; 158 if (i == m_points.end()) return false;
155 EditCommand *command = new EditCommand(this, tr("Edit Data")); 159 EditCommand *command = new EditCommand(this, tr("Edit Data"));
156 160
157 Point point(*i); 161 Point point(*i);
158 command->deletePoint(point); 162 command->deletePoint(point);
159 163
160 switch (column) { 164 switch (column) {
161 case 0: case 1: point.frame = value.toInt(); break;
162 case 2: point.label = value.toString(); break; 165 case 2: point.label = value.toString(); break;
163 } 166 }
164 167
165 command->addPoint(point); 168 command->addPoint(point);
166 return command->finish(); 169 return command->finish();