Changeset 15 in flair-src for trunk/tools/FlairGCS/src/DataRemote.cpp


Ignore:
Timestamp:
Apr 8, 2016, 3:40:57 PM (5 years ago)
Author:
Bayard Gildas
Message:

sources reformatted with flair-format-dir script

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/FlairGCS/src/DataRemote.cpp

    r10 r15  
    1010#include "ConnectionLayout.h"
    1111
    12 DataRemote::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.;
     12DataRemote::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.;
    1719
    18     connectionLayout()->addDataRemote(this);
     20  connectionLayout()->addDataRemote(this);
    1921
    20     //pour ne pas faire de doublons qd on change la periode
    21     SetIsExpandable(true);
     22  // pour ne pas faire de doublons qd on change la periode
     23  SetIsExpandable(true);
    2224}
    2325
    24 DataRemote::~DataRemote() {
    25     connectionLayout()->removeDataRemote(this);
     26DataRemote::~DataRemote() { connectionLayout()->removeDataRemote(this); }
     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)")
     36                          .arg((uint16_t)(qRound(refresh_rate * 1000))));
     37  c->setEnabled(auto_refresh);
     38  menu->addSeparator();
     39
     40  d = menu->addAction("log");
     41  d->setCheckable(true);
     42  d->setChecked(is_logging);
    2643}
    2744
    28 void DataRemote::appendmenu(QMenu * menu) {
    29     menu->addSeparator();
     45QAction *DataRemote::execmenu(QWidget *parent, QMenu *menu, QPoint point) {
     46  QAction *z;
    3047
    31     b=menu->addAction("auto refresh");
    32     b->setCheckable(true);
    33     b->setChecked(auto_refresh);
     48  z = menu->exec(point);
    3449
    35     c=menu->addAction(QString("set refresh rate (%1ms)").arg((uint16_t)(qRound(refresh_rate*1000))));
    36     c->setEnabled(auto_refresh);
    37     menu->addSeparator();
     50  // auto_refresh=b->isChecked();
    3851
    39     d=menu->addAction("log");
    40     d->setCheckable(true);
    41     d->setChecked(is_logging);
    42 }
     52  if (z == b) {
     53    SendPeriod(RefreshRate_ms(), b->isChecked());
     54  }
    4355
    44 QAction* DataRemote::execmenu(QWidget* parent,QMenu * menu,QPoint point) {
    45     QAction *z;
     56  if (z == c) {
     57    bool ok;
     58    // uint16_t time = QInputDialog::getInt(this, QString("Set refresh rate
     59    // (%1)").arg(title().text()),tr("Value (ms):"),
     60    // (uint16_t)(qRound(refresh_rate*1000)), 1, 65535, 10, &ok);
     61    uint16_t time = QInputDialog::getInt(
     62        parent, "Set refresh rate ", "Value (ms):",
     63        (uint16_t)(qRound(refresh_rate * 1000)), 1, 65535, 10, &ok);
     64    if (ok == true && time != qRound(refresh_rate * 1000)) {
     65      // refresh_rate=time/1000.;
     66      SendPeriod(time, b->isChecked());
     67    }
     68  }
    4669
    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;
     70  return z;
    6671}
    6772
    6873uint16_t DataRemote::RefreshRate_ms(void) {
    69     return (uint16_t)(qRound(refresh_rate*1000.));
     74  return (uint16_t)(qRound(refresh_rate * 1000.));
    7075}
    7176
    72 bool DataRemote::IsEnabled(void) {
    73     return auto_refresh;
     77bool DataRemote::IsEnabled(void) { return auto_refresh; }
     78
     79void DataRemote::SendPeriod(int period, bool auto_refresh) {
     80  SetAttribute("period", period);
     81  SetAttribute("enabled", auto_refresh);
     82
     83  connectionLayout()->XmlToSend(XmlDoc());
     84
     85  RemoveAttribute("period");
     86  RemoveAttribute("enabled");
    7487}
    7588
    76 void 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 
    86 int DataRemote::ReceiveSize(void) {
    87     return receivesize;
    88 }
     89int DataRemote::ReceiveSize(void) { return receivesize; }
    8990
    9091void 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;
     92  refresh_rate = dom.attribute("period").toInt() / 1000.;
     93  if (dom.attribute("enabled") == "1")
     94    auto_refresh = true;
     95  else
     96    auto_refresh = false;
    9697}
Note: See TracChangeset for help on using the changeset viewer.