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.
SWGDeviceConfig.cpp
Go to the documentation of this file.
1 
14 #include "SWGDeviceConfig.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  device_id = nullptr;
32  m_device_id_isSet = false;
33  device_serial = nullptr;
34  m_device_serial_isSet = false;
35  device_sequence = 0;
37  config = nullptr;
38  m_config_isSet = false;
39 }
40 
42  this->cleanup();
43 }
44 
45 void
47  device_id = new QString("");
48  m_device_id_isSet = false;
49  device_serial = new QString("");
50  m_device_serial_isSet = false;
51  device_sequence = 0;
53  config = new SWGDeviceSettings();
54  m_config_isSet = false;
55 }
56 
57 void
59  if(device_id != nullptr) {
60  delete device_id;
61  }
62  if(device_serial != nullptr) {
63  delete device_serial;
64  }
65 
66  if(config != nullptr) {
67  delete config;
68  }
69 }
70 
72 SWGDeviceConfig::fromJson(QString &json) {
73  QByteArray array (json.toStdString().c_str());
74  QJsonDocument doc = QJsonDocument::fromJson(array);
75  QJsonObject jsonObject = doc.object();
76  this->fromJsonObject(jsonObject);
77  return this;
78 }
79 
80 void
81 SWGDeviceConfig::fromJsonObject(QJsonObject &pJson) {
82  ::SWGSDRangel::setValue(&device_id, pJson["deviceId"], "QString", "QString");
83 
84  ::SWGSDRangel::setValue(&device_serial, pJson["deviceSerial"], "QString", "QString");
85 
86  ::SWGSDRangel::setValue(&device_sequence, pJson["deviceSequence"], "qint32", "");
87 
88  ::SWGSDRangel::setValue(&config, pJson["config"], "SWGDeviceSettings", "SWGDeviceSettings");
89 
90 }
91 
92 QString
94 {
95  QJsonObject* obj = this->asJsonObject();
96 
97  QJsonDocument doc(*obj);
98  QByteArray bytes = doc.toJson();
99  delete obj;
100  return QString(bytes);
101 }
102 
103 QJsonObject*
105  QJsonObject* obj = new QJsonObject();
106  if(device_id != nullptr && *device_id != QString("")){
107  toJsonValue(QString("deviceId"), device_id, obj, QString("QString"));
108  }
109  if(device_serial != nullptr && *device_serial != QString("")){
110  toJsonValue(QString("deviceSerial"), device_serial, obj, QString("QString"));
111  }
113  obj->insert("deviceSequence", QJsonValue(device_sequence));
114  }
115  if((config != nullptr) && (config->isSet())){
116  toJsonValue(QString("config"), config, obj, QString("SWGDeviceSettings"));
117  }
118 
119  return obj;
120 }
121 
122 QString*
124  return device_id;
125 }
126 void
128  this->device_id = device_id;
129  this->m_device_id_isSet = true;
130 }
131 
132 QString*
134  return device_serial;
135 }
136 void
138  this->device_serial = device_serial;
139  this->m_device_serial_isSet = true;
140 }
141 
142 qint32
144  return device_sequence;
145 }
146 void
148  this->device_sequence = device_sequence;
149  this->m_device_sequence_isSet = true;
150 }
151 
154  return config;
155 }
156 void
158  this->config = config;
159  this->m_config_isSet = true;
160 }
161 
162 
163 bool
165  bool isObjectUpdated = false;
166  do{
167  if(device_id != nullptr && *device_id != QString("")){ isObjectUpdated = true; break;}
168  if(device_serial != nullptr && *device_serial != QString("")){ isObjectUpdated = true; break;}
169  if(m_device_sequence_isSet){ isObjectUpdated = true; break;}
170  if(config != nullptr && config->isSet()){ isObjectUpdated = true; break;}
171  }while(false);
172  return isObjectUpdated;
173 }
174 }
175 
void setDeviceSequence(qint32 device_sequence)
void toJsonValue(QString name, void *value, QJsonObject *output, QString type)
Definition: SWGHelpers.cpp:383
virtual QString asJson() override
void setConfig(SWGDeviceSettings *config)
void setDeviceId(QString *device_id)
virtual void fromJsonObject(QJsonObject &json) override
void setDeviceSerial(QString *device_serial)
SWGDeviceSettings * config
void setValue(void *value, QJsonValue obj, QString type, QString complexType)
Definition: SWGHelpers.cpp:25
virtual bool isSet() override
virtual QJsonObject * asJsonObject() override
SWGDeviceSettings * getConfig()
virtual SWGDeviceConfig * fromJson(QString &jsonString) override