GNOME Bugzilla – Bug 334791
TreeModelSort example
Last modified: 2006-04-11 17:01:34 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:
Created attachment 61378 [details] Just in case you can't grab from my webserver for some reason...
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.
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.
This should go into 2.5.x instead of 2.4.x.
(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.
Created attachment 61781 [details] Latest sorted_tree version 1.2 code. In case my webserver is unavailable.
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.
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.
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.