遍历TreeStore

如何遍历TreeStore?
gtkmm的邮件列表上有一个简单的例子,但是经过测试,发现只能遍历到第二层枝。
Gtk::TreeModel::Children child=refTreeModel->children();//只能获取到第一级分类
Gtk::TreeModel::Children::iterator iter ;
for( iter = child.begin() ; iter != child.end() ; iter++ )
{
if ((*iter)[columns.id]==t[i].parent_id)
{
row=*(refTreeModel->append(iter->children()));
break;
}
}

最终通过递归实现全部遍历,代码如下。
void CategoryView::getrow(Gtk::TreeModel::Children child,unsigned int pid, Gtk::TreeModel::Row& row)
{
Gtk::TreeModel::Children::iterator iter;
for( iter = child.begin() ; iter != child.end() ; iter++ )
{
if ((*iter)[columns.id]==pid)
{
row=*(refTreeModel->append(iter->children()));
return ;
} else getrow(iter->children(),pid,row);
if (row) return;//避免不必要的递归
}
}

This entry was posted in Linux, Program and tagged , , . Bookmark the permalink.

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

*

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Please copy the string Oyyuzi to the field below:

以新浪微博帐号登录