On sending (posting) item to the server the generated UUID is added to the local item.

This commit is contained in:
2026-02-02 16:13:44 +01:00
parent bedf8084d3
commit 63fe96fb2e
16 changed files with 145 additions and 33 deletions

View File

@ -6,20 +6,35 @@
#include "../model/metadata.h"
QList<ModelItemValues> JsonParser::toItemValuesList(const QByteArray& jsonData,
const QString& objectName) {
const QString& rootValueName) {
QList<ModelItemValues> result;
if (jsonData.isEmpty()) {
return result;
}
QJsonArray itemArray = extractItemArray(jsonData, objectName);
// NEXT tidy up the following code and encapsulate into functions;
foreach (QJsonValue value, itemArray) {
QJsonObject itemJsonObject = value.toObject();
/// check if there is an array or there is only one object inside the root object;
// TODO ? rename objectName into jsonValueName?
if (rootValueName == ITEMS_KEY_STRING) {
QJsonArray itemArray = extractItemArray(jsonData, rootValueName);
foreach (QJsonValue value, itemArray) {
QJsonObject itemJsonObject = value.toObject();
ModelItemValues values = jsonObjectToItemValues(itemJsonObject);
result.append(values);
}
}
if (rootValueName == ITEM_KEY_STRING) {
// QJsonArray itemArray = extractItemArray(jsonData, objectName);
QJsonDocument doc = QJsonDocument::fromJson(jsonData);
QJsonObject rootObject = doc.object();
QJsonObject itemJsonObject = rootObject.value(rootValueName).toObject();
ModelItemValues values = jsonObjectToItemValues(itemJsonObject);
result.append(values);
}
return result;
}
@ -28,7 +43,7 @@ QByteArray JsonParser::itemValuesListToJson(const QList<ModelItemValues>& itemVa
QJsonDocument jsonDoc;
QJsonObject rootObject;
QJsonArray itemArray;
for (const QHash<int, QVariant>& itemValues : itemValuesList) {
for (const ModelItemValues& itemValues : itemValuesList) {
QJsonObject itemObject;
QListIterator<UserRoles> i(USER_FACING_ROLES);