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

Last change on this file since 218 was 67, checked in by Sanahuja Guillaume, 8 years ago

corrections bugs checkpoint map

File size: 2.6 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 b = menu->addAction("auto refresh");
32 b->setCheckable(true);
33 b->setChecked(auto_refresh);
34
35 c = menu->addAction(QString("set refresh rate (%1ms)")
36 .arg((uint16_t)(qRound(refresh_rate * 1000))));
37 c->setEnabled(auto_refresh);
38 menu->addSeparator();
39
40 d = menu->addAction("log");
41 d->setCheckable(true);
42 d->setChecked(is_logging);
43}
44
45QAction *DataRemote::execmenu(QWidget *parent, QMenu *menu, QPoint point) {
46 QAction *z;
47
48 z = menu->exec(point);
49
50 // auto_refresh=b->isChecked();
51
52 if (z == b) {
53 SendPeriod(RefreshRate_ms(), b->isChecked());
54 }
55
56 if (z == c) {
57 bool ok;
58 // uint16_t time = QInputDialog::getInt(this, QString("Set refresh rate
59 // (%1)").arg(title().text()),tr("Value (ms):"),
60 // (uint16_t)(qRound(refresh_rate*1000)), 1, 65535, 10, &ok);
61 uint16_t time = QInputDialog::getInt(
62 parent, "Set refresh rate ", "Value (ms):",
63 (uint16_t)(qRound(refresh_rate * 1000)), 1, 65535, 10, &ok);
64 if (ok == true && time != qRound(refresh_rate * 1000)) {
65 // refresh_rate=time/1000.;
66 SendPeriod(time, b->isChecked());
67 }
68 }
69
70 return z;
71}
72
73uint16_t DataRemote::RefreshRate_ms(void) {
74 return (uint16_t)(qRound(refresh_rate * 1000.));
75}
76
77bool DataRemote::IsEnabled(void) { return auto_refresh; }
78
79void DataRemote::SendPeriod(int period, bool auto_refresh) {
80 RemoveAllAttributes();
81
82 SetAttribute("period", period);
83 SetAttribute("enabled", auto_refresh);
84
85 connectionLayout()->XmlToSend(XmlDoc());
86
87 RemoveAttribute("period");
88 RemoveAttribute("enabled");
89}
90
91int DataRemote::ReceiveSize(void) { return receivesize; }
92
93void DataRemote::XmlSetup(QDomElement dom) {
94 refresh_rate = dom.attribute("period").toInt() / 1000.;
95 if (dom.attribute("enabled") == "1")
96 auto_refresh = true;
97 else
98 auto_refresh = false;
99}
Note: See TracBrowser for help on using the repository browser.