81 lines
2.3 KiB
C++
81 lines
2.3 KiB
C++
#include "newitemdialog.h"
|
|
|
|
#include <QGridLayout>
|
|
#include <QJsonArray>
|
|
#include <QJsonObject>
|
|
#include <QLabel>
|
|
#include <QLineEdit>
|
|
#include <QSpinBox>
|
|
|
|
#include <model/tablemodel.h>
|
|
|
|
NewItemDialog::NewItemDialog(QWidget* parent)
|
|
: AbstractDialog(parent) {}
|
|
|
|
void NewItemDialog::createContent() {
|
|
if (m_contentContainer) {
|
|
delete m_contentContainer;
|
|
}
|
|
|
|
setWindowTitle(tr("New item..."));
|
|
|
|
m_contentContainer = new QWidget(this);
|
|
|
|
// REFACTOR deduce label names and types from meta data & use a factory
|
|
m_nameLabel = new QLabel("&Name");
|
|
m_nameEdit = new QLineEdit();
|
|
m_nameLabel->setBuddy(m_nameEdit);
|
|
|
|
m_descriptionLabel = new QLabel("&Description");
|
|
m_descriptionEdit = new QLineEdit();
|
|
m_descriptionLabel->setBuddy(m_descriptionEdit);
|
|
|
|
m_infoLabel = new QLabel("&Info");
|
|
m_infoEdit = new QLineEdit();
|
|
m_infoLabel->setBuddy(m_infoEdit);
|
|
|
|
m_amountLabel = new QLabel("&Amount");
|
|
m_amountBox = new QSpinBox();
|
|
m_amountBox->setMaximum(1000);
|
|
m_amountLabel->setBuddy(m_amountBox);
|
|
|
|
m_factorLabel = new QLabel("&Factor");
|
|
m_factorBox = new QDoubleSpinBox();
|
|
m_factorBox->setMaximum(1000);
|
|
m_factorLabel->setBuddy(m_factorBox);
|
|
|
|
QGridLayout* layout = new QGridLayout();
|
|
layout->addWidget(m_nameLabel, 0, 0, 1, 1);
|
|
layout->addWidget(m_nameEdit, 0, 1, 1, 1);
|
|
layout->addWidget(m_descriptionLabel, 1, 0, 1, 1);
|
|
layout->addWidget(m_descriptionEdit, 1, 1, 1, 1);
|
|
layout->addWidget(m_infoLabel, 2, 0, 1, 1);
|
|
layout->addWidget(m_infoEdit, 2, 1, 1, 1);
|
|
layout->addWidget(m_amountLabel, 3, 0, 1, 1);
|
|
layout->addWidget(m_amountBox, 3, 1, 1, 1);
|
|
layout->addWidget(m_factorLabel, 4, 0, 1, 1);
|
|
layout->addWidget(m_factorBox, 4, 1, 1, 1);
|
|
|
|
m_contentContainer->setLayout(layout);
|
|
|
|
m_outerLayout->insertWidget(0, m_contentContainer);
|
|
}
|
|
|
|
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());
|
|
|
|
QJsonDocument jsonDoc;
|
|
QJsonArray itemArray;
|
|
itemArray.append(itemObject);
|
|
jsonDoc.setArray(itemArray);
|
|
emit addItems(jsonDoc.toJson(QJsonDocument::Compact));
|
|
|
|
// resetContent();
|
|
AbstractDialog::accept();
|
|
}
|