Re: gtktree: combination filter and using gtk_tree_model_foreach




 
Hi Rob,

The trick here is to use gtk_tree_model_filter_convert_iter_to_child_iter(). That will get the iter that you 
need. It will work the same on both GTK2 and GTK3. You have to be a little careful with 
gtk_tree_model_foreach(). It is easy to add nodes and then the function will check everyone of the additional 
nodes. 

Eric

gboolean func(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data) 
{ 
  //Test counter for nodes.
  static gint i=0;
  GtkTreeIter parent;
  GtkTreeIter child_iter;
  GtkTreeIter node;
  
  if(!gtk_tree_model_iter_parent(model, &parent, iter))
    {
      if(!gtk_tree_model_iter_has_child(model, iter))
        {
          g_print("Child %i\n", i);
          gtk_tree_model_filter_convert_iter_to_child_iter(GTK_TREE_MODEL_FILTER(model), &child_iter, iter); 
          gtk_tree_store_append(store, &node, &child_iter);
          gtk_tree_store_set(store, &node, 0, "child", -1);
        }
    }
  i++;
   
  return FALSE; 
} 

 

 

-----Original Message-----
From: Rob Alblas <ralblas aimvalley nl>
To: gtk-app-devel-list <gtk-app-devel-list gnome org>
Sent: Wed, May 24, 2017 5:57 am
Subject: gtktree: combination filter and using gtk_tree_model_foreach

In a GtkTree I want to use a filter, and also extend the tree using gtk_tree_model_foreach. The combination 
of the 2 gives problems. 
In the function connected to gtk_tree_model_foreach I use the GtkTreeIter *iter argument, which gives an 
error message: 

Gtk-CRITICAL **: IA__gtk_tree_store_append: assertion `VALID_ITER (parent, tree_store)' failed 

I define tree, filter etc. as follows: 
stree = gtk_tree_store_new(1,G_TYPE_STRING); 
ftree = GTK_TREE_MODEL_FILTER(gtk_tree_model_filter_new(GTK_TREE_MODEL(stree), NULL)); 
tree = gtk_tree_view_new_with_model(GTK_TREE_MODEL(ftree)); 
model=gtk_tree_view_get_model(GTK_TREE_VIEW(tree)); 

... 
(build a part of the tree) 
... 
gtk_tree_model_foreach(model,func,NULL); 

In func: 
gboolean func(GtkTreeModel *model,GtkTreePath *path,GtkTreeIter *iter,gpointer data) 
{ 
gtk_tree_model_get(model,iter, 0, &iname, -1); 
... 
gtk_tree_store_append(stree, &iter0, iter); 
... 
} 

gtk_tree_store_append gives the mentioned error. 

If I remove the filter, and define instead: 
tree = gtk_tree_view_new_with_model(GTK_TREE_MODEL(stree)); 

then building using gtk_tree_model_foreach works fine. 
How to solve this? 

Attached an example showing the problem. 
(Note: I am using gtk2.0, don't know if the same problem is with gtk3.) 

_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list



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