Commit 29b12338 authored by Hugo Hörnquist's avatar Hugo Hörnquist

Fix problem with diff rows being blanked.

parent 22534b13
...@@ -257,8 +257,8 @@ MainWindow::MainWindow(QWidget *parent) : ...@@ -257,8 +257,8 @@ MainWindow::MainWindow(QWidget *parent) :
inventoryModel->setEditStrategy(QSqlTableModel::OnFieldChange); inventoryModel->setEditStrategy(QSqlTableModel::OnFieldChange);
// QObject::connect(inventoryModel, &QAbstractItemModel::dataChanged, QObject::connect(inventoryModel, &QAbstractItemModel::dataChanged,
// this, &MainWindow::on_inventoryModel_dataChanged); this, &MainWindow::on_inventoryModel_dataChanged);
// inventoryModel->setRelation(1, QSqlRelation("products", "id", "name")); // inventoryModel->setRelation(1, QSqlRelation("products", "id", "name"));
inventoryModel->select(); inventoryModel->select();
...@@ -272,9 +272,6 @@ MainWindow::MainWindow(QWidget *parent) : ...@@ -272,9 +272,6 @@ MainWindow::MainWindow(QWidget *parent) :
ui->inventoryCheckView->hideColumn(1); ui->inventoryCheckView->hideColumn(1);
ui->inventoryCheckView->hideColumn(2); ui->inventoryCheckView->hideColumn(2);
// TODO this line makes stuff dis-a-pear
inventoryModel->setData( inventoryModel->index(0, 5) , QVariant(5));
// -------------------------------------------------- // --------------------------------------------------
setMoneyDiffLabels(); setMoneyDiffLabels();
...@@ -331,20 +328,30 @@ MainWindow::~MainWindow() ...@@ -331,20 +328,30 @@ MainWindow::~MainWindow()
delete ui; delete ui;
} }
/*
* This updates the QSqlTableModel to contain the same data as the database.
* This is needed since it looks at a view, and can therefore not find the
* primary key. Requiring all the fields in the front-end and back-end database
* to have the exact same fields.
*
* So, the calculations here are also done in the database, and those are what
* should be used when doing further stuff with the data.
*/
void MainWindow::on_inventoryModel_dataChanged(const QModelIndex &topLeft, const QModelIndex& /*bottomRight*/, const QVector<int>& /*roles*/) void MainWindow::on_inventoryModel_dataChanged(const QModelIndex &topLeft, const QModelIndex& /*bottomRight*/, const QVector<int>& /*roles*/)
{ {
/* QSqlTableModel* model = (QSqlTableModel*) ui->inventoryCheckView->model();
if (topLeft.column() != 4) return;
DisablingModel* model = (DisablingModel*) ui->inventoryCheckView->model(); if (model->isDirty()) {
int row = topLeft.row(); int row = topLeft.row();
QModelIndex index = model->index(row, 3);
int expected = model->data(index).toInt(); bool number;
int actual = model->data(topLeft).toInt(); int expected = model->data(model->index(row, 4)).toInt();
int diff = actual - expected int actual = model->data(model->index(row, 5)).toInt(&number);
model->setData(model->index(row, 5), diff);
*/ model->setData(model->index(row, 6),
qDebug() << "Data Chaned" << topLeft; number ? expected - actual
: QVariant());
}
} }
/* /*
......
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