comparison data/model/SparseTimeValueModel.h @ 420:50a956688baa

* reorganise tabular data editor model support
author Chris Cannam
date Wed, 11 Jun 2008 16:13:25 +0000
parents 5858cc462d0a
children 397fe91dc8e0
comparison
equal deleted inserted replaced
419:64e7bbb255d3 420:50a956688baa
95 { 95 {
96 // not yet playable 96 // not yet playable
97 } 97 }
98 98
99 QString getTypeName() const { return tr("Sparse Time-Value"); } 99 QString getTypeName() const { return tr("Sparse Time-Value"); }
100
101 /**
102 * TabularModel methods.
103 */
104
105 virtual int getColumnCount() const
106 {
107 return 4;
108 }
109
110 virtual QString getHeading(int column) const
111 {
112 switch (column) {
113 case 0: return tr("Time");
114 case 1: return tr("Frame");
115 case 2: return tr("Value");
116 case 3: return tr("Label");
117 default: return tr("Unknown");
118 }
119 }
120
121 virtual QVariant getData(int row, int column, int role) const
122 {
123 if (role != Qt::EditRole && role != Qt::DisplayRole) return QVariant();
124 PointListIterator i = getPointListIteratorForRow(row);
125 if (i == m_points.end()) return QVariant();
126
127 switch (column) {
128 case 0: {
129 RealTime rt = RealTime::frame2RealTime(i->frame, getSampleRate());
130 return rt.toText().c_str();
131 }
132 case 1: return int(i->frame);
133 case 2:
134 if (role == Qt::EditRole) return i->value;
135 else return QString("%1 %2").arg(i->value).arg(getScaleUnits());
136 case 3: return i->label;
137 default: return QVariant();
138 }
139 }
140
141 virtual Command *setData(int row, int column, QVariant value, int role)
142 {
143 if (role != Qt::EditRole) return false;
144 PointListIterator i = getPointListIteratorForRow(row);
145 if (i == m_points.end()) return false;
146 EditCommand *command = new EditCommand(this, tr("Edit Data"));
147
148 Point point(*i);
149 command->deletePoint(point);
150
151 switch (column) {
152 case 0: break;
153 case 1: break;
154 case 2: point.value = value.toDouble();
155 std::cerr << "setting value of point at " << point.frame << " to " << point.value << std::endl;
156 break;
157 case 3: point.label = value.toString(); break;
158 }
159
160 command->addPoint(point);
161 return command->finish();
162 }
163
164 virtual bool isColumnTimeValue(int column) const
165 {
166 return (column < 2);
167 }
100 }; 168 };
101 169
102 170
103 #endif 171 #endif
104 172