Re: [gtkmm] Changing columns in TreeView



> > From this text I can't be sure if you want to change the number of
view's
> > or model's columns. You mix TreeView and ListStore.
>
> Both.  Say the TreeView is being used to represent and edit a matrix of
> numbers, where both dimensions can change.  Changing the number of rows
is
> easy, changing the columns isn't so obvious.

In such case I'd keep a single model-column with a ref-counted pointer to
a std::vector keeping all your numbers (or other objects) for single row
and don't mess with adding and removing model columns. I suggest pointer
because you often need to copy model column's content by value.
Ref-counted obviously to avoid annoying memory management.
Adding view columns is trivial and it should be no problem at all. Use
insert_column_with_data_func to get data from that structure kept in the
model.
Check Gex sources for sample code doing that.

> > > Is it possible to change the list of columns set in a ListStore
(given
> > in
> > > the ListStore::create function), or is it necessary to create a new
> > > ListStore?
> >
> > You can dynamically add columns both to view and store. Adding them to
> > view is much easier. Adding model columns in runtime forces you to use
not
> > a very friendly set_value()/get_value() methods...
>
> How is that done please?

I don't know :)
I've never used this mechanism, I only know it's been recently
re-implemented.

> I'm guessing it could be easier to create a new ListStore, attach it to
the
> TreeView and discard the original ListStore.  It seems an interface to
> re-set the TreeModelColumnRecord on an existing ListStore would be
useful,
> rather than just in the create function.

You'd need multiple TreeModelColumnRecord objects for each possible case.

> eg:    void ListStore::reset(const TreeModelColumnRecord &columns);
>
> Would this be possible, and improve the API of ListStore?

Rather create new store and then tell the view to use it. It wouldn't make
much sense to reset existing model with new columns.

Jarek


----------------------------------------------------------------------
Na dobry poczatek dnia... >>> http://link.interia.pl/f1629 





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