wxDataViewModel::GetValue doesn't ask for children in the order placed in wxDataViewItemArray

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
tengai
Earned a small fee
Earned a small fee
Posts: 21
Joined: Fri May 11, 2018 6:49 pm

wxDataViewModel::GetValue doesn't ask for children in the order placed in wxDataViewItemArray

Post by tengai » Wed Aug 04, 2021 4:16 pm

I've encountered an interesting order issue when expanding a child list in wxDataViewModel.

wxDataViewModel::GetChildren passes in a reference to wxDataViewItemArray and is populated with child wxDataViewItem objects.

I'd expect the order that wxDataViewModel::GetValue is called to get the value of child objects would be the order that objects are placed in wxDataViewItemArray; however, this doesn't seem to be the case.

wxDataViewItem child object placed in wxDataViewItemArray is, 0, 1, 2, 3, 4, 5.

the order wxDataViewModel::GetValue asks for child values are: 1,3,5,4,2,0; and this is the order that is display in the list. Interestingly all wxDataViewItem in wxDataViewItemArray are displayed; just in the wrong order. Attached is an image showing the display order in red.

Any idea what is going on here? Why wouldn't wxDataViewModel::GetValue ask for child values in the order placed in wxDataViewItemArray?

Image[/img]

Thanks,

Patrick
Attachments
order.png
order.png (55.54 KiB) Viewed 1147 times

User avatar
doublemax
Moderator
Moderator
Posts: 16384
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxDataViewModel::GetValue doesn't ask for children in the order placed in wxDataViewItemArray

Post by doublemax » Wed Aug 04, 2021 4:58 pm

What platform are you using and do you have a custom wxDataViewModel ?

Unless you explicitly set a sort order, there is no guarantee that the items are displayed in the same order they were inserted. It depends on the model's implementation. Storing items in a linked list would be too slow for large datasets. It's more likely the model would use an unordered map or similar container to store them.

(This is just an educated guess. All 3 major platforms use a different implementations of wxDataViewCtrl, and i don't know the internals of either of them.)
Use the source, Luke!

tengai
Earned a small fee
Earned a small fee
Posts: 21
Joined: Fri May 11, 2018 6:49 pm

Re: wxDataViewModel::GetValue doesn't ask for children in the order placed in wxDataViewItemArray

Post by tengai » Wed Aug 04, 2021 5:21 pm

This is windows. I have a Linux implementation but haven't ported and tested yet. And wxWidgets 3.1.5

Yes, wxDataViewModel is custom implementation; however, I do nothing to control how GetValue is called and I populated wxDataViewItemArray in linear order.

tengai
Earned a small fee
Earned a small fee
Posts: 21
Joined: Fri May 11, 2018 6:49 pm

Re: wxDataViewModel::GetValue doesn't ask for children in the order placed in wxDataViewItemArray

Post by tengai » Wed Aug 04, 2021 5:30 pm

> Unless you explicitly set a sort order, there is no guarantee that the items are displayed in the same order they were inserted. It depends on the model's implementation.

Can you please expand on this? How does one set the order?

User avatar
doublemax
Moderator
Moderator
Posts: 16384
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxDataViewModel::GetValue doesn't ask for children in the order placed in wxDataViewItemArray

Post by doublemax » Wed Aug 04, 2021 5:50 pm

I don't know too much about wxDVC, but after looking at the methods of related classes:

- when creating a wxDataViewColumn, add the wxDATAVIEW_COL_SORTABLE
- call wxSettableHeaderColumn::SetSortable( true )
- implement sorting related methods in your wxDataViewModel

In general, check the "dataview" sample that comes with wxWidgets.

You could also look at the implementation of the default wxDataViewModel
Use the source, Luke!

tengai
Earned a small fee
Earned a small fee
Posts: 21
Joined: Fri May 11, 2018 6:49 pm

Re: wxDataViewModel::GetValue doesn't ask for children in the order placed in wxDataViewItemArray

Post by tengai » Wed Aug 04, 2021 6:28 pm

Not setting wxDATAVIEW_COL_SORTABLE for this column. This column doesn't have the sort option. However, my other columns are sortable.

wxDataViewColumn("Value", new wxObjectPropValueRender(), 3, wxDVC_DEFAULT_WIDTH, wxALIGN_LEFT, wxDATAVIEW_COL_RESIZABLE);

So I'd expect no sorting and the order would be the order in the wxDataViewItemArray.

tengai
Earned a small fee
Earned a small fee
Posts: 21
Joined: Fri May 11, 2018 6:49 pm

Re: wxDataViewModel::GetValue doesn't ask for children in the order placed in wxDataViewItemArray

Post by tengai » Wed Aug 04, 2021 7:19 pm

I've discovered when I expand a child list the column sort routine is called with 'column' value == 4294967295.

Any explanation as to why there is a column 4294967295 (unsigned)? In a signed form 4294967295 == -1

Nothing in the docs to suggest 4294967295 (-1) is used for expanding child lists.

If I sort column 4294967295 by the index values in wxDataViewItemArray the child list display is ordered correctly.

User avatar
doublemax
Moderator
Moderator
Posts: 16384
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxDataViewModel::GetValue doesn't ask for children in the order placed in wxDataViewItemArray

Post by doublemax » Wed Aug 04, 2021 10:19 pm

Use the source, Luke!

tengai
Earned a small fee
Earned a small fee
Posts: 21
Joined: Fri May 11, 2018 6:49 pm

Re: wxDataViewModel::GetValue doesn't ask for children in the order placed in wxDataViewItemArray

Post by tengai » Wed Aug 04, 2021 10:24 pm

Well as soon as I sort another column all bets are off. All child lists in a wxDataViewModel adopts the 1,3,5,4,2,0 order and there is no way to go back to the original wxDataViewItemArray order 0,1,2,3,4,5 except by closing the window, reopening the window and reloading all the data again.
For some unknown reason sort columns are impacting a non-sorted column.

User avatar
doublemax
Moderator
Moderator
Posts: 16384
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxDataViewModel::GetValue doesn't ask for children in the order placed in wxDataViewItemArray

Post by doublemax » Wed Aug 04, 2021 10:39 pm

I have no first-hand experience with wxDVC, so unfortunately i can't help with this. But as it's a relatively old control, i doubt there is a fundamental bug in the sort handling. It's probably a case of bad documentation.

Can you adapt your code to use one of the built-in wxDataViewModels?

Or maybe create an as-simple-as-possible example that shows the problem?

Alternatively you can try asking on the wx-users group where you can reach the core wx developers. This is a user forum.
https://groups.google.com/g/wx-users

However, they will probably ask for a minimal sample, too.
Use the source, Luke!

tengai
Earned a small fee
Earned a small fee
Posts: 21
Joined: Fri May 11, 2018 6:49 pm

Re: wxDataViewModel::GetValue doesn't ask for children in the order placed in wxDataViewItemArray

Post by tengai » Wed Aug 04, 2021 11:12 pm

Ok, I discovered the difference.

When wxDataViewModel::Compare(const wxDataViewItem& item1, const wxDataViewItem& item2,...) is called I need to determine if item1 and item2 are parent wxDataViewItem or child wxDataViewItem? If child, I sort by the order in the wxDataViewItemArray; if parent, I sort by the column.

I was treating all wxDataViewItem as a parent wxDataViewItem which resulted in my child display list adopting the column sort algorithm and getting all jumbled.

Thanks!

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 5310
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxDataViewModel::GetValue doesn't ask for children in the order placed in wxDataViewItemArray

Post by ONEEYEMAN » Thu Aug 05, 2021 3:49 pm

Hi,
Are you using it as a tree or a list?

Thank you.

Post Reply