Implementing GtkTreeModels

Hi all,

There is a question at the end. Bear with me a little intro:

Most of the time I use GtkTreeStore or GtkListStore, the data that will
get displayed is stored somewhere, most probably some structs. Filling
in the rows of the store ends up in quite a bit of duplication. I
usually do this, then, by setting up my own class implementing the
GtkTreeModel iface.

This is does require work, though, and most of it is about doing things
not really related to the data in the rows, but to the list/tree
structure (gtk_tree_model_get_iter & such)

It would not be very difficult to:

1) introduce GtkAbstractListStore and GtkAbstractTreeStore (with better
names) which are exactly GtkListStore and GtkTreeStore, only they do not
manipulate column data.

2) introduce a GtkTreeModelRow interface abstracting all having to do
with retrieving data stored into rows, with api including get_n_columns,
get_column_type, get_value (suitably adapted, of course) (and probaly
not much more)

3) introduce a class GtkTreeStoreRow implementing the GtkTreeModelRow
iface, with the current implementation of rows as lists of gvalues.

4) Redefine GtkTreeStore and GtkListStore to be GtkAbstractTreeStore and
GtkAbstractListStore using this GtkTreeStoreRow to store its rows. 

All this could be done in a completely transparent way for existing
programs, since the Gtk{List,Tree}Store APIs need not change at all,
and would turn the setting up of customized GtkTreeModels (which most of
the time---I guess---are just Gtk{Tree,List}Stores with the row data
stored in various ways) much simpler and much less work: one would only
need to set up a new class implementing the GtkTreeModelRow interface.

For example, it would not be very difficult to write a class
implementing GtkTreeModelRow which generically deals with

This adds one extra level of indirection in everything dealing with
GtkTreeModels, but could also give speeds up by making it a lot simpler
to write custom GtkTreeModels.

Ok, here is the question: has a design like this been considered, or,
better, implemented? Or has it been decided against? Any ideas?

-- m

PS: please cc: me any replies, as I am not subscribed to gtk-devel-list.

Mariano Suárez-Alvarez
Departamento de Matematica - FCEyN - Universidad de Buenos Aires
Ciudad Universitaria, Pab. I. (1428) Ciudad de Buenos Aires, Argentina

    De la observación de la irreductibilidad de las creencias últimas 
    he sacado la mayor lección de mi vida. Aprendí a respetar las ideas 
    ajenas, a detenerme ante el secreto de las conciencias, a entender 
    antes de discutir, a discutir antes de condenar. Y como estoy en 
    vena de confesiones, hago una más, quizás superflua: detesto con 
    toda mi alma a los fanáticos.

    Norberto Bobbio, Italia civil.


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