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.
SWGChannel.cpp
Go to the documentation of this file.
1 
14 #include "SWGChannel.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 SWGChannel::SWGChannel(QString* json) {
26  init();
27  this->fromJson(*json);
28 }
29 
31  index = 0;
32  m_index_isSet = false;
33  id = nullptr;
34  m_id_isSet = false;
35  uid = 0L;
36  m_uid_isSet = false;
37  title = nullptr;
38  m_title_isSet = false;
39  delta_frequency = 0;
41  report = nullptr;
42  m_report_isSet = false;
43 }
44 
46  this->cleanup();
47 }
48 
49 void
51  index = 0;
52  m_index_isSet = false;
53  id = new QString("");
54  m_id_isSet = false;
55  uid = 0L;
56  m_uid_isSet = false;
57  title = new QString("");
58  m_title_isSet = false;
59  delta_frequency = 0;
61  report = new SWGChannelReport();
62  m_report_isSet = false;
63 }
64 
65 void
67 
68  if(id != nullptr) {
69  delete id;
70  }
71 
72  if(title != nullptr) {
73  delete title;
74  }
75 
76  if(report != nullptr) {
77  delete report;
78  }
79 }
80 
82 SWGChannel::fromJson(QString &json) {
83  QByteArray array (json.toStdString().c_str());
84  QJsonDocument doc = QJsonDocument::fromJson(array);
85  QJsonObject jsonObject = doc.object();
86  this->fromJsonObject(jsonObject);
87  return this;
88 }
89 
90 void
91 SWGChannel::fromJsonObject(QJsonObject &pJson) {
92  ::SWGSDRangel::setValue(&index, pJson["index"], "qint32", "");
93 
94  ::SWGSDRangel::setValue(&id, pJson["id"], "QString", "QString");
95 
96  ::SWGSDRangel::setValue(&uid, pJson["uid"], "qint64", "");
97 
98  ::SWGSDRangel::setValue(&title, pJson["title"], "QString", "QString");
99 
100  ::SWGSDRangel::setValue(&delta_frequency, pJson["deltaFrequency"], "qint32", "");
101 
102  ::SWGSDRangel::setValue(&report, pJson["report"], "SWGChannelReport", "SWGChannelReport");
103 
104 }
105 
106 QString
108 {
109  QJsonObject* obj = this->asJsonObject();
110 
111  QJsonDocument doc(*obj);
112  QByteArray bytes = doc.toJson();
113  delete obj;
114  return QString(bytes);
115 }
116 
117 QJsonObject*
119  QJsonObject* obj = new QJsonObject();
120  if(m_index_isSet){
121  obj->insert("index", QJsonValue(index));
122  }
123  if(id != nullptr && *id != QString("")){
124  toJsonValue(QString("id"), id, obj, QString("QString"));
125  }
126  if(m_uid_isSet){
127  obj->insert("uid", QJsonValue(uid));
128  }
129  if(title != nullptr && *title != QString("")){
130  toJsonValue(QString("title"), title, obj, QString("QString"));
131  }
133  obj->insert("deltaFrequency", QJsonValue(delta_frequency));
134  }
135  if((report != nullptr) && (report->isSet())){
136  toJsonValue(QString("report"), report, obj, QString("SWGChannelReport"));
137  }
138 
139  return obj;
140 }
141 
142 qint32
144  return index;
145 }
146 void
148  this->index = index;
149  this->m_index_isSet = true;
150 }
151 
152 QString*
154  return id;
155 }
156 void
157 SWGChannel::setId(QString* id) {
158  this->id = id;
159  this->m_id_isSet = true;
160 }
161 
162 qint64
164  return uid;
165 }
166 void
168  this->uid = uid;
169  this->m_uid_isSet = true;
170 }
171 
172 QString*
174  return title;
175 }
176 void
178  this->title = title;
179  this->m_title_isSet = true;
180 }
181 
182 qint32
184  return delta_frequency;
185 }
186 void
188  this->delta_frequency = delta_frequency;
189  this->m_delta_frequency_isSet = true;
190 }
191 
194  return report;
195 }
196 void
198  this->report = report;
199  this->m_report_isSet = true;
200 }
201 
202 
203 bool
205  bool isObjectUpdated = false;
206  do{
207  if(m_index_isSet){ isObjectUpdated = true; break;}
208  if(id != nullptr && *id != QString("")){ isObjectUpdated = true; break;}
209  if(m_uid_isSet){ isObjectUpdated = true; break;}
210  if(title != nullptr && *title != QString("")){ isObjectUpdated = true; break;}
211  if(m_delta_frequency_isSet){ isObjectUpdated = true; break;}
212  if(report != nullptr && report->isSet()){ isObjectUpdated = true; break;}
213  }while(false);
214  return isObjectUpdated;
215 }
216 }
217 
void setReport(SWGChannelReport *report)
Definition: SWGChannel.cpp:197
void setId(QString *id)
Definition: SWGChannel.cpp:157
void toJsonValue(QString name, void *value, QJsonObject *output, QString type)
Definition: SWGHelpers.cpp:383
SWGChannelReport * report
Definition: SWGChannel.h:83
virtual SWGChannel * fromJson(QString &jsonString) override
Definition: SWGChannel.cpp:82
virtual QJsonObject * asJsonObject() override
Definition: SWGChannel.cpp:118
void setIndex(qint32 index)
Definition: SWGChannel.cpp:147
virtual void fromJsonObject(QJsonObject &json) override
Definition: SWGChannel.cpp:91
void setValue(void *value, QJsonValue obj, QString type, QString complexType)
Definition: SWGHelpers.cpp:25
void setDeltaFrequency(qint32 delta_frequency)
Definition: SWGChannel.cpp:187
void setTitle(QString *title)
Definition: SWGChannel.cpp:177
virtual bool isSet() override
virtual QString asJson() override
Definition: SWGChannel.cpp:107
SWGChannelReport * getReport()
Definition: SWGChannel.cpp:193
virtual bool isSet() override
Definition: SWGChannel.cpp:204
void setUid(qint64 uid)
Definition: SWGChannel.cpp:167