Search code examples
qtscxml

Creating a custom data model for Qt SCXML


I'm using Qt with an SCXML state machine. I want to use the native Qt SCXML interpreter via QScxmlStateMachine. However, Qt only supports Null, EcmaScript, and C++ data models for SCXML. My state machine has a custom data model.

I would like to subclass QScxmlDataModel to support my state machine. I can see how implementing the setup(), hasScxmlProperty(), setScxmlProperty(), and scxmlProperty() functions would allow setting/getting values from the data model.

However, I don't see how to make it so that expressions and other model-specific items—such as with <transition cond="..."> or <script>...</script>—will properly be evaluated in my custom data model.

How can I make a custom data model that knows how to do more than just get/set properties?


Solution

  • You will need to override the various evaluate functions of the QScxmlDataModel :

    virtual QString evaluateToString(QScxmlExecutableContent::EvaluatorId id, bool *ok) = 0;
    virtual bool evaluateToBool(QScxmlExecutableContent::EvaluatorId id, bool *ok) = 0;
    virtual QVariant evaluateToVariant(QScxmlExecutableContent::EvaluatorId id, bool *ok) = 0;
    virtual void evaluateToVoid(QScxmlExecutableContent::EvaluatorId id, bool *ok) = 0;
    virtual void evaluateAssignment(QScxmlExecutableContent::EvaluatorId id, bool *ok) = 0;
    virtual void evaluateInitialization(QScxmlExecutableContent::EvaluatorId id, bool *ok) = 0;
    virtual bool evaluateForeach(QScxmlExecutableContent::EvaluatorId id, bool *ok, ForeachLoopBody *body) = 0;
    

    They have all been excluded from the documentation, but you can see them here.

    My guess the reason for this is that Qt SCXML module is released as Technology Preview and the API might change in the future.