Reference Manual

Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

# Inti::Gtk::TreeStore Class Reference

A GtkTreeStore C++ wrapper class. More...

`#include <inti/gtk/treestore.h>`

Inheritance diagram for Inti::Gtk::TreeStore:

List of all members.

## Public Member Functions

Constructors

- TreeStore (int n_columns,...)
    Construct a tree store of n_columns columns of each of the types passed in the variable argument list.
- TreeStore (const std::vector< GType > &types)
    Construct a tree store with a column for each type passed in the vector of GType.
- virtual ~TreeStore ()
    Destructor.

Accessors

- GtkTreeStore * gtk_tree_store () const
    Get a pointer to the GtkTreeStore structure.
- GtkTreeStoreClass * gtk_tree_store_class () const
    Get a pointer to the GtkTreeStoreClass structure.
- operator GtkTreeStore * () const
    Conversion operator; safely converts a TreeStore to a GtkTreeStore pointer.
- bool is_ancestor (const TreeIter &iter, const TreeIter &descendant) const
    Returns true if iter is an ancestor of descendant, that is, iter is the parent (or grandparent or great-grandparent) of descendant.
- int iter_depth (const TreeIter &iter) const
    Returns the depth of iter.
- bool iter_is_valid (const TreeIter &iter) const
    Checks if the given iter is a valid iter for the tree store.

Methods

- TreeIter prepend (TreeIter *parent=0)
    Prepends a new row to the tree store.
- TreeIter append (TreeIter *parent=0)
    Appends a new row to the tree store.
- TreeIter insert (int position, TreeIter *parent=0)
    Creates a new row at position.
- TreeIter insert_before (TreeIter &sibling, TreeIter *parent=0)
    Inserts a new row before sibling.
- TreeIter insert_after (TreeIter &sibling, TreeIter *parent=0)
    Inserts a new row after sibling.
- bool remove (TreeIter &iter)
    Removes iter from the tree store.
- void clear ()
    Removes all rows from the tree store.
- void reorder (const TreeIter &parent, int *new_order)
    Reorders the children of parent in the tree store to follow the order indicated by new_order.
- void swap (const TreeIter &a, const TreeIter &b)
    Swaps a and b in the same level of the tree store.
- void move_after (const TreeIter &iter, const TreeIter *position)
    Moves iter in the tree store to the position after position (iter and position should be in the same level).
- void move_before (const TreeIter &iter, const TreeIter *position)
    Moves iter in the tree store to the position before position (iter and position should be in the same level).
- void set_value (const TreeIter &iter, int column, const G::Value &value)
    Sets the data in the cell specified by iter and column.
- void set_value (const TreeIter &iter, int column, const char *str)
    Sets a string value in the cell specified by iter and column.

Templates

- template<typename DataType> void set_value (const TreeIter &iter, int column, const DataType &data)
    Sets the data in the cell specified by iter and column.
- template<typename DataType> void set_enum (const TreeIter &iter, int column, const DataType &data)
    Sets the enum data in the cell specified by iter and column.
- template<typename DataType> void set_object (const TreeIter &iter, int column, const DataType &data)
    Sets the object pointer data in the cell specified by iter and column.
- template<typename DataType> void set_pointer (const TreeIter &iter, int column, const DataType &data)
    Sets the pointer data in the cell specified by iter and column.

## Protected Member Functions

Constructors

- TreeStore (GtkTreeStore *tree_store, bool reference=true)
    Construct a new TreeStore from an existing GtkTreeStore.

## Detailed Description

A GtkTreeStore C++ wrapper class.

The TreeStore object is a tree-like model for use with a TreeView widget. It implements the TreeModel interface, and consequentialy, can use all of the methods available there. It also implements the TreeSortable interface so it can be sorted by the view. Finally, it also implements the tree drag and drop interfaces.

## Constructor & Destructor Documentation

Inti::Gtk::TreeStore::TreeStore | ( | GtkTreeStore * | tree_store,
|  | bool | reference = true
| ) | `[explicit, protected]`

Construct a new TreeStore from an existing GtkTreeStore.

Parameters:

  tree_store | A pointer to a GtkTreeStore.
  reference | Set false if the initial reference count is floating, set true if it's not.

The tree_store can be a newly created GtkTreeStore or an existing GtkTreeStore (see G::Object::Object).

Inti::Gtk::TreeStore::TreeStore | ( | int | n_columns,
|  | ... |
| ) |

Construct a tree store of n_columns columns of each of the types passed in the variable argument list.

Parameters:

  n_columns | The number of columns in the tree store.
  ... | All the GType types for the columns, from first to last.

As an example, TreeStore(3, G_TYPE_INT, G_TYPE_STRING, GDK_TYPE_PIXBUF); will create a new tree store with three columns, of type int, string and GdkPixbuf respectively.

Inti::Gtk::TreeStore::TreeStore | ( | const std::vector< GType > & | types | ) |

Construct a tree store with a column for each type passed in the vector of GType.

Parameters:

  types | A vector of GType containing the column types, from first to last.

## Member Function Documentation

TreeIter Inti::Gtk::TreeStore::append | ( | TreeIter * | parent = 0 | ) |

Appends a new row to the tree store.

Parameters:

  parent | A valid TreeIter, or null.

Returns:
  An unset TreeIter to set to the appended row.

If parent is non-null, then it will append the new row after the last child of parent, otherwise it will append a row to the top level. The returned TreeIter will point to this new row. The row will be empty after this function is called. To fill in values, you need to call set_value() or set_value_type().

TreeIter Inti::Gtk::TreeStore::insert | ( | int | position,
|  | TreeIter * | parent = 0
| ) |

Creates a new row at position.

Parameters:

  position | The position to insert the new row.
  parent | A valid TreeIter, or null.

Returns:
  An TreeIter set to the new row.

If parent is non-null, then the row will be made a child of parent. Otherwise, the row will be created at the toplevel. If position is larger than the number of rows at that level, then the new row will be inserted to the end of the list. An empty TreeIter pointing to the new row is returned. To fill in values, you need to call set_value() or set_value_type().

TreeIter Inti::Gtk::TreeStore::insert_after | ( | TreeIter & | sibling,
|  | TreeIter * | parent = 0
| ) |

Inserts a new row after sibling.

Parameters:

  sibling | A valid TreeIter.
  parent | A valid TreeIter, or null.

Returns:
  An TreeIter set to the new row.

parent is optional but if set it must be the parent of sibling. An empty TreeIter pointing to the new row is returned. To fill in values, you need to call set_value() or set_value_type().

TreeIter Inti::Gtk::TreeStore::insert_before | ( | TreeIter & | sibling,
|  | TreeIter * | parent = 0
| ) |

Inserts a new row before sibling.

Parameters:

  sibling | A valid TreeIter.
  parent | A valid TreeIter, or null.

Returns:
  An TreeIter set to the new row.

parent is optional but if set it must be the parent of sibling. An empty TreeIter pointing to the new row is returned. To fill in values, you need to call set_value() or set_value_type().

bool Inti::Gtk::TreeStore::is_ancestor | ( | const TreeIter & | iter,
|  | const TreeIter & | descendant
| ) | const

Returns true if iter is an ancestor of descendant, that is, iter is the parent (or grandparent or great-grandparent) of descendant.

Parameters:

  iter | A valid TreeIter.
  descendant | A valid TreeIter.

Returns:
  true if iter is an ancestor of descendant.

int Inti::Gtk::TreeStore::iter_depth | ( | const TreeIter & | iter | ) | const

Returns the depth of iter.

Parameters:

  iter | A valid TreeIter.

Returns:
  The depth of iter.

The depth will be 0 for anything on the root level, 1 for anything down a level, etc.

bool Inti::Gtk::TreeStore::iter_is_valid | ( | const TreeIter & | iter | ) | const

Checks if the given iter is a valid iter for the tree store.

Parameters:

  iter | A TreeIter.

Returns:
  true if the iter is still valid, false if it's not.

WARNING: This function is slow. Only use it for debugging and/or testing purposes.

void Inti::Gtk::TreeStore::move_after | ( | const TreeIter & | iter,
|  | const TreeIter * | position
| ) |

Moves iter in the tree store to the position after position (iter and position should be in the same level).

Parameters:

  iter | A TreeIter.
  position | A TreeIter, or null.

Note: This function only works with unsorted stores. If position is null, iter will be moved to the start of the level.

void Inti::Gtk::TreeStore::move_before | ( | const TreeIter & | iter,
|  | const TreeIter * | position
| ) |

Moves iter in the tree store to the position before position (iter and position should be in the same level).

Parameters:

  iter | A TreeIter.
  position | A TreeIter, or null.

Note: This function only works with unsorted stores. If position is null, iter will be moved to the end of the level.

TreeIter Inti::Gtk::TreeStore::prepend | ( | TreeIter * | parent = 0 | ) |

Prepends a new row to the tree store.

Parameters:

  parent | A valid TreeIter, or null.

Returns:
  An unset TreeIter to set to the prepended row.

If parent is non-null, then it will prepend the new row before the first child of parent, otherwise it will prepend a row to the top level. The returned TreeIter will point to this new row. The row will be empty after this function is called. To fill in values, you need to call set_value() or set_value_type().

bool Inti::Gtk::TreeStore::remove | ( | TreeIter & | iter | ) |

Removes iter from the tree store.

Parameters:

  iter | A valid TreeIter.

Returns:
  true if iter is valid, false if it's not.

After being removed, iter is set to the next valid row at that level, or invalidated if it previously pointed to the last one.

void Inti::Gtk::TreeStore::reorder | ( | const TreeIter & | parent,
|  | int * | new_order
| ) |

Reorders the children of parent in the tree store to follow the order indicated by new_order.

Parameters:

  parent | A TreeIter.
  new_order | An integer array indicating the new order for the list.

Note: This method only works with unsorted stores.

template<typename DataType>
void Inti::Gtk::TreeStore::set_enum | ( | const TreeIter & | iter,
|  | int | column,
|  | const DataType & | data
| ) | `[inline]`

Sets the enum data in the cell specified by iter and column.

Parameters:

  iter | A valid TreeIter for the row being modified.
  column | The column number to modify.
  data | The enum value to set.

This method is used to set enumeration values. The DataType is the type of the enumeration being set. There is a good example of setting values in the inti-demo program <demos/inti-demo/liststore.cc>.

template<typename DataType>
void Inti::Gtk::TreeStore::set_object | ( | const TreeIter & | iter,
|  | int | column,
|  | const DataType & | data
| ) | `[inline]`

Sets the object pointer data in the cell specified by iter and column.

Parameters:

  iter | A valid TreeIter for the row being modified.
  column | The column number to modify.
  data | A pointer to an object derived from G::Object, passed by reference.

There is a good example of setting values in the inti-demo program <demos/inti-demo/liststore.cc>.

template<typename DataType>
void Inti::Gtk::TreeStore::set_pointer | ( | const TreeIter & | iter,
|  | int | column,
|  | const DataType & | data
| ) | `[inline]`

Sets the pointer data in the cell specified by iter and column.

Parameters:

  iter | A valid TreeIter for the row being modified.
  column | The column number to modify.
  data | The pointer to set in the cell.

The data argument can be a pointer to any object. The pointer is managed internally as a generic (void*) pointer. Unlike set_object() which passes the G::Object pointer internally as a GObject pointer, set_pointer() passes the pointer as is, without interpretation. There is a good example of setting values in the inti-demo program <demos/inti-demo/liststore.cc>.

template<typename DataType>
void Inti::Gtk::TreeStore::set_value | ( | const TreeIter & | iter,
|  | int | column,
|  | const DataType & | data
| ) | `[inline]`

Sets the data in the cell specified by iter and column.

Parameters:

  iter | A valid TreeIter for the row being modified.
  column | The column number to modify.
  data | The data to set for the cell.

This method is used to set values corresponding to the standard data types used by G::Value, such as bool, int, double, String and unsigned int. There is a good example of setting values in the inti-demo program <demos/inti-demo/liststore.cc>.

void Inti::Gtk::TreeStore::set_value | ( | const TreeIter & | iter,
|  | int | column,
|  | const char * | str
| ) |

Sets a string value in the cell specified by iter and column.

Parameters:

  iter | A valid TreeIter for the row being modified.
  column | The column number to modify.
  str | The new string for the cell.

void Inti::Gtk::TreeStore::set_value | ( | const TreeIter & | iter,
|  | int | column,
|  | const G::Value & | value
| ) |

Sets the data in the cell specified by iter and column.

Parameters:

  iter | A valid TreeIter for the row being modified.
  column | The column number to modify.
  value | The new value for the cell.

The type of value must be convertible to the type of the column.

void Inti::Gtk::TreeStore::swap | ( | const TreeIter & | a,
|  | const TreeIter & | b
| ) |

Swaps a and b in the same level of the tree store.

Parameters:

  a | A TreeIter.
  b | Another TreeIter.

Note: This method only works with unsorted stores.

The documentation for this class was generated from the following file:

- treestore.h

Main Page - Footer