comparison data/model/SparseTimeValueModel.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
120 } 120 }
121 } 121 }
122 122
123 virtual QVariant getData(int row, int column, int role) const 123 virtual QVariant getData(int row, int column, int role) const
124 { 124 {
125 if (role != Qt::EditRole &&
126 role != Qt::DisplayRole &&
127 role != SortRole) return QVariant();
128 PointListIterator i = getPointListIteratorForRow(row); 125 PointListIterator i = getPointListIteratorForRow(row);
129 if (i == m_points.end()) return QVariant(); 126 if (i == m_points.end()) return QVariant();
130 127
131 switch (column) { 128 switch (column) {
132 case 0: { 129 case 0: {
141 case 3: return i->label; 138 case 3: return i->label;
142 default: return QVariant(); 139 default: return QVariant();
143 } 140 }
144 } 141 }
145 142
146 virtual Command *getSetDataCommand(int row, int column, const QVariant &value, int role) const 143 virtual Command *getSetDataCommand(int row, int column, const QVariant &value, int role)
147 { 144 {
148 if (role != Qt::EditRole) return false; 145 if (role != Qt::EditRole) return false;
149 PointListIterator i = getPointListIteratorForRow(row); 146 PointListIterator i = getPointListIteratorForRow(row);
150 if (i == m_points.end()) { 147 if (i == m_points.end()) return false;
151 std::cerr << "Failed to find point iterator for row " << row << std::endl;
152 return false;
153 }
154 EditCommand *command = new EditCommand(this, tr("Edit Data")); 148 EditCommand *command = new EditCommand(this, tr("Edit Data"));
155 149
156 Point point(*i); 150 Point point(*i);
157 command->deletePoint(point); 151 command->deletePoint(point);
158 152
159 switch (column) { 153 switch (column) {
160 case 0: break; 154 case 0: case 1: point.frame = value.toInt(); break;
161 case 1: break;
162 case 2: point.value = value.toDouble(); break; 155 case 2: point.value = value.toDouble(); break;
163 case 3: point.label = value.toString(); break; 156 case 3: point.label = value.toString(); break;
164 } 157 }
165 158
166 command->addPoint(point); 159 command->addPoint(point);