Re: [gtkmm] TreeView/TreeModel navigation
- From: 3rdShift <vladg erols com>
- To: Gtkmm List <gtkmm-list gnome org>
- Subject: Re: [gtkmm] TreeView/TreeModel navigation
- Date: 29 Nov 2002 20:55:29 -0500
I finally found it:
there is a thing called TreePath object that is created by the TreeModel
(and derivatives). TreePath is similar to TreeIter in the context of a
ListStore with only difference that it behaves as a bi-directional
iterator. It has next() and prev() methods - all that I need to slide up
and down the list. prev() returns bool - when it is false, you know you
just hit the roof. Surprisingly, next() does not.
So, here's how I move up:
void
MainWindow_ui::
on_up_clicked ()
{
Gtk::TreeModel::iterator iter = m_tree_sel_ref->get_selected ();
Gtk::TreeModel::Path path = m_list_store_ref->get_path (iter);
DL((APP,"I am on row %s\n", path.to_string ().c_str ()));
if (path.prev ()) {
m_tree_sel_ref->select (path);
}
}
TreePath can also be converted to the row number by something like:
int row_num = atoi (TreePath::to_string ().c_str ());
I think I need a better understanding how responsibilities are split
between TreeView and TreeModel the way Gtk+2.0 implements them. Anyone
has a link to the *white paper* behind its design or a link to some
discussion somewhere. It didn't just appear one morning in Gtk+ code
tree. There must have been some substantial discussion happened
somewhere about its design. I have searched gtk-app-develop-list archive
with not much luck.
-Vlad
On Fri, 2002-11-29 at 19:23, Chris Vine wrote:
> On Friday 29 November 2002 4:17 am, 3rdShift wrote:
> > Hi,
> >
> > I am re-reading TreeView/TreeModel reference, docmentation and demo
> > examples again and again and can't seem to find a way to navigate
> > through ListStore. With CList I used to get a row number when user
> > selects the row.
> >
> > 1) How do I get the selected row number?
> >
> > In the selection callback I can get to the row, but how far is
> > that row from the begin()?
> >
> > Glib::RefPtr<Gtk::TreeSelection> m_tree_sel_ref;
> > Glib::RefPtr<Gtk::ListStore> m_list_store_ref;
> >
> > Gtk::TreeModel::iterator iter = m_tree_sel_ref->get_selected ();
> > Gtk::TreeModel::Row row = *iter;
> >
> >
> > I tried to subtract iterators just like you can do in STL, but
> > all I get is 0!
> >
> > int row_num = iter - m_list_store_ref->children ().begin ()
> >
> > 2) How can I select the previous row?
> >
> > Gtk::TreeIter is a one-directional forward iterator.
> > Any hints?
> >
> > 3) How can I know if the TreeIter points to the last row
> > in ListStore?
> >
> > I have an iterator to the currently selected row. I cannot say
> >
> > if (iter + 1 != m_list_store_ref->children ().begin ()) {
> > m_tree_sel_ref->select (++iter);
> > }
> >
> > because TreeIter does not support operator+(int).
> > However, if I increment the iterator and hit the end of the list,
> > I get gtk-CRITICAL assertion:
> >
> > TreeView-Test:27034): Gtk-CRITICAL **: file gtkliststore.c: line 518
> > (gtk_list_store_get_path): assertion `iter->stamp == GTK_LIST_STORE
> > (tree_model)->stamp' failed
>
> I have had very similar problems. To find the row immediately before the
> selected row I had to have two Gtk::TreeModel::Children::iterator objects,
> one less advanced than the other, and then iterate through the list store
> from the beginning until the more advanced one equalled
> Gtk::TreeView::get_selected()->selection(). I imagine there must be a better
> way of doing it (it is is quite inefficient with a large list), but I
> couldn't work it out from the documentation (such as it is). It is
> surprising that a Gtk::ListStore object doesn't have bidirectional interators
> (although I can see that may be a problem with a Gtk::TreeStore object).
>
> Finding out if the iterator returned by
> Gtk::TreeView::get_selected()->selection() points to the last row seemed
> rather easier. Copy it to another Gtk::TreeModel::iterator (or to a
> Gtk::TreeModel::Children::iterator), increment the copy, and see if it equals
> Gtk::ListStore::children()->end(). It worked for me, but it wouldn't
> surprise me if there is a better way. (I do not understand the error you
> report: that doesn't seem right, so there may be some other problem with your
> code).
>
> Chris.
>
> _______________________________________________
> 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]