comparison data/model/TextModel.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
99 QString("%1 subtype=\"text\"") 99 QString("%1 subtype=\"text\"")
100 .arg(extraAttributes)); 100 .arg(extraAttributes));
101 } 101 }
102 102
103 QString getTypeName() const { return tr("Text"); } 103 QString getTypeName() const { return tr("Text"); }
104
105 /**
106 * TabularModel methods.
107 */
108
109 virtual int getColumnCount() const
110 {
111 return 4;
112 }
113
114 virtual QString getHeading(int column) const
115 {
116 switch (column) {
117 case 0: return tr("Time");
118 case 1: return tr("Frame");
119 case 2: return tr("Height");
120 case 3: return tr("Label");
121 default: return tr("Unknown");
122 }
123 }
124
125 virtual QVariant getData(int row, int column, int role) const
126 {
127 PointListIterator i = getPointListIteratorForRow(row);
128 if (i == m_points.end()) return QVariant();
129
130 switch (column) {
131 case 0: {
132 if (role == SortRole) return int(i->frame);
133 RealTime rt = RealTime::frame2RealTime(i->frame, getSampleRate());
134 return rt.toText().c_str();
135 }
136 case 1: return int(i->frame);
137 case 2: return i->height;
138 case 3: return i->label;
139 default: return QVariant();
140 }
141 }
142
143 virtual Command *getSetDataCommand(int row, int column, const QVariant &value, int role)
144 {
145 if (role != Qt::EditRole) return false;
146 PointListIterator i = getPointListIteratorForRow(row);
147 if (i == m_points.end()) return false;
148 EditCommand *command = new EditCommand(this, tr("Edit Data"));
149
150 Point point(*i);
151 command->deletePoint(point);
152
153 switch (column) {
154 case 0: case 1: point.frame = value.toInt(); break;
155 case 2: point.height = value.toDouble(); break;
156 case 3: point.label = value.toString(); break;
157 }
158
159 command->addPoint(point);
160 return command->finish();
161 }
162
163 virtual bool isColumnTimeValue(int column) const
164 {
165 return (column < 2);
166 }
167
168 virtual SortType getSortType(int column) const
169 {
170 if (column == 3) return SortAlphabetical;
171 return SortNumeric;
172 }
173
104 }; 174 };
105 175
106 176
107 #endif 177 #endif
108 178