diff options
Diffstat (limited to 'src/controls/Private/qquickrangemodel.cpp')
| -rw-r--r-- | src/controls/Private/qquickrangemodel.cpp | 44 |
1 files changed, 29 insertions, 15 deletions
diff --git a/src/controls/Private/qquickrangemodel.cpp b/src/controls/Private/qquickrangemodel.cpp index d68ac1632..9356861ea 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)); |
