An item can be added to the model with accepting the NewItemDialog.
This commit is contained in:
@ -1,6 +1,8 @@
|
||||
#include "newitemdialog.h"
|
||||
|
||||
#include <QGridLayout>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonObject>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QSpinBox>
|
||||
@ -58,3 +60,21 @@ void NewItemDialog::createContent() {
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
@ -3,15 +3,25 @@
|
||||
|
||||
#include "abstractdialog.h"
|
||||
|
||||
class QDoubleSpinBox;
|
||||
class QLineEdit;
|
||||
class QSpinBox;
|
||||
class QLabel;
|
||||
class NewItemDialog : public AbstractDialog {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
NewItemDialog(QWidget* parent = nullptr);
|
||||
|
||||
void createContent() override;
|
||||
|
||||
signals:
|
||||
void addItems(const QByteArray& jsonDoc);
|
||||
|
||||
public slots:
|
||||
void accept() override;
|
||||
// void reject() override;
|
||||
|
||||
private:
|
||||
QLabel* m_nameLabel = nullptr;
|
||||
QLineEdit* m_nameEdit = nullptr;
|
||||
|
||||
Reference in New Issue
Block a user