Project

General

Profile

Actions

Bug #14941

open
SE

WAbstractProxyModel fails to provide header information (flags, data) on empty table

Bug #14941: WAbstractProxyModel fails to provide header information (flags, data) on empty table

Added by Stephan Ehlers 5 days ago. Updated 5 days ago.

Status:
New
Priority:
Normal
Assignee:
-
Target version:
-
Start date:
11/03/2026
Due date:
% Done:

0%

Estimated time:

Description

The current (4.15.0) implementation of WAbstractProxyModel::headerData is as follows (headerFlags comes with the same issue):

cpp17::any WAbstractProxyModel::headerData(int section, Orientation orientation,
                                        ItemDataRole role) const
{
  if (orientation == Wt::Orientation::Horizontal) {
    section = mapToSource(index(0, section, Wt::WModelIndex())).column();
  } else {
    section = mapToSource(index(section, 0, Wt::WModelIndex())).row();
  }
  return sourceModel_->headerData(section, orientation, role);
}

Consider the following "edge" case (it's really not that edgy):

  1. A table is empty (i.e. no rows for the horizontal header or no columns for the vertical header).
  2. The header itself is not empty (i.e. there are columns for the horizontal header, and/or there are rows for the vertical header).
  3. index is implemented in a well-behaved manner (i.e. it does not return valid indices for non-existent cells).

The current implementation fails to provide the correct data. Even though that data likely exists.

Ideas for a fix:
a) index should always generate a valid index, even if it is out-of-bounds. Checks would have to be enforced in other places.
b) Hack in a valid index by calling createIndex instead of index. This will likely fail inside mapToSource, since the source model might also be empty and our hack doesn't cover that.
c) Completely avoid using an index, and instead provide an overload to mapToSource like this: mapToSource(int section, Orientation orientation)

Maybe there are better approaches; out of those mentioned, only method c) would provide a clean solution in my opinion, but it would have to be implemented such that every existing proxy model stays intact. Either it provides a default implementation that calls the original overload, or that original overload gets a default implementation that does something like this: return sourceModel()->index(mapToSource(index.row(), Orientation::Vertical), mapToSource(index.column(), Orientation::Horizontal));

If all of this sounds sensible, I'd be willing to try my hands at a patch.

SE Updated by Stephan Ehlers 5 days ago Actions #1

I can think of two cases where this would crop up - both require a proxy model to be part of the stack:

  1. You start with an empty table.
  2. You filter a non-empty table until there are no results left - and then anything triggers an update of the header.
Actions

Also available in: PDF Atom