Original date:2019-09-03 08:58:58 Edited by: irv Subject: Re: EuGTK:Filtering ListViews

It possibly needs to be explained: the GtkTreeModelFilter is just a "hook" that you set to call your filtering function. Gtk just does a "foreach()", calling your function for each item in the list whenever the need arises.

The return from your function determines whether or not the particular row will be visible or hidden.

Simple, eh?

Your function receives as parameters a pointer to the filter-model, and a pointer to an iterator.

This filter-model does not contain the data in your list. It's sort of an index, like the extra column of data that Spock was using.

If the data has been sorted or edited, you'll need to obtain the actual data stored at the location that GTK's foreach() is examining. That is, the data in the real model which the TreeModelFilter is tracking. To get the real model, you get the "child" of the filter-model with a call to gtk_tree_model_filter_get_model().

(I know, it makes no sense.)

Once you have that, the iterator can be used to obtain the data item that you're wanting to inspect to see if it should be visible, right?


You first have to use gtk_tree_model_filter_convert_iter_to_child_iter() to get a pointer to the actual data item.


For huge data sets that may take a long time to load, it's worth writing and testing the code to do this. It will only be a few lines, but the documentation is so opaque that it takes a lot of trial and error to figure out what they mean.

For small data sets, it's probably easier to just filter the data in Euphoria, then clear out and reload the list as needed.

In the example given in the pastey, I have taken a shortcut, by converting the iter into a path, which is then converted to an integer which points to the row in the real Eu data. I retrieve the column that needs inspecting in the normal Eu way: data[row][col]

If you add a function to display the selected student when double-clicked (connect the row-activated signal) you'll see that you get the wrong student's name displayed after the list has been sorted. integer row = get(tv_selection,"selected row") no longer gets the correct row of data!

To get the correct row, you do something similar to the above, except using the tree model sort instead as your "tracker" model from which to get the iterator... etc.

A full demo will be provided shortly. If anyone is interested.

Not Categorized, Please Help


Quick Links

User menu

Not signed in.

Misc Menu