Using JsonParser to generate JSON document to pass in the addItems signal & using roles instead of their names (compiler will complain if a role is not existent anymore).
This commit is contained in:
@ -6,8 +6,8 @@
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QSpinBox>
|
||||
|
||||
#include <model/tablemodel.h>
|
||||
#include "formats/jsonparser.h"
|
||||
#include "model/metadata.h"
|
||||
|
||||
NewItemDialog::NewItemDialog(QWidget* parent)
|
||||
: AbstractDialog(parent) {}
|
||||
@ -62,18 +62,15 @@ void NewItemDialog::createContent() {
|
||||
}
|
||||
|
||||
void NewItemDialog::accept() {
|
||||
QJsonObject itemObject;
|
||||
itemObject.insert("Name", m_nameEdit->text());
|
||||
itemObject.insert("Description", m_descriptionEdit->text());
|
||||
itemObject.insert("Info", m_infoEdit->text());
|
||||
itemObject.insert("Amount", m_amountBox->value());
|
||||
itemObject.insert("Factor", m_factorBox->value());
|
||||
QHash<int, QVariant> itemValues;
|
||||
itemValues.insert(NameRole, m_nameEdit->text());
|
||||
itemValues.insert(DescriptionRole, m_descriptionEdit->text());
|
||||
itemValues.insert(InfoRole, m_infoEdit->text());
|
||||
itemValues.insert(AmountRole, m_amountBox->value());
|
||||
itemValues.insert(FactorRole, m_factorBox->value());
|
||||
|
||||
QJsonDocument jsonDoc;
|
||||
QJsonArray itemArray;
|
||||
itemArray.append(itemObject);
|
||||
jsonDoc.setArray(itemArray);
|
||||
emit addItems(jsonDoc.toJson(QJsonDocument::Compact));
|
||||
const QByteArray jsonDoc = JsonParser::itemValuesListToJson({itemValues}, ITEM_KEY_STRING);
|
||||
emit addItems(jsonDoc);
|
||||
|
||||
// resetContent();
|
||||
AbstractDialog::accept();
|
||||
|
||||
Reference in New Issue
Block a user