comparison data/model/NoteModel.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
comparison
equal deleted inserted replaced
423:6a96bff0bd59 424:eafef13bb0b3
160 indent, 160 indent,
161 QString("%1 valueQuantization=\"%2\"") 161 QString("%1 valueQuantization=\"%2\"")
162 .arg(extraAttributes).arg(m_valueQuantization)); 162 .arg(extraAttributes).arg(m_valueQuantization));
163 } 163 }
164 164
165 /**
166 * TabularModel methods.
167 */
168
169 virtual int getColumnCount() const
170 {
171 return 6;
172 }
173
174 virtual QString getHeading(int column) const
175 {
176 switch (column) {
177 case 0: return tr("Time");
178 case 1: return tr("Frame");
179 case 2: return tr("Pitch");
180 case 3: return tr("Duration");
181 case 4: return tr("Level");
182 case 5: return tr("Label");
183 default: return tr("Unknown");
184 }
185 }
186
187 virtual QVariant getData(int row, int column, int role) const
188 {
189 PointListIterator i = getPointListIteratorForRow(row);
190 if (i == m_points.end()) return QVariant();
191
192 switch (column) {
193 case 0: {
194 if (role == SortRole) return int(i->frame);
195 RealTime rt = RealTime::frame2RealTime(i->frame, getSampleRate());
196 return rt.toText().c_str();
197 }
198 case 1: return int(i->frame);
199 case 2:
200 if (role == Qt::EditRole || role == SortRole) return i->value;
201 else return QString("%1 %2").arg(i->value).arg(getScaleUnits());
202 case 3: return int(i->duration);
203 case 4: return i->level;
204 case 5: return i->label;
205 default: return QVariant();
206 }
207 }
208
209 virtual Command *getSetDataCommand(int row, int column, const QVariant &value, int role)
210 {
211 if (role != Qt::EditRole) return false;
212 PointListIterator i = getPointListIteratorForRow(row);
213 if (i == m_points.end()) return false;
214 EditCommand *command = new EditCommand(this, tr("Edit Data"));
215
216 Point point(*i);
217 command->deletePoint(point);
218
219 switch (column) {
220 case 0: case 1: point.frame = value.toInt(); break;
221 case 2: point.value = value.toDouble(); break;
222 case 3: point.duration = value.toInt(); break;
223 case 4: point.level = value.toDouble(); break;
224 case 5: point.label = value.toString(); break;
225 }
226
227 command->addPoint(point);
228 return command->finish();
229 }
230
231 virtual bool isColumnTimeValue(int column) const
232 {
233 return (column < 2);
234 }
235
236 virtual SortType getSortType(int column) const
237 {
238 if (column == 5) return SortAlphabetical;
239 return SortNumeric;
240 }
241
165 protected: 242 protected:
166 float m_valueQuantization; 243 float m_valueQuantization;
167 }; 244 };
168 245
169 #endif 246 #endif