Re: GtkTreeView: displaying structures and sorting



Havoc Pennington <hp redhat com> writes:

And, finally, while I have your attention: even if I pick the first
option, accepting that the list store will duplicate all of my data and
I'm careful to refresh the data when it changes, how can I sort data
that is displayed by a Pixbuf?  (For example, I have a "type" column,
which displays an icon representing the type; sorting on it should at
least group the rows by their type, and I'd like to choose the order
myself.)

I think the basic answer is that you want to set the sort function. 
You can apparently have an arbitrary number of sort functions; the
"column IDs" for the sort functions are separate IDs from the model or
view column IDs. Or something, it confused me too. ;-)

You can set up custom id's to sort the model by.

enum
  {
    SORT_BY_FOO = 0,
    SORT_BY_BAR,
    SORT_BY_BAZ
  }

list = gtk_list_store_new (1, G_TYPE_POINTER);
gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (list),
                                 SORT_BY_FOO,
                                 my_foo_sort_func, my_data, g_free);
gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (list),
                                 SORT_BY_BAR,
                                 my_bar_sort_func, my_data, g_free);
gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (list),
                                 SORT_BY_BAZ,
                                 my_baz_sort_func, my_data, g_free);


Then, when you make your columns, you can do:

gtk_tree_view_column_set_sort_column_id (GTK_TREE_VIEW_COLUMN (foo_column), SORT_BY_FOO);
gtk_tree_view_column_set_sort_column_id (GTK_TREE_VIEW_COLUMN (bar_column), SORT_BY_BAR);
gtk_tree_view_column_set_sort_column_id (GTK_TREE_VIEW_COLUMN (baz_column), SORT_BY_BAZ);

to make each column sort on the right function.

Hope this helps,
-Jonathan



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]