25 setValue(
void* value, QJsonValue obj, QString type, QString complexType) {
26 if(value ==
nullptr) {
30 if(QStringLiteral(
"bool").compare(type) == 0) {
31 bool * val =
static_cast<bool*
>(value);
34 else if(QStringLiteral(
"qint32").compare(type) == 0) {
35 qint32 *val =
static_cast<qint32*
>(value);
38 else if(QStringLiteral(
"qint64").compare(type) == 0) {
39 qint64 *val =
static_cast<qint64*
>(value);
40 *val = obj.toVariant().toLongLong();
42 else if(QStringLiteral(
"float").compare(type) == 0) {
43 float *val =
static_cast<float*
>(value);
44 *val = obj.toDouble();
46 else if(QStringLiteral(
"double").compare(type) == 0) {
47 double *val =
static_cast<double*
>(value);
48 *val = obj.toDouble();
50 else if (QStringLiteral(
"QString").compare(type) == 0) {
51 QString **val =
static_cast<QString**
>(value);
55 if(*val !=
nullptr)
delete *val;
56 *val =
new QString(obj.toString());
61 if(*val !=
nullptr)
delete *val;
66 qDebug() <<
"Can't set value because the target pointer is nullptr";
69 else if (QStringLiteral(
"QDateTime").compare(type) == 0) {
70 QDateTime **val =
static_cast<QDateTime**
>(value);
75 if(*val !=
nullptr)
delete *val;
76 *val =
new QDateTime(QDateTime::fromString(obj.toString(), Qt::ISODate));
81 if(*val !=
nullptr)
delete *val;
86 qDebug() <<
"Can't set value because the target pointer is nullptr";
89 else if (QStringLiteral(
"QDate").compare(type) == 0) {
90 QDate **val =
static_cast<QDate**
>(value);
95 if(*val !=
nullptr)
delete *val;
96 *val =
new QDate(QDate::fromString(obj.toString(), Qt::ISODate));
101 if(*val !=
nullptr)
delete *val;
106 qDebug() <<
"Can't set value because the target pointer is nullptr";
109 else if (QStringLiteral(
"QByteArray").compare(type) == 0) {
110 QByteArray **val =
static_cast<QByteArray**
>(value);
115 if(*val !=
nullptr)
delete *val;
117 *val =
new QByteArray(QByteArray::fromBase64(QByteArray::fromStdString(obj.toString().toStdString())));
122 if(*val !=
nullptr)
delete *val;
127 qDebug() <<
"Can't set value because the target pointer is nullptr";
130 else if(type.startsWith(
"SWG") && obj.isObject()) {
132 QJsonObject jsonObj = obj.toObject();
137 if(*val !=
nullptr)
delete *val;
141 else if(type.startsWith(
"QList") && QString(
"").compare(complexType) != 0 && obj.isArray()) {
143 if(complexType.startsWith(
"SWG")) {
144 auto output =
reinterpret_cast<QList<SWGObject *> **
> (value);
145 for (
auto item : **output) {
146 if(item !=
nullptr)
delete item;
149 QJsonArray arr = obj.toArray();
150 for (
const QJsonValue & jval : arr) {
153 QJsonObject t = jval.toObject();
155 (*output)->append(val);
158 else if(QStringLiteral(
"qint32").compare(complexType) == 0) {
159 auto output =
reinterpret_cast<QList<qint32> **
> (value);
161 QJsonArray arr = obj.toArray();
162 for (
const QJsonValue & jval : arr){
165 (*output)->push_back(val);
168 else if(QStringLiteral(
"qint64").compare(complexType) == 0) {
169 auto output =
reinterpret_cast<QList<qint64> **
> (value);
171 QJsonArray arr = obj.toArray();
172 for (
const QJsonValue & jval : arr){
175 (*output)->push_back(val);
178 else if(QStringLiteral(
"bool").compare(complexType) == 0) {
179 auto output =
reinterpret_cast<QList<bool> **
> (value);
181 QJsonArray arr = obj.toArray();
182 for (
const QJsonValue & jval : arr){
185 (*output)->push_back(val);
188 else if(QStringLiteral(
"float").compare(complexType) == 0) {
189 auto output =
reinterpret_cast<QList<float> **
> (value);
191 QJsonArray arr = obj.toArray();
192 for (
const QJsonValue & jval : arr){
195 (*output)->push_back(val);
198 else if(QStringLiteral(
"double").compare(complexType) == 0) {
199 auto output =
reinterpret_cast<QList<double> **
> (value);
201 QJsonArray arr = obj.toArray();
202 for (
const QJsonValue & jval : arr){
205 (*output)->push_back(val);
208 else if(QStringLiteral(
"QString").compare(complexType) == 0) {
209 auto output =
reinterpret_cast<QList<QString*> **
> (value);
210 for (
auto item : **output) {
211 if(item !=
nullptr)
delete item;
214 QJsonArray arr = obj.toArray();
215 for (
const QJsonValue & jval : arr){
216 QString * val =
new QString();
218 (*output)->push_back(val);
221 else if(QStringLiteral(
"QDate").compare(complexType) == 0) {
222 auto output =
reinterpret_cast<QList<QDate*> **
> (value);
223 for (
auto item : **output) {
224 if(item !=
nullptr)
delete item;
227 QJsonArray arr = obj.toArray();
228 for (
const QJsonValue & jval : arr){
229 QDate * val =
new QDate();
231 (*output)->push_back(val);
234 else if(QStringLiteral(
"QDateTime").compare(complexType) == 0) {
235 auto output =
reinterpret_cast<QList<QDateTime*> **
> (value);
236 for (
auto item : **output) {
237 if(item !=
nullptr)
delete item;
240 QJsonArray arr = obj.toArray();
241 for (
const QJsonValue & jval : arr){
242 QDateTime * val =
new QDateTime();
244 (*output)->push_back(val);
248 else if(type.startsWith(
"QMap") && QString(
"").compare(complexType) != 0 && obj.isObject()) {
250 if(complexType.startsWith(
"SWG")) {
251 auto output =
reinterpret_cast<QMap<QString, SWGObject*> **
> (value);
252 for (
auto item : **output) {
253 if(item !=
nullptr)
delete item;
256 auto varmap = obj.toObject().toVariantMap();
257 if(varmap.count() > 0){
258 for(
auto itemkey : varmap.keys() ){
260 auto jsonval = QJsonValue::fromVariant(varmap.value(itemkey));
262 (*output)->insert(itemkey, val);
266 else if(QStringLiteral(
"qint32").compare(complexType) == 0) {
267 auto output =
reinterpret_cast<QMap<QString, qint32> **
> (value);
269 auto varmap = obj.toObject().toVariantMap();
270 if(varmap.count() > 0){
271 for(
auto itemkey : varmap.keys() ){
273 auto jsonval = QJsonValue::fromVariant(varmap.value(itemkey));
275 (*output)->insert( itemkey, val);
279 else if(QStringLiteral(
"qint64").compare(complexType) == 0) {
280 auto output =
reinterpret_cast<QMap<QString, qint64> **
> (value);
282 auto varmap = obj.toObject().toVariantMap();
283 if(varmap.count() > 0){
284 for(
auto itemkey : varmap.keys() ){
286 auto jsonval = QJsonValue::fromVariant(varmap.value(itemkey));
288 (*output)->insert( itemkey, val);
292 else if(QStringLiteral(
"bool").compare(complexType) == 0) {
293 auto output =
reinterpret_cast<QMap<QString, bool> **
> (value);
295 auto varmap = obj.toObject().toVariantMap();
296 if(varmap.count() > 0){
297 for(
auto itemkey : varmap.keys() ){
299 auto jsonval = QJsonValue::fromVariant(varmap.value(itemkey));
301 (*output)->insert( itemkey, val);
305 else if(QStringLiteral(
"float").compare(complexType) == 0) {
306 auto output =
reinterpret_cast<QMap<QString, float> **
> (value);
308 auto varmap = obj.toObject().toVariantMap();
309 if(varmap.count() > 0){
310 for(
auto itemkey : varmap.keys() ){
312 auto jsonval = QJsonValue::fromVariant(varmap.value(itemkey));
314 (*output)->insert( itemkey, val);
318 else if(QStringLiteral(
"double").compare(complexType) == 0) {
319 auto output =
reinterpret_cast<QMap<QString, double> **
> (value);
321 auto varmap = obj.toObject().toVariantMap();
322 if(varmap.count() > 0){
323 for(
auto itemkey : varmap.keys() ){
325 auto jsonval = QJsonValue::fromVariant(varmap.value(itemkey));
327 (*output)->insert( itemkey, val);
331 else if(QStringLiteral(
"QString").compare(complexType) == 0) {
332 auto output =
reinterpret_cast<QMap<QString, QString*> **
> (value);
333 for (
auto item : **output) {
334 if(item !=
nullptr)
delete item;
337 auto varmap = obj.toObject().toVariantMap();
338 if(varmap.count() > 0){
339 for(
auto itemkey : varmap.keys() ){
340 QString * val =
new QString();
341 auto jsonval = QJsonValue::fromVariant(varmap.value(itemkey));
343 (*output)->insert( itemkey, val);
347 else if(QStringLiteral(
"QDate").compare(complexType) == 0) {
348 auto output =
reinterpret_cast<QMap<QString, QDate*> **
> (value);
349 for (
auto item : **output) {
350 if(item !=
nullptr)
delete item;
353 auto varmap = obj.toObject().toVariantMap();
354 if(varmap.count() > 0){
355 for(
auto itemkey : varmap.keys() ){
356 QDate * val =
new QDate();
357 auto jsonval = QJsonValue::fromVariant(varmap.value(itemkey));
359 (*output)->insert( itemkey, val);
363 else if(QStringLiteral(
"QDateTime").compare(complexType) == 0) {
364 auto output =
reinterpret_cast<QMap<QString, QDateTime*> **
> (value);
365 for (
auto item : **output) {
366 if(item !=
nullptr)
delete item;
369 auto varmap = obj.toObject().toVariantMap();
370 if(varmap.count() > 0){
371 for(
auto itemkey : varmap.keys() ){
372 QDateTime * val =
new QDateTime();
373 auto jsonval = QJsonValue::fromVariant(varmap.value(itemkey));
375 (*output)->insert( itemkey, val);
383 toJsonValue(QString name,
void* value, QJsonObject* output, QString type) {
384 if(value ==
nullptr) {
387 if(type.startsWith(
"SWG")) {
389 if(SWGobject !=
nullptr) {
393 if(name !=
nullptr) {
394 output->insert(name, *o);
395 if(o !=
nullptr)
delete o;
399 for(QString key : o->keys()) {
400 output->insert(key, o->value(key));
406 else if(QStringLiteral(
"QString").compare(type) == 0) {
407 QString* str =
static_cast<QString*
>(value);
408 output->insert(name, QJsonValue(*str));
410 else if(QStringLiteral(
"qint32").compare(type) == 0) {
411 qint32* str =
static_cast<qint32*
>(value);
412 output->insert(name, QJsonValue(*str));
414 else if(QStringLiteral(
"qint64").compare(type) == 0) {
415 qint64* str =
static_cast<qint64*
>(value);
416 output->insert(name, QJsonValue(*str));
418 else if(QStringLiteral(
"bool").compare(type) == 0) {
419 bool* str =
static_cast<bool*
>(value);
420 output->insert(name, QJsonValue(*str));
422 else if(QStringLiteral(
"float").compare(type) == 0) {
423 float* str =
static_cast<float*
>(value);
424 output->insert(name, QJsonValue((
double)*str));
426 else if(QStringLiteral(
"double").compare(type) == 0) {
427 double* str =
static_cast<double*
>(value);
428 output->insert(name, QJsonValue(*str));
430 else if(QStringLiteral(
"QDate").compare(type) == 0) {
431 QDate* date =
static_cast<QDate*
>(value);
432 output->insert(name, QJsonValue(date->toString(Qt::ISODate)));
434 else if(QStringLiteral(
"QDateTime").compare(type) == 0) {
435 QDateTime* datetime =
static_cast<QDateTime*
>(value);
436 output->insert(name, QJsonValue(datetime->toString(Qt::ISODate)));
438 else if(QStringLiteral(
"QByteArray").compare(type) == 0) {
439 QByteArray* byteArray =
static_cast<QByteArray*
>(value);
440 output->insert(name, QJsonValue(QString(byteArray->toBase64())));
445 toJsonArray(QList<void*>* value, QJsonObject* output, QString innerName, QString innerType) {
446 if((value ==
nullptr) || (output ==
nullptr)) {
449 QJsonArray outputarray;
450 if(innerType.startsWith(
"SWG")){
451 for(
void* obj : *value) {
453 if(SWGobject !=
nullptr)
456 outputarray.append(*o);
461 else if(QStringLiteral(
"QString").compare(innerType) == 0) {
462 for(QString* obj : *(
reinterpret_cast<QList<QString*>*
>(value))){
463 outputarray.append(QJsonValue(*obj));
466 else if(QStringLiteral(
"QDate").compare(innerType) == 0) {
467 for(QDate* obj : *(
reinterpret_cast<QList<QDate*>*
>(value))){
468 outputarray.append(QJsonValue(obj->toString(Qt::ISODate)));
471 else if(QStringLiteral(
"QDateTime").compare(innerType) == 0) {
472 for(QDateTime* obj : *(
reinterpret_cast<QList<QDateTime*>*
>(value))){
473 outputarray.append(QJsonValue(obj->toString(Qt::ISODate))); }
475 else if(QStringLiteral(
"QByteArray").compare(innerType) == 0) {
476 for(QByteArray* obj : *(
reinterpret_cast<QList<QByteArray*>*
>(value))){
477 outputarray.append(QJsonValue(QString(obj->toBase64())));
480 else if(QStringLiteral(
"qint32").compare(innerType) == 0) {
481 for(qint32 obj : *(
reinterpret_cast<QList<qint32>*
>(value)))
482 outputarray.append(QJsonValue(obj));
484 else if(QStringLiteral(
"qint64").compare(innerType) == 0) {
485 for(qint64 obj : *(
reinterpret_cast<QList<qint64>*
>(value)))
486 outputarray.append(QJsonValue(obj));
488 else if(QStringLiteral(
"bool").compare(innerType) == 0) {
489 for(
bool obj : *(
reinterpret_cast<QList<bool>*
>(value)))
490 outputarray.append(QJsonValue(obj));
492 else if(QStringLiteral(
"float").compare(innerType) == 0) {
493 for(
float obj : *(
reinterpret_cast<QList<float>*
>(value)))
494 outputarray.append(QJsonValue(obj));
496 else if(QStringLiteral(
"double").compare(innerType) == 0) {
497 for(
double obj : *(
reinterpret_cast<QList<double>*
>(value)))
498 outputarray.append(QJsonValue(obj));
500 output->insert(innerName, outputarray);
504 toJsonMap(QMap<QString, void*>* value, QJsonObject* output, QString innerName, QString innerType) {
505 if((value ==
nullptr) || (output ==
nullptr)) {
509 if(innerType.startsWith(
"SWG")){
510 auto items =
reinterpret_cast< QMap<QString, SWGObject*> *
>(value);
511 for(
auto itemkey: items->keys()) {
515 else if(QStringLiteral(
"QString").compare(innerType) == 0) {
516 auto items =
reinterpret_cast< QMap<QString, QString*> *
>(value);
517 for(
auto itemkey: items->keys()) {
521 else if(QStringLiteral(
"QDate").compare(innerType) == 0) {
522 auto items =
reinterpret_cast< QMap<QString, QDate*> *
>(value);
523 for(
auto itemkey: items->keys()) {
527 else if(QStringLiteral(
"QDateTime").compare(innerType) == 0) {
528 auto items =
reinterpret_cast< QMap<QString, QDateTime*> *
>(value);
529 for(
auto itemkey: items->keys()) {
533 else if(QStringLiteral(
"QByteArray").compare(innerType) == 0) {
534 auto items =
reinterpret_cast< QMap<QString, QByteArray*> *
>(value);
535 for(
auto itemkey: items->keys()) {
539 else if(QStringLiteral(
"qint32").compare(innerType) == 0) {
540 auto items =
reinterpret_cast< QMap<QString, qint32> *
>(value);
541 for(
auto itemkey: items->keys()) {
542 auto val = items->value(itemkey);
546 else if(QStringLiteral(
"qint64").compare(innerType) == 0) {
547 auto items =
reinterpret_cast< QMap<QString, qint64> *
>(value);
548 for(
auto itemkey: items->keys()) {
549 auto val = items->value(itemkey);
553 else if(QStringLiteral(
"bool").compare(innerType) == 0) {
554 auto items =
reinterpret_cast< QMap<QString, bool> *
>(value);
555 for(
auto itemkey: items->keys()) {
556 auto val = items->value(itemkey);
560 else if(QStringLiteral(
"float").compare(innerType) == 0) {
561 auto items =
reinterpret_cast< QMap<QString, float> *
>(value);
562 for(
auto itemkey: items->keys()) {
563 auto val = items->value(itemkey);
567 else if(QStringLiteral(
"double").compare(innerType) == 0) {
568 auto items =
reinterpret_cast< QMap<QString, double> *
>(value);
569 for(
auto itemkey: items->keys() ) {
570 auto val = items->value(itemkey);
574 output->insert(innerName, mapobj);
579 QString* str =
static_cast<QString*
>(value);
580 return QString(*str);
585 return QString::number(value);
590 return QString::number(value);
595 return QString(value ?
"true" :
"false");
void toJsonValue(QString name, void *value, QJsonObject *output, QString type)
void toJsonMap(QMap< QString, void *> *value, QJsonObject *output, QString innerName, QString innerType)
void * create(QString type)
virtual QJsonObject * asJsonObject()
void setValue(void *value, QJsonValue obj, QString type, QString complexType)
void toJsonArray(QList< void *> *value, QJsonObject *output, QString innerName, QString innerType)
virtual void fromJsonObject(QJsonObject &json)
QString stringValue(QString *value)