如何遍历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;//避免不必要的递归
}
}
2012 年二月 一 二 三 四 五 六 日 « 一 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 近期评论
- wlx [微博 ] 发表在《google彻底被封?》
- snake 发表在《google彻底被封?》
- Andrew Pelt 发表在《debian testing上安装oracle 10g》
- tiplip 发表在《webmap.cn使用的WEBGIS技术》
- 求助Evolution问题!! 发表在《evolution crashed in gutsy alpha》
分类目录
标签
anjuta apache backup breezy c++ compile convert dapper debian dns edgy evolution feisty firefox flash gnome gobang GRASS gutsy humor intrepid Linux mailman MapServer mysql openoffice Oracle php phpbb postfix PostGIS postgresql qgis sarge scim skype subversion svn tomcat ubuntu utf8 westdc Windows wordpress 中文