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) :
inventoryModel->setEditStrategy(QSqlTableModel::OnFieldChange);
// QObject::connect(inventoryModel, &QAbstractItemModel::dataChanged,
// this, &MainWindow::on_inventoryModel_dataChanged);
QObject::connect(inventoryModel, &QAbstractItemModel::dataChanged,
this, &MainWindow::on_inventoryModel_dataChanged);
// inventoryModel->setRelation(1, QSqlRelation("products", "id", "name"));
inventoryModel->select();
......@@ -272,9 +272,6 @@ MainWindow::MainWindow(QWidget *parent) :
ui->inventoryCheckView->hideColumn(1);
ui->inventoryCheckView->hideColumn(2);
// TODO this line makes stuff dis-a-pear
inventoryModel->setData( inventoryModel->index(0, 5) , QVariant(5));
// --------------------------------------------------
setMoneyDiffLabels();
......@@ -331,20 +328,30 @@ MainWindow::~MainWindow()
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*/)
{
/*
if (topLeft.column() != 4) return;
QSqlTableModel* model = (QSqlTableModel*) ui->inventoryCheckView->model();
DisablingModel* model = (DisablingModel*) ui->inventoryCheckView->model();
int row = topLeft.row();
QModelIndex index = model->index(row, 3);
int expected = model->data(index).toInt();
int actual = model->data(topLeft).toInt();
int diff = actual - expected
model->setData(model->index(row, 5), diff);
*/
qDebug() << "Data Chaned" << topLeft;
if (model->isDirty()) {
int row = topLeft.row();
bool number;
int expected = model->data(model->index(row, 4)).toInt();
int actual = model->data(model->index(row, 5)).toInt(&number);
model->setData(model->index(row, 6),
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