summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2023-04-17 13:20:00 +0200
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2023-04-18 01:22:55 +0200
commit0d858dd08b10b79fca67f7f3defc46ab68bcf7fa (patch)
tree848cc4829917790fde5744fd5aea3daa3b8cafb3 /src
parent179413a14e8e9866b35bf0ef5959480fec066188 (diff)
downloadqtdeclarative-0d858dd08b10b79fca67f7f3defc46ab68bcf7fa.tar.gz
QQuickItem: merge notifyChangeListeners overloads
The two template methods did the same, we can use if constexpr to detect whether the function pointer is a member function pointer and call it on the listener object if so, otherwise as a free function. Refactoring, but enables bug fixes and stability improvements in follow up commits. Pick-to: 6.5 Change-Id: Idc3f81fd22f3246482fdc99fcdae43074c70d9df Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/quick/items/qquickitem_p.h22
1 files changed, 7 insertions, 15 deletions
diff --git a/src/quick/items/qquickitem_p.h b/src/quick/items/qquickitem_p.h
index f98a5b2336..e1e909d1a2 100644
--- a/src/quick/items/qquickitem_p.h
+++ b/src/quick/items/qquickitem_p.h
@@ -338,7 +338,7 @@ public:
#endif // QT_NO_DEBUG_STREAM
};
- // call QQuickItemChangeListener PMF
+ // call QQuickItemChangeListener
template <typename Fn, typename ...Args>
void notifyChangeListeners(QQuickItemPrivate::ChangeTypes changeTypes, Fn &&function, Args &&...args)
{
@@ -347,20 +347,12 @@ public:
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);
+ if (change.types & changeTypes) {
+ if constexpr (std::is_member_function_pointer_v<Fn>)
+ (change.listener->*function)(args...);
+ else
+ function(change, args...);
+ }
}
}