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.
SWGArgInfo.cpp
Go to the documentation of this file.
1 
14 #include "SWGArgInfo.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 SWGArgInfo::SWGArgInfo(QString* json) {
26  init();
27  this->fromJson(*json);
28 }
29 
31  key = nullptr;
32  m_key_isSet = false;
33  value_type = nullptr;
34  m_value_type_isSet = false;
35  value_string = nullptr;
36  m_value_string_isSet = false;
37  name = nullptr;
38  m_name_isSet = false;
39  description = nullptr;
40  m_description_isSet = false;
41  units = nullptr;
42  m_units_isSet = false;
43  range = nullptr;
44  m_range_isSet = false;
45  value_options = nullptr;
46  m_value_options_isSet = false;
47  option_names = nullptr;
48  m_option_names_isSet = false;
49 }
50 
52  this->cleanup();
53 }
54 
55 void
57  key = new QString("");
58  m_key_isSet = false;
59  value_type = new QString("");
60  m_value_type_isSet = false;
61  value_string = new QString("");
62  m_value_string_isSet = false;
63  name = new QString("");
64  m_name_isSet = false;
65  description = new QString("");
66  m_description_isSet = false;
67  units = new QString("");
68  m_units_isSet = false;
69  range = new SWGRangeFloat();
70  m_range_isSet = false;
71  value_options = new QList<QString*>();
72  m_value_options_isSet = false;
73  option_names = new QList<QString*>();
74  m_option_names_isSet = false;
75 }
76 
77 void
79  if(key != nullptr) {
80  delete key;
81  }
82  if(value_type != nullptr) {
83  delete value_type;
84  }
85  if(value_string != nullptr) {
86  delete value_string;
87  }
88  if(name != nullptr) {
89  delete name;
90  }
91  if(description != nullptr) {
92  delete description;
93  }
94  if(units != nullptr) {
95  delete units;
96  }
97  if(range != nullptr) {
98  delete range;
99  }
100  if(value_options != nullptr) {
101  auto arr = value_options;
102  for(auto o: *arr) {
103  delete o;
104  }
105  delete value_options;
106  }
107  if(option_names != nullptr) {
108  auto arr = option_names;
109  for(auto o: *arr) {
110  delete o;
111  }
112  delete option_names;
113  }
114 }
115 
116 SWGArgInfo*
117 SWGArgInfo::fromJson(QString &json) {
118  QByteArray array (json.toStdString().c_str());
119  QJsonDocument doc = QJsonDocument::fromJson(array);
120  QJsonObject jsonObject = doc.object();
121  this->fromJsonObject(jsonObject);
122  return this;
123 }
124 
125 void
126 SWGArgInfo::fromJsonObject(QJsonObject &pJson) {
127  ::SWGSDRangel::setValue(&key, pJson["key"], "QString", "QString");
128 
129  ::SWGSDRangel::setValue(&value_type, pJson["valueType"], "QString", "QString");
130 
131  ::SWGSDRangel::setValue(&value_string, pJson["valueString"], "QString", "QString");
132 
133  ::SWGSDRangel::setValue(&name, pJson["name"], "QString", "QString");
134 
135  ::SWGSDRangel::setValue(&description, pJson["description"], "QString", "QString");
136 
137  ::SWGSDRangel::setValue(&units, pJson["units"], "QString", "QString");
138 
139  ::SWGSDRangel::setValue(&range, pJson["range"], "SWGRangeFloat", "SWGRangeFloat");
140 
141 
142  ::SWGSDRangel::setValue(&value_options, pJson["valueOptions"], "QList", "QString");
143 
144  ::SWGSDRangel::setValue(&option_names, pJson["optionNames"], "QList", "QString");
145 }
146 
147 QString
149 {
150  QJsonObject* obj = this->asJsonObject();
151 
152  QJsonDocument doc(*obj);
153  QByteArray bytes = doc.toJson();
154  delete obj;
155  return QString(bytes);
156 }
157 
158 QJsonObject*
160  QJsonObject* obj = new QJsonObject();
161  if(key != nullptr && *key != QString("")){
162  toJsonValue(QString("key"), key, obj, QString("QString"));
163  }
164  if(value_type != nullptr && *value_type != QString("")){
165  toJsonValue(QString("valueType"), value_type, obj, QString("QString"));
166  }
167  if(value_string != nullptr && *value_string != QString("")){
168  toJsonValue(QString("valueString"), value_string, obj, QString("QString"));
169  }
170  if(name != nullptr && *name != QString("")){
171  toJsonValue(QString("name"), name, obj, QString("QString"));
172  }
173  if(description != nullptr && *description != QString("")){
174  toJsonValue(QString("description"), description, obj, QString("QString"));
175  }
176  if(units != nullptr && *units != QString("")){
177  toJsonValue(QString("units"), units, obj, QString("QString"));
178  }
179  if((range != nullptr) && (range->isSet())){
180  toJsonValue(QString("range"), range, obj, QString("SWGRangeFloat"));
181  }
182  if(value_options->size() > 0){
183  toJsonArray((QList<void*>*)value_options, obj, "valueOptions", "QString");
184  }
185  if(option_names->size() > 0){
186  toJsonArray((QList<void*>*)option_names, obj, "optionNames", "QString");
187  }
188 
189  return obj;
190 }
191 
192 QString*
194  return key;
195 }
196 void
198  this->key = key;
199  this->m_key_isSet = true;
200 }
201 
202 QString*
204  return value_type;
205 }
206 void
208  this->value_type = value_type;
209  this->m_value_type_isSet = true;
210 }
211 
212 QString*
214  return value_string;
215 }
216 void
218  this->value_string = value_string;
219  this->m_value_string_isSet = true;
220 }
221 
222 QString*
224  return name;
225 }
226 void
228  this->name = name;
229  this->m_name_isSet = true;
230 }
231 
232 QString*
234  return description;
235 }
236 void
238  this->description = description;
239  this->m_description_isSet = true;
240 }
241 
242 QString*
244  return units;
245 }
246 void
248  this->units = units;
249  this->m_units_isSet = true;
250 }
251 
254  return range;
255 }
256 void
258  this->range = range;
259  this->m_range_isSet = true;
260 }
261 
262 QList<QString*>*
264  return value_options;
265 }
266 void
268  this->value_options = value_options;
269  this->m_value_options_isSet = true;
270 }
271 
272 QList<QString*>*
274  return option_names;
275 }
276 void
278  this->option_names = option_names;
279  this->m_option_names_isSet = true;
280 }
281 
282 
283 bool
285  bool isObjectUpdated = false;
286  do{
287  if(key != nullptr && *key != QString("")){ isObjectUpdated = true; break;}
288  if(value_type != nullptr && *value_type != QString("")){ isObjectUpdated = true; break;}
289  if(value_string != nullptr && *value_string != QString("")){ isObjectUpdated = true; break;}
290  if(name != nullptr && *name != QString("")){ isObjectUpdated = true; break;}
291  if(description != nullptr && *description != QString("")){ isObjectUpdated = true; break;}
292  if(units != nullptr && *units != QString("")){ isObjectUpdated = true; break;}
293  if(range != nullptr && range->isSet()){ isObjectUpdated = true; break;}
294  if(value_options->size() > 0){ isObjectUpdated = true; break;}
295  if(option_names->size() > 0){ isObjectUpdated = true; break;}
296  }while(false);
297  return isObjectUpdated;
298 }
299 }
300 
QString * getDescription()
Definition: SWGArgInfo.cpp:233
QList< QString * > * value_options
Definition: SWGArgInfo.h:99
virtual bool isSet() override
Definition: SWGArgInfo.cpp:284
QList< QString * > * getValueOptions()
Definition: SWGArgInfo.cpp:263
QList< QString * > * getOptionNames()
Definition: SWGArgInfo.cpp:273
void setName(QString *name)
Definition: SWGArgInfo.cpp:227
void toJsonValue(QString name, void *value, QJsonObject *output, QString type)
Definition: SWGHelpers.cpp:383
void setValueOptions(QList< QString *> *value_options)
Definition: SWGArgInfo.cpp:267
virtual void fromJsonObject(QJsonObject &json) override
Definition: SWGArgInfo.cpp:126
virtual QJsonObject * asJsonObject() override
Definition: SWGArgInfo.cpp:159
void setRange(SWGRangeFloat *range)
Definition: SWGArgInfo.cpp:257
void setValueString(QString *value_string)
Definition: SWGArgInfo.cpp:217
void setValueType(QString *value_type)
Definition: SWGArgInfo.cpp:207
SWGRangeFloat * range
Definition: SWGArgInfo.h:96
void setKey(QString *key)
Definition: SWGArgInfo.cpp:197
SWGRangeFloat * getRange()
Definition: SWGArgInfo.cpp:253
void setUnits(QString *units)
Definition: SWGArgInfo.cpp:247
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
QString * getValueString()
Definition: SWGArgInfo.cpp:213
void setDescription(QString *description)
Definition: SWGArgInfo.cpp:237
virtual SWGArgInfo * fromJson(QString &jsonString) override
Definition: SWGArgInfo.cpp:117
void setOptionNames(QList< QString *> *option_names)
Definition: SWGArgInfo.cpp:277
QList< QString * > * option_names
Definition: SWGArgInfo.h:102
virtual QString asJson() override
Definition: SWGArgInfo.cpp:148
virtual bool isSet() override