Re: Cast Gtk::TreeModel::iterator to int



El 2 / desembre / 2009 03:45, Milosz Derezynski
<internalerror gmail com> ha escrit:
> A Gtk::TreeModel::Path is just a wrapper for a GtkTreePath which truly is
> just an array of ints. If you have a simple vector-like model then you can
> get a row number from the TreePath like Jose said it.
>
> 2009/12/2 José Alburquerque <jaalburquerque cox net>
>>
>> On Tue, 2009-12-01 at 21:55 +0100, Glus Xof wrote:
>> > 2009/12/1 Murray Cumming <murrayc murrayc com>:
>> > > On Mon, 2009-11-30 at 19:25 +0100, Glus Xof wrote:
>> > >> Hello guys,
>> > >>
>> > >> A very stupid question... (but I don't find the answer).
>> > >>
>> > >> Is it possible to cast a Gtk::TreeModel::iterator value to int (or
>> > >> gint) ???
>> > >
>> > > If that int should be a row number, then you can convert the iter to a
>> > > Gtk::TreeModel::Path.
>> > >
>> >
>> > Sorry Mr. Cumming, I don't reach to see for the moment what you
>> > suggest... I'd need the row number as an int (or gint) value, not as a
>> > Gtk::TreeModel::Path...
>>
>> To get a row number from a path, use
>> Gtk::TreeModel::Path::get_indices().  It returns an array of the
>> components in the path, which can be stored in a standard container.
>>
>> If the model is a ListStore, the first component of the path should be
>> the row number.  If it is a TreeStore, the first component is also a row
>> in the model, but the next component represents the location of a child
>> row with respect to the parent, and so on.
>>
>> --
>> José
>>

Honestly, I have seen the  Gtk::TreeModel::Path::get_indices() method
before, but I didn't consider it because I didn't know why the array
of int(s), while I need just one int... Jose came again to give me
light... because TreeStore nodes also exist...

So,

Glib::RefPtr <Gtk::ListStore>  m_refTreeModel;
Gtk::TreeModel::iterator iter;
Gtk::TreeModel::Path cellpath=m_refTreeModel->get_path(iter);
std::vector<gint> rowindex = cellpath.get_indices();

The right value is rowindex[0]... ;)

Thanks to all,

Glus.


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