aboutsummaryrefslogtreecommitdiffstats
path: root/src/templates/qquickpageindicator.cpp
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@theqtcompany.com>2015-10-15 15:31:04 +0200
committerJ-P Nurmi <jpnurmi@theqtcompany.com>2015-10-16 15:12:22 +0000
commit28f6dfd8e86057d71de02c6448b0000e14773775 (patch)
treec21691908b44bfa5d02ad2fc7bb3ea889ef2d2ff /src/templates/qquickpageindicator.cpp
parent8a37e702a531dfb9d3db2e7b7adb2078c33f147f (diff)
PageIndicator: fix initialization of the 'pressed' context-property
Component.onCompleted was too late, so now it's done as soon as delegate instances are created. Change-Id: I2bc3e051de6e005c914494a7c674f6c04582ec23 Task-number: QTBUG-48721 Reviewed-by: J-P Nurmi <jpnurmi@theqtcompany.com>
Diffstat (limited to 'src/templates/qquickpageindicator.cpp')
-rw-r--r--src/templates/qquickpageindicator.cpp26
1 files changed, 17 insertions, 9 deletions
diff --git a/src/templates/qquickpageindicator.cpp b/src/templates/qquickpageindicator.cpp
index 90f75444..9708cc8a 100644
--- a/src/templates/qquickpageindicator.cpp
+++ b/src/templates/qquickpageindicator.cpp
@@ -37,6 +37,8 @@
#include "qquickpageindicator_p.h"
#include "qquickcontrol_p_p.h"
+#include <QtQuick/private/qquickitemchangelistener_p.h>
+
QT_BEGIN_NAMESPACE
/*!
@@ -58,7 +60,7 @@ QT_BEGIN_NAMESPACE
\sa SwipeView, {Customizing PageIndicator}, Indicators
*/
-class QQuickPageIndicatorPrivate : public QQuickControlPrivate
+class QQuickPageIndicatorPrivate : public QQuickControlPrivate, public QQuickItemChangeListener
{
Q_DECLARE_PUBLIC(QQuickPageIndicator)
@@ -70,6 +72,8 @@ public:
void updatePressed(bool pressed, const QPoint &pos = QPoint());
void setContextProperty(QQuickItem *item, const QString &name, const QVariant &value);
+ void itemChildAdded(QQuickItem *, QQuickItem *child);
+
int count;
int currentIndex;
bool interactive;
@@ -108,6 +112,12 @@ void QQuickPageIndicatorPrivate::setContextProperty(QQuickItem *item, const QStr
}
}
+void QQuickPageIndicatorPrivate::itemChildAdded(QQuickItem *, QQuickItem *child)
+{
+ if (!QQuickItemPrivate::get(child)->isTransparentForPositioner())
+ setContextProperty(child, QStringLiteral("pressed"), false);
+}
+
QQuickPageIndicator::QQuickPageIndicator(QQuickItem *parent) :
QQuickControl(*(new QQuickPageIndicatorPrivate), parent)
{
@@ -229,16 +239,14 @@ void QQuickPageIndicator::setColor(const QColor &color)
}
}
-void QQuickPageIndicator::componentComplete()
+void QQuickPageIndicator::contentItemChange(QQuickItem *newItem, QQuickItem *oldItem)
{
Q_D(QQuickPageIndicator);
- QQuickControl::componentComplete();
- if (d->contentItem) {
- foreach (QQuickItem *child, d->contentItem->childItems()) {
- if (!QQuickItemPrivate::get(child)->isTransparentForPositioner())
- d->setContextProperty(child, QStringLiteral("pressed"), false);
- }
- }
+ QQuickControl::contentItemChange(newItem, oldItem);
+ if (oldItem)
+ QQuickItemPrivate::get(oldItem)->removeItemChangeListener(d, QQuickItemPrivate::Children);
+ if (newItem)
+ QQuickItemPrivate::get(newItem)->addItemChangeListener(d, QQuickItemPrivate::Children);
}
void QQuickPageIndicator::mousePressEvent(QMouseEvent *event)