Re: GtkTreeModelSort



Stuart Jansen <smj8 email byu edu> writes:

I've been fairly impressed with the new tree CMV design so far. However,
I'm having a hard time using the GtkTreeModelSort and modifying the
data.

Let me see if I've got this right:
Because there is no way to access the data once it is put into a
GtkListStore or GtkTreeStore, a seperate copy must be maintained. Like
in gtk-demo were editable values are stored ina a GArray. (Can I just
say that not being able to read the stored values is a _real_ pain?)

No.  You can certainly access the data once it's in a List/Tree store.
The whole purpose of the design is to avoid duplicating data when
possible.

To get values, just use:
gtk_tree_model_get (model,
                    iter,
                    COL_1, &val1,
                    COL_2, &val2,
                    -1);
etc.

To avoid changing the order of the rows in the GtkListStore, I can't
just sort the GtkTreeModel (actually GtkListStore) but must wrap it in a
GtkTreeModelSort. (With the advantage that I can define sort functions
for individual columns.)

You can define sort functions for individual columns with the
GtkListStore as well.  It also implements the GtkTreeSortable interface.

I'm doing that and can edit/add rows without a problem. I'm having real
trouble removing rows, however. Could someone give at least a generally
description or better (bless your heart) example code describing the
correct way to use a GtkTreeModelSort?

GtkTreeModelSort is just a wrapper model and cannot be modified
directly.  You simply have to add/remove rows to the model being mapped
(ie, gtk_list_store_append, gtk_list_store_remove).

Hope that helped,
-Jonathan



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