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.
SWGSDRPlayReport.cpp
Go to the documentation of this file.
1 
14 #include "SWGSDRPlayReport.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  sample_rates = nullptr;
32  m_sample_rates_isSet = false;
33  bandwidths = nullptr;
34  m_bandwidths_isSet = false;
35  intermediate_frequencies = nullptr;
37  frequency_bands = nullptr;
39 }
40 
42  this->cleanup();
43 }
44 
45 void
47  sample_rates = new QList<SWGSampleRate*>();
48  m_sample_rates_isSet = false;
49  bandwidths = new QList<SWGBandwidth*>();
50  m_bandwidths_isSet = false;
51  intermediate_frequencies = new QList<SWGFrequency*>();
53  frequency_bands = new QList<SWGFrequencyBand*>();
55 }
56 
57 void
59  if(sample_rates != nullptr) {
60  auto arr = sample_rates;
61  for(auto o: *arr) {
62  delete o;
63  }
64  delete sample_rates;
65  }
66  if(bandwidths != nullptr) {
67  auto arr = bandwidths;
68  for(auto o: *arr) {
69  delete o;
70  }
71  delete bandwidths;
72  }
73  if(intermediate_frequencies != nullptr) {
74  auto arr = intermediate_frequencies;
75  for(auto o: *arr) {
76  delete o;
77  }
79  }
80  if(frequency_bands != nullptr) {
81  auto arr = frequency_bands;
82  for(auto o: *arr) {
83  delete o;
84  }
85  delete frequency_bands;
86  }
87 }
88 
91  QByteArray array (json.toStdString().c_str());
92  QJsonDocument doc = QJsonDocument::fromJson(array);
93  QJsonObject jsonObject = doc.object();
94  this->fromJsonObject(jsonObject);
95  return this;
96 }
97 
98 void
99 SWGSDRPlayReport::fromJsonObject(QJsonObject &pJson) {
100 
101  ::SWGSDRangel::setValue(&sample_rates, pJson["sampleRates"], "QList", "SWGSampleRate");
102 
103  ::SWGSDRangel::setValue(&bandwidths, pJson["bandwidths"], "QList", "SWGBandwidth");
104 
105  ::SWGSDRangel::setValue(&intermediate_frequencies, pJson["intermediateFrequencies"], "QList", "SWGFrequency");
106 
107  ::SWGSDRangel::setValue(&frequency_bands, pJson["frequencyBands"], "QList", "SWGFrequencyBand");
108 }
109 
110 QString
112 {
113  QJsonObject* obj = this->asJsonObject();
114 
115  QJsonDocument doc(*obj);
116  QByteArray bytes = doc.toJson();
117  delete obj;
118  return QString(bytes);
119 }
120 
121 QJsonObject*
123  QJsonObject* obj = new QJsonObject();
124  if(sample_rates->size() > 0){
125  toJsonArray((QList<void*>*)sample_rates, obj, "sampleRates", "SWGSampleRate");
126  }
127  if(bandwidths->size() > 0){
128  toJsonArray((QList<void*>*)bandwidths, obj, "bandwidths", "SWGBandwidth");
129  }
130  if(intermediate_frequencies->size() > 0){
131  toJsonArray((QList<void*>*)intermediate_frequencies, obj, "intermediateFrequencies", "SWGFrequency");
132  }
133  if(frequency_bands->size() > 0){
134  toJsonArray((QList<void*>*)frequency_bands, obj, "frequencyBands", "SWGFrequencyBand");
135  }
136 
137  return obj;
138 }
139 
140 QList<SWGSampleRate*>*
142  return sample_rates;
143 }
144 void
146  this->sample_rates = sample_rates;
147  this->m_sample_rates_isSet = true;
148 }
149 
150 QList<SWGBandwidth*>*
152  return bandwidths;
153 }
154 void
156  this->bandwidths = bandwidths;
157  this->m_bandwidths_isSet = true;
158 }
159 
160 QList<SWGFrequency*>*
163 }
164 void
166  this->intermediate_frequencies = intermediate_frequencies;
168 }
169 
170 QList<SWGFrequencyBand*>*
172  return frequency_bands;
173 }
174 void
176  this->frequency_bands = frequency_bands;
177  this->m_frequency_bands_isSet = true;
178 }
179 
180 
181 bool
183  bool isObjectUpdated = false;
184  do{
185  if(sample_rates->size() > 0){ isObjectUpdated = true; break;}
186  if(bandwidths->size() > 0){ isObjectUpdated = true; break;}
187  if(intermediate_frequencies->size() > 0){ isObjectUpdated = true; break;}
188  if(frequency_bands->size() > 0){ isObjectUpdated = true; break;}
189  }while(false);
190  return isObjectUpdated;
191 }
192 }
193 
void setIntermediateFrequencies(QList< SWGFrequency *> *intermediate_frequencies)
void setBandwidths(QList< SWGBandwidth *> *bandwidths)
QList< SWGSampleRate * > * getSampleRates()
void setFrequencyBands(QList< SWGFrequencyBand *> *frequency_bands)
virtual QJsonObject * asJsonObject() override
virtual SWGSDRPlayReport * fromJson(QString &jsonString) override
virtual bool isSet() override
QList< SWGFrequency * > * intermediate_frequencies
QList< SWGBandwidth * > * getBandwidths()
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< SWGSampleRate * > * sample_rates
QList< SWGFrequency * > * getIntermediateFrequencies()
QList< SWGFrequencyBand * > * getFrequencyBands()
QList< SWGBandwidth * > * bandwidths
void setSampleRates(QList< SWGSampleRate *> *sample_rates)
virtual QString asJson() override
virtual void fromJsonObject(QJsonObject &json) override
QList< SWGFrequencyBand * > * frequency_bands