Commit 00d0ed5e authored by Hugo Hörnquist's avatar Hugo Hörnquist

Diff GUI buttons work again

parent db889ed2
......@@ -237,13 +237,11 @@ MainWindow::MainWindow(QWidget *parent) :
// ==================================================
// TODO
clear_stockDiffTemp();
QList<int> inventoryCheckDisabled;
inventoryCheckDisabled << 0 << 1 << 2 << 3 << 4 << 6;
DisablingModel* inventoryModel = new DisablingModel(inventoryCheckDisabled);
// inventoryModel->setTable("stock_diff_temp");
inventoryModel->setTable("diff_view");
inventoryModel->setHeaderData(0, Qt::Horizontal, "id");
inventoryModel->setHeaderData(1, Qt::Horizontal, "product id");
......@@ -253,14 +251,11 @@ MainWindow::MainWindow(QWidget *parent) :
inventoryModel->setHeaderData(5, Qt::Horizontal, "Faktiskt");
inventoryModel->setHeaderData(6, Qt::Horizontal, "Diff");
qDebug() << "Primary key" << inventoryModel->primaryKey();
inventoryModel->setEditStrategy(QSqlTableModel::OnFieldChange);
QObject::connect(inventoryModel, &QAbstractItemModel::dataChanged,
this, &MainWindow::on_inventoryModel_dataChanged);
// inventoryModel->setRelation(1, QSqlRelation("products", "id", "name"));
inventoryModel->select();
ui->inventoryCheckView->setModel(inventoryModel);
ui->inventoryCheckView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
......@@ -738,7 +733,7 @@ void MainWindow::on_diffDrawer_textChanged(const QString &arg1)
void MainWindow::on_submitStockDiff_clicked()
{
QSqlQuery("DELETE FROM stock_diff_temp");
QSqlQuery("DELETE FROM diff_view");
((QSqlRelationalTableModel*) ui->inventoryCheckView->model())->select();
}
......@@ -775,23 +770,19 @@ void MainWindow::open_till()
port_write(port_name, '1');
}
// TODO this function does what it should on the db layer
// but doesn't update the ui as expected
void MainWindow::on_stockDiffReset_clicked()
{
clear_stockDiffTemp();
// TODO TODO this doesn't update the ui for some reason!
if (!((QSqlRelationalTableModel*) ui->stockView->model())->select())
qDebug() << __LINE__;
((QSqlTableModel*) ui->inventoryCheckView->model())->select();
}
// this also inserts the new needed data into stock_diff_temp
// this also inserts the new needed data into diff_help
void MainWindow::clear_stockDiffTemp()
{
// TODO transaction
QSqlQuery("UPDATE my_db_settings SET value = 0 WHERE name = 'stock_diff_temp_transfer'");
QSqlQuery("DELETE FROM stock_diff_temp");
QSqlQuery("DELETE FROM diff_help");
QSqlQuery("UPDATE my_db_settings SET value = 1 WHERE name = 'stock_diff_temp_transfer'");
}
......
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