Re: GtkListStore: forcing a sort
- From: Mattperry <guy somewhere fscked org>
- To: Owen Taylor <otaylor redhat com>
- Cc: gtk-app-devel-list gnome org
- Subject: Re: GtkListStore: forcing a sort
- Date: Sun, 13 Apr 2003 16:46:16 -0500
Thus spake Owen Taylor (otaylor redhat com):
On Sat, 2003-04-12 at 04:32, Mattperry wrote:
I have looked through the API reference and mailing lists, and I can't
seem to find an answer to this somewhat simple question. I have a
GtkTreeView which uses a GtkListStore model. The list store is
populated with a struct (ie, store = gtk_list_store_new(1, G_TYPE_POINTER);
I add many columns and use gtk_tree_view_column_set_cell_data_func() to
display various records of my structure in the columns in different
ways. Now, this works very well, as I only have one copy of the data,
and any change takes effect immediately. However, I would like to sort
the list after any change has been made to the data.
I have found the automatic sorting features unsatisfactory for two
reasons. First, I need to sort based on 2 columns simultaneously (one
has priority), and it doesn't seem like I can do this. Second, I want
to be able to issue a sort command whenever I want, rather than wait for
the user to click on the title of one of the columns. It seems like
such a sort function would be fairly standard. Where can I find this
functionality?
Note that, if a list store has a sort function, it's _always_ sorted;
there is no concept of sorting it.
gtk_tree_sortable_set_sort_func() and
gtk_tree_sortable_set_default_sort_func() let you sort with whatever
functions you want.
Regards,
Owen
I'm using gtk_tree_sortable_set_default_sort_func(), but I notice my
sort function is never called. My sort function looks like this:
gint list_cmp(GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, gpointer d)
{
struct sound_entry *entry1, *entry2;
gtk_tree_model_get(model, a, DATA_COL, &entry1, -1);
gtk_tree_model_get(model, b, DATA_COL, &entry2, -1);
g_warning("sort");
return sound_cmp(entry1, entry2);
}
"sort" never gets printed, and my list never gets sorted. Also, I don't
see how it's possible that the list store is always sorted if my data
changes independently of my list store. I have a function like this:
gtk_list_store_set(store, iter, DATA_COL, entry, -1);
and then function renderers to render the different columns of this
entry. If I change entry->name, for example, how is the list store to
notice this? How can I tell it that it needs to be sorted? As it
stands, using ..._set_default_sort_func() results in my sort function
never being called (regardles of whether I set the sort_column_id to the
DEFAULT_SORT_COLUMN_ID). Is this a bug?
--
const char* mattPerry = "mjperry2 uiuc edu";
Marge: "I was enjoying a quiet evening in the backyard, when suddenly,
without warning, I was abducted by aliens."
Aliens: "Warning! Warning! You are about to be abducted!"
-- The Simpsons
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]