Re: Help using QStateMachine
No one has any help or advice?
Re: Help using QStateMachine
I am having trouble understanding what you want, however I think QStateMachine might not be a good solution to your problem. I don't see any benefit of tracking the mouse state using an external state machine. I think it would be much easier to have a flag for marking the current mode and invoking code based on current mode from within mouse event handler methods. Of course you could make a state machine for it (and I'd suggest to make it a hierarchical one) but it will not make your code cleaner or better, it will just require your time to implement it.
Re: Help using QStateMachine
Wysota, thanks for the reply. I already have a smaller implementation similar to your description, that handles zooming, panning, and selecting areas within the plot, but does not use the Qt state machine framework.
However, I now want to be able to add the ability to select and manipulate individual items within the plot (for example, to select a glyph marking a data point, or to add a new item that selects a region and then adjust its position). The logic in the mouse handlers starts to get very complex, keeping track of which state the mouse is in, whether an object is selected, being moved or resized, etc. It also becomes harder and harder to modify it - suppose I want to use the right button for some action, but also want to use context menus when that action is not "active"?
So, this is why I think a hierarchical (as you suggest) state machine would be better. It would allow me to encapsulate the responses to various mouse and key actions to the various states (and greatly simplify mouse handlers since each state would have no conditional branching based on other states).
But as I asked in my o.p., the QStateMachine framework allows you to build such a system, but it seems that in the base QAbstractState / QState classes, there isn't a way to find out -how- you got into that state. There is a QAbstractState:: onEntry() method, but to use it requires derivation of a new class for each state instead of simply using QState as-is.
The QState::assignProperty() method would do everything I need, if I could figure out a way to get the current mouse position assigned to a property on entry into a state.
Anyway, I will continue to pound my head against this wall until the wall falls down or I fall unconcious from blood loss.
Re: Help using QStateMachine
You should think about decentralizing your code. Instead of stuffing everything into one event handler you should have separate components responsible for separate pieces of logic for your framework. Moreover if it makes a difference how you got into a particular state then most likely it seems you identified the states incorrectly. If you wish to set some values when you enter some state, then sure, you can reimplement onEntry(). However if I understand correctly what you are trying to do, I think it is better to subclass the transition class and reimplement QAbstractTransition::onTransition().
Re: Help using QStateMachine
Quote:
Instead of stuffing everything into one event handler you should have separate components responsible for separate pieces of logic for your framework.
Thus my interest in using the Qt state machine framework.
Quote:
Originally Posted by
wysota
Ah, that might do it. I actually don't care how I got into the state; I need to capture information from the event that caused the transition (mouse position and button, key code, or mouse wheel delta), then use that to assign properties.
Thanks for the help.
Edit: Yes, that will definitely work. Thanks.
Re: Help using QStateMachine
Quote:
Originally Posted by
d_stranz
Thus my interest in using the Qt state machine framework.
In my opinion this is not a correct approach. Using a state machine will not divide your code into logical components, you'll still have a single monster that does everything.