FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Implementing custom tree model for TreeView using TreeModel.
Goto page 1, 2  Next
 
Post new topic   Reply to topic     Forum Index -> gtkD
View previous topic :: View next topic  
Author Message
eldar



Joined: 14 Jun 2008
Posts: 101
Location: Ufa, Russia

PostPosted: Thu Jul 10, 2008 10:12 am    Post subject: Implementing custom tree model for TreeView using TreeModel. Reply with quote

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 Smile
Back to top
View user's profile Send private message
okibi



Joined: 04 Jan 2007
Posts: 170

PostPosted: Thu Jul 10, 2008 10:59 am    Post subject: Reply with quote

I believe this is something that Mike Wey is working on. Please take a look at Ticket 24 for more info.
Back to top
View user's profile Send private message
Mike Wey



Joined: 07 May 2007
Posts: 428

PostPosted: Thu Jul 10, 2008 11:59 am    Post subject: Reply with quote

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 Smile
Back to top
View user's profile Send private message
eldar



Joined: 14 Jun 2008
Posts: 101
Location: Ufa, Russia

PostPosted: Thu Jul 10, 2008 12:23 pm    Post subject: Reply with quote

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()
      {

      }
}

Embarassed 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
View user's profile Send private message
Mike Wey



Joined: 07 May 2007
Posts: 428

PostPosted: Thu Jul 10, 2008 3:36 pm    Post subject: Reply with quote

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
View user's profile Send private message
eldar



Joined: 14 Jun 2008
Posts: 101
Location: Ufa, Russia

PostPosted: Thu Jul 10, 2008 10:17 pm    Post subject: Reply with quote

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
View user's profile Send private message
Mike Wey



Joined: 07 May 2007
Posts: 428

PostPosted: Fri Jul 11, 2008 11:47 am    Post subject: Reply with quote

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
View user's profile Send private message
eldar



Joined: 14 Jun 2008
Posts: 101
Location: Ufa, Russia

PostPosted: Sun Jul 13, 2008 3:10 am    Post subject: Reply with quote

Code:

private import gtk.TreeModel;
class ObjectsTreeModel : TreeModel
{
   private:
      GtkTreeModel gtkTreeModel;
   public:
      this()
      {
         super(&gtkTreeModel);
      }
}

I think I'm doing something wrong because when calling super(&gtkTreeModel) 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
View user's profile Send private message
Mike Wey



Joined: 07 May 2007
Posts: 428

PostPosted: Sun Jul 13, 2008 11:25 am    Post subject: Reply with quote

Thats because GtkTreeModel doesn't derive from GObject, but is an GInterface.
Back to top
View user's profile Send private message
eldar



Joined: 14 Jun 2008
Posts: 101
Location: Ufa, Russia

PostPosted: Sun Jul 13, 2008 10:30 pm    Post subject: Reply with quote

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? Rolling Eyes
Back to top
View user's profile Send private message
Mike Wey



Joined: 07 May 2007
Posts: 428

PostPosted: Mon Jul 14, 2008 11:46 am    Post subject: Reply with quote

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? Rolling Eyes


I haven't tried building a custom treemodel myself. I want to do it at some point though.
Back to top
View user's profile Send private message
Mike Wey



Joined: 07 May 2007
Posts: 428

PostPosted: Tue Jul 29, 2008 2:11 pm    Post subject: Reply with quote

eldar wrote:
Maybe you have some small working example which you could post, so I will not bother you with every little question? Rolling Eyes


Check out the new Demo in svn r548, an extendable TreeModel was added in svn r546
Back to top
View user's profile Send private message
eldar



Joined: 14 Jun 2008
Posts: 101
Location: Ufa, Russia

PostPosted: Sun Aug 03, 2008 7:10 am    Post subject: Reply with quote

Thank's a lot, I really waited for this feature!!
Back to top
View user's profile Send private message
eldar



Joined: 14 Jun 2008
Posts: 101
Location: Ufa, Russia

PostPosted: Wed Aug 20, 2008 7:27 am    Post subject: Reply with quote

I am now creating custom TreeModel. The default implementation is using C-pointers to structures. I think it is kind of C-way - D hi level programs doesn't deal with such low-level things. C# or python for example doesn't provide pointers - but gtk wrappers for these languages provide creating custom models: http://www.pygtk.org/pygtk2tutorial/sec-GenericTreeModel.html for pygtk and http://anonsvn.mono-project.com/viewcvs/trunk/gtk-sharp/sample/TreeModelDemo.cs?view=markup for gtk#. So maybe it will be better to get rid of pointers and do it in the hi-level-languages way.
Back to top
View user's profile Send private message
Mike Wey



Joined: 07 May 2007
Posts: 428

PostPosted: Wed Aug 20, 2008 12:24 pm    Post subject: Reply with quote

If i remember correctly when implementing a custom list for the demo ( http://www.dsource.org/projects/gtkd/browser/trunk/demos/gtkD/DemoCustomList/CustomList.d ) i only used pointers for GtkTreeIter.UserData. the C# demo seems to do the same:

Code:
result.UserData = (IntPtr) gch;


casting the UserData to store to a pointer.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> gtkD All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group