Mercurial > hg > svcore
comparison data/model/ModelDataTableModel.cpp @ 1455:ec9e65fcf749
The use of the begin/end pairs here just seems to cause too many rows to be deleted (from the visual representation, not the underlying model). Things apparently work better if we just modify the underlying model and let the change signals percolate back up again. To that end, update the change handlers so as to cover their proper ranges with dataChanged signals.
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 16:03:35 +0100 |
parents | cbdd534f517a |
children | 70e172e6cc59 |
comparison
equal
deleted
inserted
replaced
1454:743c38b209d0 | 1455:ec9e65fcf749 |
---|---|
71 ModelDataTableModel::insertRow(int row, const QModelIndex &parent) | 71 ModelDataTableModel::insertRow(int row, const QModelIndex &parent) |
72 { | 72 { |
73 if (!m_model) return false; | 73 if (!m_model) return false; |
74 if (parent.isValid()) return false; | 74 if (parent.isValid()) return false; |
75 | 75 |
76 emit beginInsertRows(parent, row, row); | |
77 | |
78 Command *command = m_model->getInsertRowCommand(getUnsorted(row)); | 76 Command *command = m_model->getInsertRowCommand(getUnsorted(row)); |
79 | 77 |
80 if (command) { | 78 if (command) { |
81 emit addCommand(command); | 79 emit addCommand(command); |
82 } | 80 } |
83 | 81 |
84 emit endInsertRows(); | |
85 | |
86 return (command ? true : false); | 82 return (command ? true : false); |
87 } | 83 } |
88 | 84 |
89 bool | 85 bool |
90 ModelDataTableModel::removeRow(int row, const QModelIndex &parent) | 86 ModelDataTableModel::removeRow(int row, const QModelIndex &parent) |
91 { | 87 { |
92 if (!m_model) return false; | 88 if (!m_model) return false; |
93 if (parent.isValid()) return false; | 89 if (parent.isValid()) return false; |
94 | 90 |
95 emit beginRemoveRows(parent, row, row); | |
96 | |
97 Command *command = m_model->getRemoveRowCommand(getUnsorted(row)); | 91 Command *command = m_model->getRemoveRowCommand(getUnsorted(row)); |
98 | 92 |
99 if (command) { | 93 if (command) { |
100 emit addCommand(command); | 94 emit addCommand(command); |
101 } | 95 } |
102 | |
103 emit endRemoveRows(); | |
104 | 96 |
105 return (command ? true : false); | 97 return (command ? true : false); |
106 } | 98 } |
107 | 99 |
108 Qt::ItemFlags | 100 Qt::ItemFlags |
142 int | 134 int |
143 ModelDataTableModel::rowCount(const QModelIndex &parent) const | 135 ModelDataTableModel::rowCount(const QModelIndex &parent) const |
144 { | 136 { |
145 if (!m_model) return 0; | 137 if (!m_model) return 0; |
146 if (parent.isValid()) return 0; | 138 if (parent.isValid()) return 0; |
147 return m_model->getRowCount(); | 139 int count = m_model->getRowCount(); |
140 return count; | |
148 } | 141 } |
149 | 142 |
150 int | 143 int |
151 ModelDataTableModel::columnCount(const QModelIndex &parent) const | 144 ModelDataTableModel::columnCount(const QModelIndex &parent) const |
152 { | 145 { |
213 } | 206 } |
214 | 207 |
215 void | 208 void |
216 ModelDataTableModel::modelChanged() | 209 ModelDataTableModel::modelChanged() |
217 { | 210 { |
211 SVDEBUG << "ModelDataTableModel::modelChanged" << endl; | |
212 QModelIndex ix0; | |
213 QModelIndex ix1; | |
214 if (rowCount() > 0) { | |
215 ix0 = createIndex(0, 0); | |
216 int lastCol = columnCount() - 1; | |
217 if (lastCol < 0) lastCol = 0; | |
218 ix1 = createIndex(rowCount(), lastCol); | |
219 } | |
220 SVDEBUG << "emitting dataChanged from row " << ix0.row() << " to " << ix1.row() << endl; | |
221 emit dataChanged(ix0, ix1); | |
218 clearSort(); | 222 clearSort(); |
219 emit layoutChanged(); | 223 emit layoutChanged(); |
220 } | 224 } |
221 | 225 |
222 void | 226 void |
223 ModelDataTableModel::modelChangedWithin(sv_frame_t, sv_frame_t) | 227 ModelDataTableModel::modelChangedWithin(sv_frame_t f0, sv_frame_t f1) |
224 { | 228 { |
225 //!!! inefficient | 229 SVDEBUG << "ModelDataTableModel::modelChangedWithin(" << f0 << "," << f1 << ")" << endl; |
230 QModelIndex ix0 = getModelIndexForFrame(f0); | |
231 QModelIndex ix1 = getModelIndexForFrame(f1); | |
232 int row0 = ix0.row(); | |
233 int row1 = ix1.row(); | |
234 if (row0 > 0) { | |
235 ix0 = createIndex(row0 - 1, ix0.column(), (void *)0); | |
236 } | |
237 if (row1 + 1 < rowCount()) { | |
238 ix1 = createIndex(row1 + 1, ix1.column(), (void *)0); | |
239 } | |
240 SVDEBUG << "emitting dataChanged from row " << ix0.row() << " to " << ix1.row() << endl; | |
241 emit dataChanged(ix0, ix1); | |
226 clearSort(); | 242 clearSort(); |
227 emit layoutChanged(); | 243 emit layoutChanged(); |
228 } | 244 } |
229 | 245 |
230 void | 246 void |