-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.h
More file actions
67 lines (54 loc) · 1.8 KB
/
action.h
File metadata and controls
67 lines (54 loc) · 1.8 KB
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
#ifndef ACTION_H
#define ACTION_H
#include <QtQml/qqml.h>
#include "command.h"
#include "commandservice.h"
namespace NCR {
class Action {
QML_INTERFACE
public:
Action() = default;
virtual ~Action() = default;
Q_INVOKABLE virtual void execute() = 0;
};
}
Q_DECLARE_INTERFACE(NCR::Action, "Action")
namespace NCR {
class CommandAction : public QObject, public Action {
Q_OBJECT
Q_PROPERTY(CommandService* service READ service WRITE service NOTIFY serviceChanged)
Q_PROPERTY(QString command READ get_command WRITE set_command NOTIFY commandChanged)
QML_ELEMENT
QML_IMPLEMENTS_INTERFACES(NCR::Action)
public:
CommandAction() =default;
CommandAction(const Command& command, CommandService* service) : command_(command), service_(service) { }
CommandAction(const QString& command, CommandService* service) : service_(service) { set_command(command); }
Q_INVOKABLE void execute() override {
service_->send_command(command_);
}
Q_INVOKABLE void set_command(const QString& command) { command_.command(command.toStdString()); }
Q_INVOKABLE void set_parameter(const QString& name, const QString& value) {
command_.set_parameter(name.toStdString(), value.toStdString());
}
Q_INVOKABLE void remove_parameter(const QString& name) { command_.remove_parameter(name.toStdString()); }
CommandService* service() { return service_; }
Command& command() { return command_; }
Q_INVOKABLE QString get_command() { return QString::fromStdString(command_.command()); }
void service(CommandService* service) {
service_ = service;
emit serviceChanged();
}
void command(const Command& command) {
command_ = command;
emit commandChanged();
}
signals:
void commandChanged();
void serviceChanged();
private:
CommandService* service_;
Command command_;
};
}
#endif // ACTION_H