diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2019-07-02 13:23:09 +0200 |
---|---|---|
committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2019-07-02 15:32:03 +0200 |
commit | 64c1fbe96c68b1286a70242ff4922be140128cb2 (patch) | |
tree | c95a2d68fc50319f04e6cbae4c471c524c66ba5f | |
parent | dfd12d4079b339a140d4697c7ca92c5ea4233315 (diff) |
use boolean for when property
QQuickState used to store "when" as a QQmlBinding to reduce state
oscillation.
It is unclear whether this is still an issue, but it breaks if a user
sets "when" to a primitive value like "true" or "1".
Fixes: QTBUG-76838
Change-Id: If400e5b1283687838ed252be2dfa52067f44564e
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
-rw-r--r-- | src/quick/util/qquickstate.cpp | 9 | ||||
-rw-r--r-- | src/quick/util/qquickstate_p.h | 8 | ||||
-rw-r--r-- | src/quick/util/qquickstate_p_p.h | 5 | ||||
-rw-r--r-- | src/quick/util/qquickstategroup.cpp | 5 | ||||
-rw-r--r-- | tests/auto/quick/qquickstates/data/trivialWhen.qml | 5 | ||||
-rw-r--r-- | tests/auto/quick/qquickstates/tst_qquickstates.cpp | 10 |
6 files changed, 28 insertions, 14 deletions
diff --git a/src/quick/util/qquickstate.cpp b/src/quick/util/qquickstate.cpp index 3ca6440784..473539ab2c 100644 --- a/src/quick/util/qquickstate.cpp +++ b/src/quick/util/qquickstate.cpp @@ -192,7 +192,7 @@ bool QQuickState::isNamed() const bool QQuickState::isWhenKnown() const { Q_D(const QQuickState); - return d->when != nullptr; + return d->whenKnown; } /*! @@ -219,15 +219,16 @@ bool QQuickState::isWhenKnown() const } \endqml */ -QQmlBinding *QQuickState::when() const +bool QQuickState::when() const { Q_D(const QQuickState); - return d->when.data(); + return d->when; } -void QQuickState::setWhen(QQmlBinding *when) +void QQuickState::setWhen(bool when) { Q_D(QQuickState); + d->whenKnown = true; d->when = when; if (d->group) d->group->updateAutoState(); diff --git a/src/quick/util/qquickstate_p.h b/src/quick/util/qquickstate_p.h index 79874ee78e..576ba9834c 100644 --- a/src/quick/util/qquickstate_p.h +++ b/src/quick/util/qquickstate_p.h @@ -152,7 +152,7 @@ class Q_QUICK_PRIVATE_EXPORT QQuickState : public QObject Q_OBJECT Q_PROPERTY(QString name READ name WRITE setName) - Q_PROPERTY(QQmlBinding *when READ when WRITE setWhen) + Q_PROPERTY(bool when READ when WRITE setWhen) Q_PROPERTY(QString extend READ extends WRITE setExtends) Q_PROPERTY(QQmlListProperty<QQuickStateOperation> changes READ changes) Q_CLASSINFO("DefaultProperty", "changes") @@ -166,11 +166,9 @@ public: void setName(const QString &); bool isNamed() const; - /*'when' is a QQmlBinding to limit state changes oscillation - due to the unpredictable order of evaluation of bound expressions*/ bool isWhenKnown() const; - QQmlBinding *when() const; - void setWhen(QQmlBinding *); + bool when() const; + void setWhen(bool); QString extends() const; void setExtends(const QString &); diff --git a/src/quick/util/qquickstate_p_p.h b/src/quick/util/qquickstate_p_p.h index 61472b4d06..70d6f1d185 100644 --- a/src/quick/util/qquickstate_p_p.h +++ b/src/quick/util/qquickstate_p_p.h @@ -203,12 +203,13 @@ class QQuickStatePrivate : public QObjectPrivate public: QQuickStatePrivate() - : named(false), inState(false), group(nullptr) {} + : when(false), whenKnown(false), named(false), inState(false), group(nullptr) {} typedef QList<QQuickSimpleAction> SimpleActionList; QString name; - QQmlBinding::Ptr when; + bool when; + bool whenKnown; bool named; struct OperationGuard : public QQmlGuard<QQuickStateOperation> diff --git a/src/quick/util/qquickstategroup.cpp b/src/quick/util/qquickstategroup.cpp index b53949d21c..0adae82dcc 100644 --- a/src/quick/util/qquickstategroup.cpp +++ b/src/quick/util/qquickstategroup.cpp @@ -348,10 +348,9 @@ bool QQuickStateGroupPrivate::updateAutoState() QQuickState *state = states.at(ii); if (state->isWhenKnown()) { if (state->isNamed()) { - if (state->when() && state->when()->evaluate().toBool()) { + if (state->when()) { if (stateChangeDebug()) - qWarning() << "Setting auto state due to:" - << state->when()->expression(); + qWarning() << "Setting auto state due to expression"; if (currentState != state->name()) { q->setState(state->name()); return true; diff --git a/tests/auto/quick/qquickstates/data/trivialWhen.qml b/tests/auto/quick/qquickstates/data/trivialWhen.qml new file mode 100644 index 0000000000..9f7f3161e9 --- /dev/null +++ b/tests/auto/quick/qquickstates/data/trivialWhen.qml @@ -0,0 +1,5 @@ +import QtQuick 2.12 + +State { + when: true +} diff --git a/tests/auto/quick/qquickstates/tst_qquickstates.cpp b/tests/auto/quick/qquickstates/tst_qquickstates.cpp index 50554f6333..1eb797f54f 100644 --- a/tests/auto/quick/qquickstates/tst_qquickstates.cpp +++ b/tests/auto/quick/qquickstates/tst_qquickstates.cpp @@ -138,6 +138,7 @@ private slots: void QTBUG_38492(); void revertListMemoryLeak(); void duplicateStateName(); + void trivialWhen(); }; void tst_qquickstates::initTestCase() @@ -1665,6 +1666,15 @@ void tst_qquickstates::duplicateStateName() QVERIFY(!item.isNull()); } +// QTBUG-76838 +void tst_qquickstates::trivialWhen() +{ + QQmlEngine engine; + + QQmlComponent c(&engine, testFileUrl("trivialWhen.qml")); + QVERIFY(c.create()); +} + QTEST_MAIN(tst_qquickstates) |