GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Fri Apr 18, 2014 11:20 pm

All times are UTC




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: tree view filter refilter
PostPosted: Sun Mar 16, 2008 10:00 am 
Offline

Joined: Sun Mar 16, 2008 9:44 am
Posts: 1
Hello,
I'm trying to develop my first application in Gtk. It's a simple two views window. When selected an item from de one on the left, the treeview shown on the right view gets filtered by the selected condition.
The problem is how to connect the two views in order to filter accordingly. I can't see how to pass the pointer to the tree view filter from the add_cols_grup() function. If I try to get it with the ookup_widget() I get no rows in the filtered window. I've tried using a global GtkTreeView variable but I get this error message:

Gtk-CRITICAL **;
gtk_tree_model_filter_refilter: assertion 'GTK_IS_MODEL_FILTER(filter)' failed

Can somebody give some help?
I list below part of the code.
Thanks in advance

Mount

[code lang=c]
static gboolean
Filter_func (GtkTreeModel *model,
GtkTreeIter *iter,
gpointer data)
{
gchar *grp;
gboolean ret = FALSE;

gtk_tree_model_get (model, iter, COL_GROUP, &grp, -1);
if (strcmp (grp, selname) == 0)
{
ret = TRUE;
}
g_free (grp);
return ret;
}

static void
group_selected (GtkTreeSelection *selection,
gpointer data)
{
GtkTreeModel *treeview;
GtkTreeIter iter;
GtkTreeModel *model;
gchar *name;

GtkWidget *widget = lookup_widget (GTK_WIDGET (window), "treeview");

treeview = gtk_tree_view_get_model (GTK_TREE_VIEW (widget));

if (gtk_tree_selection_get_selected (selection, &model, &iter))
{
gtk_tree_model_get (model, &iter, COL_NAME, &name, -1);
selname = g_strdup (*name);
g_print ("You selected: %s\tselname: %s\n", name, selname);
g_free (name);
}
gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (treeview));
}

static void
add_col_groups (GtkTreeView *treeview,
GtkTreeModel *groups_model)
{
GtkCellRenderer *renderer;
GtkTreeSelection *select;

renderer = gtk_cell_renderer_text_new ();
g_object_set (renderer,
"editable", FALSE,
NULL);

g_object_set_data (G_OBJECT (renderer), "column", GINT_TO_POINTER (COL_NAME));

gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview),
-1, "Name", renderer,
"text", COL_NAME,
NULL);

select = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
gtk_tree_selection_set_mode (select, GTK_SELECTION_SINGLE);
g_signal_connect (G_OBJECT (select), "changed",
G_CALLBACK (group_selected),
NULL);
}

GtkWidget *
do_editable_cells (GtkWidget *do_widget)
{
GtkWidget *sw1;
GtkWidget *sw2;
GtkWidget *treeview;
GtkWidget *groupsview;
GtkTreeModel *items_model;
GtkTreeModel *groups_model;
GtkTreeModel *treeviewfilter;


.....


sw1 = gtk_scrolled_window_new (NULL, NULL);
sw2 = gtk_scrolled_window_new (NULL, NULL);

/* crea los modelos */
items_model = create_items_model ();
groups_model = create_groups_model ();

/* crea el tree view */
treeviewfilter = gtk_tree_model_filter_new (items_model, NULL);
treeview = gtk_tree_view_new_with_model (treeviewfilter);
gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (treeview), TRUE);
gtk_tree_selection_set_mode (gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview)),
GTK_SELECTION_SINGLE);

add_columns (GTK_TREE_VIEW (treeview), items_model);

/* crea el groups view */
groupsview = gtk_tree_view_new_with_model (groups_model);
gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (groupsview), TRUE);
gtk_tree_selection_set_mode (gtk_tree_view_get_selection (GTK_TREE_VIEW (groupsview)),
GTK_SELECTION_SINGLE);

add_col_groups (GTK_TREE_VIEW (groupsview), groups_model);

gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (treeviewfilter),
Filter_func, NULL, NULL);

gtk_container_add (GTK_CONTAINER (sw1), groupsview);
gtk_container_add (GTK_CONTAINER (sw2), treeview);

.....

return window;
}

int
main (int argc, char **argv)
{
gtk_init (&argc, &argv);
do_editable_cells (window);
gtk_main ();
return 0;
}
[/code][/code]


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group