Skip to content

SortProxyModel doesn't forward dataChanged signals #12

Description

@frankosterfeld

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions