Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>After reading your requirements and the answers and comments here I think merula's solution or something similar is the only pure Statemachine solution. </p> <p>As has been noted to make the Parallel State fire the <code>finished()</code> signal all the disabled states have to be final states, but this is not really what they should be as someone could uncheck one of the checkboxes and then you would have to move away from the final state. You can't do that as FinalState does not accept any transitions. The using the FinalState to exit the parallel state also causes the parallel state to restart when it is reentered.</p> <p>One solution could be to code up a transition that only triggers when all three states are in the "good" state, and a second one that triggers when any of those is not. Then you add the disabled and enabled states to the parallel state you already have and connect it with the aforementioned transitions. This will keep the enabled state of the button in sync with all the states of your UI pieces. It will also let you leave the parallel state and come back to a consistent set of property settings.</p> <pre><code>class AndGateTransition : public QAbstractTransition { Q_OBJECT public: AndGateTransition(QAbstractState* sourceState) : QAbstractTransition(sourceState) m_isSet(false), m_triggerOnSet(true), m_triggerOnUnset(false) void setTriggerSet(bool val) { m_triggerSet = val; } void setTriggerOnUnset(bool val) { m_triggerOnUnset = val; } addState(QState* state) { m_states[state] = false; connect(m_state, SIGNAL(entered()), this, SLOT(stateActivated()); connect(m_state, SIGNAL(exited()), this, SLOT(stateDeactivated()); } public slots: void stateActivated() { QObject sender = sender(); if (sender == 0) return; m_states[sender] = true; checkTrigger(); } void stateDeactivated() { QObject sender = sender(); if (sender == 0) return; m_states[sender] = false; checkTrigger(); } void checkTrigger() { bool set = true; QHashIterator&lt;QObject*, bool&gt; it(m_states) while (it.hasNext()) { it.next(); set = set&amp;&amp;it.value(); if (! set) break; } if (m_triggerOnSet &amp;&amp; set &amp;&amp; !m_isSet) { m_isSet = set; emit (triggered()); } elseif (m_triggerOnUnset &amp;&amp; !set &amp;&amp; m_isSet) { m_isSet = set; emit (triggered()); } } pivate: QHash&lt;QObject*, bool&gt; m_states; bool m_triggerOnSet; bool m_triggerOnUnset; bool m_isSet; } </code></pre> <p>Did not compile this or even test it, but it should demonstrate the principle</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload