Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Stupan
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
Hugo Hörnquist
Stupan
Commits
29b12338
Commit
29b12338
authored
Apr 08, 2018
by
Hugo Hörnquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix problem with diff rows being blanked.
parent
22534b13
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
16 deletions
+23
-16
admin/mainwindow.cpp
admin/mainwindow.cpp
+23
-16
No files found.
admin/mainwindow.cpp
View file @
29b12338
...
...
@@ -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
());
}
}
/*
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment