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.
SWGComplex.cpp
Go to the documentation of this file.
1 
14 #include "SWGComplex.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 SWGComplex::SWGComplex(QString* json) {
26  init();
27  this->fromJson(*json);
28 }
29 
31  real = 0.0f;
32  m_real_isSet = false;
33  imag = 0.0f;
34  m_imag_isSet = false;
35 }
36 
38  this->cleanup();
39 }
40 
41 void
43  real = 0.0f;
44  m_real_isSet = false;
45  imag = 0.0f;
46  m_imag_isSet = false;
47 }
48 
49 void
51 
52 
53 }
54 
56 SWGComplex::fromJson(QString &json) {
57  QByteArray array (json.toStdString().c_str());
58  QJsonDocument doc = QJsonDocument::fromJson(array);
59  QJsonObject jsonObject = doc.object();
60  this->fromJsonObject(jsonObject);
61  return this;
62 }
63 
64 void
65 SWGComplex::fromJsonObject(QJsonObject &pJson) {
66  ::SWGSDRangel::setValue(&real, pJson["real"], "float", "");
67 
68  ::SWGSDRangel::setValue(&imag, pJson["imag"], "float", "");
69 
70 }
71 
72 QString
74 {
75  QJsonObject* obj = this->asJsonObject();
76 
77  QJsonDocument doc(*obj);
78  QByteArray bytes = doc.toJson();
79  delete obj;
80  return QString(bytes);
81 }
82 
83 QJsonObject*
85  QJsonObject* obj = new QJsonObject();
86  if(m_real_isSet){
87  obj->insert("real", QJsonValue(real));
88  }
89  if(m_imag_isSet){
90  obj->insert("imag", QJsonValue(imag));
91  }
92 
93  return obj;
94 }
95 
96 float
98  return real;
99 }
100 void
102  this->real = real;
103  this->m_real_isSet = true;
104 }
105 
106 float
108  return imag;
109 }
110 void
112  this->imag = imag;
113  this->m_imag_isSet = true;
114 }
115 
116 
117 bool
119  bool isObjectUpdated = false;
120  do{
121  if(m_real_isSet){ isObjectUpdated = true; break;}
122  if(m_imag_isSet){ isObjectUpdated = true; break;}
123  }while(false);
124  return isObjectUpdated;
125 }
126 }
127 
virtual QString asJson() override
Definition: SWGComplex.cpp:73
void setReal(float real)
Definition: SWGComplex.cpp:101
void setImag(float imag)
Definition: SWGComplex.cpp:111
virtual bool isSet() override
Definition: SWGComplex.cpp:118
virtual SWGComplex * fromJson(QString &jsonString) override
Definition: SWGComplex.cpp:56
virtual QJsonObject * asJsonObject() override
Definition: SWGComplex.cpp:84
virtual void fromJsonObject(QJsonObject &json) override
Definition: SWGComplex.cpp:65
void setValue(void *value, QJsonValue obj, QString type, QString complexType)
Definition: SWGHelpers.cpp:25