source: flair-src/branches/mavlink/tools/FlairGCS/src/DataRemote.cpp@ 66

Last change on this file since 66 was 15, checked in by Bayard Gildas, 9 years ago

sources reformatted with flair-format-dir script

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 SetAttribute("period", period);
81 SetAttribute("enabled", auto_refresh);
82
83 connectionLayout()->XmlToSend(XmlDoc());
84
85 RemoveAttribute("period");
86 RemoveAttribute("enabled");
87}
88
89int DataRemote::ReceiveSize(void) { return receivesize; }
90
91void DataRemote::XmlSetup(QDomElement dom) {
92 refresh_rate = dom.attribute("period").toInt() / 1000.;
93 if (dom.attribute("enabled") == "1")
94 auto_refresh = true;
95 else
96 auto_refresh = false;
97}
Note: See TracBrowser for help on using the repository browser.