From dd70e2cb0f84bee434f2f7fb69a26732214ce690 Mon Sep 17 00:00:00 2001 From: BogDan Vatra Date: Mon, 23 Jun 2014 15:54:24 +0300 Subject: [PATCH] Emit a notifications when childMode, initial and errorState are changed. In order to properly use QState object in QML we need to know when these properties are changed. Change-Id: I37f8295e5201686a52d448cc42db331a8f8e792f Reviewed-by: Lars Knoll Reviewed-by: Alan Alpert Reviewed-by: BogDan Vatra Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/corelib/statemachine/qstate.cpp | 42 ++++++++++++++++++++++++++--- src/corelib/statemachine/qstate.h | 21 ++++++++++++--- 2 files changed, 57 insertions(+), 6 deletions(-) diff --git a/src/corelib/statemachine/qstate.cpp b/src/corelib/statemachine/qstate.cpp index f3b4c5f235..e9baddc569 100644 --- a/src/corelib/statemachine/qstate.cpp +++ b/src/corelib/statemachine/qstate.cpp @@ -309,7 +309,10 @@ void QState::setErrorState(QAbstractState *state) return; } - d->errorState = state; + if (d->errorState != state) { + d->errorState = state; + emit errorStateChanged(QState::QPrivateSignal()); + } } /*! @@ -491,7 +494,10 @@ void QState::setInitialState(QAbstractState *state) state, this); return; } - d->initialState = state; + if (d->initialState != state) { + d->initialState = state; + emit initialStateChanged(QState::QPrivateSignal()); + } } /*! @@ -509,7 +515,10 @@ QState::ChildMode QState::childMode() const void QState::setChildMode(ChildMode mode) { Q_D(QState); - d->childMode = mode; + if (d->childMode != mode) { + d->childMode = mode; + emit childModeChanged(QState::QPrivateSignal()); + } } /*! @@ -549,6 +558,33 @@ bool QState::event(QEvent *e) \sa QState::assignProperty(), QAbstractTransition::addAnimation() */ +/*! + \fn QState::childModeChanged() + \since 5.4 + + This signal is emitted when the childMode property is changed. + + \sa QState::childMode +*/ + +/*! + \fn QState::initialStateChanged() + \since 5.4 + + This signal is emitted when the initialState property is changed. + + \sa QState::initialState +*/ + +/*! + \fn QState::errorStateChanged() + \since 5.4 + + This signal is emitted when the errorState property is changed. + + \sa QState::errorState +*/ + QT_END_NAMESPACE #endif //QT_NO_STATEMACHINE diff --git a/src/corelib/statemachine/qstate.h b/src/corelib/statemachine/qstate.h index a5f2509ffb..09c98c30c6 100644 --- a/src/corelib/statemachine/qstate.h +++ b/src/corelib/statemachine/qstate.h @@ -58,9 +58,9 @@ class QStatePrivate; class Q_CORE_EXPORT QState : public QAbstractState { Q_OBJECT - Q_PROPERTY(QAbstractState* initialState READ initialState WRITE setInitialState) - Q_PROPERTY(QAbstractState* errorState READ errorState WRITE setErrorState) - Q_PROPERTY(ChildMode childMode READ childMode WRITE setChildMode) + Q_PROPERTY(QAbstractState* initialState READ initialState WRITE setInitialState NOTIFY initialStateChanged) + Q_PROPERTY(QAbstractState* errorState READ errorState WRITE setErrorState NOTIFY errorStateChanged) + Q_PROPERTY(ChildMode childMode READ childMode WRITE setChildMode NOTIFY childModeChanged) Q_ENUMS(ChildMode RestorePolicy) public: enum ChildMode { @@ -106,6 +106,21 @@ Q_SIGNALS: void propertiesAssigned( #if !defined(Q_QDOC) QPrivateSignal +#endif + ); + void childModeChanged( +#if !defined(Q_QDOC) + QPrivateSignal +#endif + ); + void initialStateChanged( +#if !defined(Q_QDOC) + QPrivateSignal +#endif + ); + void errorStateChanged( +#if !defined(Q_QDOC) + QPrivateSignal #endif );