Re: Gtk::TreeView



Rose Cumming wrote:

Hello,

I'm new to using Gtk::TreeView.
I have a tree view with 2 columns. One column for texts and one column for a boolean.

If I want to perform some functions when the "check box" (for the boolean value) is checked/unchecked on a certain row, which signal do I use to connect my signal handler?

And if this row has some children rows, is there a way I can find and iterate through these children rows under the currently selected row?

I cannot find any examples around.

Any suggestion will be appreciated.

Thanks,
Rose

_________________________________________________________________
Take advantage of powerful junk e-mail filters built on patented Microsoft® SmartScreen Technology. http://join.msn.com/?pgmarket=en-ca&page=byoa/prem&xAPID=1994&DI=1034&SU=http://hotmail.com/enca&HL=Market_MSNIS_Taglines Start enjoying all the benefits of MSN® Premium right now and get the first two months FREE*.

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

Hi Rose,

I use the checkbox as a column.  Here's how I do it:
   // create the check box column
   tree->append_column_editable("Access", m_columns.m_check);
// connect to the cell renderer's "signal_toggled" signal ((Gtk::CellRendererToggle *)tree->get_column_cell_renderer(0))->signal_toggled().connect(sigc::mem_fun(*this, &Menucfg::on_child_toggled));

As for iterating through the tree, whenever a row check box is toggled, I want to do just that, except that I want all descendents *and* ancestors of that row to be checked as well, so here is how I do that:

There are two functions involved:

// this handles both cases, the button was checked, or unchecked. First it calls // check_all_children to handle descendants, then it goes on to handle ancestors
void Menucfg::on_child_toggled(Glib::ustring str)
{
Gtk::TreeModel::Path path(str.c_str());
   Gtk::TreeModel::Row row = *(list->get_iter(path));
   Gtk::TreeModel::Row parent = *(row.parent());
   Gtk::TreeModel::Children::iterator iter;
   Gtk::TreeModel::Children children = row.children();
if(children)
       check_all_children(children,row[m_columns.m_check]);
if(row[m_columns.m_check])
   {
       while(parent)
       {
           parent[m_columns.m_check] = true;
           parent = *(parent.parent());
       }
   }
   else
   {
       while(parent)
       {
           Gtk::TreeModel::Children siblings = parent.children();
           for(iter = siblings.begin(); iter != siblings.end(); ++iter)
           {
               Gtk::TreeModel::Row child_row = *iter;
               if(child_row[m_columns.m_check])
                   break;
           }
           parent[m_columns.m_check] = (iter != siblings.end());
           parent = *(parent.parent());
       }
   }
}

// check_all_children toggles the checked state of all descendants
// of the current row if there are any.  If it encounters a row that
// also has descendants, it just recursively calls itself.
void Menucfg::check_all_children(Gtk::TreeModel::Children& children,bool condition)
{
for(Gtk::TreeModel::Children::iterator iter = children.begin(); iter != children.end(); ++iter)
   {
       Gtk::TreeModel::Row child_row = *iter;
       child_row[m_columns.m_check] = condition;
       Gtk::TreeModel::Children next = child_row.children();
       if(next)
           check_all_children(next,condition);
} }


I hope this helps.
Bob Caryl
begin:vcard
fn:Robert Caryl
n:Caryl;Robert
org:Fiscal Systems, Inc.
adr:;;102 Commerce Circle;Madison;AL;35758;USA
email;internet:bob fis-cal com
title:Senior Software Design Engineer
tel;work:356-772-8920 X108
x-mozilla-html:TRUE
url:http://www.fis-cal.com
version:2.1
end:vcard



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