summaryrefslogtreecommitdiffstats
path: root/src/qml-module/statemachine.h
blob: a192a329dfea4e9b0bf538b7a408dc0a16aee543 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/****************************************************************************
 **
 ** Copyright (c) 2015 Digia Plc
 ** For any questions to Digia, please use contact form at http://qt.digia.com/
 **
 ** All Rights Reserved.
 **
 ** NOTICE: All information contained herein is, and remains
 ** the property of Digia Plc and its suppliers,
 ** if any. The intellectual and technical concepts contained
 ** herein are proprietary to Digia Plc
 ** and its suppliers and may be covered by Finnish and Foreign Patents,
 ** patents in process, and are protected by trade secret or copyright law.
 ** Dissemination of this information or reproduction of this material
 ** is strictly forbidden unless prior written permission is obtained
 ** from Digia Plc.
 ****************************************************************************/

#ifndef STATEMACHINE_H
#define STATEMACHINE_H

#include <QVector>
#include <QQmlParserStatus>
#include <QQmlListProperty>
#include <QScxml/scxmlstatetable.h>

QT_BEGIN_NAMESPACE

class State;
class QQmlOpenMetaObject;
class StateMachine: public QObject, public QQmlParserStatus
{
    Q_OBJECT
    Q_INTERFACES(QQmlParserStatus)
    Q_PROPERTY(QQmlListProperty<QObject> states READ states NOTIFY statesChanged DESIGNABLE false)
    Q_PROPERTY(QString filename READ filename WRITE setFilename NOTIFY filenameChanged)
    Q_PROPERTY(Scxml::StateTable* stateMachine READ stateMachine WRITE setStateMachine)

    Q_CLASSINFO("DefaultProperty", "states")

public:
    typedef QVector<QObject *> Kids;
    explicit StateMachine(QObject *parent = 0);

    void classBegin() {}
    void componentComplete();
    QQmlListProperty<QObject> states();

    Scxml::StateTable *stateMachine() const;
    void setStateMachine(Scxml::StateTable *stateMachine);

    QString filename();
    void setFilename(const QString filename);

Q_SIGNALS:
    void statesChanged();
    void filenameChanged();

private:
    bool parse(const QString &filename);

private:
    QString m_filename;
    Kids m_children;
    Scxml::StateTable *m_table = nullptr;
};

QT_END_NAMESPACE

#endif