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.
SWGPresetExport.cpp
Go to the documentation of this file.
1 
14 #include "SWGPresetExport.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  file_path = nullptr;
32  m_file_path_isSet = false;
33  preset = nullptr;
34  m_preset_isSet = false;
35 }
36 
38  this->cleanup();
39 }
40 
41 void
43  file_path = new QString("");
44  m_file_path_isSet = false;
46  m_preset_isSet = false;
47 }
48 
49 void
51  if(file_path != nullptr) {
52  delete file_path;
53  }
54  if(preset != nullptr) {
55  delete preset;
56  }
57 }
58 
60 SWGPresetExport::fromJson(QString &json) {
61  QByteArray array (json.toStdString().c_str());
62  QJsonDocument doc = QJsonDocument::fromJson(array);
63  QJsonObject jsonObject = doc.object();
64  this->fromJsonObject(jsonObject);
65  return this;
66 }
67 
68 void
69 SWGPresetExport::fromJsonObject(QJsonObject &pJson) {
70  ::SWGSDRangel::setValue(&file_path, pJson["filePath"], "QString", "QString");
71 
72  ::SWGSDRangel::setValue(&preset, pJson["preset"], "SWGPresetIdentifier", "SWGPresetIdentifier");
73 
74 }
75 
76 QString
78 {
79  QJsonObject* obj = this->asJsonObject();
80 
81  QJsonDocument doc(*obj);
82  QByteArray bytes = doc.toJson();
83  delete obj;
84  return QString(bytes);
85 }
86 
87 QJsonObject*
89  QJsonObject* obj = new QJsonObject();
90  if(file_path != nullptr && *file_path != QString("")){
91  toJsonValue(QString("filePath"), file_path, obj, QString("QString"));
92  }
93  if((preset != nullptr) && (preset->isSet())){
94  toJsonValue(QString("preset"), preset, obj, QString("SWGPresetIdentifier"));
95  }
96 
97  return obj;
98 }
99 
100 QString*
102  return file_path;
103 }
104 void
106  this->file_path = file_path;
107  this->m_file_path_isSet = true;
108 }
109 
112  return preset;
113 }
114 void
116  this->preset = preset;
117  this->m_preset_isSet = true;
118 }
119 
120 
121 bool
123  bool isObjectUpdated = false;
124  do{
125  if(file_path != nullptr && *file_path != QString("")){ isObjectUpdated = true; break;}
126  if(preset != nullptr && preset->isSet()){ isObjectUpdated = true; break;}
127  }while(false);
128  return isObjectUpdated;
129 }
130 }
131 
void toJsonValue(QString name, void *value, QJsonObject *output, QString type)
Definition: SWGHelpers.cpp:383
virtual QJsonObject * asJsonObject() override
virtual QString asJson() override
SWGPresetIdentifier * getPreset()
SWGPresetIdentifier * preset
virtual void fromJsonObject(QJsonObject &json) override
void setPreset(SWGPresetIdentifier *preset)
void setValue(void *value, QJsonValue obj, QString type, QString complexType)
Definition: SWGHelpers.cpp:25
virtual SWGPresetExport * fromJson(QString &jsonString) override
void setFilePath(QString *file_path)
virtual bool isSet() override