Mercurial > hg > svcore
changeset 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 | 743c38b209d0 |
children | 904e031c9c76 |
files | base/ViewManagerBase.h data/model/ModelDataTableModel.cpp data/model/ModelDataTableModel.h |
diffstat | 3 files changed, 31 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/base/ViewManagerBase.h Tue Apr 17 10:54:48 2018 +0100 +++ b/base/ViewManagerBase.h Mon Apr 23 16:03:35 2018 +0100 @@ -13,8 +13,8 @@ COPYING included with this distribution for more information. */ -#ifndef _VIEW_MANAGER_BASE_H_ -#define _VIEW_MANAGER_BASE_H_ +#ifndef SV_VIEW_MANAGER_BASE_H +#define SV_VIEW_MANAGER_BASE_H #include <QObject>
--- 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(); }
--- a/data/model/ModelDataTableModel.h Tue Apr 17 10:54:48 2018 +0100 +++ b/data/model/ModelDataTableModel.h Mon Apr 23 16:03:35 2018 +0100 @@ -13,8 +13,8 @@ COPYING included with this distribution for more information. */ -#ifndef _MODEL_DATA_TABLE_MODEL_H_ -#define _MODEL_DATA_TABLE_MODEL_H_ +#ifndef SV_MODEL_DATA_TABLE_MODEL_H +#define SV_MODEL_DATA_TABLE_MODEL_H #include <QAbstractItemModel>