View previous topic :: View next topic |
Author |
Message |
eldar
Joined: 14 Jun 2008 Posts: 101 Location: Ufa, Russia
|
Posted: Thu Jul 10, 2008 10:12 am Post subject: Implementing custom tree model for TreeView using TreeModel. |
|
|
I want to implement a custom tree model - I did this before, when I was using Qt - and I think GTK provides the same functionality. TreeModel in my opinion is actually a Composite pattern from GoF. I inspected TestWindow demo from gtkD demos, but it is using in all cases TreeStore and adds manually data to it. It's good for simple cases - but I need to implement a model myself.
I tried to search the web for GTK examples in other languages - but what I found(in C) is rather complicated - and of course programming style in D is completely different.
That's my vision what the implementation of the tree model should consist of:
1) columns count method - it's clear
2) parent item - root item for the whole tree
3) child count method - method should return number of child nodes for each node
4) get value method - method should get a TreePath as a parameter and return string/checkstate(for checkbox in the treenode)/icon - something like
SomeType getValue(TreePath path, int column)
I think that's all. That's the vision of a Qt user - maybe GTK does it in a different way - I really don't know. I will appreciate any help, and I hope if I succeed I will defenitely post something like a tutorial how to implement TreeModel in gtkD |
|
Back to top |
|
|
okibi
Joined: 04 Jan 2007 Posts: 170
|
Posted: Thu Jul 10, 2008 10:59 am Post subject: |
|
|
I believe this is something that Mike Wey is working on. Please take a look at Ticket 24 for more info. |
|
Back to top |
|
|
Mike Wey
Joined: 07 May 2007 Posts: 428
|
Posted: Thu Jul 10, 2008 11:59 am Post subject: |
|
|
Thats part of the puzzle.
There is also Ticket #19 for a custom treemodel.
The way i would like to see this implemented is so that users would just need to inherit from gtkTreeModel and override the needed functions.
and hopefully i'll get there at some point |
|
Back to top |
|
|
eldar
Joined: 14 Jun 2008 Posts: 101 Location: Ufa, Russia
|
Posted: Thu Jul 10, 2008 12:23 pm Post subject: |
|
|
I also thought I need to inherit from gtk.TreeModel. I began to write the code:
Code: |
module dataObjects.ObjectsTreeModel;
private import gtk.TreeModel;
class ObjectsTreeModel : TreeModel
{
public:
this()
{
}
}
|
But it is wrong - because TreeModel constructor has the following signature:
Code: |
public this (GtkTreeModel* gtkTreeModel)
|
So I get this message:
constructor dataObjects.ObjectsTreeModel.ObjectsTreeModel.this no match for implicit super() call in constructor
Error: Command failed, aborting.
What am I doing wrong? |
|
Back to top |
|
|
Mike Wey
Joined: 07 May 2007 Posts: 428
|
Posted: Thu Jul 10, 2008 3:36 pm Post subject: |
|
|
It's not implemented like this for now. gtk.TreeModel only has the constructor that accepts a gtk struct because it's really an interface, in svn r517 the implementation in GtkD is changed to an interface to reflect this. |
|
Back to top |
|
|
eldar
Joined: 14 Jun 2008 Posts: 101 Location: Ufa, Russia
|
Posted: Thu Jul 10, 2008 10:17 pm Post subject: |
|
|
I checked the previous revision of TreeModel - it was also that I have to pass the gtk struct to the constructor.
So right now I need to create gtk struct(object? I'm not good at C implenetation of GObject) manually - and then pass it to the constructor? What kind of gtk struct it should be? Just general GObject? |
|
Back to top |
|
|
Mike Wey
Joined: 07 May 2007 Posts: 428
|
Posted: Fri Jul 11, 2008 11:47 am Post subject: |
|
|
eldar wrote: | I checked the previous revision of TreeModel - it was also that I have to pass the gtk struct to the constructor.
So right now I need to create gtk struct(object? I'm not good at C implenetation of GObject) manually - and then pass it to the constructor? What kind of gtk struct it should be? Just general GObject? |
It accepts an struct that implements the TreeModel Interface, The glib way.
For more on how to do that i would look at C examples. |
|
Back to top |
|
|
eldar
Joined: 14 Jun 2008 Posts: 101 Location: Ufa, Russia
|
Posted: Sun Jul 13, 2008 3:10 am Post subject: |
|
|
Code: |
private import gtk.TreeModel;
class ObjectsTreeModel : TreeModel
{
private:
GtkTreeModel gtkTreeModel;
public:
this()
{
super(>kTreeModel);
}
}
|
I think I'm doing something wrong because when calling super(>kTreeModel) it gives the following message:
(geoid:31286): GLib-GObject-CRITICAL **: g_object_get_data: assertion `G_IS_OBJECT (object)' failed
(geoid:31286): GLib-GObject-CRITICAL **: g_object_get_data: assertion `G_IS_OBJECT (object)' failed
(geoid:31286): GLib-GObject-CRITICAL **: g_object_set_data_full: assertion `G_IS_OBJECT (object)' failed |
|
Back to top |
|
|
Mike Wey
Joined: 07 May 2007 Posts: 428
|
Posted: Sun Jul 13, 2008 11:25 am Post subject: |
|
|
Thats because GtkTreeModel doesn't derive from GObject, but is an GInterface. |
|
Back to top |
|
|
eldar
Joined: 14 Jun 2008 Posts: 101 Location: Ufa, Russia
|
Posted: Sun Jul 13, 2008 10:30 pm Post subject: |
|
|
I'm trying to understand now how to work with it. In C-example there is an interface - which is a struct of pointers to functions, and I have to assign real functions that I implement to the pointers. Here we have TreeModelIF. But, for example TreeModelIF.getValue is implemented in TreeModelT :
Code: |
public void getValue(TreeIter iter, int column, Value value)
{
// void gtk_tree_model_get_value (GtkTreeModel *tree_model, GtkTreeIter *iter, gint column, GValue *value);
gtk_tree_model_get_value(getTreeModelTStruct(), (iter is null) ? null : iter.getTreeIterStruct(), column, (value is null) ? null : value.getValueStruct());
}
|
If I reimplement getValue in my subclass of TreeModel - this implementation will be hidden. What is the point?
Maybe you have some small working example which you could post, so I will not bother you with every little question? |
|
Back to top |
|
|
Mike Wey
Joined: 07 May 2007 Posts: 428
|
Posted: Mon Jul 14, 2008 11:46 am Post subject: |
|
|
eldar wrote: | I'm trying to understand now how to work with it. In C-example there is an interface - which is a struct of pointers to functions, and I have to assign real functions that I implement to the pointers. Here we have TreeModelIF. But, for example TreeModelIF.getValue is implemented in TreeModelT :
Code: |
public void getValue(TreeIter iter, int column, Value value)
{
// void gtk_tree_model_get_value (GtkTreeModel *tree_model, GtkTreeIter *iter, gint column, GValue *value);
gtk_tree_model_get_value(getTreeModelTStruct(), (iter is null) ? null : iter.getTreeIterStruct(), column, (value is null) ? null : value.getValueStruct());
}
| If I reimplement getValue in my subclass of TreeModel - this implementation will be hidden. What is the point? |
For how it's currently implemented in GtkD, subclassing TreeModel won't do you much good. For now i would subclass gobject.ObjectG and implement the TreeModelIF interface with it.
Quote: | Maybe you have some small working example which you could post, so I will not bother you with every little question? |
I haven't tried building a custom treemodel myself. I want to do it at some point though. |
|
Back to top |
|
|
Mike Wey
Joined: 07 May 2007 Posts: 428
|
Posted: Tue Jul 29, 2008 2:11 pm Post subject: |
|
|
eldar wrote: | Maybe you have some small working example which you could post, so I will not bother you with every little question? |
Check out the new Demo in svn r548, an extendable TreeModel was added in svn r546 |
|
Back to top |
|
|
eldar
Joined: 14 Jun 2008 Posts: 101 Location: Ufa, Russia
|
Posted: Sun Aug 03, 2008 7:10 am Post subject: |
|
|
Thank's a lot, I really waited for this feature!! |
|
Back to top |
|
|
eldar
Joined: 14 Jun 2008 Posts: 101 Location: Ufa, Russia
|
|
Back to top |
|
|
Mike Wey
Joined: 07 May 2007 Posts: 428
|
|
Back to top |
|
|
|