diff options
author | Ulf Hermann <[email protected]> | 2019-11-25 16:10:04 +0100 |
---|---|---|
committer | Ulf Hermann <[email protected]> | 2020-02-07 09:37:53 +0100 |
commit | 6d0a453f41d304239285d64b06612c36922be701 (patch) | |
tree | 36a77a421948753d9512484f04efc7744941de88 /src/quick/util/qquickstategroup.cpp | |
parent | 053547fba7e83e894d8af3a63d022daa6a34ce99 (diff) |
Use the extended QQmlListProperty interface in a few places
Task-number: QTBUG-79263
Change-Id: If518f644b5b9eddbacfb1cb16fbb557127ffcfb2
Reviewed-by: Simon Hausmann <[email protected]>
Reviewed-by: Shawn Rutledge <[email protected]>
Diffstat (limited to 'src/quick/util/qquickstategroup.cpp')
-rw-r--r-- | src/quick/util/qquickstategroup.cpp | 36 |
1 files changed, 32 insertions, 4 deletions
diff --git a/src/quick/util/qquickstategroup.cpp b/src/quick/util/qquickstategroup.cpp index 46e7d62fc1..2109aafc10 100644 --- a/src/quick/util/qquickstategroup.cpp +++ b/src/quick/util/qquickstategroup.cpp @@ -70,6 +70,8 @@ public: static int count_state(QQmlListProperty<QQuickState> *list); static QQuickState *at_state(QQmlListProperty<QQuickState> *list, int index); static void clear_states(QQmlListProperty<QQuickState> *list); + static void replace_states(QQmlListProperty<QQuickState> *list, int index, QQuickState *state); + static void removeLast_states(QQmlListProperty<QQuickState> *list); static void append_transition(QQmlListProperty<QQuickTransition> *list, QQuickTransition *state); static int count_transitions(QQmlListProperty<QQuickTransition> *list); @@ -163,10 +165,13 @@ QList<QQuickState *> QQuickStateGroup::states() const QQmlListProperty<QQuickState> QQuickStateGroup::statesProperty() { Q_D(QQuickStateGroup); - return QQmlListProperty<QQuickState>(this, &d->states, &QQuickStateGroupPrivate::append_state, - &QQuickStateGroupPrivate::count_state, - &QQuickStateGroupPrivate::at_state, - &QQuickStateGroupPrivate::clear_states); + return QQmlListProperty<QQuickState>(this, &d->states, + &QQuickStateGroupPrivate::append_state, + &QQuickStateGroupPrivate::count_state, + &QQuickStateGroupPrivate::at_state, + &QQuickStateGroupPrivate::clear_states, + &QQuickStateGroupPrivate::replace_states, + &QQuickStateGroupPrivate::removeLast_states); } void QQuickStateGroupPrivate::append_state(QQmlListProperty<QQuickState> *list, QQuickState *state) @@ -201,6 +206,29 @@ void QQuickStateGroupPrivate::clear_states(QQmlListProperty<QQuickState> *list) _this->d_func()->states.clear(); } +void QQuickStateGroupPrivate::replace_states(QQmlListProperty<QQuickState> *list, int index, QQuickState *state) +{ + auto *self = qobject_cast<QQuickStateGroup *>(list->object); + auto *d = self->d_func(); + auto *oldState = d->states.at(index); + if (oldState != state) { + oldState->setStateGroup(nullptr); + state->setStateGroup(self); + d->states.replace(index, state); + if (d->currentState == oldState->name()) + d->setCurrentStateInternal(state->name(), true); + } +} + +void QQuickStateGroupPrivate::removeLast_states(QQmlListProperty<QQuickState> *list) +{ + auto *d = qobject_cast<QQuickStateGroup *>(list->object)->d_func(); + if (d->currentState == d->states.last()->name()) + d->setCurrentStateInternal(d->states.length() > 1 ? d->states.first()->name() : QString(), true); + d->states.last()->setStateGroup(nullptr); + d->states.removeLast(); +} + /*! \qmlproperty list<Transition> QtQuick::StateGroup::transitions This property holds a list of transitions defined by the state group. |