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