On Wed, 12 May 2021 18:16:51 +0200 Andreas Falkenhahn wrote:
AF> On 12.05.2021 at 17:55 Vadim Zeitlin wrote:
AF> > Just dump all the items in the current sort order if this is what you
AF> > need. You can either reuse the model Compare() to do it, or implement your
AF> > own Compare() and reuse the code in it in your dump function.
AF> But wouldn't that be overhead galore? Suppose I wanted to know the item
AF> at row N in the current sort order.
We can suppose anything we want, but I'd rather suppose you can avoid
needing it in the first place. Although I can imagine wanting to dump all
items in the sort order, I just don't see why would you want to get one row
at the given index (which is, of course, not even an index in the first
place, but a sequence of indices, generally speaking, as the items in this
control form a tree and not just a flat list).
AF> But I'm still not sure if this would work because I also need things like
AF> "delete row N" where N is a row in the current sort order - not in the
AF> model's order.
Where does this "N" come from? Typically users select the item to operate
on by clicking on it, or otherwise selecting it. It seems very strange to
specify the items by their position rather than either by their item or
screen coordinates. Are you sure there is no way to do what you want in a
much simpler way?
Anyhow, to keep this discussion at least slightly productive, if you
really need it, you absolutely need a function returning a wxDataViewItem
for the corresponding index. You could implement it in your own code, but
doing it in wx itself would make more sense. After looking at GTK docs
again, I think it should be possible to do it there by using GtkTreePath,
which is just such a collection of indices that you want (and so just a
single index for the flat tree). IIUC you should be able to use
gtk_tree_path_new_from_indicesv(&index, 1) to create the path you need and
once you have the path you can use the existing GTKPathToItem(), so it
actually looks pretty simple.
You can also use gtk_tree_view_get_visible_range() and then
gtk_tree_path_next() to iterate over all the currently visible paths, even
in the general case (in your case it would be enough to just increment the
index, of course).
AF> For this I'd need a way to do the same thing in reverse, i.e. find out
AF> the corresponding model row for a given display row. It's complicated
Yes, not doing it would definitely be simpler...