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.
SWGNamedEnum.cpp
Go to the documentation of this file.
1 
14 #include "SWGNamedEnum.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  name = nullptr;
32  m_name_isSet = false;
33  value = 0;
34  m_value_isSet = false;
35 }
36 
38  this->cleanup();
39 }
40 
41 void
43  name = new QString("");
44  m_name_isSet = false;
45  value = 0;
46  m_value_isSet = false;
47 }
48 
49 void
51  if(name != nullptr) {
52  delete name;
53  }
54 
55 }
56 
58 SWGNamedEnum::fromJson(QString &json) {
59  QByteArray array (json.toStdString().c_str());
60  QJsonDocument doc = QJsonDocument::fromJson(array);
61  QJsonObject jsonObject = doc.object();
62  this->fromJsonObject(jsonObject);
63  return this;
64 }
65 
66 void
67 SWGNamedEnum::fromJsonObject(QJsonObject &pJson) {
68  ::SWGSDRangel::setValue(&name, pJson["name"], "QString", "QString");
69 
70  ::SWGSDRangel::setValue(&value, pJson["value"], "qint32", "");
71 
72 }
73 
74 QString
76 {
77  QJsonObject* obj = this->asJsonObject();
78 
79  QJsonDocument doc(*obj);
80  QByteArray bytes = doc.toJson();
81  delete obj;
82  return QString(bytes);
83 }
84 
85 QJsonObject*
87  QJsonObject* obj = new QJsonObject();
88  if(name != nullptr && *name != QString("")){
89  toJsonValue(QString("name"), name, obj, QString("QString"));
90  }
91  if(m_value_isSet){
92  obj->insert("value", QJsonValue(value));
93  }
94 
95  return obj;
96 }
97 
98 QString*
100  return name;
101 }
102 void
104  this->name = name;
105  this->m_name_isSet = true;
106 }
107 
108 qint32
110  return value;
111 }
112 void
114  this->value = value;
115  this->m_value_isSet = true;
116 }
117 
118 
119 bool
121  bool isObjectUpdated = false;
122  do{
123  if(name != nullptr && *name != QString("")){ isObjectUpdated = true; break;}
124  if(m_value_isSet){ isObjectUpdated = true; break;}
125  }while(false);
126  return isObjectUpdated;
127 }
128 }
129 
void toJsonValue(QString name, void *value, QJsonObject *output, QString type)
Definition: SWGHelpers.cpp:383
void setName(QString *name)
virtual SWGNamedEnum * fromJson(QString &jsonString) override
void setValue(qint32 value)
virtual QJsonObject * asJsonObject() override
virtual QString asJson() override
void setValue(void *value, QJsonValue obj, QString type, QString complexType)
Definition: SWGHelpers.cpp:25
virtual bool isSet() override
virtual void fromJsonObject(QJsonObject &json) override