From 06e104b9c305d3db0dd1848e6e633ee3888fd1de Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Tue, 26 Apr 2011 16:20:39 +0200 Subject: Removing the "resetInternalData" slot in QAbstractProxyModel This reverts commits 0916a68056154ecb60e4ea2c79726ab2e49b1532 and 6f1384fcbeea993d5be47590c696de60215b7608. This effectively reverts most of MR 694. Reviewed-by: Olivier --- .../tst_qsortfilterproxymodel.cpp | 137 --------------------- 1 file changed, 137 deletions(-) (limited to 'tests/auto/qsortfilterproxymodel') diff --git a/tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp b/tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp index d26f0cd0f5..8e7f39335c 100644 --- a/tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp +++ b/tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp @@ -149,7 +149,6 @@ private slots: void testMultipleProxiesWithSelection(); void mapSelectionFromSource(); - void testResetInternalData(); void filteredColumns(); protected: @@ -3183,142 +3182,6 @@ void tst_QSortFilterProxyModel::taskQTBUG_10287_unnecessaryMapCreation() // No assert failure, it passes. } -/** - * A proxy which changes the background color for items ending in 'y' or 'r' - */ -class CustomDataProxy : public QSortFilterProxyModel -{ - Q_OBJECT - -public: - CustomDataProxy(QObject *parent = 0) - : QSortFilterProxyModel(parent) - { - setDynamicSortFilter(true); - } - - void setSourceModel(QAbstractItemModel *sourceModel) - { - // It would be possible to use only the modelReset signal of the source model to clear - // the data in *this, however, this requires that the slot is connected - // before QSortFilterProxyModel::setSourceModel is called, and even then depends - // on the order of invokation of slots being the same as the order of connection. - // ie, not reliable. -// connect(sourceModel, SIGNAL(modelReset()), SLOT(resetInternalData())); - QSortFilterProxyModel::setSourceModel(sourceModel); - // Making the connect after the setSourceModel call clears the data too late. -// connect(sourceModel, SIGNAL(modelReset()), SLOT(resetInternalData())); - - // This could be done in data(), but the point is to need to cache something in the proxy - // which needs to be cleared on reset. - for (int i = 0; i < sourceModel->rowCount(); ++i) - { - if (sourceModel->index(i, 0).data().toString().endsWith(QLatin1Char('y'))) - { - m_backgroundColours.insert(i, Qt::blue); - } else if (sourceModel->index(i, 0).data().toString().endsWith(QLatin1Char('r'))) - { - m_backgroundColours.insert(i, Qt::red); - } - } - } - - QVariant data(const QModelIndex &index, int role) const - { - if (role != Qt::BackgroundRole) - return QSortFilterProxyModel::data(index, role); - return m_backgroundColours.value(index.row()); - } - -private slots: - void resetInternalData() - { - m_backgroundColours.clear(); - } - -private: - QHash m_backgroundColours; -}; - -class ModelObserver : public QObject -{ - Q_OBJECT -public: - ModelObserver(QAbstractItemModel *model, QObject *parent = 0) - : QObject(parent), m_model(model) - { - connect(m_model, SIGNAL(modelAboutToBeReset()), SLOT(modelAboutToBeReset())); - connect(m_model, SIGNAL(modelReset()), SLOT(modelReset())); - } - -public slots: - void modelAboutToBeReset() - { - int reds = 0, blues = 0; - for (int i = 0; i < m_model->rowCount(); ++i) - { - QColor color = m_model->index(i, 0).data(Qt::BackgroundRole).value(); - if (color == Qt::blue) - ++blues; - if (color == Qt::red) - ++reds; - } - QCOMPARE(blues, 11); - QCOMPARE(reds, 4); - } - - void modelReset() - { - int reds = 0, blues = 0; - for (int i = 0; i < m_model->rowCount(); ++i) - { - QColor color = m_model->index(i, 0).data(Qt::BackgroundRole).value(); - if (color == Qt::blue) - ++blues; - if (color == Qt::red) - ++reds; - } - QCOMPARE(reds, 0); - QCOMPARE(blues, 0); - } - -private: - QAbstractItemModel * const m_model; - -}; - -void tst_QSortFilterProxyModel::testResetInternalData() -{ - - QStringListModel model(QStringList() << "Monday" - << "Tuesday" - << "Wednesday" - << "Thursday" - << "Friday" - << "January" - << "February" - << "March" - << "April" - << "May" - << "Saturday" - << "June" - << "Sunday" - << "July" - << "August" - << "September" - << "October" - << "November" - << "December"); - - CustomDataProxy proxy; - proxy.setSourceModel(&model); - - ModelObserver observer(&proxy); - - // Cause the source model to reset. - model.setStringList(QStringList() << "Spam" << "Eggs"); -} - class FilteredColumnProxyModel : public QSortFilterProxyModel { Q_OBJECT -- cgit v1.2.1