[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] | 11 | DataRemote::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] | 26 | DataRemote::~DataRemote() { connectionLayout()->removeDataRemote(this); }
|
---|
[9] | 27 |
|
---|
[15] | 28 | void 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] | 50 | QAction *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 |
|
---|
| 85 | uint16_t DataRemote::RefreshRate_ms(void) {
|
---|
[15] | 86 | return (uint16_t)(qRound(refresh_rate * 1000.));
|
---|
[9] | 87 | }
|
---|
| 88 |
|
---|
[444] | 89 | uint16_t DataRemote::NbBuffering(void) {
|
---|
| 90 | return nb_buffering;
|
---|
| 91 | }
|
---|
| 92 |
|
---|
[15] | 93 | bool DataRemote::IsEnabled(void) { return auto_refresh; }
|
---|
[9] | 94 |
|
---|
[437] | 95 | void DataRemote::SendPeriod(uint16_t period, bool auto_refresh) {
|
---|
[67] | 96 | RemoveAllAttributes();
|
---|
| 97 |
|
---|
[15] | 98 | SetAttribute("period", period);
|
---|
| 99 | SetAttribute("enabled", auto_refresh);
|
---|
| 100 | connectionLayout()->XmlToSend(XmlDoc());
|
---|
| 101 | RemoveAttribute("period");
|
---|
| 102 | RemoveAttribute("enabled");
|
---|
[9] | 103 | }
|
---|
| 104 |
|
---|
[437] | 105 | void DataRemote::SendNbBuffering(uint16_t nb_buffering) {
|
---|
| 106 | RemoveAllAttributes();
|
---|
| 107 |
|
---|
| 108 | SetAttribute("nb_buf", nb_buffering);
|
---|
| 109 | connectionLayout()->XmlToSend(XmlDoc());
|
---|
| 110 | RemoveAttribute("nb_buf");
|
---|
| 111 | }
|
---|
| 112 |
|
---|
[269] | 113 | void DataRemote::XmlSetup(QDomElement *dom) {
|
---|
[437] | 114 | refresh_rate = dom->attribute("period").toUShort() / 1000.;
|
---|
| 115 | nb_buffering = dom->attribute("nb_buf").toUShort();
|
---|
[269] | 116 | if (dom->attribute("enabled") == "1")
|
---|
[15] | 117 | auto_refresh = true;
|
---|
| 118 | else
|
---|
| 119 | auto_refresh = false;
|
---|
[9] | 120 | }
|
---|