25#include <QXmlStreamWriter>
29struct ScxmlExporter::Private
37 bool writeState(
State *state);
38 bool writeStateInner(
State *state);
39 bool writeTransition(
const Transition *transition);
42 QXmlStreamWriter m_writer;
45ScxmlExporter::Private::Private(QByteArray *array,
ScxmlExporter *q)
52ScxmlExporter::Private::Private(QIODevice *device,
ScxmlExporter *q)
60 : d(new Private(array, this))
65 : d(new Private(device, this))
73void ScxmlExporter::Private::init()
75 m_writer.setAutoFormatting(
true);
87 if (d->m_writer.hasError()) {
92 return d->writeStateMachine(machine);
95bool ScxmlExporter::Private::writeStateMachine(
StateMachine *machine)
102 m_writer.writeStartDocument();
103 m_writer.writeStartElement(QStringLiteral(
"scxml"));
104 m_writer.writeDefaultNamespace(QStringLiteral(
"http://www.w3.org/2005/07/scxml"));
105 m_writer.writeAttribute(QStringLiteral(
"version"), QStringLiteral(
"1.0"));
106 if (!writeStateInner(machine))
108 m_writer.writeEndElement();
109 m_writer.writeEndDocument();
110 return !m_writer.hasError();
113bool ScxmlExporter::Private::writeState(
State *state)
115 if (qobject_cast<PseudoState *>(state)) {
119 m_writer.writeStartElement(QStringLiteral(
"state"));
120 if (!writeStateInner(state))
122 m_writer.writeEndElement();
126bool ScxmlExporter::Private::writeStateInner(
State *state)
128 if (state->
label().isEmpty()) {
133 if (qobject_cast<StateMachine *>(state)) {
134 m_writer.writeAttribute(QStringLiteral(
"name"), state->
label());
136 m_writer.writeAttribute(QStringLiteral(
"id"), state->
label());
140 if (initial->label().isEmpty()) {
144 m_writer.writeAttribute(QStringLiteral(
"initial"), initial->label());
147 const auto stateTransitions = state->
transitions();
148 for (
const Transition *transition : stateTransitions) {
149 writeTransition(transition);
153 return std::all_of(childStates.begin(), childStates.end(),
154 [
this](
State *child) { return writeState(child); });
157bool ScxmlExporter::Private::writeTransition(
const Transition *transition)
159 m_writer.writeStartElement(QStringLiteral(
"transition"));
160 m_writer.writeAttribute(QStringLiteral(
"event"), transition->
label());
162 m_writer.writeAttribute(QStringLiteral(
"target"), targetState->label());
164 m_writer.writeEndElement();
void setErrorString(const QString &errorString)
ScxmlExporter(QByteArray *array)
virtual bool exportMachine(StateMachine *machine) override
QList< Transition * > transitions() const
QList< State * > childStates() const
KDSME::State * targetState
KDSME_CORE_EXPORT State * findInitialState(const State *state)
KDSME_CORE_EXPORT QString displayString(const QObject *object, DisplayOption option=NoStrip)