Mercurial > hg > svcore
diff 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 |
line wrap: on
line diff
--- a/data/model/ModelDataTableModel.cpp Tue Apr 17 10:54:48 2018 +0100 +++ b/data/model/ModelDataTableModel.cpp Mon Apr 23 16:03:35 2018 +0100 @@ -73,16 +73,12 @@ if (!m_model) return false; if (parent.isValid()) return false; - emit beginInsertRows(parent, row, row); - Command *command = m_model->getInsertRowCommand(getUnsorted(row)); if (command) { emit addCommand(command); } - emit endInsertRows(); - return (command ? true : false); } @@ -92,16 +88,12 @@ if (!m_model) return false; if (parent.isValid()) return false; - emit beginRemoveRows(parent, row, row); - Command *command = m_model->getRemoveRowCommand(getUnsorted(row)); if (command) { emit addCommand(command); } - emit endRemoveRows(); - return (command ? true : false); } @@ -144,7 +136,8 @@ { if (!m_model) return 0; if (parent.isValid()) return 0; - return m_model->getRowCount(); + int count = m_model->getRowCount(); + return count; } int @@ -215,14 +208,37 @@ void ModelDataTableModel::modelChanged() { + SVDEBUG << "ModelDataTableModel::modelChanged" << endl; + QModelIndex ix0; + QModelIndex ix1; + if (rowCount() > 0) { + ix0 = createIndex(0, 0); + int lastCol = columnCount() - 1; + if (lastCol < 0) lastCol = 0; + ix1 = createIndex(rowCount(), lastCol); + } + SVDEBUG << "emitting dataChanged from row " << ix0.row() << " to " << ix1.row() << endl; + emit dataChanged(ix0, ix1); clearSort(); emit layoutChanged(); } void -ModelDataTableModel::modelChangedWithin(sv_frame_t, sv_frame_t) +ModelDataTableModel::modelChangedWithin(sv_frame_t f0, sv_frame_t f1) { - //!!! inefficient + SVDEBUG << "ModelDataTableModel::modelChangedWithin(" << f0 << "," << f1 << ")" << endl; + QModelIndex ix0 = getModelIndexForFrame(f0); + QModelIndex ix1 = getModelIndexForFrame(f1); + int row0 = ix0.row(); + int row1 = ix1.row(); + if (row0 > 0) { + ix0 = createIndex(row0 - 1, ix0.column(), (void *)0); + } + if (row1 + 1 < rowCount()) { + ix1 = createIndex(row1 + 1, ix1.column(), (void *)0); + } + SVDEBUG << "emitting dataChanged from row " << ix0.row() << " to " << ix1.row() << endl; + emit dataChanged(ix0, ix1); clearSort(); emit layoutChanged(); }