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.
SWGPresetGroup.cpp
Go to the documentation of this file.
1 
14 #include "SWGPresetGroup.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  group_name = nullptr;
32  m_group_name_isSet = false;
33  nb_presets = 0;
34  m_nb_presets_isSet = false;
35  presets = nullptr;
36  m_presets_isSet = false;
37 }
38 
40  this->cleanup();
41 }
42 
43 void
45  group_name = new QString("");
46  m_group_name_isSet = false;
47  nb_presets = 0;
48  m_nb_presets_isSet = false;
49  presets = new QList<SWGPresetItem*>();
50  m_presets_isSet = false;
51 }
52 
53 void
55  if(group_name != nullptr) {
56  delete group_name;
57  }
58 
59  if(presets != nullptr) {
60  auto arr = presets;
61  for(auto o: *arr) {
62  delete o;
63  }
64  delete presets;
65  }
66 }
67 
69 SWGPresetGroup::fromJson(QString &json) {
70  QByteArray array (json.toStdString().c_str());
71  QJsonDocument doc = QJsonDocument::fromJson(array);
72  QJsonObject jsonObject = doc.object();
73  this->fromJsonObject(jsonObject);
74  return this;
75 }
76 
77 void
78 SWGPresetGroup::fromJsonObject(QJsonObject &pJson) {
79  ::SWGSDRangel::setValue(&group_name, pJson["groupName"], "QString", "QString");
80 
81  ::SWGSDRangel::setValue(&nb_presets, pJson["nbPresets"], "qint32", "");
82 
83 
84  ::SWGSDRangel::setValue(&presets, pJson["presets"], "QList", "SWGPresetItem");
85 }
86 
87 QString
89 {
90  QJsonObject* obj = this->asJsonObject();
91 
92  QJsonDocument doc(*obj);
93  QByteArray bytes = doc.toJson();
94  delete obj;
95  return QString(bytes);
96 }
97 
98 QJsonObject*
100  QJsonObject* obj = new QJsonObject();
101  if(group_name != nullptr && *group_name != QString("")){
102  toJsonValue(QString("groupName"), group_name, obj, QString("QString"));
103  }
104  if(m_nb_presets_isSet){
105  obj->insert("nbPresets", QJsonValue(nb_presets));
106  }
107  if(presets->size() > 0){
108  toJsonArray((QList<void*>*)presets, obj, "presets", "SWGPresetItem");
109  }
110 
111  return obj;
112 }
113 
114 QString*
116  return group_name;
117 }
118 void
120  this->group_name = group_name;
121  this->m_group_name_isSet = true;
122 }
123 
124 qint32
126  return nb_presets;
127 }
128 void
130  this->nb_presets = nb_presets;
131  this->m_nb_presets_isSet = true;
132 }
133 
134 QList<SWGPresetItem*>*
136  return presets;
137 }
138 void
139 SWGPresetGroup::setPresets(QList<SWGPresetItem*>* presets) {
140  this->presets = presets;
141  this->m_presets_isSet = true;
142 }
143 
144 
145 bool
147  bool isObjectUpdated = false;
148  do{
149  if(group_name != nullptr && *group_name != QString("")){ isObjectUpdated = true; break;}
150  if(m_nb_presets_isSet){ isObjectUpdated = true; break;}
151  if(presets->size() > 0){ isObjectUpdated = true; break;}
152  }while(false);
153  return isObjectUpdated;
154 }
155 }
156 
QList< SWGPresetItem * > * getPresets()
void toJsonValue(QString name, void *value, QJsonObject *output, QString type)
Definition: SWGHelpers.cpp:383
void setGroupName(QString *group_name)
virtual QString asJson() override
virtual QJsonObject * asJsonObject() override
void setNbPresets(qint32 nb_presets)
QList< SWGPresetItem * > * presets
void setPresets(QList< SWGPresetItem *> *presets)
virtual void fromJsonObject(QJsonObject &json) override
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
virtual SWGPresetGroup * fromJson(QString &jsonString) override
virtual bool isSet() override