## GdaTree

GdaTree — A tree-structure

## Stability Level

Stable, unless otherwise indicated

## Functions

GdaTree * | gda_tree_new ()
void | gda_tree_add_manager ()
void | gda_tree_clean ()
gboolean | gda_tree_update_all ()
gboolean | gda_tree_update_part ()
gboolean | gda_tree_update_children ()
GSList * | gda_tree_get_nodes_in_path ()
GdaTreeNode * | gda_tree_get_node ()
gchar * | gda_tree_get_node_path ()
GdaTreeManager * | gda_tree_get_node_manager ()
void | gda_tree_set_attribute ()
void | gda_tree_dump ()

## Properties

gboolean | is-list | Read

## Signals

void | node-changed | Run Last
void | node-deleted | Run Last
void | node-has-child-toggled | Run Last
void | node-inserted | Run Last

## Types and Values

| GdaTree

## Object Hierarchy

        GObject
        ╰── GdaTree

## Includes

    #include <libgda/gda-statement-extra.h>

## Description

The GdaTree is the top level object representing hierarchically structured data. From this object it is also possible (depending on the tree managers it uses), to clean (remove all the nodes) the whole tree, or to request a complete or partial update of the nodes.

It is also possible to set attributes to the tree itself (as it is possible to do for tree nodes), or to dump the whole or part of a tree in an indented and easy to read fashion.

## Functions

### gda_tree_new ()

    GdaTree *
    gda_tree_new (void);

Creates a new GdaTree object

#### Returns

a new GdaTree object.

[transfer full]

Since: 4.2

### gda_tree_add_manager ()

    void
    gda_tree_add_manager (GdaTree *tree,
                          GdaTreeManager *manager);

Sets `manager` as a top GdaTreeManager object, which will be responsible for creating top level nodes in `tree` .

#### Parameters

tree | a GdaTree object |
manager | a GdaTreeManager object. | [transfer none]

Since: 4.2

### gda_tree_clean ()

    void
    gda_tree_clean (GdaTree *tree);

Removes any node in `tree`

#### Parameters

tree | a GdaTree object |

Since: 4.2

### gda_tree_update_all ()

    gboolean
    gda_tree_update_all (GdaTree *tree,
                         GError **error);

Requests that `tree` be populated with nodes. If an error occurs, then `tree` 's contents is left unchanged, and otherwise `tree` 's previous contents is completely replaced by the new one.

#### Parameters

tree | a GdaTree object |
error | a place to store errors, or `NULL`. | [allow-none]

#### Returns

TRUE if no error occurred.

Since: 4.2

### gda_tree_update_part ()

    gboolean
    gda_tree_update_part (GdaTree *tree,
                          GdaTreeNode *node,
                          GError **error);

Requests that `tree` be populated with nodes, starting from `node`

#### Parameters

tree | a GdaTree object |
node | a GdaTreeNode node in `tree` |
error | a place to store errors, or `NULL`. | [allow-none]

#### Returns

TRUE if no error occurred.

Since: 4.2

### gda_tree_update_children ()

    gboolean
    gda_tree_update_children (GdaTree *tree,
                              GdaTreeNode *node,
                              GError **error);

Update the children of `node` in `tree` (not recursively, to update recursively, use `gda_tree_update_part()`). If `node` is `NULL` then the top level nodes are updated.

#### Parameters

tree | a GdaTree object |
node | a GdaTreeNode node in `tree` , or `NULL`. | [allow-none]
error | a place to store errors, or `NULL`. | [allow-none]

#### Returns

TRUE if no error occurred.

Since: 4.2.8

### gda_tree_get_nodes_in_path ()

    GSList *
    gda_tree_get_nodes_in_path (GdaTree *tree,
                                const gchar *tree_path,
                                gboolean use_names);

The returned list is a list of all the GdaTreeNode nodes below the node at the specified path.

As a corner case if `tree_path` is `NULL`, then the returned list contains all the top level nodes.

#### Parameters

tree | a GdaTree object |
tree_path | full path to the required nodes (if `use_names` is `TRUE`, then it must start with '/'), or `NULL`. | [allow-none]
use_names | if `TRUE`, then `tree_path` will be interpreted as a unix style path, and if `FALSE`, then `tree_path` will be interpreted similarly to the GtkTreePath's string representation. |

#### Returns

a new list of GdaTreeNode pointers, free it with `g_slist_free()`.

[transfer container][element-type GdaTreeNode]

Since: 4.2

### gda_tree_get_node ()

    GdaTreeNode *
    gda_tree_get_node (GdaTree *tree,
                       const gchar *tree_path,
                       gboolean use_names);

Locates a GdaTreeNode using the `tree_path` path.

#### Parameters

tree | a GdaTree object |
tree_path | full path to the required nodes (if `use_names` is `TRUE`, then it must start with '/') |
use_names | if `TRUE`, then `tree_path` will be interpreted as a unix style path, and if `FALSE`, then `tree_path` will be interpreted similarly to the GtkTreePath's string representation. |

#### Returns

the requested GdaTreeNode pointer, or `NULL` if not found.

[transfer none][allow-none]

Since: 4.2

### gda_tree_get_node_path ()

    gchar *
    gda_tree_get_node_path (GdaTree *tree,
                            GdaTreeNode *node);

Get the path associated to `node` in `tree` .

#### Parameters

tree | a GdaTree |
node | a GdaTreeNode node in `tree` |

#### Returns

a new string, or `NULL` if `node` is not in `tree` .

[transfer full]

Since: 4.2

### gda_tree_get_node_manager ()

    GdaTreeManager *
    gda_tree_get_node_manager (GdaTree *tree,
                               GdaTreeNode *node);

Get the GdaTreeManager which created `node` in `tree`

#### Parameters

tree | a GdaTree |
node | a GdaTreeNode present in `tree` |

#### Returns

the GdaTreeManager, or `NULL` if `node` is not present in `tree` .

[transfer none]

Since: 4.2

### gda_tree_set_attribute ()

    void
    gda_tree_set_attribute (GdaTree *tree,
                            const gchar *attribute,
                            const GValue *value,
                            GDestroyNotify destroy);

Sets an attribute to `tree` , which will be accessible to any node in it.

#### Parameters

tree | a GdaTree object |
attribute | attribute name |
value | a GValue, or `NULL` |
destroy | a function to be called when `attribute` is not needed anymore, or `NULL` |

Since: 4.2

### gda_tree_dump ()

    void
    gda_tree_dump (GdaTree *tree,
                   GdaTreeNode *node,
                   FILE *stream);

Dumps the contents of `tree` to `stream` , using a hierarchical view.

#### Parameters

tree | a GdaTree |
node | a GdaTreeNode to start the dump from, or `NULL` for a full dump. | [allow-none]
stream | a stream to send the dump to, or `NULL` for STDOUT. | [allow-none]

Since: 4.2

## Types and Values

### GdaTree

    typedef struct _GdaTree GdaTree;

## Property Details

### The `“is-list”` property

      “is-list”                  gboolean

Tells if the GdaTree is a list or a tree.

Owner: GdaTree

Flags: Read

Default value: FALSE

## Signal Details

### The `“node-changed”` signal

    void
    user_function (GdaTree     *tree,
                   GdaTreeNode *node,
                   gpointer     user_data)

Gets emitted when a `node` has changed in `tree`

#### Parameters

tree | the GdaTree |
node | the GdaTreeNode which has changed |
user_data | user data set when the signal handler was connected. |

Flags: Run Last

Since: 4.2

### The `“node-deleted”` signal

    void
    user_function (GdaTree *tree,
                   gchar   *node_path,
                   gpointer user_data)

Gets emitted when a `node` has been removed from `tree`

#### Parameters

tree | the GdaTree |
node_path | the position the node held in `tree` as a tree path |
user_data | user data set when the signal handler was connected. |

Flags: Run Last

Since: 4.2

### The `“node-has-child-toggled”` signal

    void
    user_function (GdaTree     *tree,
                   GdaTreeNode *node,
                   gpointer     user_data)

Gets emitted when a `node` has has a child when it did not have any or when it does not have a ny children anymore when it had some

#### Parameters

tree | the GdaTree |
node | the GdaTreeNode which changed from having children to being a leaf or the other way around |
user_data | user data set when the signal handler was connected. |

Flags: Run Last

Since: 4.2

### The `“node-inserted”` signal

    void
    user_function (GdaTree     *tree,
                   GdaTreeNode *node,
                   gpointer     user_data)

Gets emitted when a `node` has been inserted in `tree`

#### Parameters

tree | the GdaTree |
node | the GdaTreeNode which has inserted |
user_data | user data set when the signal handler was connected. |

Flags: Run Last

Since: 4.2