SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
SWGDVSerialDevices.cpp
Go to the documentation of this file.
1 
14 #include "SWGDVSerialDevices.h"
15 
16 #include "SWGHelpers.h"
17 
18 #include <QJsonDocument>
19 #include <QJsonArray>
20 #include <QObject>
21 #include <QDebug>
22 
23 namespace SWGSDRangel {
24 
26  init();
27  this->fromJson(*json);
28 }
29 
31  nb_devices = 0;
32  m_nb_devices_isSet = false;
33  dv_serial_devices = nullptr;
35 }
36 
38  this->cleanup();
39 }
40 
41 void
43  nb_devices = 0;
44  m_nb_devices_isSet = false;
45  dv_serial_devices = new QList<SWGDVSerialDevice*>();
47 }
48 
49 void
51 
52  if(dv_serial_devices != nullptr) {
53  auto arr = dv_serial_devices;
54  for(auto o: *arr) {
55  delete o;
56  }
57  delete dv_serial_devices;
58  }
59 }
60 
63  QByteArray array (json.toStdString().c_str());
64  QJsonDocument doc = QJsonDocument::fromJson(array);
65  QJsonObject jsonObject = doc.object();
66  this->fromJsonObject(jsonObject);
67  return this;
68 }
69 
70 void
72  ::SWGSDRangel::setValue(&nb_devices, pJson["nbDevices"], "qint32", "");
73 
74 
75  ::SWGSDRangel::setValue(&dv_serial_devices, pJson["dvSerialDevices"], "QList", "SWGDVSerialDevice");
76 }
77 
78 QString
80 {
81  QJsonObject* obj = this->asJsonObject();
82 
83  QJsonDocument doc(*obj);
84  QByteArray bytes = doc.toJson();
85  delete obj;
86  return QString(bytes);
87 }
88 
89 QJsonObject*
91  QJsonObject* obj = new QJsonObject();
93  obj->insert("nbDevices", QJsonValue(nb_devices));
94  }
95  if(dv_serial_devices->size() > 0){
96  toJsonArray((QList<void*>*)dv_serial_devices, obj, "dvSerialDevices", "SWGDVSerialDevice");
97  }
98 
99  return obj;
100 }
101 
102 qint32
104  return nb_devices;
105 }
106 void
108  this->nb_devices = nb_devices;
109  this->m_nb_devices_isSet = true;
110 }
111 
112 QList<SWGDVSerialDevice*>*
114  return dv_serial_devices;
115 }
116 void
118  this->dv_serial_devices = dv_serial_devices;
119  this->m_dv_serial_devices_isSet = true;
120 }
121 
122 
123 bool
125  bool isObjectUpdated = false;
126  do{
127  if(m_nb_devices_isSet){ isObjectUpdated = true; break;}
128  if(dv_serial_devices->size() > 0){ isObjectUpdated = true; break;}
129  }while(false);
130  return isObjectUpdated;
131 }
132 }
133 
virtual SWGDVSerialDevices * fromJson(QString &jsonString) override
virtual QString asJson() override
QList< SWGDVSerialDevice * > * getDvSerialDevices()
void setNbDevices(qint32 nb_devices)
void setDvSerialDevices(QList< SWGDVSerialDevice *> *dv_serial_devices)
virtual QJsonObject * asJsonObject() override
void setValue(void *value, QJsonValue obj, QString type, QString complexType)
Definition: SWGHelpers.cpp:25
void toJsonArray(QList< void *> *value, QJsonObject *output, QString innerName, QString innerType)
Definition: SWGHelpers.cpp:445
QList< SWGDVSerialDevice * > * dv_serial_devices
virtual void fromJsonObject(QJsonObject &json) override