From fae4a2555a9402e8cecf67242b29dca624cc61e8 Mon Sep 17 00:00:00 2001 From: kb Date: Fri, 9 Mar 2012 12:29:09 +0100 Subject: Disconnect slots from the old sourcemodel in QIdentityProxyModel When setting a new sourcemodel QIdentityProxyModel::setSourceModel tries to disconnect from signals belonging to the NEW model instead of from the existing sourceModel(). QIdentityProxyModel thus receives signals from both the old model(s) and the new model. This results in ASSERTS triggering in various slots, for example: "Q_ASSERT(topLeft.isValid() ? topLeft.model() == model : true);" in QIdentityProxyModelPrivate::_q_sourceDataChanged. Change-Id: Ic6f65a9ee10981d00206335f2edef78272fadc1a Reviewed-by: Stephen Kelly --- src/corelib/itemmodels/qidentityproxymodel.cpp | 80 +++++++++++++------------- 1 file changed, 40 insertions(+), 40 deletions(-) (limited to 'src/corelib/itemmodels') diff --git a/src/corelib/itemmodels/qidentityproxymodel.cpp b/src/corelib/itemmodels/qidentityproxymodel.cpp index 1f95ac0660..9cac40469a 100644 --- a/src/corelib/itemmodels/qidentityproxymodel.cpp +++ b/src/corelib/itemmodels/qidentityproxymodel.cpp @@ -328,87 +328,87 @@ QVariant QIdentityProxyModel::headerData(int section, Qt::Orientation orientatio /*! \reimp */ -void QIdentityProxyModel::setSourceModel(QAbstractItemModel* sourceModel) +void QIdentityProxyModel::setSourceModel(QAbstractItemModel* newSourceModel) { beginResetModel(); - if (sourceModel) { - disconnect(sourceModel, SIGNAL(rowsAboutToBeInserted(const QModelIndex &, int, int)), + if (sourceModel()) { + disconnect(sourceModel(), SIGNAL(rowsAboutToBeInserted(const QModelIndex &, int, int)), this, SLOT(_q_sourceRowsAboutToBeInserted(const QModelIndex &, int, int))); - disconnect(sourceModel, SIGNAL(rowsInserted(const QModelIndex &, int, int)), + disconnect(sourceModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)), this, SLOT(_q_sourceRowsInserted(const QModelIndex &, int, int))); - disconnect(sourceModel, SIGNAL(rowsAboutToBeRemoved(const QModelIndex &, int, int)), + disconnect(sourceModel(), SIGNAL(rowsAboutToBeRemoved(const QModelIndex &, int, int)), this, SLOT(_q_sourceRowsAboutToBeRemoved(const QModelIndex &, int, int))); - disconnect(sourceModel, SIGNAL(rowsRemoved(const QModelIndex &, int, int)), + disconnect(sourceModel(), SIGNAL(rowsRemoved(const QModelIndex &, int, int)), this, SLOT(_q_sourceRowsRemoved(const QModelIndex &, int, int))); - disconnect(sourceModel, SIGNAL(rowsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int)), + disconnect(sourceModel(), SIGNAL(rowsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int)), this, SLOT(_q_sourceRowsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int))); - disconnect(sourceModel, SIGNAL(rowsMoved(const QModelIndex &, int, int, const QModelIndex &, int)), + disconnect(sourceModel(), SIGNAL(rowsMoved(const QModelIndex &, int, int, const QModelIndex &, int)), this, SLOT(_q_sourceRowsMoved(const QModelIndex &, int, int, const QModelIndex &, int))); - disconnect(sourceModel, SIGNAL(columnsAboutToBeInserted(const QModelIndex &, int, int)), + disconnect(sourceModel(), SIGNAL(columnsAboutToBeInserted(const QModelIndex &, int, int)), this, SLOT(_q_sourceColumnsAboutToBeInserted(const QModelIndex &, int, int))); - disconnect(sourceModel, SIGNAL(columnsInserted(const QModelIndex &, int, int)), + disconnect(sourceModel(), SIGNAL(columnsInserted(const QModelIndex &, int, int)), this, SLOT(_q_sourceColumnsInserted(const QModelIndex &, int, int))); - disconnect(sourceModel, SIGNAL(columnsAboutToBeRemoved(const QModelIndex &, int, int)), + disconnect(sourceModel(), SIGNAL(columnsAboutToBeRemoved(const QModelIndex &, int, int)), this, SLOT(_q_sourceColumnsAboutToBeRemoved(const QModelIndex &, int, int))); - disconnect(sourceModel, SIGNAL(columnsRemoved(const QModelIndex &, int, int)), + disconnect(sourceModel(), SIGNAL(columnsRemoved(const QModelIndex &, int, int)), this, SLOT(_q_sourceColumnsRemoved(const QModelIndex &, int, int))); - disconnect(sourceModel, SIGNAL(columnsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int)), + disconnect(sourceModel(), SIGNAL(columnsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int)), this, SLOT(_q_sourceColumnsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int))); - disconnect(sourceModel, SIGNAL(columnsMoved(const QModelIndex &, int, int, const QModelIndex &, int)), + disconnect(sourceModel(), SIGNAL(columnsMoved(const QModelIndex &, int, int, const QModelIndex &, int)), this, SLOT(_q_sourceColumnsMoved(const QModelIndex &, int, int, const QModelIndex &, int))); - disconnect(sourceModel, SIGNAL(modelAboutToBeReset()), + disconnect(sourceModel(), SIGNAL(modelAboutToBeReset()), this, SLOT(_q_sourceModelAboutToBeReset())); - disconnect(sourceModel, SIGNAL(modelReset()), + disconnect(sourceModel(), SIGNAL(modelReset()), this, SLOT(_q_sourceModelReset())); - disconnect(sourceModel, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)), + disconnect(sourceModel(), SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)), this, SLOT(_q_sourceDataChanged(const QModelIndex &, const QModelIndex &))); - disconnect(sourceModel, SIGNAL(headerDataChanged(Qt::Orientation,int,int)), + disconnect(sourceModel(), SIGNAL(headerDataChanged(Qt::Orientation,int,int)), this, SLOT(_q_sourceHeaderDataChanged(Qt::Orientation,int,int))); - disconnect(sourceModel, SIGNAL(layoutAboutToBeChanged()), + disconnect(sourceModel(), SIGNAL(layoutAboutToBeChanged()), this, SLOT(_q_sourceLayoutAboutToBeChanged())); - disconnect(sourceModel, SIGNAL(layoutChanged()), + disconnect(sourceModel(), SIGNAL(layoutChanged()), this, SLOT(_q_sourceLayoutChanged())); } - QAbstractProxyModel::setSourceModel(sourceModel); + QAbstractProxyModel::setSourceModel(newSourceModel); - if (sourceModel) { - connect(sourceModel, SIGNAL(rowsAboutToBeInserted(const QModelIndex &, int, int)), + if (sourceModel()) { + connect(sourceModel(), SIGNAL(rowsAboutToBeInserted(const QModelIndex &, int, int)), SLOT(_q_sourceRowsAboutToBeInserted(const QModelIndex &, int, int))); - connect(sourceModel, SIGNAL(rowsInserted(const QModelIndex &, int, int)), + connect(sourceModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)), SLOT(_q_sourceRowsInserted(const QModelIndex &, int, int))); - connect(sourceModel, SIGNAL(rowsAboutToBeRemoved(const QModelIndex &, int, int)), + connect(sourceModel(), SIGNAL(rowsAboutToBeRemoved(const QModelIndex &, int, int)), SLOT(_q_sourceRowsAboutToBeRemoved(const QModelIndex &, int, int))); - connect(sourceModel, SIGNAL(rowsRemoved(const QModelIndex &, int, int)), + connect(sourceModel(), SIGNAL(rowsRemoved(const QModelIndex &, int, int)), SLOT(_q_sourceRowsRemoved(const QModelIndex &, int, int))); - connect(sourceModel, SIGNAL(rowsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int)), + connect(sourceModel(), SIGNAL(rowsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int)), SLOT(_q_sourceRowsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int))); - connect(sourceModel, SIGNAL(rowsMoved(const QModelIndex &, int, int, const QModelIndex &, int)), + connect(sourceModel(), SIGNAL(rowsMoved(const QModelIndex &, int, int, const QModelIndex &, int)), SLOT(_q_sourceRowsMoved(const QModelIndex &, int, int, const QModelIndex &, int))); - connect(sourceModel, SIGNAL(columnsAboutToBeInserted(const QModelIndex &, int, int)), + connect(sourceModel(), SIGNAL(columnsAboutToBeInserted(const QModelIndex &, int, int)), SLOT(_q_sourceColumnsAboutToBeInserted(const QModelIndex &, int, int))); - connect(sourceModel, SIGNAL(columnsInserted(const QModelIndex &, int, int)), + connect(sourceModel(), SIGNAL(columnsInserted(const QModelIndex &, int, int)), SLOT(_q_sourceColumnsInserted(const QModelIndex &, int, int))); - connect(sourceModel, SIGNAL(columnsAboutToBeRemoved(const QModelIndex &, int, int)), + connect(sourceModel(), SIGNAL(columnsAboutToBeRemoved(const QModelIndex &, int, int)), SLOT(_q_sourceColumnsAboutToBeRemoved(const QModelIndex &, int, int))); - connect(sourceModel, SIGNAL(columnsRemoved(const QModelIndex &, int, int)), + connect(sourceModel(), SIGNAL(columnsRemoved(const QModelIndex &, int, int)), SLOT(_q_sourceColumnsRemoved(const QModelIndex &, int, int))); - connect(sourceModel, SIGNAL(columnsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int)), + connect(sourceModel(), SIGNAL(columnsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int)), SLOT(_q_sourceColumnsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int))); - connect(sourceModel, SIGNAL(columnsMoved(const QModelIndex &, int, int, const QModelIndex &, int)), + connect(sourceModel(), SIGNAL(columnsMoved(const QModelIndex &, int, int, const QModelIndex &, int)), SLOT(_q_sourceColumnsMoved(const QModelIndex &, int, int, const QModelIndex &, int))); - connect(sourceModel, SIGNAL(modelAboutToBeReset()), + connect(sourceModel(), SIGNAL(modelAboutToBeReset()), SLOT(_q_sourceModelAboutToBeReset())); - connect(sourceModel, SIGNAL(modelReset()), + connect(sourceModel(), SIGNAL(modelReset()), SLOT(_q_sourceModelReset())); - connect(sourceModel, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)), + connect(sourceModel(), SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)), SLOT(_q_sourceDataChanged(const QModelIndex &, const QModelIndex &))); - connect(sourceModel, SIGNAL(headerDataChanged(Qt::Orientation,int,int)), + connect(sourceModel(), SIGNAL(headerDataChanged(Qt::Orientation,int,int)), SLOT(_q_sourceHeaderDataChanged(Qt::Orientation,int,int))); - connect(sourceModel, SIGNAL(layoutAboutToBeChanged()), + connect(sourceModel(), SIGNAL(layoutAboutToBeChanged()), SLOT(_q_sourceLayoutAboutToBeChanged())); - connect(sourceModel, SIGNAL(layoutChanged()), + connect(sourceModel(), SIGNAL(layoutChanged()), SLOT(_q_sourceLayoutChanged())); } -- cgit v1.2.3