Re: [gnome-db] Tree-structured data



Vivien Malerba wrote:
> If you can think of any good data presentation to the user, I'll be
> happy to include your ideas/code.
IMO a good starting point could be GtkTreeStore, plus
expand()/collapse() methods (only expand() actually fetches rows from db).
We need another method (and a constructor) to set the query used by
expand() to retrieve child nodes and which column to use as parameter.
OR we could provide a callback (it's more general).

> Ok, can you propose some API/Code for that?
Here's my API proposal. It probably needs some fine tuning (I'm quite
biased by my experience implementing my own case) but it should be a
good starting point.

GdaDataModelTree *gda_data_model_tree_new(
	gint cols,
	void (*expand_cbk)(GdaDataModelTree *, GdaRow *, gpointer),
	gpointer data);
This creates the model. expand_cbk is the callback used when expanding a
row. It gets the tree, a pointer to the row being expanded and user-data.
I don't think an automatic freeze/thaw is a good idea... Better leave it
to the programmer.

void gda_data_model_tree_expand(GdaDataModelTree *, GdaRow *);
This programmatically expands a node (actually calling expand_cbk).

void gda_data_model_tree_collapse(GdaDataModelTree *, GdaRow *);
This programmatically collapses a node, removing from the model its
children.

What I noticed is that, in Gtk+2, if you want a node to have an expander
you have to add a child node (even if empty) AND NEVER REMOVE IT. So
during the first call you already have the first node and must not
remove it, just set the values. To handle all the nodes in the same way,
expand() could first call expand_cbk() THEN remove the first node.
collapse() could add an empty node at the start and then remove all the
others. But when expand_cbk adds an expandable row it have to add the
empty node as child.

BYtE,
 Diego.



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