示例#1
0
void CodeGenerator::generateMap()
{
    QFile codeFile(":code.json");
    if (!codeFile.open(QIODevice::ReadOnly))
    {
        qWarning("Could not open code file");
        return;
    }
    QByteArray codeData = codeFile.readAll();

    QJsonDocument JDoc(QJsonDocument::fromJson(codeData));
    if (!JDoc.isObject())
    {
        qWarning("Code file: invalid file format");
        return;
    }

    QJsonObject Main = JDoc.object();
    QJsonArray Snippets = Main["snippets"].toArray();
    QJsonArray Events = Main["events"].toArray();
    QJsonArray Commands = Main["commands"].toArray();
    QJsonArray Controls = Main["controls"].toArray();
    QJsonArray Expressions = Main["expressions"].toArray();

    for (QJsonArray::const_iterator it = Snippets.constBegin(); it != Snippets.constEnd(); it++)
    {
        QJsonObject Snippet = it->toObject();
        _snippets[Snippet["name"].toString()] = processCodeField(Snippet["code"].toArray());
    }

    for (QJsonArray::const_iterator it = Events.constBegin(); it != Events.constEnd(); it++)
    {
        QJsonObject Event = it->toObject();
        CodeGenerator::Event tmp = {processCodeField(Event["code"].toArray()), Event["register"].toString()};
        _events[Event["name"].toString()] = tmp;
    }

    for (QJsonArray::const_iterator it = Commands.constBegin(); it != Commands.constEnd(); it++)
    {
        QJsonObject Command = it->toObject();
        _commands[Command["name"].toString()] = processCodeField(Command["code"].toArray());
    }

    for (QJsonArray::const_iterator it = Controls.constBegin(); it != Controls.constEnd(); it++)
    {
        QJsonObject Control = it->toObject();
        _controls[Control["name"].toString()] = processCodeField(Control["code"].toArray());
    }

    for (QJsonArray::const_iterator it = Expressions.constBegin(); it != Expressions.constEnd(); it++)
    {
        QJsonObject Expression = it->toObject();
        _expressions[Expression["name"].toString()] = Expression["code"].toString();
    }
}
示例#2
0
	bool RestGetOrders::ReceiveJson(const QJsonDocument& json, int nCode)
	{
		qDebug() << json;

		QList<OrdersData> listOrdersData;

		OrdersData od;

		QJsonArray jaOrders = json.array();
		for (QJsonArray::const_iterator citor = jaOrders.constBegin();
			citor != jaOrders.constEnd(); ++citor)
		{
			QJsonObject joOrder = citor->toObject();

			od.nId = joOrder[szElemText[ET_ID]].toInt();
			od.eType = static_cast<OrderType>(joOrder[szElemText[ET_TYPE]].toInt());
			od.dOrderPrice = joOrder[szElemText[ET_ORDER_PRICE]].toVariant().toDouble();
			od.dOrderAmount = joOrder[szElemText[ET_ORDER_AMOUNT]].toVariant().toDouble();
			od.dProcessedAmount = joOrder[szElemText[ET_PROCESSED_AMOUNT]].toVariant().toDouble();
			od.dtOrderTime = QDateTime::fromTime_t(joOrder[szElemText[ET_ORDER_TIME]].toInt());

			listOrdersData.append(od);
		}

		emit signal_Receive(listOrdersData);

		return true;
	}
示例#3
0
void Order::loadFromJson(const QJsonObject &json)
{
    if (json.isEmpty()) {
        return;
    }

    Q_D(Order);

    QScopedPointer<const PPEnumsMap> em(new PPEnumsMap);

    d->setId(json.value(QStringLiteral("id")).toString());

    d->setReferenceId(json.value(QStringLiteral("reference_id")).toString());

    const QJsonObject ao = json.value(QStringLiteral("amount")).toObject();
    PaymentAmount *oldAo = amount();
    if (!ao.isEmpty()) {
        if (oldAo) {
            oldAo->loadFromJson(ao);
        } else {
            setAmount(new PaymentAmount(ao, this));
        }
    } else {
        setAmount(nullptr);
        delete oldAo;
    }


    d->setPaymentMode(em->paymentModeTypeTokenToEnum(json.value(QStringLiteral("payment_mode")).toString()));

    d->setState(em->stateTypeTokenToEnum(json.value(QStringLiteral("state")).toString()));

    d->setReasonCode(em->reasonCodeTokenToEnum(json.value(QStringLiteral("reason_code")).toString()));

    d->setProtectionEligibility(em->protectionEligibilityTokenToEnum(json.value(QStringLiteral("protection_eligibility")).toString()));

    const QString pets = json.value(QStringLiteral("protection_eligibility_type")).toString();
    if (!pets.isEmpty()) {
        QList<Geltan::PP::PayPal::ProtectionEligibilityType> petList;
        const QStringList petsList = pets.split(QChar(','));
        petList.reserve(petsList.size());
        for (const QString &pet : petsList) {
            petList.append(em->protectionEligibilityTypeTokenToEnum(pet));
        }
        d->setProtectionEligibilityType(petList);
    } else {
        d->setProtectionEligibilityType(QList<Geltan::PP::PayPal::ProtectionEligibilityType>());
    }

    d->setParentPayment(json.value(QStringLiteral("parent_payment")).toString());

    const QJsonObject fmfo = json.value(QStringLiteral("fmf_details")).toObject();
    FMFDetails *oldFmf = fmfDetails();
    if (!fmfo.isEmpty()) {
        if (oldFmf) {
            oldFmf->loadFromJson(fmfo);
        } else {
            d->setFmfDetails(new FMFDetails(fmfo, this));
        }
    } else {
        d->setFmfDetails(nullptr);
        delete oldFmf;
    }

    const QString ct = json.value(QStringLiteral("create_time")).toString();
    if (!ct.isEmpty()) {
        d->setCreateTime(QDateTime::fromString(ct, Qt::ISODate));
    } else {
        d->setCreateTime(QDateTime());
    }

    const QString ut = json.value(QStringLiteral("update_time")).toString();
    if (!ut.isEmpty()) {
        d->setUpdateTime(QDateTime::fromString(ut, Qt::ISODate));
    } else {
        d->setUpdateTime(QDateTime());
    }

    const QJsonArray la = json.value(QStringLiteral("links")).toArray();
    d->clearLinks();
    Q_EMIT linksChanged(links());
    if (!la.isEmpty()) {
        QList<Link*> linksToAdd;
        QJsonArray::const_iterator i = la.constBegin();
        while (i != la.constEnd()) {
            linksToAdd.append(new Link(i->toObject()));
            ++i;
        }
        d->setLinks(linksToAdd);
    }
}