Disconnect slots from the old sourcemodel in QIdentityProxyModel
authorkb <k.blammo@gmail.com>
Fri, 9 Mar 2012 11:29:09 +0000 (12:29 +0100)
committerQt by Nokia <qt-info@nokia.com>
Wed, 14 Mar 2012 10:37:18 +0000 (11:37 +0100)
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 <stephen.kelly@kdab.com>
src/corelib/itemmodels/qidentityproxymodel.cpp

index 1f95ac0..9cac404 100644 (file)
@@ -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()));
     }