aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/items/qquickitem_p.h
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2021-12-03 13:27:51 +0100
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2021-12-04 13:49:07 +0100
commit79c3cbe54eac3612bfe28232a765cf93d4abd665 (patch)
tree31f0753c564f698fea8d36ebb9ff63376d5f4d4b /src/quick/items/qquickitem_p.h
parent6254b383309a0c3cd273264466105a7e3599a1ed (diff)
Refactor: move change listener notification logic into helpers
A dozen loops doing more or less the same, all with the comment "intentional copy (QTBUG-54732)", are best factored out into a helper. Most of the loops call a different QQuickItemChangeListener member, so provide a template that expects a pointer to a QQuickItemChangeListener member function. Some loops have some additional logic, so provide a second template that just calls a functor. No functional change, but needed for follow-up fixes to focus reason handling in Qt Quick Controls. Pick-to: 6.2 Change-Id: I6b11e06331da44b288315fc0732009d5f34f539a Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/quick/items/qquickitem_p.h')
-rw-r--r--src/quick/items/qquickitem_p.h27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/quick/items/qquickitem_p.h b/src/quick/items/qquickitem_p.h
index 51ef850d5f..576d392a26 100644
--- a/src/quick/items/qquickitem_p.h
+++ b/src/quick/items/qquickitem_p.h
@@ -331,6 +331,7 @@ public:
ImplicitWidth = 0x100,
ImplicitHeight = 0x200,
Enabled = 0x400,
+ AllChanges = 0xFFFFFFFF
};
Q_DECLARE_FLAGS(ChangeTypes, ChangeType)
@@ -358,6 +359,32 @@ public:
QQuickGeometryChange gTypes; //NOTE: not used for ==
};
+ // call QQuickItemChangeListener PMF
+ template <typename Fn, typename ...Args>
+ void notifyChangeListeners(QQuickItemPrivate::ChangeTypes changeTypes, Fn &&function, Args &&...args)
+ {
+ if (changeListeners.isEmpty())
+ return;
+
+ const auto listeners = changeListeners; // NOTE: intentional copy (QTBUG-54732)
+ for (const QQuickItemPrivate::ChangeListener &change : listeners) {
+ if (change.types & changeTypes)
+ (change.listener->*function)(args...);
+ }
+ }
+ // call functor
+ template <typename Fn>
+ void notifyChangeListeners(QQuickItemPrivate::ChangeTypes changeTypes, Fn &&function) {
+ if (changeListeners.isEmpty())
+ return;
+
+ const auto listeners = changeListeners; // NOTE: intentional copy (QTBUG-54732)
+ for (const QQuickItemPrivate::ChangeListener &change : listeners) {
+ if (change.types & changeTypes)
+ function(change);
+ }
+ }
+
struct ExtraData {
ExtraData();