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 "newitemdialog.h"
|
||||||
|
|
||||||
#include <QGridLayout>
|
#include <QGridLayout>
|
||||||
|
#include <QJsonArray>
|
||||||
|
#include <QJsonObject>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
#include <QSpinBox>
|
#include <QSpinBox>
|
||||||
@ -58,3 +60,21 @@ void NewItemDialog::createContent() {
|
|||||||
|
|
||||||
m_outerLayout->insertWidget(0, m_contentContainer);
|
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"
|
#include "abstractdialog.h"
|
||||||
|
|
||||||
|
class QDoubleSpinBox;
|
||||||
class QLineEdit;
|
class QLineEdit;
|
||||||
class QSpinBox;
|
class QSpinBox;
|
||||||
class QLabel;
|
class QLabel;
|
||||||
class NewItemDialog : public AbstractDialog {
|
class NewItemDialog : public AbstractDialog {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
NewItemDialog(QWidget* parent = nullptr);
|
NewItemDialog(QWidget* parent = nullptr);
|
||||||
|
|
||||||
void createContent() override;
|
void createContent() override;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void addItems(const QByteArray& jsonDoc);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void accept() override;
|
||||||
|
// void reject() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QLabel* m_nameLabel = nullptr;
|
QLabel* m_nameLabel = nullptr;
|
||||||
QLineEdit* m_nameEdit = nullptr;
|
QLineEdit* m_nameEdit = nullptr;
|
||||||
|
|||||||
@ -8,6 +8,7 @@
|
|||||||
#include "Dialogs/newitemdialog.h"
|
#include "Dialogs/newitemdialog.h"
|
||||||
#include "data/settingshandler.h"
|
#include "data/settingshandler.h"
|
||||||
#include "genericcore.h"
|
#include "genericcore.h"
|
||||||
|
#include "model/tablemodel.h"
|
||||||
|
|
||||||
static QString updateTextClean = "Do you want to update the application now?";
|
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?";
|
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());
|
restoreGeometry(settings.value("geometry").toByteArray());
|
||||||
restoreState(settings.value("windowState").toByteArray());
|
restoreState(settings.value("windowState").toByteArray());
|
||||||
|
|
||||||
|
m_tableModel = m_core->getModel();
|
||||||
|
ui->tableView->setModel(m_tableModel.get());
|
||||||
|
|
||||||
createActions();
|
createActions();
|
||||||
createHelpMenu();
|
createHelpMenu();
|
||||||
createGuiDialogs();
|
createGuiDialogs();
|
||||||
@ -44,9 +48,6 @@ MainWindow::MainWindow(QWidget* parent)
|
|||||||
connect(this, &MainWindow::displayStatusMessage, this, &MainWindow::showStatusMessage);
|
connect(this, &MainWindow::displayStatusMessage, this, &MainWindow::showStatusMessage);
|
||||||
connect(this, &MainWindow::checkForUpdates, this,
|
connect(this, &MainWindow::checkForUpdates, this,
|
||||||
&MainWindow::on_actionCheck_for_update_triggered, Qt::QueuedConnection);
|
&MainWindow::on_actionCheck_for_update_triggered, Qt::QueuedConnection);
|
||||||
|
|
||||||
m_tableModel = m_core->getModel();
|
|
||||||
ui->tableView->setModel(m_tableModel.get());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow() { delete ui; }
|
MainWindow::~MainWindow() { delete ui; }
|
||||||
@ -129,8 +130,6 @@ void MainWindow::on_pushButton_clicked() {
|
|||||||
|
|
||||||
void MainWindow::openNewItemDialog() {
|
void MainWindow::openNewItemDialog() {
|
||||||
showStatusMessage(tr("Invoked 'Edit|New Item'"));
|
showStatusMessage(tr("Invoked 'Edit|New Item'"));
|
||||||
qInfo() << "'open new item dialog' action triggered...";
|
|
||||||
|
|
||||||
m_newItemDialog->show();
|
m_newItemDialog->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -268,4 +267,6 @@ void MainWindow::createHelpMenu() {
|
|||||||
void MainWindow::createGuiDialogs() {
|
void MainWindow::createGuiDialogs() {
|
||||||
m_newItemDialog = make_unique<NewItemDialog>(this);
|
m_newItemDialog = make_unique<NewItemDialog>(this);
|
||||||
m_newItemDialog->createContent();
|
m_newItemDialog->createContent();
|
||||||
|
connect(m_newItemDialog.get(), &NewItemDialog::addItems, m_tableModel.get(),
|
||||||
|
&TableModel::appendItems);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
|
|
||||||
class NewItemDialog;
|
class NewItemDialog;
|
||||||
class QAbstractItemModel;
|
class TableModel;
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
@ -46,7 +46,7 @@ class MainWindow : public QMainWindow {
|
|||||||
|
|
||||||
// GenericCore* m_core;
|
// GenericCore* m_core;
|
||||||
unique_ptr<GenericCore> m_core;
|
unique_ptr<GenericCore> m_core;
|
||||||
shared_ptr<QAbstractItemModel> m_tableModel;
|
shared_ptr<TableModel> m_tableModel;
|
||||||
|
|
||||||
/// File actions
|
/// File actions
|
||||||
unique_ptr<QAction> m_newFileAct;
|
unique_ptr<QAction> m_newFileAct;
|
||||||
|
|||||||
Reference in New Issue
Block a user