summaryrefslogtreecommitdiffstats
path: root/examples/statemachine/errorstateplugins/spin_ai_with_error/spin_ai_with_error.h
blob: d5204553cc19a0a278e6120ede83b9a60f16dcf0 (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
#ifndef SPIN_AI_WITH_ERROR_H
#define SPIN_AI_WITH_ERROR_H

#include <errorstate/plugin.h>

#include <QObject>
#include <QState>
#include <QVariant>

class SpinState: public QState
{
    Q_OBJECT
public:
    SpinState(QObject *tank, QState *parent) : QState(parent), m_tank(tank)
    {
    }

public slots:
    void spin() 
    {
        m_tank->setProperty("direction", 90.0);
    }

protected:
    void onEntry(QEvent *)
    {
        connect(m_tank, SIGNAL(actionCompleted()), this, SLOT(spin()));
        spin();        
    }

private:
    QObject *m_tank;

};

class SpinAiWithError: public QObject, public Plugin
{
    Q_OBJECT
    Q_INTERFACES(Plugin)
public:
    SpinAiWithError() { setObjectName("Spin and destroy with runtime error in state machine"); }

    virtual QState *create(QState *parentState, QObject *tank);
};

#endif