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

Last change on this file since 10 was 10, checked in by Sanahuja Guillaume, 5 years ago

lic

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