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.
SWGCommand.cpp
Go to the documentation of this file.
1 
14 #include "SWGCommand.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 SWGCommand::SWGCommand(QString* json) {
26  init();
27  this->fromJson(*json);
28 }
29 
31  group = nullptr;
32  m_group_isSet = false;
33  description = nullptr;
34  m_description_isSet = false;
35  command = nullptr;
36  m_command_isSet = false;
37  arg_string = nullptr;
38  m_arg_string_isSet = false;
39  key = 0;
40  m_key_isSet = false;
41  key_modifiers = 0;
42  m_key_modifiers_isSet = false;
43  associate_key = 0;
44  m_associate_key_isSet = false;
45  release = 0;
46  m_release_isSet = false;
47 }
48 
50  this->cleanup();
51 }
52 
53 void
55  group = new QString("");
56  m_group_isSet = false;
57  description = new QString("");
58  m_description_isSet = false;
59  command = new QString("");
60  m_command_isSet = false;
61  arg_string = new QString("");
62  m_arg_string_isSet = false;
63  key = 0;
64  m_key_isSet = false;
65  key_modifiers = 0;
66  m_key_modifiers_isSet = false;
67  associate_key = 0;
68  m_associate_key_isSet = false;
69  release = 0;
70  m_release_isSet = false;
71 }
72 
73 void
75  if(group != nullptr) {
76  delete group;
77  }
78  if(description != nullptr) {
79  delete description;
80  }
81  if(command != nullptr) {
82  delete command;
83  }
84  if(arg_string != nullptr) {
85  delete arg_string;
86  }
87 
88 
89 
90 
91 }
92 
94 SWGCommand::fromJson(QString &json) {
95  QByteArray array (json.toStdString().c_str());
96  QJsonDocument doc = QJsonDocument::fromJson(array);
97  QJsonObject jsonObject = doc.object();
98  this->fromJsonObject(jsonObject);
99  return this;
100 }
101 
102 void
103 SWGCommand::fromJsonObject(QJsonObject &pJson) {
104  ::SWGSDRangel::setValue(&group, pJson["group"], "QString", "QString");
105 
106  ::SWGSDRangel::setValue(&description, pJson["description"], "QString", "QString");
107 
108  ::SWGSDRangel::setValue(&command, pJson["command"], "QString", "QString");
109 
110  ::SWGSDRangel::setValue(&arg_string, pJson["argString"], "QString", "QString");
111 
112  ::SWGSDRangel::setValue(&key, pJson["key"], "qint32", "");
113 
114  ::SWGSDRangel::setValue(&key_modifiers, pJson["keyModifiers"], "qint32", "");
115 
116  ::SWGSDRangel::setValue(&associate_key, pJson["associateKey"], "qint32", "");
117 
118  ::SWGSDRangel::setValue(&release, pJson["release"], "qint32", "");
119 
120 }
121 
122 QString
124 {
125  QJsonObject* obj = this->asJsonObject();
126 
127  QJsonDocument doc(*obj);
128  QByteArray bytes = doc.toJson();
129  delete obj;
130  return QString(bytes);
131 }
132 
133 QJsonObject*
135  QJsonObject* obj = new QJsonObject();
136  if(group != nullptr && *group != QString("")){
137  toJsonValue(QString("group"), group, obj, QString("QString"));
138  }
139  if(description != nullptr && *description != QString("")){
140  toJsonValue(QString("description"), description, obj, QString("QString"));
141  }
142  if(command != nullptr && *command != QString("")){
143  toJsonValue(QString("command"), command, obj, QString("QString"));
144  }
145  if(arg_string != nullptr && *arg_string != QString("")){
146  toJsonValue(QString("argString"), arg_string, obj, QString("QString"));
147  }
148  if(m_key_isSet){
149  obj->insert("key", QJsonValue(key));
150  }
152  obj->insert("keyModifiers", QJsonValue(key_modifiers));
153  }
155  obj->insert("associateKey", QJsonValue(associate_key));
156  }
157  if(m_release_isSet){
158  obj->insert("release", QJsonValue(release));
159  }
160 
161  return obj;
162 }
163 
164 QString*
166  return group;
167 }
168 void
170  this->group = group;
171  this->m_group_isSet = true;
172 }
173 
174 QString*
176  return description;
177 }
178 void
180  this->description = description;
181  this->m_description_isSet = true;
182 }
183 
184 QString*
186  return command;
187 }
188 void
190  this->command = command;
191  this->m_command_isSet = true;
192 }
193 
194 QString*
196  return arg_string;
197 }
198 void
200  this->arg_string = arg_string;
201  this->m_arg_string_isSet = true;
202 }
203 
204 qint32
206  return key;
207 }
208 void
210  this->key = key;
211  this->m_key_isSet = true;
212 }
213 
214 qint32
216  return key_modifiers;
217 }
218 void
220  this->key_modifiers = key_modifiers;
221  this->m_key_modifiers_isSet = true;
222 }
223 
224 qint32
226  return associate_key;
227 }
228 void
230  this->associate_key = associate_key;
231  this->m_associate_key_isSet = true;
232 }
233 
234 qint32
236  return release;
237 }
238 void
240  this->release = release;
241  this->m_release_isSet = true;
242 }
243 
244 
245 bool
247  bool isObjectUpdated = false;
248  do{
249  if(group != nullptr && *group != QString("")){ isObjectUpdated = true; break;}
250  if(description != nullptr && *description != QString("")){ isObjectUpdated = true; break;}
251  if(command != nullptr && *command != QString("")){ isObjectUpdated = true; break;}
252  if(arg_string != nullptr && *arg_string != QString("")){ isObjectUpdated = true; break;}
253  if(m_key_isSet){ isObjectUpdated = true; break;}
254  if(m_key_modifiers_isSet){ isObjectUpdated = true; break;}
255  if(m_associate_key_isSet){ isObjectUpdated = true; break;}
256  if(m_release_isSet){ isObjectUpdated = true; break;}
257  }while(false);
258  return isObjectUpdated;
259 }
260 }
261 
void toJsonValue(QString name, void *value, QJsonObject *output, QString type)
Definition: SWGHelpers.cpp:383
void setArgString(QString *arg_string)
Definition: SWGCommand.cpp:199
virtual SWGCommand * fromJson(QString &jsonString) override
Definition: SWGCommand.cpp:94
virtual QJsonObject * asJsonObject() override
Definition: SWGCommand.cpp:134
virtual QString asJson() override
Definition: SWGCommand.cpp:123
void setDescription(QString *description)
Definition: SWGCommand.cpp:179
void setCommand(QString *command)
Definition: SWGCommand.cpp:189
void setGroup(QString *group)
Definition: SWGCommand.cpp:169
void setKeyModifiers(qint32 key_modifiers)
Definition: SWGCommand.cpp:219
void setKey(qint32 key)
Definition: SWGCommand.cpp:209
QString * getDescription()
Definition: SWGCommand.cpp:175
virtual void fromJsonObject(QJsonObject &json) override
Definition: SWGCommand.cpp:103
virtual bool isSet() override
Definition: SWGCommand.cpp:246
void setValue(void *value, QJsonValue obj, QString type, QString complexType)
Definition: SWGHelpers.cpp:25
void setRelease(qint32 release)
Definition: SWGCommand.cpp:239
void setAssociateKey(qint32 associate_key)
Definition: SWGCommand.cpp:229