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

Last change on this file since 436 was 436, checked in by Sanahuja Guillaume, 18 months ago

gcs:sync graphs

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