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

@ -86,7 +86,7 @@ QHash<QString, std::vector<std::string>> CsvParser::extractColumnValues(
const rapidcsv::Document& doc) {
QHash<QString, std::vector<std::string>> columnValueMap;
for (const QString& columnName : headerNames) {
// NEXT add support for optional columns
// TODO add support for optional columns
// if (optionalCsvHeaderNames.contains(columnName)) {
// const std::vector<std::string> columnNames = doc.GetColumnNames();
// int columnIdx = doc.GetColumnIdx(columnName.toStdString());
@ -147,7 +147,7 @@ QVariant CsvParser::parseItemValue(const int role, const std::string& valueStrin
result = doubleValue;
// } else if (typeColumns.contains(columnName)) {
// // NEXT validate string is allowed
// // TODO validate string is allowed
// values[role] = QString::fromStdString(columnValueMap.value(columnName).at(row));
} else {
/// no type recognized for column

View File

@ -3,7 +3,7 @@
#include <QString>
typedef QHash<int, QVariant> ModelItemValues;
typedef QMap<int, QVariant> ModelItemValues;
namespace rapidcsv {
class Document;

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);

View File

@ -8,14 +8,14 @@ class QString;
class QByteArray;
class QJsonArray;
typedef QHash<int, QVariant> ModelItemValues;
typedef QMap<int, QVariant> ModelItemValues;
using namespace std;
class JsonParser {
public:
static QList<ModelItemValues> toItemValuesList(const QByteArray& jsonData,
const QString& objectName = "");
const QString& rootValueName = "");
static QByteArray itemValuesListToJson(const QList<ModelItemValues>& itemValuesList,
const QString& objectName = "");