0

I am developing a vector drawing application. I have a QStateMachine with 4 QStates: DefaultState, SelectionState, LineDrawingState, PolygonDrawingState. When the user clicks the appropriate tool button, the corresponding transition is triggered and the state is entered. The user is able to switch between any of 4 tools (and underlying states).

Here is the problem. I have to instantiate 3 transition objects for every single state so the state machine is able to switch from the current state to any other state. I mean I have to:

defaultState->addTransition(new SwitchModeTransition(GPM_SelectObject, selectionState) );
defaultState->addTransition(new SwitchModeTransition(GPM_DrawLine, lineDrawingState) );
defaultState->addTransition(new SwitchModeTransition(GPM_DrawPolygon, polygonDrawingState) );
...
selectionState->addTransition(new SwitchModeTransition(GPM_Default, defaultState) );
selectionState->addTransition(new SwitchModeTransition(GPM_DrawLine, lineDrawingState) );
selectionState->addTransition(new SwitchModeTransition(GPM_DrawPolygon, polygonDrawingState) );
... // and so on for every single state

This seems to be very redundant. Is there any more simple way to make QStateMachine to switch between all 4 states when the corresponding transition is triggered?

ezpresso
  • 7,896
  • 13
  • 62
  • 94

0 Answers0