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.
SWGPresets.cpp
Go to the documentation of this file.
1 
14 #include "SWGPresets.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 SWGPresets::SWGPresets(QString* json) {
26  init();
27  this->fromJson(*json);
28 }
29 
31  nb_groups = 0;
32  m_nb_groups_isSet = false;
33  groups = nullptr;
34  m_groups_isSet = false;
35 }
36 
38  this->cleanup();
39 }
40 
41 void
43  nb_groups = 0;
44  m_nb_groups_isSet = false;
45  groups = new QList<SWGPresetGroup*>();
46  m_groups_isSet = false;
47 }
48 
49 void
51 
52  if(groups != nullptr) {
53  auto arr = groups;
54  for(auto o: *arr) {
55  delete o;
56  }
57  delete groups;
58  }
59 }
60 
62 SWGPresets::fromJson(QString &json) {
63  QByteArray array (json.toStdString().c_str());
64  QJsonDocument doc = QJsonDocument::fromJson(array);
65  QJsonObject jsonObject = doc.object();
66  this->fromJsonObject(jsonObject);
67  return this;
68 }
69 
70 void
71 SWGPresets::fromJsonObject(QJsonObject &pJson) {
72  ::SWGSDRangel::setValue(&nb_groups, pJson["nbGroups"], "qint32", "");
73 
74 
75  ::SWGSDRangel::setValue(&groups, pJson["groups"], "QList", "SWGPresetGroup");
76 }
77 
78 QString
80 {
81  QJsonObject* obj = this->asJsonObject();
82 
83  QJsonDocument doc(*obj);
84  QByteArray bytes = doc.toJson();
85  delete obj;
86  return QString(bytes);
87 }
88 
89 QJsonObject*
91  QJsonObject* obj = new QJsonObject();
93  obj->insert("nbGroups", QJsonValue(nb_groups));
94  }
95  if(groups->size() > 0){
96  toJsonArray((QList<void*>*)groups, obj, "groups", "SWGPresetGroup");
97  }
98 
99  return obj;
100 }
101 
102 qint32
104  return nb_groups;
105 }
106 void
108  this->nb_groups = nb_groups;
109  this->m_nb_groups_isSet = true;
110 }
111 
112 QList<SWGPresetGroup*>*
114  return groups;
115 }
116 void
117 SWGPresets::setGroups(QList<SWGPresetGroup*>* groups) {
118  this->groups = groups;
119  this->m_groups_isSet = true;
120 }
121 
122 
123 bool
125  bool isObjectUpdated = false;
126  do{
127  if(m_nb_groups_isSet){ isObjectUpdated = true; break;}
128  if(groups->size() > 0){ isObjectUpdated = true; break;}
129  }while(false);
130  return isObjectUpdated;
131 }
132 }
133 
virtual QJsonObject * asJsonObject() override
Definition: SWGPresets.cpp:90
virtual void fromJsonObject(QJsonObject &json) override
Definition: SWGPresets.cpp:71
virtual QString asJson() override
Definition: SWGPresets.cpp:79
QList< SWGPresetGroup * > * getGroups()
Definition: SWGPresets.cpp:113
QList< SWGPresetGroup * > * groups
Definition: SWGPresets.h:59
virtual SWGPresets * fromJson(QString &jsonString) override
Definition: SWGPresets.cpp:62
void setNbGroups(qint32 nb_groups)
Definition: SWGPresets.cpp:107
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
void setGroups(QList< SWGPresetGroup *> *groups)
Definition: SWGPresets.cpp:117
virtual bool isSet() override
Definition: SWGPresets.cpp:124