QHistoryState Class

The QHistoryState class provides a means of returning to a previously active substate. More...

Header: #include <QHistoryState>
qmake: QT += core
Since: Qt 4.6
Inherits: QAbstractState

Public Types

enum HistoryType { ShallowHistory, DeepHistory }

Properties

Public Functions

QHistoryState(QState *parent = nullptr)
QHistoryState(QHistoryState::HistoryType type, QState *parent = nullptr)
virtual ~QHistoryState()
QAbstractState * defaultState() const
QAbstractTransition * defaultTransition() const
QHistoryState::HistoryType historyType() const
void setDefaultState(QAbstractState *state)
void setDefaultTransition(QAbstractTransition *transition)
void setHistoryType(QHistoryState::HistoryType type)

Signals

Reimplemented Protected Functions

virtual bool event(QEvent *e) override
virtual void onEntry(QEvent *event) override
virtual void onExit(QEvent *event) override

Additional Inherited Members

  • 1 public slot inherited from QObject
  • 11 static public members inherited from QObject
  • 3 protected functions inherited from QAbstractState
  • 9 protected functions inherited from QObject

Detailed Description

The QHistoryState class provides a means of returning to a previously active substate.

A history state is a pseudo-state that represents the child state that the parent state was in the last time the parent state was exited. A transition with a history state as its target is in fact a transition to one or more other child states of the parent state. QHistoryState is part of The State Machine Framework.

Use the setDefaultState() function to set the state that should be entered if the parent state has never been entered. Example:

QStateMachine machine;

QState *s1 = new QState();
QState *s11 = new QState(s1);
QState *s12 = new QState(s1);

QHistoryState *s1h = new QHistoryState(s1);
s1h->setDefaultState(s11);

machine.addState(s1);

QState *s2 = new QState();
machine.addState(s2);

QPushButton *button = new QPushButton();
// Clicking the button will cause the state machine to enter the child state
// that s1 was in the last time s1 was exited, or the history state's default
// state if s1 has never been entered.
s1->addTransition(button, SIGNAL(clicked()), s1h);

If more than one default state has to be entered, or if the transition to the default state(s) has to be acted upon, the defaultTransition should be set instead. Note that the eventTest() method of that transition will never be called: the selection and execution of the transition is done automatically when entering the history state.

By default a history state is shallow, meaning that it won't remember nested states. This can be configured through the historyType property.

Member Type Documentation

enum QHistoryState::HistoryType

This enum specifies the type of history that a QHistoryState records.

Constant Value Description
QHistoryState::ShallowHistory 0 Only the immediate child states of the parent state are recorded. In this case a transition with the history state as its target will end up in the immediate child state that the parent was in the last time it was exited. This is the default.
QHistoryState::DeepHistory 1 Nested states are recorded. In this case a transition with the history state as its target will end up in the most deeply nested descendant state the parent was in the last time it was exited.

Property Documentation

defaultState : QAbstractState*

This property holds the default state of this history state

Access functions:

QAbstractState * defaultState() const
void setDefaultState(QAbstractState *state)

Notifier signal:

void defaultStateChanged() [see note below]

Note: This is a private signal. It can be used in signal connections but cannot be emitted by the user.

defaultTransition : QAbstractTransition*

This property holds the default transition of this history state

Access functions:

QAbstractTransition * defaultTransition() const
void setDefaultTransition(QAbstractTransition *transition)

Notifier signal:

void defaultTransitionChanged() [see note below]

Note: This is a private signal. It can be used in signal connections but cannot be emitted by the user.

historyType : HistoryType

This property holds the type of history that this history state records

The default value of this property is QHistoryState::ShallowHistory.

Access functions:

QHistoryState::HistoryType historyType() const
void setHistoryType(QHistoryState::HistoryType type)

Notifier signal:

void historyTypeChanged() [see note below]

Note: This is a private signal. It can be used in signal connections but cannot be emitted by the user.

Member Function Documentation

QHistoryState::QHistoryState(QState *parent = nullptr)

Constructs a new shallow history state with the given parent state.

QHistoryState::QHistoryState(QHistoryState::HistoryType type, QState *parent = nullptr)

Constructs a new history state of the given type, with the given parent state.

[virtual] QHistoryState::~QHistoryState()

Destroys this history state.

QAbstractState *QHistoryState::defaultState() const

Returns this history state's default state. The default state indicates the state to transition to if the parent state has never been entered before.

Note: Getter function for property defaultState.

See also setDefaultState().

[signal] void QHistoryState::defaultStateChanged()

This signal is emitted when the defaultState property is changed.

This function was introduced in Qt 5.4.

Note: This is a private signal. It can be used in signal connections but cannot be emitted by the user.

Note: Notifier signal for property defaultState.

See also QHistoryState::defaultState.

QAbstractTransition *QHistoryState::defaultTransition() const

Returns this history state's default transition. The default transition is taken when the history state has never been entered before. The target states of the default transition therefore make up the default state.

This function was introduced in Qt 5.6.

Note: Getter function for property defaultTransition.

See also setDefaultTransition().

[signal] void QHistoryState::defaultTransitionChanged()

This signal is emitted when the defaultTransition property is changed.

This function was introduced in Qt 5.6.

Note: This is a private signal. It can be used in signal connections but cannot be emitted by the user.

Note: Notifier signal for property defaultTransition.

See also QHistoryState::defaultTransition.

[override virtual protected] bool QHistoryState::event(QEvent *e)

Reimplemented from QAbstractState::event().

QHistoryState::HistoryType QHistoryState::historyType() const

Returns the type of history that this history state records.

Note: Getter function for property historyType.

See also setHistoryType().

[signal] void QHistoryState::historyTypeChanged()

This signal is emitted when the historyType property is changed.

This function was introduced in Qt 5.4.

Note: This is a private signal. It can be used in signal connections but cannot be emitted by the user.

Note: Notifier signal for property historyType.

See also QHistoryState::historyType.

[override virtual protected] void QHistoryState::onEntry(QEvent *event)

Reimplemented from QAbstractState::onEntry().

[override virtual protected] void QHistoryState::onExit(QEvent *event)

Reimplemented from QAbstractState::onExit().

void QHistoryState::setDefaultState(QAbstractState *state)

Sets this history state's default state to be the given state. state must be a sibling of this history state.

Note that this function does not set state as the initial state of its parent.

Note: Setter function for property defaultState.

See also defaultState().

void QHistoryState::setDefaultTransition(QAbstractTransition *transition)

Sets this history state's default transition to be the given transition. This will set the source state of the transition to the history state.

Note that the eventTest method of the transition will never be called.

This function was introduced in Qt 5.6.

Note: Setter function for property defaultTransition.

See also defaultTransition().

void QHistoryState::setHistoryType(QHistoryState::HistoryType type)

Sets the type of history that this history state records.

Note: Setter function for property historyType.

See also historyType().

Voted #1 for:

  • Easiest to learn
  • Most time saving
  • Best support

Develop Cross-Platform Apps and Games 50% Faster!

  • Voted the best supported, most time-saving and easiest to learn cross-platform development tool
  • Based on the Qt framework, with native performance and appearance on all platforms including iOS and Android
  • Offers a variety of plugins to monetize, analyze and engage users
FREE!
create apps
create games
cross platform
native performance
3rd party services
game network
multiplayer
level editor
easiest to learn
biggest time saving
best support