diff --git a/src/controls/Private/qquickrangemodel.cpp b/src/controls/Private/qquickrangemodel.cpp index d68ac16320cb8b23c4143f7cf4539808bb5b279e..9356861ea232b814c95ca2c21cc5183cc637891e 100644 --- a/src/controls/Private/qquickrangemodel.cpp +++ b/src/controls/Private/qquickrangemodel.cpp @@ -66,6 +66,7 @@ void QQuickRangeModelPrivate::init() posatmin = 0; posatmax = 0; inverted = false; + componentInitialized = false; } /*! @@ -147,6 +148,8 @@ qreal QQuickRangeModelPrivate::publicValue(qreal value) const void QQuickRangeModelPrivate::emitValueAndPositionIfChanged(const qreal oldValue, const qreal oldPosition) { Q_Q(QQuickRangeModel); + if (!componentInitialized) + return; // Effective value and position might have changed even in cases when e.g. d->value is // unchanged. This will be the case when operating with values outside range: @@ -219,12 +222,13 @@ void QQuickRangeModel::setPositionRange(qreal min, qreal max) // the positionChanged signal. d->pos = d->equivalentPosition(d->value); - if (emitPosAtMinChanged) - emit positionAtMinimumChanged(d->posatmin); - if (emitPosAtMaxChanged) - emit positionAtMaximumChanged(d->posatmax); - - d->emitValueAndPositionIfChanged(value(), oldPosition); + if (d->componentInitialized) { + if (emitPosAtMinChanged) + emit positionAtMinimumChanged(d->posatmin); + if (emitPosAtMaxChanged) + emit positionAtMaximumChanged(d->posatmax); + d->emitValueAndPositionIfChanged(value(), oldPosition); + } } /*! Sets the range of valid values, that \l value can assume externally, with @@ -251,12 +255,13 @@ void QQuickRangeModel::setRange(qreal min, qreal max) // Update internal position if it was changed. It can occurs if internal value changes, due to range update d->pos = d->equivalentPosition(d->value); - if (emitMinimumChanged) - emit minimumChanged(d->minimum); - if (emitMaximumChanged) - emit maximumChanged(d->maximum); - - d->emitValueAndPositionIfChanged(oldValue, oldPosition); + if (d->componentInitialized) { + if (emitMinimumChanged) + emit minimumChanged(d->minimum); + if (emitMaximumChanged) + emit maximumChanged(d->maximum); + d->emitValueAndPositionIfChanged(oldValue, oldPosition); + } } /*! @@ -319,8 +324,10 @@ void QQuickRangeModel::setStepSize(qreal stepSize) const qreal oldPosition = position(); d->stepSize = stepSize; - emit stepSizeChanged(d->stepSize); - d->emitValueAndPositionIfChanged(oldValue, oldPosition); + if (d->componentInitialized) { + emit stepSizeChanged(d->stepSize); + d->emitValueAndPositionIfChanged(oldValue, oldPosition); + } } qreal QQuickRangeModel::stepSize() const @@ -343,6 +350,11 @@ qreal QQuickRangeModel::positionForValue(qreal value) const return d->publicPosition(unconstrainedPosition); } +void QQuickRangeModel::componentComplete() +{ + d_ptr->componentInitialized = true; +} + /*! \property QQuickRangeModel::position \brief the current position of the model @@ -481,7 +493,9 @@ void QQuickRangeModel::setInverted(bool inverted) return; d->inverted = inverted; - emit invertedChanged(d->inverted); + + if (d->componentInitialized) + emit invertedChanged(d->inverted); // After updating the internal value, the position property can change. setPosition(d->equivalentPosition(d->value)); diff --git a/src/controls/Private/qquickrangemodel_p.h b/src/controls/Private/qquickrangemodel_p.h index 22edbd46f0831ec7f9b3803e465bdcb4249da32f..dd78094852b4253723ccd9eb11299b39aef22b24 100644 --- a/src/controls/Private/qquickrangemodel_p.h +++ b/src/controls/Private/qquickrangemodel_p.h @@ -41,9 +41,10 @@ QT_BEGIN_NAMESPACE class QQuickRangeModelPrivate; -class QQuickRangeModel : public QObject +class QQuickRangeModel : public QObject, public QQmlParserStatus { Q_OBJECT + Q_INTERFACES(QQmlParserStatus) Q_PROPERTY(qreal value READ value WRITE setValue NOTIFY valueChanged USER true) Q_PROPERTY(qreal minimumValue READ minimum WRITE setMinimum NOTIFY minimumChanged) Q_PROPERTY(qreal maximumValue READ maximum WRITE setMaximum NOTIFY maximumChanged) @@ -84,6 +85,9 @@ public: Q_INVOKABLE qreal valueForPosition(qreal position) const; Q_INVOKABLE qreal positionForValue(qreal value) const; + void classBegin() Q_DECL_OVERRIDE {} + void componentComplete() Q_DECL_OVERRIDE; + public Q_SLOTS: void toMinimum(); void toMaximum(); diff --git a/src/controls/Private/qquickrangemodel_p_p.h b/src/controls/Private/qquickrangemodel_p_p.h index d611b38186ac359c4f9ca02d03e6e6af31b87ab5..0255ea4fd1ee0448a557086d0202808e80c457cf 100644 --- a/src/controls/Private/qquickrangemodel_p_p.h +++ b/src/controls/Private/qquickrangemodel_p_p.h @@ -61,6 +61,8 @@ public: qreal posatmin, posatmax; qreal minimum, maximum, stepSize, pos, value; + bool componentInitialized; + uint inverted : 1; QQuickRangeModel *q_ptr;