cszawisza
6th November 2014, 16:36
Hi!
I have a dialog with comboBox, couple of line edits and other stuff. In comboBox I have several entries that define what fields should be disabled and witch shouldn't be.
What I want to achieve is simple, when current index in comboBox changes, application should go to state defined by index of newly selected item. Now everything is handled by if else statements, but i decided to use QStateMachine instead.
When indexes in comboBox change in one direction, everything workis fine:
state1 -> state2;
state2 -> state3;
state3 -> state4;
To define two way index change I neeed to add new transactions to state machine, that will les the state machine to go back
state1 -> state2; // UP
state1 -> state4; // DOWN
state2 -> state3;
state2 -> state1;
state3 -> state4;
state3 -> state2;
state4 -> state1;
state4 -> state3;
To this works if user uses scroll to go through all comboBox fields, but when he choose something by clicking it (e.g. index from 4 to 2) I have no transaction that can handle this "action", so I need to add more transactions... In other words I need to write ALL-TO-ALL transactions to achieve what I want.
Is there another way of doing something like this? some kind of "stateless stateMachine" or a mechanism that can by used to "call" specific state?
I know stat state machine is designed not to do something like I want, but it is quite easy to use and it's simpler then write own code :)
I have a dialog with comboBox, couple of line edits and other stuff. In comboBox I have several entries that define what fields should be disabled and witch shouldn't be.
What I want to achieve is simple, when current index in comboBox changes, application should go to state defined by index of newly selected item. Now everything is handled by if else statements, but i decided to use QStateMachine instead.
When indexes in comboBox change in one direction, everything workis fine:
state1 -> state2;
state2 -> state3;
state3 -> state4;
To define two way index change I neeed to add new transactions to state machine, that will les the state machine to go back
state1 -> state2; // UP
state1 -> state4; // DOWN
state2 -> state3;
state2 -> state1;
state3 -> state4;
state3 -> state2;
state4 -> state1;
state4 -> state3;
To this works if user uses scroll to go through all comboBox fields, but when he choose something by clicking it (e.g. index from 4 to 2) I have no transaction that can handle this "action", so I need to add more transactions... In other words I need to write ALL-TO-ALL transactions to achieve what I want.
Is there another way of doing something like this? some kind of "stateless stateMachine" or a mechanism that can by used to "call" specific state?
I know stat state machine is designed not to do something like I want, but it is quite easy to use and it's simpler then write own code :)