summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/itemmodels
diff options
context:
space:
mode:
authorAhmad Samir <a.samirh78@gmail.com>2023-09-06 20:51:15 +0300
committerAhmad Samir <a.samirh78@gmail.com>2023-12-15 16:52:10 +0300
commit675b4f63feab7c81c75e49f6dea82a39dd18f489 (patch)
tree94d92034e8b89a1051322495d6320d38b5cd00d1 /tests/auto/corelib/itemmodels
parent1648d2d93a9b4c9a787be01b070aa2ca1eb31099 (diff)
QIdentityProxyModel: add setHandleSourceLayoutChanges(bool)
Some sub-classes have special handling of source model layout changes (abbreviated as SMLC from here on out), they relied on disconnecting the connections to the _q_*layout* slots in the private class using the SLOT macro. This isn't possible any more after recent changes (and the method were renamed to remove _q_ prefix). Sub-classes resorting to using private API is a clear sign some functionality is missing from the public API, so a cleaner solution for this issue is adding this setter which enables sub-classes to tell QIdentityProxyModel to leave handling of the SMLC to them. Thanks to David Faure for the idea/solution. [ChangeLog][QtCore][QIdentityProxyModel] Added setHandleSourceLayoutChanges(bool) method to allow sub-classes to indicate to QIdentityProxyModel that they will handle source model layout changes on their own. Also added a getter, isHandleSourceLayoutChanges(). Change-Id: I1de79dd693ce32a6e2df9a7c81dd4abdc5f00248 Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
Diffstat (limited to 'tests/auto/corelib/itemmodels')
-rw-r--r--tests/auto/corelib/itemmodels/qidentityproxymodel/tst_qidentityproxymodel.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/auto/corelib/itemmodels/qidentityproxymodel/tst_qidentityproxymodel.cpp b/tests/auto/corelib/itemmodels/qidentityproxymodel/tst_qidentityproxymodel.cpp
index b1de23d619..467910ef48 100644
--- a/tests/auto/corelib/itemmodels/qidentityproxymodel/tst_qidentityproxymodel.cpp
+++ b/tests/auto/corelib/itemmodels/qidentityproxymodel/tst_qidentityproxymodel.cpp
@@ -27,6 +27,16 @@ public:
const QModelIndex idx = index(0, 0, QModelIndex());
Q_EMIT dataChanged(idx, idx, QList<int>() << 1);
}
+
+ // Workaround QObject::isSignalConnected() being a protected method
+ bool isConnected(const QMetaMethod &m) const { return isSignalConnected(m); }
+};
+
+class IdentityProxyModel : public QIdentityProxyModel
+{
+public:
+ // The name has to be different than the method from the base class
+ void setHandleSLC(bool b) { setHandleSourceLayoutChanges(b); }
};
class tst_QIdentityProxyModel : public QObject
@@ -53,6 +63,9 @@ private slots:
void persistIndexOnLayoutChange();
void createPersistentOnLayoutAboutToBeChanged();
+
+ void testSetHandleLayoutChanges();
+
protected:
void verifyIdentity(QAbstractItemModel *model, const QModelIndex &parent = QModelIndex());
@@ -513,5 +526,27 @@ void tst_QIdentityProxyModel::createPersistentOnLayoutAboutToBeChanged() // QTBU
QCOMPARE(layoutChangedSpy.size(), 1);
}
+void tst_QIdentityProxyModel::testSetHandleLayoutChanges()
+{
+ const std::array layoutSignals = {
+ QMetaMethod::fromSignal(&QAbstractItemModel::layoutChanged),
+ QMetaMethod::fromSignal(&QAbstractItemModel::layoutAboutToBeChanged),
+ };
+
+ DataChangedModel model;
+ IdentityProxyModel proxy;
+ proxy.setSourceModel(&model);
+ for (const auto &m : layoutSignals)
+ QVERIFY(model.isConnected(m)); // Connected by default
+
+ proxy.setSourceModel(nullptr);
+
+ // Disable handling (connecting to layotu signals) of source model layout changes
+ proxy.setHandleSLC(false);
+ proxy.setSourceModel(&model);
+ for (const auto &m : layoutSignals)
+ QVERIFY(!model.isConnected(m));
+}
+
QTEST_MAIN(tst_QIdentityProxyModel)
#include "tst_qidentityproxymodel.moc"