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.
SWGInstanceConfigResponse.cpp
Go to the documentation of this file.
1 
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  preferences = nullptr;
32  m_preferences_isSet = false;
33  working_preset = nullptr;
34  m_working_preset_isSet = false;
35  presets = nullptr;
36  m_presets_isSet = false;
37  commands = nullptr;
38  m_commands_isSet = false;
39 }
40 
42  this->cleanup();
43 }
44 
45 void
48  m_preferences_isSet = false;
49  working_preset = new SWGPreset();
50  m_working_preset_isSet = false;
51  presets = new QList<SWGPreset*>();
52  m_presets_isSet = false;
53  commands = new QList<SWGCommand*>();
54  m_commands_isSet = false;
55 }
56 
57 void
59  if(preferences != nullptr) {
60  delete preferences;
61  }
62  if(working_preset != nullptr) {
63  delete working_preset;
64  }
65  if(presets != nullptr) {
66  auto arr = presets;
67  for(auto o: *arr) {
68  delete o;
69  }
70  delete presets;
71  }
72  if(commands != nullptr) {
73  auto arr = commands;
74  for(auto o: *arr) {
75  delete o;
76  }
77  delete commands;
78  }
79 }
80 
83  QByteArray array (json.toStdString().c_str());
84  QJsonDocument doc = QJsonDocument::fromJson(array);
85  QJsonObject jsonObject = doc.object();
86  this->fromJsonObject(jsonObject);
87  return this;
88 }
89 
90 void
92  ::SWGSDRangel::setValue(&preferences, pJson["preferences"], "SWGPreferences", "SWGPreferences");
93 
94  ::SWGSDRangel::setValue(&working_preset, pJson["workingPreset"], "SWGPreset", "SWGPreset");
95 
96 
97  ::SWGSDRangel::setValue(&presets, pJson["presets"], "QList", "SWGPreset");
98 
99  ::SWGSDRangel::setValue(&commands, pJson["commands"], "QList", "SWGCommand");
100 }
101 
102 QString
104 {
105  QJsonObject* obj = this->asJsonObject();
106 
107  QJsonDocument doc(*obj);
108  QByteArray bytes = doc.toJson();
109  delete obj;
110  return QString(bytes);
111 }
112 
113 QJsonObject*
115  QJsonObject* obj = new QJsonObject();
116  if((preferences != nullptr) && (preferences->isSet())){
117  toJsonValue(QString("preferences"), preferences, obj, QString("SWGPreferences"));
118  }
119  if((working_preset != nullptr) && (working_preset->isSet())){
120  toJsonValue(QString("workingPreset"), working_preset, obj, QString("SWGPreset"));
121  }
122  if(presets->size() > 0){
123  toJsonArray((QList<void*>*)presets, obj, "presets", "SWGPreset");
124  }
125  if(commands->size() > 0){
126  toJsonArray((QList<void*>*)commands, obj, "commands", "SWGCommand");
127  }
128 
129  return obj;
130 }
131 
134  return preferences;
135 }
136 void
138  this->preferences = preferences;
139  this->m_preferences_isSet = true;
140 }
141 
142 SWGPreset*
144  return working_preset;
145 }
146 void
148  this->working_preset = working_preset;
149  this->m_working_preset_isSet = true;
150 }
151 
152 QList<SWGPreset*>*
154  return presets;
155 }
156 void
158  this->presets = presets;
159  this->m_presets_isSet = true;
160 }
161 
162 QList<SWGCommand*>*
164  return commands;
165 }
166 void
168  this->commands = commands;
169  this->m_commands_isSet = true;
170 }
171 
172 
173 bool
175  bool isObjectUpdated = false;
176  do{
177  if(preferences != nullptr && preferences->isSet()){ isObjectUpdated = true; break;}
178  if(working_preset != nullptr && working_preset->isSet()){ isObjectUpdated = true; break;}
179  if(presets->size() > 0){ isObjectUpdated = true; break;}
180  if(commands->size() > 0){ isObjectUpdated = true; break;}
181  }while(false);
182  return isObjectUpdated;
183 }
184 }
185 
void setWorkingPreset(SWGPreset *working_preset)
void toJsonValue(QString name, void *value, QJsonObject *output, QString type)
Definition: SWGHelpers.cpp:383
void setPresets(QList< SWGPreset *> *presets)
virtual bool isSet() override
Definition: SWGPreset.cpp:298
void setPreferences(SWGPreferences *preferences)
virtual void fromJsonObject(QJsonObject &json) override
virtual QJsonObject * asJsonObject() override
void setCommands(QList< SWGCommand *> *commands)
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 SWGInstanceConfigResponse * fromJson(QString &jsonString) override
virtual bool isSet() override