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.
SWGPreferences.cpp
Go to the documentation of this file.
1 
14 #include "SWGPreferences.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  source_type = nullptr;
32  m_source_type_isSet = false;
33  source_device = nullptr;
34  m_source_device_isSet = false;
35  audio_type = nullptr;
36  m_audio_type_isSet = false;
37  audio_device = nullptr;
38  m_audio_device_isSet = false;
39  source_index = 0;
40  m_source_index_isSet = false;
41  latitude = 0.0f;
42  m_latitude_isSet = false;
43  longitude = 0.0f;
44  m_longitude_isSet = false;
47  use_log_file = 0;
48  m_use_log_file_isSet = false;
49  log_file_name = nullptr;
50  m_log_file_name_isSet = false;
53 }
54 
56  this->cleanup();
57 }
58 
59 void
61  source_type = new QString("");
62  m_source_type_isSet = false;
63  source_device = new QString("");
64  m_source_device_isSet = false;
65  audio_type = new QString("");
66  m_audio_type_isSet = false;
67  audio_device = new QString("");
68  m_audio_device_isSet = false;
69  source_index = 0;
70  m_source_index_isSet = false;
71  latitude = 0.0f;
72  m_latitude_isSet = false;
73  longitude = 0.0f;
74  m_longitude_isSet = false;
77  use_log_file = 0;
78  m_use_log_file_isSet = false;
79  log_file_name = new QString("");
80  m_log_file_name_isSet = false;
83 }
84 
85 void
87  if(source_type != nullptr) {
88  delete source_type;
89  }
90  if(source_device != nullptr) {
91  delete source_device;
92  }
93  if(audio_type != nullptr) {
94  delete audio_type;
95  }
96  if(audio_device != nullptr) {
97  delete audio_device;
98  }
99 
100 
101 
102 
103 
104  if(log_file_name != nullptr) {
105  delete log_file_name;
106  }
107 
108 }
109 
111 SWGPreferences::fromJson(QString &json) {
112  QByteArray array (json.toStdString().c_str());
113  QJsonDocument doc = QJsonDocument::fromJson(array);
114  QJsonObject jsonObject = doc.object();
115  this->fromJsonObject(jsonObject);
116  return this;
117 }
118 
119 void
120 SWGPreferences::fromJsonObject(QJsonObject &pJson) {
121  ::SWGSDRangel::setValue(&source_type, pJson["sourceType"], "QString", "QString");
122 
123  ::SWGSDRangel::setValue(&source_device, pJson["sourceDevice"], "QString", "QString");
124 
125  ::SWGSDRangel::setValue(&audio_type, pJson["audioType"], "QString", "QString");
126 
127  ::SWGSDRangel::setValue(&audio_device, pJson["audioDevice"], "QString", "QString");
128 
129  ::SWGSDRangel::setValue(&source_index, pJson["sourceIndex"], "qint32", "");
130 
131  ::SWGSDRangel::setValue(&latitude, pJson["latitude"], "float", "");
132 
133  ::SWGSDRangel::setValue(&longitude, pJson["longitude"], "float", "");
134 
135  ::SWGSDRangel::setValue(&console_min_log_level, pJson["consoleMinLogLevel"], "qint32", "");
136 
137  ::SWGSDRangel::setValue(&use_log_file, pJson["useLogFile"], "qint32", "");
138 
139  ::SWGSDRangel::setValue(&log_file_name, pJson["logFileName"], "QString", "QString");
140 
141  ::SWGSDRangel::setValue(&file_min_log_level, pJson["fileMinLogLevel"], "qint32", "");
142 
143 }
144 
145 QString
147 {
148  QJsonObject* obj = this->asJsonObject();
149 
150  QJsonDocument doc(*obj);
151  QByteArray bytes = doc.toJson();
152  delete obj;
153  return QString(bytes);
154 }
155 
156 QJsonObject*
158  QJsonObject* obj = new QJsonObject();
159  if(source_type != nullptr && *source_type != QString("")){
160  toJsonValue(QString("sourceType"), source_type, obj, QString("QString"));
161  }
162  if(source_device != nullptr && *source_device != QString("")){
163  toJsonValue(QString("sourceDevice"), source_device, obj, QString("QString"));
164  }
165  if(audio_type != nullptr && *audio_type != QString("")){
166  toJsonValue(QString("audioType"), audio_type, obj, QString("QString"));
167  }
168  if(audio_device != nullptr && *audio_device != QString("")){
169  toJsonValue(QString("audioDevice"), audio_device, obj, QString("QString"));
170  }
172  obj->insert("sourceIndex", QJsonValue(source_index));
173  }
174  if(m_latitude_isSet){
175  obj->insert("latitude", QJsonValue(latitude));
176  }
177  if(m_longitude_isSet){
178  obj->insert("longitude", QJsonValue(longitude));
179  }
181  obj->insert("consoleMinLogLevel", QJsonValue(console_min_log_level));
182  }
184  obj->insert("useLogFile", QJsonValue(use_log_file));
185  }
186  if(log_file_name != nullptr && *log_file_name != QString("")){
187  toJsonValue(QString("logFileName"), log_file_name, obj, QString("QString"));
188  }
190  obj->insert("fileMinLogLevel", QJsonValue(file_min_log_level));
191  }
192 
193  return obj;
194 }
195 
196 QString*
198  return source_type;
199 }
200 void
202  this->source_type = source_type;
203  this->m_source_type_isSet = true;
204 }
205 
206 QString*
208  return source_device;
209 }
210 void
212  this->source_device = source_device;
213  this->m_source_device_isSet = true;
214 }
215 
216 QString*
218  return audio_type;
219 }
220 void
222  this->audio_type = audio_type;
223  this->m_audio_type_isSet = true;
224 }
225 
226 QString*
228  return audio_device;
229 }
230 void
232  this->audio_device = audio_device;
233  this->m_audio_device_isSet = true;
234 }
235 
236 qint32
238  return source_index;
239 }
240 void
242  this->source_index = source_index;
243  this->m_source_index_isSet = true;
244 }
245 
246 float
248  return latitude;
249 }
250 void
252  this->latitude = latitude;
253  this->m_latitude_isSet = true;
254 }
255 
256 float
258  return longitude;
259 }
260 void
262  this->longitude = longitude;
263  this->m_longitude_isSet = true;
264 }
265 
266 qint32
268  return console_min_log_level;
269 }
270 void
272  this->console_min_log_level = console_min_log_level;
273  this->m_console_min_log_level_isSet = true;
274 }
275 
276 qint32
278  return use_log_file;
279 }
280 void
282  this->use_log_file = use_log_file;
283  this->m_use_log_file_isSet = true;
284 }
285 
286 QString*
288  return log_file_name;
289 }
290 void
292  this->log_file_name = log_file_name;
293  this->m_log_file_name_isSet = true;
294 }
295 
296 qint32
298  return file_min_log_level;
299 }
300 void
302  this->file_min_log_level = file_min_log_level;
303  this->m_file_min_log_level_isSet = true;
304 }
305 
306 
307 bool
309  bool isObjectUpdated = false;
310  do{
311  if(source_type != nullptr && *source_type != QString("")){ isObjectUpdated = true; break;}
312  if(source_device != nullptr && *source_device != QString("")){ isObjectUpdated = true; break;}
313  if(audio_type != nullptr && *audio_type != QString("")){ isObjectUpdated = true; break;}
314  if(audio_device != nullptr && *audio_device != QString("")){ isObjectUpdated = true; break;}
315  if(m_source_index_isSet){ isObjectUpdated = true; break;}
316  if(m_latitude_isSet){ isObjectUpdated = true; break;}
317  if(m_longitude_isSet){ isObjectUpdated = true; break;}
318  if(m_console_min_log_level_isSet){ isObjectUpdated = true; break;}
319  if(m_use_log_file_isSet){ isObjectUpdated = true; break;}
320  if(log_file_name != nullptr && *log_file_name != QString("")){ isObjectUpdated = true; break;}
321  if(m_file_min_log_level_isSet){ isObjectUpdated = true; break;}
322  }while(false);
323  return isObjectUpdated;
324 }
325 }
326 
void toJsonValue(QString name, void *value, QJsonObject *output, QString type)
Definition: SWGHelpers.cpp:383
void setLongitude(float longitude)
void setUseLogFile(qint32 use_log_file)
void setFileMinLogLevel(qint32 file_min_log_level)
void setSourceDevice(QString *source_device)
void setSourceIndex(qint32 source_index)
virtual QJsonObject * asJsonObject() override
void setLogFileName(QString *log_file_name)
void setConsoleMinLogLevel(qint32 console_min_log_level)
void setValue(void *value, QJsonValue obj, QString type, QString complexType)
Definition: SWGHelpers.cpp:25
void setSourceType(QString *source_type)
void setAudioDevice(QString *audio_device)
void setLatitude(float latitude)
virtual void fromJsonObject(QJsonObject &json) override
void setAudioType(QString *audio_type)
virtual QString asJson() override
virtual SWGPreferences * fromJson(QString &jsonString) override
virtual bool isSet() override