Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SortFilterProxyModel and ItemSelectionModel #73

Open
novoslinux opened this issue Jan 26, 2020 · 1 comment
Open

SortFilterProxyModel and ItemSelectionModel #73

novoslinux opened this issue Jan 26, 2020 · 1 comment

Comments

@novoslinux
Copy link

novoslinux commented Jan 26, 2020

Hi!

I am looking for a way to do ItemSelectionModel with SortFilterProxyModel.
As the QML ItemSelectionModel does not have a selectAll (can only select single Indices)
I pass the ItemSelectionModel to c++
c++item_selection_model->select(QItemSelection(startRowIndex, endRowIndex), QItemSelectionModel::Select);
So far so good all the indices that should be selected will be selected and
//QML item_selection_model.rowIntersectsSelection(index, 0)
does the correct thing but once you filter or sort something the order is messed up
(rowIntersectsSelection will report indices that should not be selected and not report indices that should be selected).

@oKcerG what are your thoughts on how to handle such case in oKcerG/SortFilterProxyModel?

  1. There is the option to just clear everything on filter or sort changes.
  2. Select items non-contiguously would be incredibly slow.
@oKcerG
Copy link
Owner

oKcerG commented Feb 2, 2020

Hi!

Do you use the ItemSelectionModel on the source model?
Did you forgot to map the indexes to the source model?

I experimented a bit and it seemed to work here, with such a delegate and a ItemSelectionModel on the source model:

ItemDelegate {
    readonly property var modelIndex: proxyModel.mapToSource(proxyModel.index(model.row, 0))
    onClicked: selectionModel.select(modelIndex, ItemSelectionModel.Toggle)
    highlighted: selectionModel.selectedIndex.indexOf(modelIndex) !== -1
}

It also works with : highlighted: selectionModel.selectedIndexes, selectionModel.rowIntersectsSelection(proxyModel.mapToSource(model.index), modelIndex.parent) but that's more verbose and hacky with the binding to selectedIndexes to force the reevaluation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants