WIP: gtk_tree_model_get_data_from_path() OK
This commit is contained in:
parent
e9a67bcf4a
commit
9c501b296f
|
@ -92,7 +92,7 @@ static void iterating_a_model_in_a_depth_first_fashion (GtkTreeModel *model)
|
|||
// gboolean (*GtkTreeModelForeachFunc) (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data);
|
||||
GtkTreeIter iter, iter_parent;
|
||||
gboolean valid = 0;
|
||||
GtkTreePath *chemin;
|
||||
// GtkTreePath *chemin;
|
||||
char *str_data;
|
||||
int row_count = 0;
|
||||
|
||||
|
@ -106,18 +106,6 @@ static void iterating_a_model_in_a_depth_first_fashion (GtkTreeModel *model)
|
|||
gtk_tree_model_get (model, &iter, STRING_COLUMN, &str_data, -1);
|
||||
g_print ("next row %d: (%s) < False (should be 'A' - line 104)\n", row_count, str_data);
|
||||
|
||||
chemin = gtk_tree_path_new_from_string ("0:0:0:1:0:1");
|
||||
gtk_tree_model_get_iter (model, &iter, chemin);
|
||||
gtk_tree_model_get (model, &iter, STRING_COLUMN, &str_data, -1);
|
||||
g_print ("row from path 0:0:0:1:0:1 %d = (%s)\n", row_count, str_data);
|
||||
gtk_tree_path_free (chemin);
|
||||
|
||||
|
||||
/* GtkTreeIter parent_iter; gtk_tree_model_iter_nth_child (my_tree_model, &iter, NULL, 3); // walk the tree to find the iterator */
|
||||
/* parent_iter = iter; gtk_tree_model_iter_nth_child (my_tree_model, &iter, &parent_iter, 2); */
|
||||
/* parent_iter = iter; gtk_tree_model_iter_nth_child (my_tree_model, &iter, &parent_iter, 5); */
|
||||
|
||||
|
||||
/* while (valid) first row 0: (ROOT) next row 0: (D)*/
|
||||
/* { */
|
||||
/* char *str_data; */
|
||||
|
@ -133,42 +121,36 @@ static void iterating_a_model_in_a_depth_first_fashion (GtkTreeModel *model)
|
|||
/* } */
|
||||
}
|
||||
|
||||
// Three ways of getting the iter pointing to the location https://developer-old.gnome.org/gtk4/stable/GtkTreeModel.html#gtk-tree-row-reference-new
|
||||
/* static void acquiring_a_GtkTreeIter (GtkTreeModel *my_tree_model, GtkTreePath *my_tree_path) */
|
||||
/* { */
|
||||
/* GtkTreeIter iter; // get the iterator from a string */
|
||||
/* gtk_tree_model_get_iter (model, &iter, my_tree_path); */
|
||||
/* gtk_tree_model_get (model, &iter, STRING_COLUMN, &str_data, -1); */
|
||||
/* g_print ("row from path %s %d = (%s)\n", gtk_tree_path_to_string (my_tree_path), row_count, str_data); */
|
||||
/* gtk_tree_path_free (my_tree_path); */
|
||||
/* } */
|
||||
static void /* https://developer-old.gnome.org/gtk4/stable/GtkTreeModel.html#GtkTreePath-struct and #gtk-tree-row-reference-new */
|
||||
gtk_tree_model_get_data_from_path (GtkTreeModel *my_tree_model,
|
||||
GtkCellEditable *cell_editable,
|
||||
GtkTreeIter *my_iter,
|
||||
GdkEvent *event,
|
||||
GtkTreePath *my_path)
|
||||
{
|
||||
char *str_data;
|
||||
|
||||
gtk_tree_model_get_iter (my_tree_model, &my_iter, my_path);
|
||||
gtk_tree_model_get (my_tree_model, &my_iter, STRING_COLUMN, &str_data, -1);
|
||||
g_print ("row from path %s = (%s)\n",\
|
||||
gtk_tree_model_get_string_from_iter(my_tree_model, &my_iter),
|
||||
str_data);
|
||||
gtk_tree_path_free (my_path);
|
||||
}
|
||||
|
||||
|
||||
static void /* https://developer-old.gnome.org/gtk4/stable/GtkTreeModel.html#GtkTreePath-struct and #gtk-tree-row-reference-new */
|
||||
edit_a_cell (GtkTreeModel *my_tree_model,
|
||||
gtk_tree_model_edit_a_cell (GtkTreeModel *my_tree_model,
|
||||
GtkCellEditable *cell_editable,
|
||||
GtkTreeIter *iter,
|
||||
GtkTreeIter *my_iter,
|
||||
GdkEvent *event,
|
||||
GtkTreePath *path)
|
||||
GtkTreePath *my_path)
|
||||
{
|
||||
GtkTreePath *any_path = gtk_tree_path_new_first (); // Creates and returns a new GtkTreePath.
|
||||
// The string representation of this path is “0”.
|
||||
const char *any_path_string = gtk_tree_path_to_string (any_path); // Generates a string representation of the path.
|
||||
// Path is expected to be a colon separated list of numbers. For example, the string “10:4:0”.
|
||||
// This string would create a path of depth 3 pointing to the 11th child of the root node,
|
||||
// the 5th child of that 11th child, and the 1st child of that 5th child.
|
||||
// If the path has depth 0, NULL is returned.
|
||||
any_path = gtk_tree_path_new_from_indices (10,4,0); // Creates a new path with first_index and varargs as indices.
|
||||
gtk_tree_model_get_iter_from_string (my_tree_model, iter, any_path_string); // Sets iter to a valid iterator pointing to path.
|
||||
// If path does not exist, iter is set to an invalid iterator and FALSE is returned.
|
||||
|
||||
// gpointer *data; gboolean b = (*GtkTreeModelForeachFunc) (my_tree_model, path, iter, data);
|
||||
// Type of the callback passed to gtk_tree_model_foreach() to iterate over the rows in a tree model.
|
||||
|
||||
gtk_tree_model_get (my_tree_model, iter); // Gets the value of one or more cells in the row referenced by iter
|
||||
gtk_tree_model_get (my_tree_model, my_iter); // Gets the value of one or more cells in the row referenced by iter
|
||||
gtk_cell_editable_start_editing (cell_editable, event); // Begins editing on a cell_editable .
|
||||
gtk_cell_editable_editing_done (cell_editable); // Emits the “editing-done” signal.
|
||||
gtk_tree_model_row_deleted (my_tree_model, path); // Emits the “row-deleted” signal on tree_model .
|
||||
gtk_tree_model_row_inserted (my_tree_model, path, iter); // Emits the “row-inserted” signal on tree_model .
|
||||
gtk_tree_model_row_deleted (my_tree_model, my_path); // Emits the “row-deleted” signal on tree_model .
|
||||
gtk_tree_model_row_inserted (my_tree_model, my_path, my_iter); // Emits the “row-inserted” signal on tree_model .
|
||||
}
|
||||
|
||||
/* TreeItem structure */
|
||||
|
@ -257,9 +239,10 @@ do_tree_store (GtkWidget *do_widget)
|
|||
/* create tree_model */
|
||||
my_tree_model = create_node_recursive (my_tree_store, O, NULL, 0);
|
||||
iterating_a_model_in_a_depth_first_fashion (my_tree_model);
|
||||
GtkTreePath *my_path = gtk_tree_path_new_from_string ("0:0:1:0:1");
|
||||
// GtkTreePath *my_path = gtk_tree_path_new_from_string ("0:0:1:0:1");
|
||||
// acquiring_a_GtkTreeIter (my_tree_model, my_path);
|
||||
// GtkTreeIter *my_iter; edit_a_cell (my_tree_model, NULL, my_iter, NULL, my_path);
|
||||
// GtkTreeIter *my_iter;
|
||||
gtk_tree_model_get_data_from_path (my_tree_model, NULL, NULL, NULL, gtk_tree_path_new_from_string ("0:0:0:2"));
|
||||
|
||||
/* create tree view */
|
||||
treeview = gtk_tree_view_new_with_model (my_tree_model);
|
||||
|
|
Loading…
Reference in New Issue