Can someone help me make the SLR dialog do what I want?

Josh Sled jsled at asynchronous.org
Fri Aug 24 19:57:00 EDT 2007


Tim Wunder <tim at thewunders.org> writes:
> OK... So I :
> "Filter specific rows, based on data from a "visible column", a column storing 
> booleans indicating whether the row should be filtered or not, or based on 
> the return value of a "visible function", which gets a model, iter and 
> user_data and returns a boolean indicating whether the row should be filtered 
> or not."
> Where do I do this filtering? I guess I'd need to create some sort of "visible 
> function" that would make visible that which I want to filter??? 

Right ... well... you'll want to make that which you want to filter
*invisible*, but... ;)

When you create the GtkTreeModelFilter, you provide a function that fits the
signature of GtkTreeModelFilterVisibleFunc [1].  That is, make a new function
that has the same return value and arguments, and obeys the semantics
defined, then just use it's name to pass a pointer to the function for the
filtering algorithm to invoke later.  Something like:

    static gboolean
    _gnc_sxslr_filter_func(GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
    {
        // filters out even rows
        // (I made up the function name; this is all handwavy... --jsled)
        gboolean is_even_row = gtk_tree_iter_get_row_number(model, iter) % 2 == 0;
        return !is_even_row;
    }

    // [...]

    GtkTreeModel *filtered_model = gtk_tree_model_filter_new(existing_model, NULL);
    gtk_tree_model_filter_set_visible_func(filtered_model, _gnc_sxslr_filter_func, NULL, NULL);


This is very similar to the use of an Interface in object-oriented languages
... the function pointer can be thought of as a functional interface.


> And WTF is 
> an "iter"?

It represents a particular row in a particular model.  The 4th paragraph of
[2] has a bit more color.

Generally, you'll want to read [3] to get a sense of how the TreeModel and
TreeView (and the rest of the related classes/types) interact.  The design is
non-trival, but I don't really consider it overly complex, either. 

[1] http://library.gnome.org/devel/gtk/unstable/GtkTreeModelFilter.html#GtkTreeModelFilterVisibleFunc
[2] http://library.gnome.org/devel/gtk/unstable/GtkTreeModel.html#id3511622
[3] http://library.gnome.org/devel/gtk/unstable/TreeWidget.html

(All this is in your local devhelp, too.)


>> Color coding is always tricky ... in cultural significance ... in how it
[...]
> Yeah, I know. But it would look purdy if it had colors. ;)

Heh. :)

-- 
...jsled
http://asynchronous.org/ - a=jsled; b=asynchronous.org; echo ${a}@${b}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 188 bytes
Desc: not available
Url : http://lists.gnucash.org/pipermail/gnucash-devel/attachments/20070824/5c52dac7/attachment.bin 


More information about the gnucash-devel mailing list