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.
SWGArgValue.cpp
Go to the documentation of this file.
1 
14 #include "SWGArgValue.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 SWGArgValue::SWGArgValue(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 }
38 
40  this->cleanup();
41 }
42 
43 void
45  key = new QString("");
46  m_key_isSet = false;
47  value_type = new QString("");
48  m_value_type_isSet = false;
49  value_string = new QString("");
50  m_value_string_isSet = false;
51 }
52 
53 void
55  if(key != nullptr) {
56  delete key;
57  }
58  if(value_type != nullptr) {
59  delete value_type;
60  }
61  if(value_string != nullptr) {
62  delete value_string;
63  }
64 }
65 
67 SWGArgValue::fromJson(QString &json) {
68  QByteArray array (json.toStdString().c_str());
69  QJsonDocument doc = QJsonDocument::fromJson(array);
70  QJsonObject jsonObject = doc.object();
71  this->fromJsonObject(jsonObject);
72  return this;
73 }
74 
75 void
76 SWGArgValue::fromJsonObject(QJsonObject &pJson) {
77  ::SWGSDRangel::setValue(&key, pJson["key"], "QString", "QString");
78 
79  ::SWGSDRangel::setValue(&value_type, pJson["valueType"], "QString", "QString");
80 
81  ::SWGSDRangel::setValue(&value_string, pJson["valueString"], "QString", "QString");
82 
83 }
84 
85 QString
87 {
88  QJsonObject* obj = this->asJsonObject();
89 
90  QJsonDocument doc(*obj);
91  QByteArray bytes = doc.toJson();
92  delete obj;
93  return QString(bytes);
94 }
95 
96 QJsonObject*
98  QJsonObject* obj = new QJsonObject();
99  if(key != nullptr && *key != QString("")){
100  toJsonValue(QString("key"), key, obj, QString("QString"));
101  }
102  if(value_type != nullptr && *value_type != QString("")){
103  toJsonValue(QString("valueType"), value_type, obj, QString("QString"));
104  }
105  if(value_string != nullptr && *value_string != QString("")){
106  toJsonValue(QString("valueString"), value_string, obj, QString("QString"));
107  }
108 
109  return obj;
110 }
111 
112 QString*
114  return key;
115 }
116 void
118  this->key = key;
119  this->m_key_isSet = true;
120 }
121 
122 QString*
124  return value_type;
125 }
126 void
128  this->value_type = value_type;
129  this->m_value_type_isSet = true;
130 }
131 
132 QString*
134  return value_string;
135 }
136 void
138  this->value_string = value_string;
139  this->m_value_string_isSet = true;
140 }
141 
142 
143 bool
145  bool isObjectUpdated = false;
146  do{
147  if(key != nullptr && *key != QString("")){ isObjectUpdated = true; break;}
148  if(value_type != nullptr && *value_type != QString("")){ isObjectUpdated = true; break;}
149  if(value_string != nullptr && *value_string != QString("")){ isObjectUpdated = true; break;}
150  }while(false);
151  return isObjectUpdated;
152 }
153 }
154 
virtual QJsonObject * asJsonObject() override
Definition: SWGArgValue.cpp:97
void toJsonValue(QString name, void *value, QJsonObject *output, QString type)
Definition: SWGHelpers.cpp:383
virtual bool isSet() override
virtual void fromJsonObject(QJsonObject &json) override
Definition: SWGArgValue.cpp:76
void setValueString(QString *value_string)
virtual SWGArgValue * fromJson(QString &jsonString) override
Definition: SWGArgValue.cpp:67
virtual QString asJson() override
Definition: SWGArgValue.cpp:86
void setValueType(QString *value_type)
void setValue(void *value, QJsonValue obj, QString type, QString complexType)
Definition: SWGHelpers.cpp:25
void setKey(QString *key)