Unite data from two QSqlRelationTableModel into one TableView
-
wrote on 17 Mar 2017, 19:15 last edited by
Hi,
is there any way to unite data from TableModel #1 with data from TableModel #2 in a TableView?
Ofcource i could write them from one model to another, but i need to change data in TableModel #2. (Is it possible to write them back, but its seems to be wrong way).
I though that it could be done by writing my own successor of QAbstractProxyModel, but i dont succeed with this.
Is it a proper way or there is something else? -
Hi,
is there any way to unite data from TableModel #1 with data from TableModel #2 in a TableView?
Ofcource i could write them from one model to another, but i need to change data in TableModel #2. (Is it possible to write them back, but its seems to be wrong way).
I though that it could be done by writing my own successor of QAbstractProxyModel, but i dont succeed with this.
Is it a proper way or there is something else?wrote on 17 Mar 2017, 20:53 last edited by VRonin@SergeyK12 said in Unite data from two QSqlRelationTableModel into one TableView:
I though that it could be done by writing my own successor of QAbstractProxyModel
It can't as QAbstractProxyModel only supports 1 source model, you'd have to go one step back and reimplement QAbstractItemModel
@SergeyK12 said in Unite data from two QSqlRelationTableModel into one TableView:
is there any way to unite data from TableModel #1 with data from TableModel #2
Define "unite". append the rows of TableModel #2 to TableModel #1? put the columns side by side?
-
wrote on 17 Mar 2017, 21:25 last edited by
I mean - put the columns side by side.
Table #1 consist of parameter name, unit etc. and its value is in Table #2. Im trying to show them in one TableView (and it seems like i must think about this strange logic)
So, it is impossible to add additional model in successor of QAbstractProxyModel by my own as a private field and the setter for it?
I will try to use QAbstractItemModel -
Hi,
Why about making a QSqlQueryModel with the query to build that data the way you want it ?
-
wrote on 18 Mar 2017, 10:15 last edited by
If you do not need the changes in the models to feed back into the database just use QSqlQueryModel as @SGaist suggested and let SQL do the merging for you.
If you need the changes to go in the DB then probably the fastest way is using KExtraColumnsProxyModel and link the extra columns to the TableModel #2
-
wrote on 18 Mar 2017, 21:31 last edited by
Thanks for your request.
Since i need to change data inside DB i suppose i should use KDE (but its too hard to build a library).
What should i do to write ny own proxy with such property?
I almost write one, it could show me data but data from #2 table is in gray mode (i couldnt change them, and there is a rectangle inside the cell screenshot).I reimplement the following method of QIdentityProxyModel:
- data, index, columnCount
- add a private field with QSqlRelationTableModeland the setter.
I suppose there is something alse which i should reimplement to make field in 5 cell editebel. SetData ofcource, but why is it in a gray mode? There is a method which make cells editable?
Thanks
-
wrote on 18 Mar 2017, 21:46 last edited by SergeyK12
Here is my methods
int columnCount(const QModelIndex &) const { return sourceModel()->columnCount()+1; } QVariant data(const QModelIndex &ind, int role) const { if(ind.column() < 4) return sourceModel()->data(mapToSource(ind), role); else return m_model->data(m_model->index(m_id, ind.row()+1)); } void setExtraColumnModel(int id, QSqlRelationalTableModel *model) { m_id = id; m_model = model; } private: int m_id; QSqlRelationalTableModel *m_model;
-
Thanks for your request.
Since i need to change data inside DB i suppose i should use KDE (but its too hard to build a library).
What should i do to write ny own proxy with such property?
I almost write one, it could show me data but data from #2 table is in gray mode (i couldnt change them, and there is a rectangle inside the cell screenshot).I reimplement the following method of QIdentityProxyModel:
- data, index, columnCount
- add a private field with QSqlRelationTableModeland the setter.
I suppose there is something alse which i should reimplement to make field in 5 cell editebel. SetData ofcource, but why is it in a gray mode? There is a method which make cells editable?
Thanks
wrote on 20 Mar 2017, 08:21 last edited by@SergeyK12 said in Unite data from two QSqlRelationTableModel into one TableView:
I reimplement the following method of QIdentityProxyModel:
data, index, columnCount
add a private field with QSqlRelationTableModeland the setter.I suppose there is something alse which i should reimplement to make field in 5 cell editebel. SetData ofcource, but why is it in a gray mode? There is a method which make cells editable?
You can't have a proxy model with 2 source models. internally it will rely on mapFromSource and mapToSource which won't work in your case, start directly from QAbstractItemModel.
The methods you reimplemented are fine, you miss rowCount(), setData() and flags()
use KDE (but its too hard to build a library).
no it's not... detailed instructions to build any tier 1 KDE module (spoiler alert: it's only 9 cmd lines): https://forum.qt.io/topic/76533/copy-selected-rows-of-a-table-to-a-model/12
8/8