summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@qt.io>2018-09-26 15:12:28 +0200
committerMitch Curtis <mitch.curtis@qt.io>2018-10-02 09:16:59 +0000
commitec1fdecefa04652e2a9e013d47245936973bce12 (patch)
tree29cfd20ea37ba9a6e345ca1f15f244ff702da42b
parent777cd6e9b10c83f5826fde67ad00a85c978218c0 (diff)
Add QQuickItemPrivate::updateOrAddItemChangeListener()
This is identical to the existing updateOrAddGeometryChangeListener(), except that it updates the regular "types" member, not "gTypes". This function will allow preventing duplicate change listeners, at the expensive of a call to QVector::indexOf(). It's useful when there is no other way for calling code to check if a listener will be a duplicate before adding it. Task-number: QTBUG-69056 Task-number: QTBUG-70729 Change-Id: Idba039f355023e8d45a8b46e4af95aa81c13c3f4 Reviewed-by: Michael Brasser <michael.brasser@live.com> Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
-rw-r--r--src/quick/items/qquickitem.cpp10
-rw-r--r--src/quick/items/qquickitem_p.h1
2 files changed, 11 insertions, 0 deletions
diff --git a/src/quick/items/qquickitem.cpp b/src/quick/items/qquickitem.cpp
index e568a27ed7..132c0617f3 100644
--- a/src/quick/items/qquickitem.cpp
+++ b/src/quick/items/qquickitem.cpp
@@ -3908,6 +3908,16 @@ void QQuickItemPrivate::addItemChangeListener(QQuickItemChangeListener *listener
changeListeners.append(ChangeListener(listener, types));
}
+void QQuickItemPrivate::updateOrAddItemChangeListener(QQuickItemChangeListener *listener, ChangeTypes types)
+{
+ const ChangeListener changeListener(listener, types);
+ const int index = changeListeners.indexOf(changeListener);
+ if (index > -1)
+ changeListeners[index].types = changeListener.types;
+ else
+ changeListeners.append(changeListener);
+}
+
void QQuickItemPrivate::removeItemChangeListener(QQuickItemChangeListener *listener, ChangeTypes types)
{
ChangeListener change(listener, types);
diff --git a/src/quick/items/qquickitem_p.h b/src/quick/items/qquickitem_p.h
index 93287cf0aa..0204ac07c5 100644
--- a/src/quick/items/qquickitem_p.h
+++ b/src/quick/items/qquickitem_p.h
@@ -400,6 +400,7 @@ public:
QVector<QQuickItemPrivate::ChangeListener> changeListeners;
void addItemChangeListener(QQuickItemChangeListener *listener, ChangeTypes types);
+ void updateOrAddItemChangeListener(QQuickItemChangeListener *listener, ChangeTypes types);
void removeItemChangeListener(QQuickItemChangeListener *, ChangeTypes types);
void updateOrAddGeometryChangeListener(QQuickItemChangeListener *listener, QQuickGeometryChange types);
void updateOrRemoveGeometryChangeListener(QQuickItemChangeListener *listener, QQuickGeometryChange types);