Re: Getting the TreeModelColumns from a Glade file

On 06/14/2010 02:46 AM, José Alburquerque wrote:
On Sat, 2010-06-12 at 06:40 +0200, Dominik Gabi wrote:

I'd like to set and get the values of a Gtk::TreeStore that I've
instantiated in Glade. I'd like to do this the way it is done in the
gtkmm-tutorial (with the overloaded [] operator of the TreeRow).
If you can get the model using Gtk::Builder::get_object(), it should be
possible to get to a desired row by dereferencing an iterator of the
model (see Gtk::TreeModel::get_iter()[1] and the section on "Iterating
over Model Rows"[2] in the online book).  You would have to define a
Gtk::TreeModelColumnRecord corresponding to the model so that something

(*iter)[columns.a_column] = ...;

could be done.


problem is that, I either generate the whole TreeView in the code (which
I'd like to avoid, if somehow possible) and specify the necessary
TreeModelColumns by hand, or I have to extract them somehow from what is
generated in Glade. Since the columns are not objects in Glade, I was
hoping I could access them using the model or the view... Unfortunately
I can't find anything in the documentation.
It should be possible to get the columns of the TreeView (created in
glade) using Gtk::TreeView::get_column().

Is there an easier way to manipulate a TreeRow or am I just missing
something here?

Unfortunately Gtk::TreeView::get_column() returns a TreeViewColumn whereas Gtk::TreeRow::operator[] takes an TreeModelColumn as argument. I've solved the problem with the following code which is not as nice as the book solution but works fine for now.

enum {TITLE=0, URI, NEW, TYPE};    // Columns

template <class T>
void get_value(Gtk::TreeIter it, int column, T &result)
    if (it)
        it->get_value(column, result);

template <class T>
void set_value(Gtk::TreeIter it, int column, T &value)
    if (it)
        it->set_value(column, value);


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