Commit 9afb0a24 authored by Hugo Hörnquist's avatar Hugo Hörnquist

Made product listings auto save

parent 60a3d300
......@@ -135,6 +135,8 @@ MainWindow::MainWindow(QWidget *parent) :
model->setHeaderData(5, Qt::Horizontal, "Pris");
model->setHeaderData(6, Qt::Horizontal, "Till Salu?");
model->setEditStrategy(QSqlTableModel::OnFieldChange);
QObject::connect(
model, &QSqlTableModel::dataChanged,
this, &MainWindow::on_productModel_dataChanged
......@@ -158,8 +160,6 @@ MainWindow::MainWindow(QWidget *parent) :
view->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
view->horizontalHeader()->setSectionResizeMode(4, QHeaderView::Stretch);
set_productModel_dirty_helper();
// ==================================================
QSqlRelationalTableModel* stockModel = new QSqlRelationalTableModel();
......@@ -334,20 +334,15 @@ void MainWindow::on_inventoryModel_dataChanged(const QModelIndex &topLeft, const
}
/*
* Sets a help string wheater or not the productModel is saved
* This updates acquisitions with the new names when products are edited.
* TODO inventeringssystemet uppdateras inte här, bör det göra det?
* TODO inte heller lager-status, dock har den en refresh knapp.
*/
void MainWindow::on_productModel_dataChanged(const QModelIndex& /*topLeft*/, const QModelIndex& /*bottmRight*/, const QVector<int>& /*roles*/)
{
set_productModel_dirty_helper();
}
void MainWindow::set_productModel_dirty_helper()
{
QSqlTableModel* model = (QSqlTableModel*) ui->tableView->model();
if (model->isDirty())
ui->productListingDirtyLabel->setText("Unsaved Changes");
else
ui->productListingDirtyLabel->setText("Everything Saved");
// TODO this is possibly quite slow, test on slow system.
((QSqlTableModel*) ui->productSearch->model())->select();
((QSqlTableModel*) ui->purchaseView->model())->select();
}
/*
......@@ -378,22 +373,6 @@ void MainWindow::on_checkBox_toggled(bool checked)
model->setFilter("sale_status IN (0, 1)");
}
void MainWindow::on_saveButton_clicked()
{
model->submitAll();
set_productModel_dirty_helper();
// updates the acquisitions tab after products are modified
((QSqlTableModel*) ui->productSearch->model())->select();
((QSqlTableModel*) ui->purchaseView->model())->select();
}
void MainWindow::on_resetButton_clicked()
{
model->revertAll();
set_productModel_dirty_helper();
}
// Add new row for new product
void MainWindow::on_newItemButton_clicked()
{
......
......@@ -23,10 +23,6 @@ public:
private slots:
void on_checkBox_toggled(bool checked);
void on_saveButton_clicked();
void on_resetButton_clicked();
void on_newItemButton_clicked();
void on_deleteButton_clicked();
......
......@@ -111,27 +111,6 @@
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="productListingDirtyLabel">
<property name="text">
<string>Everything Saved</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="resetButton">
<property name="text">
<string>Reset</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="saveButton">
<property name="text">
<string>Save</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment