comparison 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
comparison
equal deleted inserted replaced
423:6a96bff0bd59 424:eafef13bb0b3
134 private: 134 private:
135 ImageModel *m_model; 135 ImageModel *m_model;
136 ImagePoint m_oldPoint; 136 ImagePoint m_oldPoint;
137 ImagePoint m_newPoint; 137 ImagePoint m_newPoint;
138 }; 138 };
139
140 /**
141 * TabularModel methods.
142 */
143
144 virtual int getColumnCount() const
145 {
146 return 4;
147 }
148
149 virtual QString getHeading(int column) const
150 {
151 switch (column) {
152 case 0: return tr("Time");
153 case 1: return tr("Frame");
154 case 2: return tr("Image");
155 case 3: return tr("Label");
156 default: return tr("Unknown");
157 }
158 }
159
160 virtual QVariant getData(int row, int column, int role) const
161 {
162 PointListIterator i = getPointListIteratorForRow(row);
163 if (i == m_points.end()) return QVariant();
164
165 switch (column) {
166 case 0: {
167 if (role == SortRole) return int(i->frame);
168 RealTime rt = RealTime::frame2RealTime(i->frame, getSampleRate());
169 return rt.toText().c_str();
170 }
171 case 1: return int(i->frame);
172 case 2: return i->image;
173 case 3: return i->label;
174 default: return QVariant();
175 }
176 }
177
178 virtual Command *getSetDataCommand(int row, int column, const QVariant &value, int role)
179 {
180 if (role != Qt::EditRole) return false;
181 PointListIterator i = getPointListIteratorForRow(row);
182 if (i == m_points.end()) return false;
183 EditCommand *command = new EditCommand(this, tr("Edit Data"));
184
185 Point point(*i);
186 command->deletePoint(point);
187
188 switch (column) {
189 case 0: case 1: point.frame = value.toInt(); break;
190 case 2: point.image = value.toString(); break;
191 case 3: point.label = value.toString(); break;
192 }
193
194 command->addPoint(point);
195 return command->finish();
196 }
197
198 virtual bool isColumnTimeValue(int column) const
199 {
200 return (column < 2);
201 }
202
203 virtual SortType getSortType(int column) const
204 {
205 if (column > 2) return SortAlphabetical;
206 return SortNumeric;
207 }
139 }; 208 };
140 209
141 210
142 #endif 211 #endif
143 212