1 | // %flair:license{
|
---|
2 | // This file is part of the Flair framework distributed under the
|
---|
3 | // CECILL-C License, Version 1.0.
|
---|
4 | // %flair:license}
|
---|
5 | #include "DataRemote.h"
|
---|
6 | #include <QMenu>
|
---|
7 | #include <QInputDialog>
|
---|
8 | #include <QtXml>
|
---|
9 | #include "ConnectionLayout.h"
|
---|
10 |
|
---|
11 | DataRemote::DataRemote(QString name, QString type, XmlWidget *parent,
|
---|
12 | bool enabled, uint16_t period, uint16_t nb_buffering)
|
---|
13 | : XmlWidget(name, type, parent) {
|
---|
14 | auto_refresh = enabled;
|
---|
15 | is_logging = true;
|
---|
16 | receivesize = 0;
|
---|
17 | refresh_rate = (double)period / 1000.;
|
---|
18 | this->nb_buffering=nb_buffering;
|
---|
19 |
|
---|
20 | connectionLayout()->addDataRemote(this);
|
---|
21 |
|
---|
22 | // pour ne pas faire de doublons qd on change la periode
|
---|
23 | SetIsExpandable(true);
|
---|
24 | }
|
---|
25 |
|
---|
26 | DataRemote::~DataRemote() { connectionLayout()->removeDataRemote(this); }
|
---|
27 |
|
---|
28 | void DataRemote::appendmenu(QMenu *menu) {
|
---|
29 | menu->addSeparator();
|
---|
30 |
|
---|
31 | SetAutoRefresh = menu->addAction("auto refresh");
|
---|
32 | SetAutoRefresh->setCheckable(true);
|
---|
33 | SetAutoRefresh->setChecked(auto_refresh);
|
---|
34 |
|
---|
35 | setRefreshRate = menu->addAction(QString("set refresh rate (%1ms)")
|
---|
36 | .arg((uint16_t)(qRound(refresh_rate * 1000))));
|
---|
37 | setRefreshRate->setEnabled(auto_refresh);
|
---|
38 |
|
---|
39 | menu->addSeparator();
|
---|
40 | setNbBuffering = menu->addAction(QString("set nb buffering (%1)").arg(nb_buffering));
|
---|
41 |
|
---|
42 | /* menu->addSeparator();
|
---|
43 |
|
---|
44 | log = menu->addAction("log");
|
---|
45 | log->setCheckable(true);
|
---|
46 | log->setChecked(is_logging);
|
---|
47 | */
|
---|
48 | }
|
---|
49 |
|
---|
50 | QAction *DataRemote::execmenu(QWidget *parent, QMenu *menu, QPoint point) {
|
---|
51 | QAction *action;
|
---|
52 |
|
---|
53 | action = menu->exec(point);
|
---|
54 |
|
---|
55 | if (action == SetAutoRefresh) {
|
---|
56 | SendPeriod(RefreshRate_ms(), SetAutoRefresh->isChecked());
|
---|
57 | }
|
---|
58 |
|
---|
59 | if (action == setRefreshRate) {
|
---|
60 | bool ok;
|
---|
61 |
|
---|
62 | uint16_t time = QInputDialog::getInt(
|
---|
63 | parent, "Set refresh rate ", "Value (ms):",
|
---|
64 | (uint16_t)(qRound(refresh_rate * 1000)), 1, 65535, 10, &ok);
|
---|
65 | if (ok && time != qRound(refresh_rate * 1000)) {
|
---|
66 | // refresh_rate=time/1000.;
|
---|
67 | SendPeriod(time, SetAutoRefresh->isChecked());
|
---|
68 | }
|
---|
69 | }
|
---|
70 |
|
---|
71 | if (action == setNbBuffering) {
|
---|
72 | bool ok;
|
---|
73 |
|
---|
74 | uint16_t nb_buffering = QInputDialog::getInt(
|
---|
75 | parent, "Set nb buffering ", "Value :",
|
---|
76 | this->nb_buffering, 1, 65535, 10, &ok);
|
---|
77 | if (ok && nb_buffering !=this->nb_buffering) {
|
---|
78 | SendNbBuffering(nb_buffering);
|
---|
79 | }
|
---|
80 | }
|
---|
81 |
|
---|
82 | return action;
|
---|
83 | }
|
---|
84 |
|
---|
85 | uint16_t DataRemote::RefreshRate_ms(void) {
|
---|
86 | return (uint16_t)(qRound(refresh_rate * 1000.));
|
---|
87 | }
|
---|
88 |
|
---|
89 | bool DataRemote::IsEnabled(void) { return auto_refresh; }
|
---|
90 |
|
---|
91 | void DataRemote::SendPeriod(uint16_t period, bool auto_refresh) {
|
---|
92 | RemoveAllAttributes();
|
---|
93 |
|
---|
94 | SetAttribute("period", period);
|
---|
95 | SetAttribute("enabled", auto_refresh);
|
---|
96 | connectionLayout()->XmlToSend(XmlDoc());
|
---|
97 | RemoveAttribute("period");
|
---|
98 | RemoveAttribute("enabled");
|
---|
99 | }
|
---|
100 |
|
---|
101 | void DataRemote::SendNbBuffering(uint16_t nb_buffering) {
|
---|
102 | RemoveAllAttributes();
|
---|
103 |
|
---|
104 | SetAttribute("nb_buf", nb_buffering);
|
---|
105 | connectionLayout()->XmlToSend(XmlDoc());
|
---|
106 | RemoveAttribute("nb_buf");
|
---|
107 | }
|
---|
108 |
|
---|
109 | int DataRemote::ReceiveSize(void) { return receivesize; }
|
---|
110 |
|
---|
111 | void DataRemote::XmlSetup(QDomElement *dom) {
|
---|
112 | refresh_rate = dom->attribute("period").toUShort() / 1000.;
|
---|
113 | nb_buffering = dom->attribute("nb_buf").toUShort();
|
---|
114 | if (dom->attribute("enabled") == "1")
|
---|
115 | auto_refresh = true;
|
---|
116 | else
|
---|
117 | auto_refresh = false;
|
---|
118 | }
|
---|