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

SortProxyModel doesn't forward dataChanged signals #12

Open
frankosterfeld opened this issue Mar 18, 2021 · 2 comments
Open

SortProxyModel doesn't forward dataChanged signals #12

frankosterfeld opened this issue Mar 18, 2021 · 2 comments

Comments

@frankosterfeld
Copy link
Contributor

frankosterfeld commented Mar 18, 2021

source data changes, in particular for roles other than the sort role, are not forwarded (SortProxyModel::handleDataChanged), thus having a SortProxyModel in the stack makes you "lose" updates.

In a customer project using SPM, I just implemented it using linear search to do the mapping:

int minRow = std::numeric_limits<int>::max();
int maxRow = -1;

for (int sourceRow = topLeft.row(); sourceRow <= bottomRight.row(); ++sourceRow) {
    auto it = std::find(m_rowMap.cbegin(), m_rowMap.cend(), sourceRow);
    Q_ASSERT(it != m_rowMap.cend());
    const auto proxyRow = static_cast<int>(std::distance(m_rowMap.cbegin(), it));
    minRow = std::min(minRow, proxyRow);
    maxRow = std::max(maxRow, proxyRow);
}

Q_ASSERT(minRow <= maxRow);

emit dataChanged(index(minRow, 0), index(maxRow, 0), roles);

That does the job for my use case, but generic solution probably should use something more efficient.

@AndreSomers
Copy link

Hi Frank,

Thank you for your bug report. I have implemented a solution different from yours, based on keeping a reverse map and only emitting the dataChanged signal for the rows that that we got the signal for in the first place but grouping those in as few signals as possible. The change is now in review internally first before publishing.

Cheers, and happy to see the code gets some use outside of KDAB,

André

@dantti
Copy link
Contributor

dantti commented Nov 12, 2023

@AndreSomers was this merged in gerrit? can we close this?

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

3 participants