From: Axel S. <Axe...@en...> - 2009-03-02 20:56:00
|
Hi Wolfgang, On Mar 2, 2009, at 14:27, Wolfgang Jeltsch wrote: > Hello, > > as far as I understand, a tree model contains a forest whose nodes > are marked > with data of an arbitrary type. For example, there is the type > ListStore a > where the “a” can be any type. So there is no notion of column in tree > models. Columns belong to a view and the values shown in a column are > determined by applying some function to the one-and-only value at the > respective row in the model. > > Now, I don’t understand why treeModelGetValue takes a ColumnId > argument. I > would expect it to just take a tree model and a tree iterator and > return the > one-and-only value at the respective row. > > Could someone please explain? > Yes, we can! Indeed, most widgets implement the CellLayout interface which means that you can setup the association between the Haskell stores and the widget using cellLayoutSetAttributes. This API has no need for columns. However, there are few widgets or properties in Gtk+ that still do not implement the CellLayout inferface, or don't implement it properly. Examples are the IconView widget or if you want to set a sorting function. These functions all require a column. Thus, the module CustomStore (form which ListStore and TreeStore are derived) contains the function customStoreSetColumn to set up a 'fake' column. Specifically, a 'ColumnId' is be associated with an extraction function using 'customStoreSetColumn'. The numbers of these columns can be arbitrary, but since they are stored in a lookup table, they should be small, positive numbers. So, you'd declare a constant column id, add the extraction function and then pass this column number to a widget that depends on column numbers. The reason the generic TreeModel interface contains a treeModelGetValue only for ColumnIds and not for complete rows is that it is indeed the generic variant of ListStore and TreeStore: if you have a fully typed model (e.g. ListStore String) you can extract a row using listStoreGetValue. If you only have the base class of type TreeModel, there's no way you can extract a value in a type safe way. Thus, the only way to extract a value from a TreeModel using treeModelGetValue is to use a ColumnId which carries the type. The function treeModelGetValue is not really needed, but I added it for symmetry as it sometimes gives cleaner code if you define a sort function, for instance. I hope this helps, Axel. |