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.
SWGPresetItem.cpp
Go to the documentation of this file.
1 
14 #include "SWGPresetItem.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  center_frequency = 0L;
33  type = nullptr;
34  m_type_isSet = false;
35  name = nullptr;
36  m_name_isSet = false;
37 }
38 
40  this->cleanup();
41 }
42 
43 void
45  center_frequency = 0L;
47  type = new QString("");
48  m_type_isSet = false;
49  name = new QString("");
50  m_name_isSet = false;
51 }
52 
53 void
55 
56  if(type != nullptr) {
57  delete type;
58  }
59  if(name != nullptr) {
60  delete name;
61  }
62 }
63 
65 SWGPresetItem::fromJson(QString &json) {
66  QByteArray array (json.toStdString().c_str());
67  QJsonDocument doc = QJsonDocument::fromJson(array);
68  QJsonObject jsonObject = doc.object();
69  this->fromJsonObject(jsonObject);
70  return this;
71 }
72 
73 void
74 SWGPresetItem::fromJsonObject(QJsonObject &pJson) {
75  ::SWGSDRangel::setValue(&center_frequency, pJson["centerFrequency"], "qint64", "");
76 
77  ::SWGSDRangel::setValue(&type, pJson["type"], "QString", "QString");
78 
79  ::SWGSDRangel::setValue(&name, pJson["name"], "QString", "QString");
80 
81 }
82 
83 QString
85 {
86  QJsonObject* obj = this->asJsonObject();
87 
88  QJsonDocument doc(*obj);
89  QByteArray bytes = doc.toJson();
90  delete obj;
91  return QString(bytes);
92 }
93 
94 QJsonObject*
96  QJsonObject* obj = new QJsonObject();
98  obj->insert("centerFrequency", QJsonValue(center_frequency));
99  }
100  if(type != nullptr && *type != QString("")){
101  toJsonValue(QString("type"), type, obj, QString("QString"));
102  }
103  if(name != nullptr && *name != QString("")){
104  toJsonValue(QString("name"), name, obj, QString("QString"));
105  }
106 
107  return obj;
108 }
109 
110 qint64
112  return center_frequency;
113 }
114 void
116  this->center_frequency = center_frequency;
117  this->m_center_frequency_isSet = true;
118 }
119 
120 QString*
122  return type;
123 }
124 void
126  this->type = type;
127  this->m_type_isSet = true;
128 }
129 
130 QString*
132  return name;
133 }
134 void
136  this->name = name;
137  this->m_name_isSet = true;
138 }
139 
140 
141 bool
143  bool isObjectUpdated = false;
144  do{
145  if(m_center_frequency_isSet){ isObjectUpdated = true; break;}
146  if(type != nullptr && *type != QString("")){ isObjectUpdated = true; break;}
147  if(name != nullptr && *name != QString("")){ isObjectUpdated = true; break;}
148  }while(false);
149  return isObjectUpdated;
150 }
151 }
152 
virtual SWGPresetItem * fromJson(QString &jsonString) override
void setCenterFrequency(qint64 center_frequency)
void toJsonValue(QString name, void *value, QJsonObject *output, QString type)
Definition: SWGHelpers.cpp:383
void setType(QString *type)
virtual QString asJson() override
virtual bool isSet() override
virtual void fromJsonObject(QJsonObject &json) override
virtual QJsonObject * asJsonObject() override
void setValue(void *value, QJsonValue obj, QString type, QString complexType)
Definition: SWGHelpers.cpp:25
void setName(QString *name)