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.
SWGPreset.cpp
Go to the documentation of this file.
1 
14 #include "SWGPreset.h"
15 
16 #include "SWGHelpers.h"
17 
18 #include <QJsonDocument>
19 #include <QJsonArray>
20 #include <QObject>
21 #include <QDebug>
22 
23 namespace SWGSDRangel {
24 
25 SWGPreset::SWGPreset(QString* json) {
26  init();
27  this->fromJson(*json);
28 }
29 
31  source_preset = 0;
32  m_source_preset_isSet = false;
33  group = nullptr;
34  m_group_isSet = false;
35  description = nullptr;
36  m_description_isSet = false;
37  center_frequency = 0L;
39  m_spectrum_config = nullptr;
45  channel_configs = nullptr;
47  device_configs = nullptr;
48  m_device_configs_isSet = false;
49  layout = nullptr;
50  m_layout_isSet = false;
51 }
52 
54  this->cleanup();
55 }
56 
57 void
59  source_preset = 0;
60  m_source_preset_isSet = false;
61  group = new QString("");
62  m_group_isSet = false;
63  description = new QString("");
64  m_description_isSet = false;
65  center_frequency = 0L;
73  channel_configs = new QList<SWGChannelConfig*>();
75  device_configs = new QList<SWGDeviceConfig*>();
76  m_device_configs_isSet = false;
77  layout = new QString("");
78  m_layout_isSet = false;
79 }
80 
81 void
83 
84  if(group != nullptr) {
85  delete group;
86  }
87  if(description != nullptr) {
88  delete description;
89  }
90 
91  if(m_spectrum_config != nullptr) {
92  delete m_spectrum_config;
93  }
94 
95 
96  if(channel_configs != nullptr) {
97  auto arr = channel_configs;
98  for(auto o: *arr) {
99  delete o;
100  }
101  delete channel_configs;
102  }
103  if(device_configs != nullptr) {
104  auto arr = device_configs;
105  for(auto o: *arr) {
106  delete o;
107  }
108  delete device_configs;
109  }
110  if(layout != nullptr) {
111  delete layout;
112  }
113 }
114 
115 SWGPreset*
116 SWGPreset::fromJson(QString &json) {
117  QByteArray array (json.toStdString().c_str());
118  QJsonDocument doc = QJsonDocument::fromJson(array);
119  QJsonObject jsonObject = doc.object();
120  this->fromJsonObject(jsonObject);
121  return this;
122 }
123 
124 void
125 SWGPreset::fromJsonObject(QJsonObject &pJson) {
126  ::SWGSDRangel::setValue(&source_preset, pJson["sourcePreset"], "qint32", "");
127 
128  ::SWGSDRangel::setValue(&group, pJson["group"], "QString", "QString");
129 
130  ::SWGSDRangel::setValue(&description, pJson["description"], "QString", "QString");
131 
132  ::SWGSDRangel::setValue(&center_frequency, pJson["centerFrequency"], "qint64", "");
133 
134  ::SWGSDRangel::setValue(&m_spectrum_config, pJson["m_spectrumConfig"], "SWGGLSpectrum", "SWGGLSpectrum");
135 
136  ::SWGSDRangel::setValue(&dc_offset_correction, pJson["dcOffsetCorrection"], "qint32", "");
137 
138  ::SWGSDRangel::setValue(&iq_imbalance_correction, pJson["iqImbalanceCorrection"], "qint32", "");
139 
140 
141  ::SWGSDRangel::setValue(&channel_configs, pJson["channelConfigs"], "QList", "SWGChannelConfig");
142 
143  ::SWGSDRangel::setValue(&device_configs, pJson["deviceConfigs"], "QList", "SWGDeviceConfig");
144  ::SWGSDRangel::setValue(&layout, pJson["layout"], "QString", "QString");
145 
146 }
147 
148 QString
150 {
151  QJsonObject* obj = this->asJsonObject();
152 
153  QJsonDocument doc(*obj);
154  QByteArray bytes = doc.toJson();
155  delete obj;
156  return QString(bytes);
157 }
158 
159 QJsonObject*
161  QJsonObject* obj = new QJsonObject();
163  obj->insert("sourcePreset", QJsonValue(source_preset));
164  }
165  if(group != nullptr && *group != QString("")){
166  toJsonValue(QString("group"), group, obj, QString("QString"));
167  }
168  if(description != nullptr && *description != QString("")){
169  toJsonValue(QString("description"), description, obj, QString("QString"));
170  }
172  obj->insert("centerFrequency", QJsonValue(center_frequency));
173  }
174  if((m_spectrum_config != nullptr) && (m_spectrum_config->isSet())){
175  toJsonValue(QString("m_spectrumConfig"), m_spectrum_config, obj, QString("SWGGLSpectrum"));
176  }
178  obj->insert("dcOffsetCorrection", QJsonValue(dc_offset_correction));
179  }
181  obj->insert("iqImbalanceCorrection", QJsonValue(iq_imbalance_correction));
182  }
183  if(channel_configs->size() > 0){
184  toJsonArray((QList<void*>*)channel_configs, obj, "channelConfigs", "SWGChannelConfig");
185  }
186  if(device_configs->size() > 0){
187  toJsonArray((QList<void*>*)device_configs, obj, "deviceConfigs", "SWGDeviceConfig");
188  }
189  if(layout != nullptr && *layout != QString("")){
190  toJsonValue(QString("layout"), layout, obj, QString("QString"));
191  }
192 
193  return obj;
194 }
195 
196 qint32
198  return source_preset;
199 }
200 void
202  this->source_preset = source_preset;
203  this->m_source_preset_isSet = true;
204 }
205 
206 QString*
208  return group;
209 }
210 void
212  this->group = group;
213  this->m_group_isSet = true;
214 }
215 
216 QString*
218  return description;
219 }
220 void
222  this->description = description;
223  this->m_description_isSet = true;
224 }
225 
226 qint64
228  return center_frequency;
229 }
230 void
232  this->center_frequency = center_frequency;
233  this->m_center_frequency_isSet = true;
234 }
235 
238  return m_spectrum_config;
239 }
240 void
242  this->m_spectrum_config = m_spectrum_config;
243  this->m_m_spectrum_config_isSet = true;
244 }
245 
246 qint32
248  return dc_offset_correction;
249 }
250 void
252  this->dc_offset_correction = dc_offset_correction;
253  this->m_dc_offset_correction_isSet = true;
254 }
255 
256 qint32
259 }
260 void
262  this->iq_imbalance_correction = iq_imbalance_correction;
263  this->m_iq_imbalance_correction_isSet = true;
264 }
265 
266 QList<SWGChannelConfig*>*
268  return channel_configs;
269 }
270 void
271 SWGPreset::setChannelConfigs(QList<SWGChannelConfig*>* channel_configs) {
272  this->channel_configs = channel_configs;
273  this->m_channel_configs_isSet = true;
274 }
275 
276 QList<SWGDeviceConfig*>*
278  return device_configs;
279 }
280 void
281 SWGPreset::setDeviceConfigs(QList<SWGDeviceConfig*>* device_configs) {
282  this->device_configs = device_configs;
283  this->m_device_configs_isSet = true;
284 }
285 
286 QString*
288  return layout;
289 }
290 void
292  this->layout = layout;
293  this->m_layout_isSet = true;
294 }
295 
296 
297 bool
299  bool isObjectUpdated = false;
300  do{
301  if(m_source_preset_isSet){ isObjectUpdated = true; break;}
302  if(group != nullptr && *group != QString("")){ isObjectUpdated = true; break;}
303  if(description != nullptr && *description != QString("")){ isObjectUpdated = true; break;}
304  if(m_center_frequency_isSet){ isObjectUpdated = true; break;}
305  if(m_spectrum_config != nullptr && m_spectrum_config->isSet()){ isObjectUpdated = true; break;}
306  if(m_dc_offset_correction_isSet){ isObjectUpdated = true; break;}
307  if(m_iq_imbalance_correction_isSet){ isObjectUpdated = true; break;}
308  if(channel_configs->size() > 0){ isObjectUpdated = true; break;}
309  if(device_configs->size() > 0){ isObjectUpdated = true; break;}
310  if(layout != nullptr && *layout != QString("")){ isObjectUpdated = true; break;}
311  }while(false);
312  return isObjectUpdated;
313 }
314 }
315 
QString * getDescription()
Definition: SWGPreset.cpp:217
void toJsonValue(QString name, void *value, QJsonObject *output, QString type)
Definition: SWGHelpers.cpp:383
QList< SWGDeviceConfig * > * device_configs
Definition: SWGPreset.h:107
QList< SWGChannelConfig * > * getChannelConfigs()
Definition: SWGPreset.cpp:267
void setDcOffsetCorrection(qint32 dc_offset_correction)
Definition: SWGPreset.cpp:251
virtual bool isSet() override
Definition: SWGPreset.cpp:298
void setSourcePreset(qint32 source_preset)
Definition: SWGPreset.cpp:201
virtual QJsonObject * asJsonObject() override
Definition: SWGPreset.cpp:160
virtual bool isSet() override
SWGGLSpectrum * m_spectrum_config
Definition: SWGPreset.h:95
qint32 getIqImbalanceCorrection()
Definition: SWGPreset.cpp:257
void setMSpectrumConfig(SWGGLSpectrum *m_spectrum_config)
Definition: SWGPreset.cpp:241
bool m_iq_imbalance_correction_isSet
Definition: SWGPreset.h:102
void setChannelConfigs(QList< SWGChannelConfig *> *channel_configs)
Definition: SWGPreset.cpp:271
qint32 getDcOffsetCorrection()
Definition: SWGPreset.cpp:247
bool m_dc_offset_correction_isSet
Definition: SWGPreset.h:99
void setIqImbalanceCorrection(qint32 iq_imbalance_correction)
Definition: SWGPreset.cpp:261
void setDescription(QString *description)
Definition: SWGPreset.cpp:221
void setGroup(QString *group)
Definition: SWGPreset.cpp:211
virtual SWGPreset * fromJson(QString &jsonString) override
Definition: SWGPreset.cpp:116
SWGGLSpectrum * getMSpectrumConfig()
Definition: SWGPreset.cpp:237
void setCenterFrequency(qint64 center_frequency)
Definition: SWGPreset.cpp:231
virtual void fromJsonObject(QJsonObject &json) override
Definition: SWGPreset.cpp:125
bool m_m_spectrum_config_isSet
Definition: SWGPreset.h:96
QString * description
Definition: SWGPreset.h:89
void setValue(void *value, QJsonValue obj, QString type, QString complexType)
Definition: SWGHelpers.cpp:25
void setLayout(QString *layout)
Definition: SWGPreset.cpp:291
void toJsonArray(QList< void *> *value, QJsonObject *output, QString innerName, QString innerType)
Definition: SWGHelpers.cpp:445
qint32 iq_imbalance_correction
Definition: SWGPreset.h:101
qint32 dc_offset_correction
Definition: SWGPreset.h:98
virtual QString asJson() override
Definition: SWGPreset.cpp:149
QList< SWGDeviceConfig * > * getDeviceConfigs()
Definition: SWGPreset.cpp:277
void setDeviceConfigs(QList< SWGDeviceConfig *> *device_configs)
Definition: SWGPreset.cpp:281
QList< SWGChannelConfig * > * channel_configs
Definition: SWGPreset.h:104