Re: custom treemodel?





Murray Cumming wrote:

Say I've got a class containing a list of values.  For example, a
Palette class containing a list of colors (something like the
following incomplete class declaration):

  class Palette
  {
     public:
        typedef std::vector<rgb_t> color_list_type;
        // snipped other methods
        color_list_type& colors(void);

     private:
        color_list_type m_colors;
  };

Now say I want to display these values in a treeview.  One option is
obviously to copy all of the values from m_colors into a
Gtk::ListModel.  But this has a rather large disadvantage in that when
I make some changes in the treeview (i.e. add a new item, re-order
items, remove items), I would need to copy these items out of the
listmodel into a Palette whenever I want to use this group of items as
a Palette type.

Maybe you should just store the Palette in the list model and use
cell_data_func callbacks to show it in the treeview.

I'd rather just have the treeview display data directly from the
Palette class so that I don't need to copy / synchronize things back
and forth.  So in order to display data directly from the Palette
class, I'd need to have Palette inherit from Gtk::TreeModel (i.e.
implement a custom TreeModel).  There is an example in gtkmm CVS that
shows how to implement a custom TreeModel, but unfortunately I haven't
had much luck deciphering it (especially the GlueItem stuff).  And
besides the example, the documentation on implementing custom
TreeModels is pretty sparse,  Has anybody really done this before?

I've done it in Glom, but the gtkmm example is simpler.

After poking around a bit in my freshly built gtkmm, I noticed this:

gtkmm/examples/Makefile.am
# Doesn't build with GLIBMM_ENABLE_PROPERTIES unset:
#cellrenderercustom

Dunno if thats important or not though.

Does anybody know of other examples I could look at?  Is there a
better way to solve this problem than implementing a custom TreeModel?

What I think would be helpful is some guidance on what methods need to
be implemented / overridden and approximately what they're supposed to
do, etc.  I'd be willing to put together a document like this (maybe
as a section in the tutorial) if I can get it figured out.

Murray Cumming
murrayc murrayc com
www.murrayc.com
www.openismus.com

_______________________________________________
gtkmm-list mailing list
gtkmm-list gnome org
http://mail.gnome.org/mailman/listinfo/gtkmm-list




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]