Fix resetting or changing the source model of a KRecursiveFilterProxyModel.

We need to disconnect from a previous source model if present, not the new
one, and we need to be prepared for the new source model to be 0.

REVIEW: 126117
wilder
Volker Krause 10 years ago
parent 7f5b5d4158
commit 9f8b448cf4
  1. 38
      src/krecursivefilterproxymodel.cpp

@ -336,26 +336,28 @@ bool KRecursiveFilterProxyModel::acceptRow(int sourceRow, const QModelIndex &sou
void KRecursiveFilterProxyModel::setSourceModel(QAbstractItemModel *model)
{
// Standard disconnect.
if (passRolesToDataChanged()) {
disconnect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector<int>)),
this, SLOT(sourceDataChanged(QModelIndex,QModelIndex,QVector<int>)));
} else {
disconnect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
this, SLOT(sourceDataChanged(QModelIndex,QModelIndex)));
}
// Standard disconnect of the previous source model, if present
if (sourceModel()) {
if (passRolesToDataChanged()) {
disconnect(sourceModel(), SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector<int>)),
this, SLOT(sourceDataChanged(QModelIndex,QModelIndex,QVector<int>)));
} else {
disconnect(sourceModel(), SIGNAL(dataChanged(QModelIndex,QModelIndex)),
this, SLOT(sourceDataChanged(QModelIndex,QModelIndex)));
}
disconnect(model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)),
this, SLOT(sourceRowsAboutToBeInserted(QModelIndex,int,int)));
disconnect(sourceModel(), SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)),
this, SLOT(sourceRowsAboutToBeInserted(QModelIndex,int,int)));
disconnect(model, SIGNAL(rowsInserted(QModelIndex,int,int)),
this, SLOT(sourceRowsInserted(QModelIndex,int,int)));
disconnect(sourceModel(), SIGNAL(rowsInserted(QModelIndex,int,int)),
this, SLOT(sourceRowsInserted(QModelIndex,int,int)));
disconnect(model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),
this, SLOT(sourceRowsAboutToBeRemoved(QModelIndex,int,int)));
disconnect(sourceModel(), SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),
this, SLOT(sourceRowsAboutToBeRemoved(QModelIndex,int,int)));
disconnect(model, SIGNAL(rowsRemoved(QModelIndex,int,int)),
this, SLOT(sourceRowsRemoved(QModelIndex,int,int)));
disconnect(sourceModel(), SIGNAL(rowsRemoved(QModelIndex,int,int)),
this, SLOT(sourceRowsRemoved(QModelIndex,int,int)));
}
QSortFilterProxyModel::setSourceModel(model);
@ -423,6 +425,10 @@ void KRecursiveFilterProxyModel::setSourceModel(QAbstractItemModel *model)
// to see if H matches the filter (which it now does as L now exists).
// That is done in sourceRowsInserted.
if (!model) {
return;
}
if (passRolesToDataChanged()) {
disconnect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector<int>)),
this, SLOT(_q_sourceDataChanged(QModelIndex,QModelIndex,QVector<int>)));

Loading…
Cancel
Save