Re: GtkTreeModelMapping



On 16 Feb 2001, Owen Taylor wrote:

> 
> Alexander Larsson <alla lysator liu se> writes:
> 
> > I was gonna put some abstract types in a GtkTreeView to view them, only
> > i didn't want to copy strings from it and place in a GtkListStore, so I
> > wrote a TreeModel that takes another model and generates a new one where
> > the columns can be specified as transformations of the data in the
> > original model.
> > 
> > For each column in the model a (src_column, col_type, map_func, user_data)
> > tupel is used to map the value, where the map_func is of the type:
> > 
> > typedef void (* GValueMapFunc) (const GValue *a,
> > 				GValue *b,
> > 				gpointer user_data);
> > 
> > 
> > I think this is of general interest. Comments?
> 
> The way that I suggested to Jonathan earlier to do this, and the
> way he had half implemented (it's only a few lines of code) is
> to avoid the whole column thing at all in this case, and to
> able to provide a function for a particular column which 
> is passed in, as an argument, the tree row and the renderer,
> and is responsible for setting the attributes on the cell
> renderer.
> 
> So, you have (roughly) something like:
> 
> email_name_column_set_attrs (GtkTreeViewColum *column,
>                              GtkTreeModel     *model,
>                              GtkTreeIter      *iter)
> {
>   GtkEmailMessage *message;
>   GdkColor color;
> 
>   gtk_tree_model_get (model, 0, &message, NULL);
> 
>   email_message_get_status_color (message, &color);
>   g_object_set (column->renderer,
>                 "foreground_gdk", &color,
>                 "text",           model->name,
>                 NULL);
> }  
>                          
> 
> Jonathan's adding the other few lines for that now - take a look
> what he commits and see if you like it.

It sounds excellent.

/ Alex






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