Re: Sorting a TreeModel
- From: "Joe Van Dyk" <joevandyk gmail com>
- To: gtkmm-list gnome org
- Subject: Re: Sorting a TreeModel
- Date: Wed, 10 Jan 2007 12:20:39 -0800
On 1/9/07, Joe Van Dyk <joevandyk gmail com> wrote:
I have a TreeModel that's wrapped with a TreeModelSort object. I then
mark the TreeViewColumn sortable with:
So, when I click on the treeview's column header, it does do the right
thing. It shows a down arrow and sorts the column ascending. If I
click the column header again, it shows an up arrow and sorts the
However! If I click the column header again, there's no arrow and the
column goes back to being unsorted. I don't want this behavior. The
column should always be sorted one way or another when I click the
I'm using Gtk and Gtkmm 2.4 if it matters.
And a related question:
In my TreeModel, I have a bunch of floats. When these floats are
displayed in the TreeView, they should be rounded to two or three
decimal places. You should be able to sort on those columns as well.
The TreeModel can contain about to 1000 rows or so, each row has 30
columns. About half of those columns contain these floats. The
TreeModel is updated at least once a second. So, performance might be
I've figured out a couple ways of doing it:
1. Convert the floats to strings using snprintf, insert those strings
into the TreeModel. Makes sorting more difficult (they're strings,
2. Store the floats into the TreeModel. Use a cell rendering
function to round the floats and output a string. I've heard that
using cell renders are slow though.
3. Store the floats into the TreeModel. For each float, also store a
rounded string into the TreeModel. Tell the TreeViewColumn to use the
rounded string to display and the float for when sorting. I'm leaning
towards this option.
Any feedback is greatly appreciated.
] [Thread Prev