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

Last change on this file since 9 was 9, checked in by Sanahuja Guillaume, 7 years ago

gcs

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