summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@theqtcompany.com>2014-10-24 11:28:01 +0200
committerJ-P Nurmi <jpnurmi@theqtcompany.com>2014-10-30 16:50:44 +0100
commit6811722011970ee66f69c8b50417ca5f66943111 (patch)
tree202291680bd3dcdab41358d9e238b6e302a5e440
parent89d67ca33fcd1dd19278d248007d8aef4097407b (diff)
downloadqtquickcontrols-6811722011970ee66f69c8b50417ca5f66943111.tar.gz
Revert "qquickrangemodel: don't emit signals before component is completed"
This reverts commit 774f2aa14e8742d77bb92968b06fab4dc35d79b4 that broke sliders (auto test for RangeModel included to prevent that from happening again) in the Qt Quick Enterprise Controls gallery. Some sliders with a hard-coded range [0..360] and value 240 ended up having a value of 0 at Component.onCompleted. Change-Id: Ib3024c51c0552ac06528ba47b08e1a33a5f48324 Reviewed-by: Mitch Curtis <mitch.curtis@digia.com>
-rw-r--r--src/controls/Private/qquickrangemodel.cpp44
-rw-r--r--src/controls/Private/qquickrangemodel_p.h6
-rw-r--r--src/controls/Private/qquickrangemodel_p_p.h2
-rw-r--r--tests/auto/controls/data/rangemodel/bindings.qml67
-rw-r--r--tests/auto/controls/data/tst_rangemodel.qml19
5 files changed, 102 insertions, 36 deletions
diff --git a/src/controls/Private/qquickrangemodel.cpp b/src/controls/Private/qquickrangemodel.cpp
index 9356861e..d68ac163 100644
--- a/src/controls/Private/qquickrangemodel.cpp
+++ b/src/controls/Private/qquickrangemodel.cpp
@@ -66,7 +66,6 @@ void QQuickRangeModelPrivate::init()
posatmin = 0;
posatmax = 0;
inverted = false;
- componentInitialized = false;
}
/*!
@@ -148,8 +147,6 @@ 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:
@@ -222,13 +219,12 @@ void QQuickRangeModel::setPositionRange(qreal min, qreal max)
// the positionChanged signal.
d->pos = d->equivalentPosition(d->value);
- if (d->componentInitialized) {
- if (emitPosAtMinChanged)
- emit positionAtMinimumChanged(d->posatmin);
- if (emitPosAtMaxChanged)
- emit positionAtMaximumChanged(d->posatmax);
- d->emitValueAndPositionIfChanged(value(), oldPosition);
- }
+ 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
@@ -255,13 +251,12 @@ 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 (d->componentInitialized) {
- if (emitMinimumChanged)
- emit minimumChanged(d->minimum);
- if (emitMaximumChanged)
- emit maximumChanged(d->maximum);
- d->emitValueAndPositionIfChanged(oldValue, oldPosition);
- }
+ if (emitMinimumChanged)
+ emit minimumChanged(d->minimum);
+ if (emitMaximumChanged)
+ emit maximumChanged(d->maximum);
+
+ d->emitValueAndPositionIfChanged(oldValue, oldPosition);
}
/*!
@@ -324,10 +319,8 @@ void QQuickRangeModel::setStepSize(qreal stepSize)
const qreal oldPosition = position();
d->stepSize = stepSize;
- if (d->componentInitialized) {
- emit stepSizeChanged(d->stepSize);
- d->emitValueAndPositionIfChanged(oldValue, oldPosition);
- }
+ emit stepSizeChanged(d->stepSize);
+ d->emitValueAndPositionIfChanged(oldValue, oldPosition);
}
qreal QQuickRangeModel::stepSize() const
@@ -350,11 +343,6 @@ 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
@@ -493,9 +481,7 @@ void QQuickRangeModel::setInverted(bool inverted)
return;
d->inverted = inverted;
-
- if (d->componentInitialized)
- emit invertedChanged(d->inverted);
+ 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 dd780948..22edbd46 100644
--- a/src/controls/Private/qquickrangemodel_p.h
+++ b/src/controls/Private/qquickrangemodel_p.h
@@ -41,10 +41,9 @@ QT_BEGIN_NAMESPACE
class QQuickRangeModelPrivate;
-class QQuickRangeModel : public QObject, public QQmlParserStatus
+class QQuickRangeModel : public QObject
{
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)
@@ -85,9 +84,6 @@ 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 0255ea4f..d611b381 100644
--- a/src/controls/Private/qquickrangemodel_p_p.h
+++ b/src/controls/Private/qquickrangemodel_p_p.h
@@ -61,8 +61,6 @@ public:
qreal posatmin, posatmax;
qreal minimum, maximum, stepSize, pos, value;
- bool componentInitialized;
-
uint inverted : 1;
QQuickRangeModel *q_ptr;
diff --git a/tests/auto/controls/data/rangemodel/bindings.qml b/tests/auto/controls/data/rangemodel/bindings.qml
new file mode 100644
index 00000000..7ecdada8
--- /dev/null
+++ b/tests/auto/controls/data/rangemodel/bindings.qml
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt Quick Controls module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.2
+import QtQuick.Controls 1.2
+import QtQuick.Controls.Private 1.0
+
+Item {
+ property alias range1: range1
+ property alias range2: range2
+ property alias range3: range3
+ RangeModel {
+ id: range1
+ value: 50
+ minimumValue: 25
+ maximumValue: 75
+ }
+ RangeModel {
+ id: range2
+ value: range1.value
+ minimumValue: range1.minimumValue
+ maximumValue: range1.maximumValue
+ }
+ RangeModel {
+ id: range3
+ value: range2.value
+ minimumValue: range2.minimumValue
+ maximumValue: range2.maximumValue
+ }
+}
diff --git a/tests/auto/controls/data/tst_rangemodel.qml b/tests/auto/controls/data/tst_rangemodel.qml
index bbb0e3bf..b29a6749 100644
--- a/tests/auto/controls/data/tst_rangemodel.qml
+++ b/tests/auto/controls/data/tst_rangemodel.qml
@@ -164,4 +164,23 @@ TestCase {
compare(spy.count, 2)
compare(range.position, 100)
}
+
+ function test_bindings() {
+ var component = Qt.createComponent("rangemodel/bindings.qml")
+ compare(component.status, Component.Ready)
+ var object = component.createObject(testCase)
+ verify(object !== null, "created object is null")
+
+ compare(object.range1.value, 50)
+ compare(object.range1.minimumValue, 25)
+ compare(object.range1.maximumValue, 75)
+
+ compare(object.range2.value, 50)
+ compare(object.range2.minimumValue, 25)
+ compare(object.range2.maximumValue, 75)
+
+ compare(object.range3.value, 50)
+ compare(object.range3.minimumValue, 25)
+ compare(object.range3.maximumValue, 75)
+ }
}