Re: custom treemodel?
- From: "Jonathon Jongsma" <jonathon jongsma gmail com>
- To: "Murray Cumming" <murrayc murrayc com>
- Cc: gtkmm-list <gtkmm-list gnome org>
- Subject: Re: custom treemodel?
- Date: Fri, 19 May 2006 08:10:35 -0500
On 5/19/06, Murray Cumming <murrayc murrayc com> wrote:
On Thu, 2006-05-18 at 18:55 -0500, Jonathon Jongsma wrote:
> OK, I think I get it now, more or less. I've just noticed, however
> that when I run the example from gtkmm CVS, I get the following
> warning:
>
> (lt-example:29959): GLib-GObject-WARNING **: cannot add interface type
> `GtkTreeModel' to type `gtkmm__CustomObject_16ExampleTreeModel', since
> type `gtkmm__CustomObject_16ExampleTreeModel' already conforms to
> interface
>
> It seems to be caused by the following lines in the constructor:
> GType gtype = G_OBJECT_TYPE(gobj()); //The custom GType created in
> the Object constructor, from the typeid.
> Gtk::TreeModel::add_interface( gtype );
>
> I don't have a lot of experience with GObject stuff, so I have no idea
> whether these should be necessary or not. But it seems to run fine
> and doesn't issue a warning when those lines are commented out. Any
> thoughts?
Yes, I think I comment them out in Glom too.
OK. Then maybe I'll just get rid of them in the example. Any objections?
So now the example runs without any warnings, and I've been working on
ideas for a 'generic' custom treemodel. I'm thinking about something
like this:
template <class T>
class CustomTreeModel : public Gtk::TreeModel, public Glib::Object
{
public:
Glib::RefPtr<CustomTreeModel> create(T container);
...
protected:
CustomTreeModel(T container) :
Glib::ObjectBase(typeid(CustomTreeModel<T>)),
Glib::Object(),
m_container(container)
{}
// implement virtual functions
...
private:
T m_container;
...
};
Then an application developer would implement a specialization of
this. Something like:
class MyListModel : public CustomTreeModel< std::list<MyAppType> >
{
public:
typedef std::list<MyAppType> value_type;
Glib::RefPtr<MyListModel> create(value_type val);
protected:
MyListModel(value_type val) :
CustomTreeModel(val)
{}
// override any virtual methods for getting a value, number of
columns, etc...
};
In fact i have a skeleton like this implemented to play around with,
but I can't get it to instantiate. When I call the
MyListModel::create() function, I keep getting errors like this:
glibmm-CRITICAL **: Glib::Interface::Interface(const
Glib::Interface_Class&): assertion `gobject_ != 0' failed
Now, I readily admit that I don't understand the GObject stuff very
well. I don't even really know why the custom treemodel should
inherit from Glib::Object. I just did it that way because the example
in cvs did it that way. One of the differences between my example and
the example in CVS is that my class is a template class. Could this
line be causing problems because of the template?
Glib::ObjectBase(typeid(CustomTreeModel<T>))
Or should I be doing the GObject type registration in the most derived
class (MyListModel) instead of CustomTreeModel? Or is my approach
just flawed in some basic way?
Any pointers would be greatly appreciated.
Jonner
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]