[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;
|
---|
| 59 | // uint16_t time = QInputDialog::getInt(this, QString("Set refresh rate
|
---|
| 60 | // (%1)").arg(title().text()),tr("Value (ms):"),
|
---|
| 61 | // (uint16_t)(qRound(refresh_rate*1000)), 1, 65535, 10, &ok);
|
---|
| 62 | uint16_t time = QInputDialog::getInt(
|
---|
| 63 | parent, "Set refresh rate ", "Value (ms):",
|
---|
| 64 | (uint16_t)(qRound(refresh_rate * 1000)), 1, 65535, 10, &ok);
|
---|
| 65 | if (ok == true && time != qRound(refresh_rate * 1000)) {
|
---|
| 66 | // refresh_rate=time/1000.;
|
---|
[222] | 67 | SendPeriod(time, autoRefresh->isChecked());
|
---|
[9] | 68 | }
|
---|
[15] | 69 | }
|
---|
[222] | 70 |
|
---|
| 71 | return action;
|
---|
[9] | 72 | }
|
---|
| 73 |
|
---|
| 74 | uint16_t DataRemote::RefreshRate_ms(void) {
|
---|
[15] | 75 | return (uint16_t)(qRound(refresh_rate * 1000.));
|
---|
[9] | 76 | }
|
---|
| 77 |
|
---|
[15] | 78 | bool DataRemote::IsEnabled(void) { return auto_refresh; }
|
---|
[9] | 79 |
|
---|
[15] | 80 | void DataRemote::SendPeriod(int period, bool auto_refresh) {
|
---|
[67] | 81 | RemoveAllAttributes();
|
---|
| 82 |
|
---|
[15] | 83 | SetAttribute("period", period);
|
---|
| 84 | SetAttribute("enabled", auto_refresh);
|
---|
[9] | 85 |
|
---|
[15] | 86 | connectionLayout()->XmlToSend(XmlDoc());
|
---|
[9] | 87 |
|
---|
[15] | 88 | RemoveAttribute("period");
|
---|
| 89 | RemoveAttribute("enabled");
|
---|
[9] | 90 | }
|
---|
| 91 |
|
---|
[15] | 92 | int DataRemote::ReceiveSize(void) { return receivesize; }
|
---|
[9] | 93 |
|
---|
| 94 | void DataRemote::XmlSetup(QDomElement dom) {
|
---|
[15] | 95 | refresh_rate = dom.attribute("period").toInt() / 1000.;
|
---|
| 96 | if (dom.attribute("enabled") == "1")
|
---|
| 97 | auto_refresh = true;
|
---|
| 98 | else
|
---|
| 99 | auto_refresh = false;
|
---|
[9] | 100 | }
|
---|