After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 334791 - TreeModelSort example
TreeModelSort example
Status: RESOLVED FIXED
Product: gtkmm
Classification: Bindings
Component: reference documentation
2.5.x
Other All
: Normal normal
: ---
Assigned To: gtkmm-forge
gtkmm-forge
Depends on:
Blocks:
 
 
Reported: 2006-03-16 18:06 UTC by R. Douglas Barbieri
Modified: 2006-04-11 17:01 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Just in case you can't grab from my webserver for some reason... (2.35 KB, application/gzip)
2006-03-16 18:08 UTC, R. Douglas Barbieri
Details
Latest sorted_tree version 1.2 code. In case my webserver is unavailable. (5.21 KB, application/gzip)
2006-03-22 18:06 UTC, R. Douglas Barbieri
Details

Description R. Douglas Barbieri 2006-03-16 18:06:18 UTC
Please describe the problem:
Murrary Cumming asked me to adapt an example for the Gtk::TreeView to
demonstrate sorting using the sort model. I am submitting it here, as per his
request.

You may find my example code here:

http://www.dooglio.net/sorted_tree.tar.gz


Steps to reproduce:
1. 
2. 
3. 


Actual results:


Expected results:


Does this happen every time?


Other information:
Comment 1 R. Douglas Barbieri 2006-03-16 18:08:53 UTC
Created attachment 61378 [details]
Just in case you can't grab from my webserver for some reason...
Comment 2 R. Douglas Barbieri 2006-03-16 18:12:34 UTC
Here is an explanation from the gtkmm email list:

> I derived it from the book/treeview/tree example code. I took out the
> tree model and replaced it with the plain old List-Store model, but
> also using Gtk::TreeModelSort. When you have a row selected, click the
> delete button and it properly converts the sort model iterator to the
> underlying list model iterator, and then deletes the row.
Comment 3 Murray Cumming 2006-03-22 12:32:32 UTC
You put the ListStore in a Gtk::TreeModelSort and then call TreeModelSort::set_sort_column(). But what advantage does this have over just calling Gtk::TreeSortable::set_sort_column() on the original ListStore?

TreeModelSort seems to only be useful for
a) Showing the same model at the same time with two different sorts.
b) Sorting a custom (not ListModel or TreeModel) treemodel that doesn't already implement TreeSortable.
Comment 4 R. Douglas Barbieri 2006-03-22 17:10:05 UTC
This should go into 2.5.x instead of 2.4.x.
Comment 5 R. Douglas Barbieri 2006-03-22 18:03:01 UTC
(In reply to comment #3)
> You put the ListStore in a Gtk::TreeModelSort and then call
> TreeModelSort::set_sort_column(). But what advantage does this have over just
> calling Gtk::TreeSortable::set_sort_column() on the original ListStore?

There is no real advantage. This was a misunderstanding on my part, and now I see clearly that ListStore already has TreeSortable implemented. It has been taken out.

> TreeModelSort seems to only be useful for
> a) Showing the same model at the same time with two different sorts.
> b) Sorting a custom (not ListModel or TreeModel) treemodel that doesn't already
> implement TreeSortable.

In a project I'm working on, I need that functionality because I have a visual sort, and an implict sort. But for this example, you're right, it's not needed.

I improved the project here: http://www.dooglio.net/source/sorted_tree_1.2.tar.gz

Also added: a column with icons, to demonstrate how to sort on non-alpha-numeric values.
Comment 6 R. Douglas Barbieri 2006-03-22 18:06:03 UTC
Created attachment 61781 [details]
Latest sorted_tree version 1.2 code. In case my webserver is unavailable.
Comment 7 Murray Cumming 2006-03-22 21:10:19 UTC
This now seems to be just an example of TreeModel::set_sort_column and TreeViewColumn::set_sort_model(). I think I'd prefer to add that to an existing example.

I would like a TreeModelSort example, though it's not essential.
Comment 8 Murray Cumming 2006-03-22 21:30:54 UTC
By the way, I just added a Sorting sub-section to the manual, to mention this stuff:
http://www.gtkmm.org/docs/gtkmm-2.4/docs/tutorial/html/ch08s05.html

I used bits of your example in it.
Comment 9 Murray Cumming 2006-04-11 17:01:34 UTC
I have also added docs/treeview/modelsort/, showing independent sorting with TreeModelSort, but I have not included it in the book because I think it would be distracting.