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;
|
||||
|
||||
@ -8,6 +8,7 @@
|
||||
#include "Dialogs/newitemdialog.h"
|
||||
#include "data/settingshandler.h"
|
||||
#include "genericcore.h"
|
||||
#include "model/tablemodel.h"
|
||||
|
||||
static QString updateTextClean = "Do you want to update the application now?";
|
||||
static QString updateTextDirty = "Do you want to save the tasks & update the application now?";
|
||||
@ -35,6 +36,9 @@ MainWindow::MainWindow(QWidget* parent)
|
||||
restoreGeometry(settings.value("geometry").toByteArray());
|
||||
restoreState(settings.value("windowState").toByteArray());
|
||||
|
||||
m_tableModel = m_core->getModel();
|
||||
ui->tableView->setModel(m_tableModel.get());
|
||||
|
||||
createActions();
|
||||
createHelpMenu();
|
||||
createGuiDialogs();
|
||||
@ -44,9 +48,6 @@ MainWindow::MainWindow(QWidget* parent)
|
||||
connect(this, &MainWindow::displayStatusMessage, this, &MainWindow::showStatusMessage);
|
||||
connect(this, &MainWindow::checkForUpdates, this,
|
||||
&MainWindow::on_actionCheck_for_update_triggered, Qt::QueuedConnection);
|
||||
|
||||
m_tableModel = m_core->getModel();
|
||||
ui->tableView->setModel(m_tableModel.get());
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow() { delete ui; }
|
||||
@ -129,8 +130,6 @@ void MainWindow::on_pushButton_clicked() {
|
||||
|
||||
void MainWindow::openNewItemDialog() {
|
||||
showStatusMessage(tr("Invoked 'Edit|New Item'"));
|
||||
qInfo() << "'open new item dialog' action triggered...";
|
||||
|
||||
m_newItemDialog->show();
|
||||
}
|
||||
|
||||
@ -268,4 +267,6 @@ void MainWindow::createHelpMenu() {
|
||||
void MainWindow::createGuiDialogs() {
|
||||
m_newItemDialog = make_unique<NewItemDialog>(this);
|
||||
m_newItemDialog->createContent();
|
||||
connect(m_newItemDialog.get(), &NewItemDialog::addItems, m_tableModel.get(),
|
||||
&TableModel::appendItems);
|
||||
}
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
#include <QMainWindow>
|
||||
|
||||
class NewItemDialog;
|
||||
class QAbstractItemModel;
|
||||
class TableModel;
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
@ -46,7 +46,7 @@ class MainWindow : public QMainWindow {
|
||||
|
||||
// GenericCore* m_core;
|
||||
unique_ptr<GenericCore> m_core;
|
||||
shared_ptr<QAbstractItemModel> m_tableModel;
|
||||
shared_ptr<TableModel> m_tableModel;
|
||||
|
||||
/// File actions
|
||||
unique_ptr<QAction> m_newFileAct;
|
||||
|
||||
Reference in New Issue
Block a user