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

Last change on this file since 437 was 437, checked in by Sanahuja Guillaume, 5 months ago

prepare for graphs buffering

File size: 3.2 KB
RevLine 
[10]1// %flair:license{
[15]2// This file is part of the Flair framework distributed under the
3// CECILL-C License, Version 1.0.
[10]4// %flair:license}
[9]5#include "DataRemote.h"
6#include <QMenu>
7#include <QInputDialog>
8#include <QtXml>
9#include "ConnectionLayout.h"
10
[15]11DataRemote::DataRemote(QString name, QString type, XmlWidget *parent,
[437]12 bool enabled, uint16_t period, uint16_t nb_buffering)
[15]13 : XmlWidget(name, type, parent) {
14 auto_refresh = enabled;
15 is_logging = true;
16 receivesize = 0;
17 refresh_rate = (double)period / 1000.;
[437]18 this->nb_buffering=nb_buffering;
19
[15]20 connectionLayout()->addDataRemote(this);
[9]21
[15]22 // pour ne pas faire de doublons qd on change la periode
23 SetIsExpandable(true);
[9]24}
25
[15]26DataRemote::~DataRemote() { connectionLayout()->removeDataRemote(this); }
[9]27
[15]28void DataRemote::appendmenu(QMenu *menu) {
29 menu->addSeparator();
[9]30
[437]31 SetAutoRefresh = menu->addAction("auto refresh");
32 SetAutoRefresh->setCheckable(true);
33 SetAutoRefresh->setChecked(auto_refresh);
[9]34
[222]35 setRefreshRate = menu->addAction(QString("set refresh rate (%1ms)")
[15]36 .arg((uint16_t)(qRound(refresh_rate * 1000))));
[222]37 setRefreshRate->setEnabled(auto_refresh);
[437]38
39 menu->addSeparator();
40 setNbBuffering = menu->addAction(QString("set nb buffering (%1)").arg(nb_buffering));
41
[222]42/* menu->addSeparator();
[9]43
[222]44 log = menu->addAction("log");
45 log->setCheckable(true);
46 log->setChecked(is_logging);
47 */
[9]48}
49
[15]50QAction *DataRemote::execmenu(QWidget *parent, QMenu *menu, QPoint point) {
[222]51 QAction *action;
[9]52
[222]53 action = menu->exec(point);
[9]54
[437]55 if (action == SetAutoRefresh) {
56 SendPeriod(RefreshRate_ms(), SetAutoRefresh->isChecked());
[15]57 }
[9]58
[222]59 if (action == setRefreshRate) {
[15]60 bool ok;
[234]61
[15]62 uint16_t time = QInputDialog::getInt(
63 parent, "Set refresh rate ", "Value (ms):",
64 (uint16_t)(qRound(refresh_rate * 1000)), 1, 65535, 10, &ok);
[437]65 if (ok && time != qRound(refresh_rate * 1000)) {
[15]66 // refresh_rate=time/1000.;
[437]67 SendPeriod(time, SetAutoRefresh->isChecked());
[9]68 }
[15]69 }
[222]70
[437]71 if (action == setNbBuffering) {
72 bool ok;
73
74 uint16_t nb_buffering = QInputDialog::getInt(
75 parent, "Set nb buffering ", "Value :",
76 this->nb_buffering, 1, 65535, 10, &ok);
77 if (ok && nb_buffering !=this->nb_buffering) {
78 SendNbBuffering(nb_buffering);
79 }
80 }
81
[222]82 return action;
[9]83}
84
85uint16_t DataRemote::RefreshRate_ms(void) {
[15]86 return (uint16_t)(qRound(refresh_rate * 1000.));
[9]87}
88
[15]89bool DataRemote::IsEnabled(void) { return auto_refresh; }
[9]90
[437]91void DataRemote::SendPeriod(uint16_t period, bool auto_refresh) {
[67]92 RemoveAllAttributes();
93
[15]94 SetAttribute("period", period);
95 SetAttribute("enabled", auto_refresh);
96 connectionLayout()->XmlToSend(XmlDoc());
97 RemoveAttribute("period");
98 RemoveAttribute("enabled");
[9]99}
100
[437]101void DataRemote::SendNbBuffering(uint16_t nb_buffering) {
102 RemoveAllAttributes();
103
104 SetAttribute("nb_buf", nb_buffering);
105 connectionLayout()->XmlToSend(XmlDoc());
106 RemoveAttribute("nb_buf");
107}
108
[15]109int DataRemote::ReceiveSize(void) { return receivesize; }
[9]110
[269]111void DataRemote::XmlSetup(QDomElement *dom) {
[437]112 refresh_rate = dom->attribute("period").toUShort() / 1000.;
113 nb_buffering = dom->attribute("nb_buf").toUShort();
[269]114 if (dom->attribute("enabled") == "1")
[15]115 auto_refresh = true;
116 else
117 auto_refresh = false;
[9]118}
Note: See TracBrowser for help on using the repository browser.