Re: Displaying domain objects with GtkTreeView



2011/11/28 RafaÅ KrupiÅski <r krupinski gmail com>:
Hi all!

How do I display list of custom objects in GtkTreeView?
GtkTreeView takes GtkListStore as a model, but it doesn't allow custom
objects, only list of gobjects.

What could that possibly mean ?

If you have custom derived GObjects, you can certainly populate a
list-store with them.

If you have "something-else-objects" that are not GObjects, you can always use
G_TYPE_POINTER to hold them (it would be up to you to ensure that their life
cycle is somehow bound to the liststore... i.e. that those objects are
not destroyed
while cell renderers are trying to access them).

On the other hand, when I want to read list's selection all I get is
the GtkListStore model - list of gobjets and I have to figure out the
actual domain object the data comes from.

You don't get a list of gobjects as far as I know, I'm not sure where you are
getting that from.

When you observe a GtkTreeSelection you get 'rows' of data, those
rows can contain any information which you put into it when you configured
the underlying list-store.

If you configured a column as a list of gobjects, then there is
probably a 'list-of-gobjects'
to be found for every row... but that would only be because you
provided those gobjects
to begin with.

I thought of adding a hidden column with some id, but maybe there is a
better solution?

Again not really sure what you are trying to do... remember that columns in a
GtkTreeModel are neither visible or hidden, they are just values which can be
rendered by a view.

Whether you decide to render all of the data from the liststore with
cell renderers
or to render just some of that data is up to you.

Hope this helps,
        -Tristan



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