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.
SWGPresetImport.cpp
Go to the documentation of this file.
1 
14 #include "SWGPresetImport.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  description = nullptr;
34  m_description_isSet = false;
35  file_path = nullptr;
36  m_file_path_isSet = false;
37 }
38 
40  this->cleanup();
41 }
42 
43 void
45  group_name = new QString("");
46  m_group_name_isSet = false;
47  description = new QString("");
48  m_description_isSet = false;
49  file_path = new QString("");
50  m_file_path_isSet = false;
51 }
52 
53 void
55  if(group_name != nullptr) {
56  delete group_name;
57  }
58  if(description != nullptr) {
59  delete description;
60  }
61  if(file_path != nullptr) {
62  delete file_path;
63  }
64 }
65 
67 SWGPresetImport::fromJson(QString &json) {
68  QByteArray array (json.toStdString().c_str());
69  QJsonDocument doc = QJsonDocument::fromJson(array);
70  QJsonObject jsonObject = doc.object();
71  this->fromJsonObject(jsonObject);
72  return this;
73 }
74 
75 void
76 SWGPresetImport::fromJsonObject(QJsonObject &pJson) {
77  ::SWGSDRangel::setValue(&group_name, pJson["groupName"], "QString", "QString");
78 
79  ::SWGSDRangel::setValue(&description, pJson["description"], "QString", "QString");
80 
81  ::SWGSDRangel::setValue(&file_path, pJson["filePath"], "QString", "QString");
82 
83 }
84 
85 QString
87 {
88  QJsonObject* obj = this->asJsonObject();
89 
90  QJsonDocument doc(*obj);
91  QByteArray bytes = doc.toJson();
92  delete obj;
93  return QString(bytes);
94 }
95 
96 QJsonObject*
98  QJsonObject* obj = new QJsonObject();
99  if(group_name != nullptr && *group_name != QString("")){
100  toJsonValue(QString("groupName"), group_name, obj, QString("QString"));
101  }
102  if(description != nullptr && *description != QString("")){
103  toJsonValue(QString("description"), description, obj, QString("QString"));
104  }
105  if(file_path != nullptr && *file_path != QString("")){
106  toJsonValue(QString("filePath"), file_path, obj, QString("QString"));
107  }
108 
109  return obj;
110 }
111 
112 QString*
114  return group_name;
115 }
116 void
118  this->group_name = group_name;
119  this->m_group_name_isSet = true;
120 }
121 
122 QString*
124  return description;
125 }
126 void
128  this->description = description;
129  this->m_description_isSet = true;
130 }
131 
132 QString*
134  return file_path;
135 }
136 void
138  this->file_path = file_path;
139  this->m_file_path_isSet = true;
140 }
141 
142 
143 bool
145  bool isObjectUpdated = false;
146  do{
147  if(group_name != nullptr && *group_name != QString("")){ isObjectUpdated = true; break;}
148  if(description != nullptr && *description != QString("")){ isObjectUpdated = true; break;}
149  if(file_path != nullptr && *file_path != QString("")){ isObjectUpdated = true; break;}
150  }while(false);
151  return isObjectUpdated;
152 }
153 }
154 
virtual SWGPresetImport * fromJson(QString &jsonString) override
void toJsonValue(QString name, void *value, QJsonObject *output, QString type)
Definition: SWGHelpers.cpp:383
virtual bool isSet() override
void setGroupName(QString *group_name)
virtual QJsonObject * asJsonObject() override
virtual QString asJson() override
void setValue(void *value, QJsonValue obj, QString type, QString complexType)
Definition: SWGHelpers.cpp:25
virtual void fromJsonObject(QJsonObject &json) override
void setFilePath(QString *file_path)
void setDescription(QString *description)