#include "PosExtendObject.h"

#include "preDefine.h"
#include <QJsonArray>

PosExtendObject::PosExtendObject(const PosExtendObject &posExtendObj, QObject *parent):QObject(parent)
{
    const QMetaObject *m = posExtendObj.metaObject();
    for( int i=m->propertyOffset(); i<m->propertyCount(); i++) {
        QMetaProperty qmp = m->property(i);
        QString key = QString::fromLatin1(qmp.name());
        QVariant value = posExtendObj.property(key.toUtf8());
        this->setProperty(key.toUtf8(), value);
    }
}

PosExtendObject& PosExtendObject::operator =(const PosExtendObject& posExtendObj)
{
    const QMetaObject *m = posExtendObj.metaObject();
    for( int i=m->propertyOffset(); i<m->propertyCount(); i++) {
        QMetaProperty qmp = m->property(i);
        QString key = QString::fromLatin1(qmp.name());
        QVariant value = posExtendObj.property(key.toUtf8());
        this->setProperty(key.toUtf8(), value);
    }
    return *this;
}

void PosExtendObject::FetchDataFromJson(const QJsonObject &json)
{
    foreach(QString key,  json.keys()) {
        setProperty(key.toUtf8(), json[key].toVariant());
    }
    return;
}

QString PosExtendObject::objectToString(){
    QString tempString;
    tempString = "{\"printType\":\"" + printType + "\","
            + "\"qty\":" + QString::number( qty ) + ","
            + "\"printName\":\"" + printName + "\","
            + "\"printDesc\":\"" + printDesc + "\"}" ;

    return tempString;
}
