source: flair-src/trunk/tools/FlairGCS/src/DataRemote.cpp@ 222

Last change on this file since 222 was 222, checked in by Sanahuja Guillaume, 4 years ago

allows realloc in graphs

File size: 2.7 KB
Line 
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 "Manager.h"
10#include "ConnectionLayout.h"
11
12DataRemote::DataRemote(QString name, QString type, XmlWidget *parent,
13 bool enabled, int period)
14 : XmlWidget(name, type, parent) {
15 auto_refresh = enabled;
16 is_logging = true;
17 receivesize = 0;
18 refresh_rate = (double)period / 1000.;
19
20 connectionLayout()->addDataRemote(this);
21
22 // pour ne pas faire de doublons qd on change la periode
23 SetIsExpandable(true);
24}
25
26DataRemote::~DataRemote() { connectionLayout()->removeDataRemote(this); }
27
28void DataRemote::appendmenu(QMenu *menu) {
29 menu->addSeparator();
30
31 autoRefresh = menu->addAction("auto refresh");
32 autoRefresh->setCheckable(true);
33 autoRefresh->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/* menu->addSeparator();
39
40 log = menu->addAction("log");
41 log->setCheckable(true);
42 log->setChecked(is_logging);
43 */
44}
45
46QAction *DataRemote::execmenu(QWidget *parent, QMenu *menu, QPoint point) {
47 QAction *action;
48
49 action = menu->exec(point);
50
51 // auto_refresh=b->isChecked();
52
53 if (action == autoRefresh) {
54 SendPeriod(RefreshRate_ms(), autoRefresh->isChecked());
55 }
56
57 if (action == setRefreshRate) {
58 bool ok;
59 // uint16_t time = QInputDialog::getInt(this, QString("Set refresh rate
60 // (%1)").arg(title().text()),tr("Value (ms):"),
61 // (uint16_t)(qRound(refresh_rate*1000)), 1, 65535, 10, &ok);
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 == true && time != qRound(refresh_rate * 1000)) {
66 // refresh_rate=time/1000.;
67 SendPeriod(time, autoRefresh->isChecked());
68 }
69 }
70
71 return action;
72}
73
74uint16_t DataRemote::RefreshRate_ms(void) {
75 return (uint16_t)(qRound(refresh_rate * 1000.));
76}
77
78bool DataRemote::IsEnabled(void) { return auto_refresh; }
79
80void DataRemote::SendPeriod(int period, bool auto_refresh) {
81 RemoveAllAttributes();
82
83 SetAttribute("period", period);
84 SetAttribute("enabled", auto_refresh);
85
86 connectionLayout()->XmlToSend(XmlDoc());
87
88 RemoveAttribute("period");
89 RemoveAttribute("enabled");
90}
91
92int DataRemote::ReceiveSize(void) { return receivesize; }
93
94void DataRemote::XmlSetup(QDomElement dom) {
95 refresh_rate = dom.attribute("period").toInt() / 1000.;
96 if (dom.attribute("enabled") == "1")
97 auto_refresh = true;
98 else
99 auto_refresh = false;
100}
Note: See TracBrowser for help on using the repository browser.