Sign up

TreeModel usage

I have a TreeStore where I can store data a TreeView displays. But I would prefer to instead make the data I already have stored elsewhere available to the TreeView. It is my understanding that a TreeModel allows me to do that, but I'm confused about how a TreeModel is used in GtkD.

If you have, say, auto a = ["hello", "world"], how can you use a TreeModel to display those two entries in a TreeView?

Re: TreeModel usage

On 03-01-18 13:49, Luís Marques wrote:

I have a TreeStore where I can store data a TreeView displays. But I would prefer to instead make the data I already have stored elsewhere available to the TreeView. It is my understanding that a TreeModel allows me to do that, but I'm confused about how a TreeModel is used in GtkD.

If you have, say, auto a = ["hello", "world"], how can you use a TreeModel to display those two entries in a TreeView?

You would need to create an class that implements the TreeModelIF
interface.

Like this:
https://github.com/gtkd-developers/GtkD/blob/master/demos/gtkD/DemoCustomList/CustomList.d

Re: TreeModel usage

On Wed, 3 Jan 2018 15:24:10 +0100, Mike Wey wrote:

You would need to create an class that implements the TreeModelIF
interface.

Thanks! For the initial model filling, the example uses a rowInserted signal for each insertion. That seems inefficient to me. In other GUI toolkits there generally was a way to fill the model and send a single signal at the end to say that the model has changed. Only then would the view check to see how many items there would be in the model. I checked at https://developer.gnome.org/gtk3/unstable/GtkTreeModel.html but I didn't see anything appropriate. Do you really have to send a signal per each item being "inserted" in the model? (in my case the whole store is already filled when the view and the GTK model are created)

Re: TreeModel usage

On 03-01-18 19:33, Luís Marques wrote:

On Wed, 3 Jan 2018 15:24:10 +0100, Mike Wey wrote:

You would need to create an class that implements the TreeModelIF
interface.

Thanks! For the initial model filling, the example uses a rowInserted signal for each insertion. That seems inefficient to me. In other GUI toolkits there generally was a way to fill the model and send a single signal at the end to say that the model has changed. Only then would the view check to see how many items there would be in the model. I checked at https://developer.gnome.org/gtk3/unstable/GtkTreeModel.html but I didn't see anything appropriate. Do you really have to send a signal per each item being "inserted" in the model? (in my case the whole store is already filled when the view and the GTK model are created)

The rowInserted signal is to let the widgets that show your model know
about changes to the underling model. If you fill the model before
adding it to a treeview, or if the model already holds the data
internally you don't need to emit the signal.

Re: TreeModel usage

On Wed, 3 Jan 2018 22:51:55 +0100, Mike Wey wrote:

On 03-01-18 19:33, Luís Marques wrote:
The rowInserted signal is to let the widgets that show your model know
about changes to the underling model. If you fill the model before
adding it to a treeview, or if the model already holds the data
internally you don't need to emit the signal.

OK, thanks! That wasn't obvious to me because the example fills the model before adding it to the TreeView, but the filling function is generic and still emits the signal.