-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswitch.h
66 lines (51 loc) · 1.58 KB
/
switch.h
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
#ifndef SWITCH_H
#define SWITCH_H
#include <QObject>
#include <QString>
#include <QPair>
#include <QList>
#include <QTimer>
#include <QMap>
class Switch : public QObject
{
Q_OBJECT
public:
enum TimerEffect {
TimerNoEffect = 0,
TimerStart,
TimerStop
};
class SwitchMessage {
public:
QString inMessage;
QString outMessage;
TimerEffect effect;
SwitchMessage(const QString& _inMessage, const QString& _outMessage, TimerEffect _effect = TimerNoEffect);
SwitchMessage(const SwitchMessage& other);
SwitchMessage();
void readJSON(const QJsonObject &json);
void writeJSON(QJsonObject &json) const;
};
// Switch(QObject *parent = nullptr);
Switch(const QString& name = QString(), QObject *parent = nullptr);
virtual ~Switch();
const QString& name() { return mName; }
QStringList knownMessages() { return messages.keys(); }
void setTimer(const QString& timerMessage, int timerPeriod = 1000 /*ms*/);
bool addMessage(const QString& inMessage, const QString& outMessage, TimerEffect effect = TimerNoEffect);
void readJSON(const QJsonObject &json);
void writeJSON(QJsonObject &json) const;
protected:
QTimer myTimer;
SwitchMessage *delayMessage;
int delayTimerLen, repeatTimerLen;
QString mName, mTimerMessage;
QMap<QString, SwitchMessage*> messages;
signals:
void postMessage(const QString& name, const QString& message);
public slots:
void processMessage(const QString& msg);
protected slots:
void sendTimerMessage();
};
#endif // SWITCH_H