Ejemplo n.º 1
0
/**
 * @brief Create a GUI driven by a state machine, realtime-debug this state machine in another window
 */
int main(int argc, char** argv)
{
    QApplication app(argc, argv);

    //! [Target setup]
    TrafficLight trafficLight;
    trafficLight.resize(110, 300);
    trafficLight.show();

    // set up the debug interface on the local registry and connect to it
    // this is simpler than writing another class that handles in-process debuggging
    // just pay the cost for the in-process communication, it's not that much anyway
    QRemoteObjectRegistryHost registryHostNode(QUrl(QStringLiteral("local:registry")));
    QRemoteObjectHost hostNode(QUrl(QStringLiteral("local:replica")), QUrl(QStringLiteral("local:registry")));
    QsmDebugInterfaceSource interfaceSource;
    interfaceSource.setQStateMachine(trafficLight.machine());
    hostNode.enableRemoting(interfaceSource.remoteObjectSource());
    //! [Target setup]

    //! [Client setup for viewing the state machine]
    StateMachineView view;
    view.resize(800, 600);
    view.show();

    QRemoteObjectNode clientNode(QUrl(QStringLiteral("local:registry")));
    auto interfaceReplica = clientNode.acquire<DebugInterfaceReplica>();
    interfaceReplica->waitForSource();

    DebugInterfaceClient client;
    client.setDebugInterface(interfaceReplica);
    QObject::connect(&client, &DebugInterfaceClient::repopulateView,
                     [&]() {
            qDebug() << "Updating state machine in view";
            view.scene()->setRootState(client.machine());
            view.scene()->layout();
        }
    );
    //! [Client setup for viewing the state machine]

    app.exec();
}
Ejemplo n.º 2
0
/**
 * @brief Loading a SCXML file from disk and displaying it
 */
int main(int argc, char** argv)
{
    QApplication app(argc, argv);

    const QString fileName = TEST_DATA_DIR "/scxml/microwave.scxml";
    QFile file(fileName);
    if (!file.exists()) {
        qWarning() << "File does not exist:" << file.fileName();
        return 1;
    }

    Q_ASSERT(file.open(QIODevice::ReadOnly));
    ScxmlImporter parser(file.readAll());
    QScopedPointer<StateMachine> machine(parser.import());
    Q_ASSERT(machine);

    StateMachineView view;
    view.scene()->setRootState(machine.data());
    view.scene()->layout();
    view.resize(800, 600);
    view.show();

    app.exec();
}