[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 "Manager.h"
|
---|
| 10 | #include "ConnectionLayout.h"
|
---|
| 11 |
|
---|
[15] | 12 | DataRemote::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.;
|
---|
[9] | 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 |
|
---|
[222] | 31 | autoRefresh = menu->addAction("auto refresh");
|
---|
| 32 | autoRefresh->setCheckable(true);
|
---|
| 33 | autoRefresh->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);
|
---|
| 38 | /* menu->addSeparator();
|
---|
[9] | 39 |
|
---|
[222] | 40 | log = menu->addAction("log");
|
---|
| 41 | log->setCheckable(true);
|
---|
| 42 | log->setChecked(is_logging);
|
---|
| 43 | */
|
---|
[9] | 44 | }
|
---|
| 45 |
|
---|
[15] | 46 | QAction *DataRemote::execmenu(QWidget *parent, QMenu *menu, QPoint point) {
|
---|
[222] | 47 | QAction *action;
|
---|
[9] | 48 |
|
---|
[222] | 49 | action = menu->exec(point);
|
---|
[9] | 50 |
|
---|
[15] | 51 | // auto_refresh=b->isChecked();
|
---|
[9] | 52 |
|
---|
[222] | 53 | if (action == autoRefresh) {
|
---|
| 54 | SendPeriod(RefreshRate_ms(), autoRefresh->isChecked());
|
---|
[15] | 55 | }
|
---|
[9] | 56 |
|
---|
[222] | 57 | if (action == setRefreshRate) {
|
---|
[15] | 58 | bool ok;
|
---|
[234] | 59 |
|
---|
[15] | 60 | uint16_t time = QInputDialog::getInt(
|
---|
| 61 | parent, "Set refresh rate ", "Value (ms):",
|
---|
| 62 | (uint16_t)(qRound(refresh_rate * 1000)), 1, 65535, 10, &ok);
|
---|
| 63 | if (ok == true && time != qRound(refresh_rate * 1000)) {
|
---|
| 64 | // refresh_rate=time/1000.;
|
---|
[222] | 65 | SendPeriod(time, autoRefresh->isChecked());
|
---|
[9] | 66 | }
|
---|
[15] | 67 | }
|
---|
[222] | 68 |
|
---|
| 69 | return action;
|
---|
[9] | 70 | }
|
---|
| 71 |
|
---|
| 72 | uint16_t DataRemote::RefreshRate_ms(void) {
|
---|
[15] | 73 | return (uint16_t)(qRound(refresh_rate * 1000.));
|
---|
[9] | 74 | }
|
---|
| 75 |
|
---|
[15] | 76 | bool DataRemote::IsEnabled(void) { return auto_refresh; }
|
---|
[9] | 77 |
|
---|
[15] | 78 | void DataRemote::SendPeriod(int period, bool auto_refresh) {
|
---|
[67] | 79 | RemoveAllAttributes();
|
---|
| 80 |
|
---|
[15] | 81 | SetAttribute("period", period);
|
---|
| 82 | SetAttribute("enabled", auto_refresh);
|
---|
| 83 | connectionLayout()->XmlToSend(XmlDoc());
|
---|
| 84 | RemoveAttribute("period");
|
---|
| 85 | RemoveAttribute("enabled");
|
---|
[9] | 86 | }
|
---|
| 87 |
|
---|
[15] | 88 | int DataRemote::ReceiveSize(void) { return receivesize; }
|
---|
[9] | 89 |
|
---|
[269] | 90 | void DataRemote::XmlSetup(QDomElement *dom) {
|
---|
| 91 | refresh_rate = dom->attribute("period").toInt() / 1000.;
|
---|
| 92 | if (dom->attribute("enabled") == "1")
|
---|
[15] | 93 | auto_refresh = true;
|
---|
| 94 | else
|
---|
| 95 | auto_refresh = false;
|
---|
[9] | 96 | }
|
---|