QSortFilterProxyModel, QAbstractItemModel
-
@Slawomir_Piernikowski
For the record, we're not sure why you want the underlying data model to have the same sort order as the in the proxy model?Data doesn't really have a sort order, sorting is just one way of viewing the data. At different times you might sort by different criteria. The proxy model also provides filtering for the view, but you don't say you want rows omitted by the filter to be removed from the underlying model, which would be the equivalent change to what you are asking about sorting?
@JonB You wrote: we're not sure why you want the underlying data model to have the same sort order as the in the proxy model?
For during setting data(call SetData function of the customized QAbstractTableModel) or simpler saying clicking on a cell in the TableView and alter the data in it I take the:
int justRemovedRowIndex = cMagazynView->GetVectMagazyn().at(index)->GetTabView().currentIndex().row();
and everything is working perfectly if sorting is not involved. -
@JonB You wrote: we're not sure why you want the underlying data model to have the same sort order as the in the proxy model?
For during setting data(call SetData function of the customized QAbstractTableModel) or simpler saying clicking on a cell in the TableView and alter the data in it I take the:
int justRemovedRowIndex = cMagazynView->GetVectMagazyn().at(index)->GetTabView().currentIndex().row();
and everything is working perfectly if sorting is not involved.@Slawomir_Piernikowski said in QSortFilterProxyModel, QAbstractItemModel:
int justRemovedRowIndex = cMagazynView->GetVectMagazyn().at(index)->GetTabView().currentIndex().row();
No idea what this means, you gave us 0 context to any of those symbols
-
@Slawomir_Piernikowski said in QSortFilterProxyModel, QAbstractItemModel:
int justRemovedRowIndex = cMagazynView->GetVectMagazyn().at(index)->GetTabView().currentIndex().row();
No idea what this means, you gave us 0 context to any of those symbols
@VRonin
int justRemovedRowIndex = cMagazynView->GetVectMagazyn().at(index)->GetTabView().currentIndex().row();- cMagazynView - pointer to class which have a member...
... QVector<MagazynView *>vectMagazyn; - vector of MagazynView pointers
GetTabView() -
QTableView &MagazynView::GetTabView() { return *tabView; }
As it is simply to see I want to get row number of the currentIndex row of the TableView
- cMagazynView - pointer to class which have a member...
-
@VRonin
int justRemovedRowIndex = cMagazynView->GetVectMagazyn().at(index)->GetTabView().currentIndex().row();- cMagazynView - pointer to class which have a member...
... QVector<MagazynView *>vectMagazyn; - vector of MagazynView pointers
GetTabView() -
QTableView &MagazynView::GetTabView() { return *tabView; }
As it is simply to see I want to get row number of the currentIndex row of the TableView
@Slawomir_Piernikowski
As @VRonin has said, you have two approaches to sorting data from the model. Either you do not use aQSortFilterProxyModel
and do the actual sorting yourself on the rows, or you do use it and the sorting happens in the proxy not the underlying data. Then, yes, you must "dereference" to get the actual index in the underlying data from the proxy, and for that you have https://doc.qt.io/qt-5/qsortfilterproxymodel.html#mapToSource. That's just how it is. - cMagazynView - pointer to class which have a member...
-
QSortFilterProxyModel
has a method to map back the index of the view to the original model: https://doc.qt.io/qt-5/qsortfilterproxymodel.html#mapToSourceInstead of using
currentIndex().row()
you can useproxyModel->mapToSource(currentIndex()).row()
-
@Slawomir_Piernikowski
As @VRonin has said, you have two approaches to sorting data from the model. Either you do not use aQSortFilterProxyModel
and do the actual sorting yourself on the rows, or you do use it and the sorting happens in the proxy not the underlying data. Then, yes, you must "dereference" to get the actual index in the underlying data from the proxy, and for that you have https://doc.qt.io/qt-5/qsortfilterproxymodel.html#mapToSource. That's just how it is.@JonB ok thanks
-
QSortFilterProxyModel
has a method to map back the index of the view to the original model: https://doc.qt.io/qt-5/qsortfilterproxymodel.html#mapToSourceInstead of using
currentIndex().row()
you can useproxyModel->mapToSource(currentIndex()).row()
@VRonin ok I will try to use this
-
After a fiew tests it looks like mapToSource did the trick.
auto magazynToBeRemoved = model->GetcMagazynVect().at(cFilterProxyModel->GetVectMagazynFilterProxyModel().at(index)->mapToSource(cMagazynView->GetVectMagazyn().at(index)->GetTabView().currentIndex()).row());
-
After a fiew tests it looks like mapToSource did the trick.
auto magazynToBeRemoved = model->GetcMagazynVect().at(cFilterProxyModel->GetVectMagazynFilterProxyModel().at(index)->mapToSource(cMagazynView->GetVectMagazyn().at(index)->GetTabView().currentIndex()).row());
@Slawomir_Piernikowski
Good. But do you really write that as a single line in your source code? -
@Slawomir_Piernikowski
Good. But do you really write that as a single line in your source code?@JonB I know that it can be not so readable for everybody but since I have been working on my soft from allmost 8 monthes I am used to such long lines of code :-)). Usually I devided such a long lines of code like this:
auto magazynToBeRemoved = model->GetcMagazynVect().at(cFilterProxyModel->GetVectMagazynFilterProxyModel().at(index)->
mapToSource(cMagazynView->GetVectMagazyn().at(index)->GetTabView().currentIndex()).row());