![]() |
![]() |
It is is designed to be usable with any appropriate data structure. The programmer just has to implement this interface on their own data type for it to be viewable by a Gtk::TreeView widget.
The model is represented as a hierarchical tree of strongly-typed, columned data. In other words, the model can be seen as a tree where every node has different values depending on which column is being queried. The type of data found in a column is determined by TreeModel::Column<> templates. The types are homogeneous per column across all nodes. It is important to note that this interface only provides a way of examining a model and observing changes. The implementation of each individual model decides how and if changes are made.
In order to make life simpler for programmers who do not need to write their own specialized model, two generic models are provided - the Gtk::TreeStore and the Gtk::ListStore. To use these, the developer simply pushes data into these models as necessary. These models provide the data structure as well as all appropriate tree interfaces. As a result, implementing drag and drop, sorting, and storing data is trivial. For the vast majority of trees and lists, these two models are sufficient.
Models are accessed on a node/column level of granularity. One can query for the value of a model at a certain node and a certain column on that node. There are two structures used to reference a particular node in a model. They are the Path and the iterator. Most of the interface consists of operations on an iterator.
A Gtk::TreeModel::Path is essentially a potential node. It is a location on a model that may or may not actually correspond to a node on a specific model.
By contrast, an Gtk::TreeModel::iterator is a reference to a specific node on a specific model. One can convert a path to an iterator by calling Gtk::TreeModel::get_iter(). These iterators are the primary way of accessing a model and are similar to the iterators used by Gtk::TextBuffer. The model interface defines a set of operations using them for navigating the model.
The RowReference is also useful, because it remains valid as long as there is an existing row pointed to by it's path. You can convert between RowReferences and iterators and Path s.
Public Types | ||||
typedef TreeNodeChildren | Children | |||
typedef TreeModelColumnRecord | ColumnRecord | |||
typedef Children::const_iterator | const_iterator | |||
typedef Children::const_reverse_iterator | const_reverse_iterator | |||
typedef Children::iterator | iterator | |||
typedef TreePath | Path | |||
typedef Children::reverse_iterator | reverse_iterator | |||
typedef TreeRow | Row | |||
typedef TreeRowReference | RowReference | |||
typedef sigc::slot< bool, const TreeModel::iterator& > | SlotForeachIter | |||
For example, void on_foreach(const Gtk::TreeModel::iterator& iter);. | ||||
typedef sigc::slot< bool, const TreeModel::Path& > | SlotForeachPath | |||
For example, void on_foreach(const Gtk::TreeModel::Path& path);. | ||||
typedef sigc::slot< bool, const TreeModel::Path&, const TreeModel::iterator& > | SlotForeachPathAndIter | |||
For example, void on_foreach(const Gtk::TreeModel::Path& path, const Gtk::TreeModel::iterator& iter);. | ||||
Public Member Functions | ||||
Children | children () const | |||
This returns an STL-like container API, for iterating over the rows. | ||||
Children | children () | |||
This returns an STL-like container API, for iterating over the rows. | ||||
void | foreach (const SlotForeachPathAndIter& slot) | |||
Calls a callback slot on each node in the model in a depth-first fashion. | ||||
void | foreach_iter (const SlotForeachIter& slot) | |||
Calls a callback slot on each node in the model in a depth-first fashion. | ||||
void | foreach_path (const SlotForeachPath& slot) | |||
Calls a callback slot on each node in the model in a depth-first fashion. | ||||
GType | get_column_type (int index) const | |||
Returns the type of the column. | ||||
TreeModelFlags | get_flags () const | |||
Returns a set of flags supported by this interface. | ||||
iterator | get_iter (const Glib::ustring& path_string) | |||
Returns a valid iterator pointing to path_string. | ||||
iterator | get_iter (const Path& path) | |||
Returns a valid iterator pointing to path. | ||||
int | get_n_columns () const | |||
Returns the number of columns supported by tree_model . | ||||
TreeModel::Path | get_path (const iterator& iter) const | |||
Returns a Gtk::TreePath referenced by iter . | ||||
Glib::ustring | get_string (const iterator& iter) const | |||
Generates a string representation of the iter. | ||||
const GtkTreeModel* | gobj () const | |||
Provides access to the underlying C GObject. | ||||
GtkTreeModel* | gobj () | |||
Provides access to the underlying C GObject. | ||||
void | row_changed (const Path& path, const iterator& iter) | |||
Emits the "row_changed" signal on tree_model . | ||||
void | row_deleted (const Path& path) | |||
Emits the "row_deleted" signal on tree_model . | ||||
void | row_has_child_toggled (const Path& path, const iterator& iter) | |||
Emits the "row_has_child_toggled" signal on tree_model . | ||||
void | row_inserted (const Path& path, const iterator& iter) | |||
Emits the "row_inserted" signal on tree_model. | ||||
void | rows_reordered (const Path& path, const iterator& iter, int* new_order) | |||
Emits the "rows_reordered" signal on tree_model . | ||||
void | rows_reordered (const Path& path, const iterator& iter, const Glib::ArrayHandle<int>& new_order) | |||
Glib::SignalProxy2< void, const TreeModel::Path&, const TreeModel::iterator& > | signal_row_changed () | |||
| ||||
Glib::SignalProxy1< void, const TreeModel::Path& > | signal_row_deleted () | |||
| ||||
Glib::SignalProxy2< void, const TreeModel::Path&, const TreeModel::iterator& > | signal_row_has_child_toggled () | |||
| ||||
Glib::SignalProxy2< void, const TreeModel::Path&, const TreeModel::iterator& > | signal_row_inserted () | |||
| ||||
Glib::SignalProxy3< void, const TreeModel::Path&, const TreeModel::iterator&, int* > | signal_rows_reordered () | |||
| ||||
virtual | ~TreeModel () | |||
Static Public Member Functions | ||||
static void | add_interface (GType gtype_implementer) | |||
Protected Member Functions | ||||
virtual void | get_value_impl (const iterator& row, int column, Glib::ValueBase& value) const | |||
virtual bool | iter_is_valid (const iterator& iter) const | |||
Override and implement this in a derived TreeModel class. | ||||
virtual void | set_value_impl (const iterator& row, int column, const Glib::ValueBase& value) | |||
Override and implement this in a derived TreeModel class, so that Row::operator() and Row::set_value() work. | ||||
Friends | ||||
class | Gtk::TreeIter | |||
class | Gtk::TreeModelSort | |||
class | Gtk::TreeRow | |||
Related Functions | ||||
(Note that these are not member functions.) | ||||
Glib::RefPtr<Gtk::TreeModel> | wrap (GtkTreeModel* object, bool take_copy=false) | |||
|
typedef TreePath Gtk::TreeModel::Path |
typedef TreeRow Gtk::TreeModel::Row |
typedef sigc::slot<bool, const TreeModel::iterator&> Gtk::TreeModel::SlotForeachIter |
For example, void on_foreach(const Gtk::TreeModel::iterator& iter);.
If the callback function returns true, then the tree ceases to be walked, and foreach() returns.
typedef sigc::slot<bool, const TreeModel::Path&> Gtk::TreeModel::SlotForeachPath |
For example, void on_foreach(const Gtk::TreeModel::Path& path);.
If the callback function returns true, then the tree ceases to be walked, and foreach() returns.
typedef sigc::slot<bool, const TreeModel::Path&, const TreeModel::iterator&> Gtk::TreeModel::SlotForeachPathAndIter |
For example, void on_foreach(const Gtk::TreeModel::Path& path, const Gtk::TreeModel::iterator& iter);.
If the callback function returns true, then the tree ceases to be walked, and foreach() returns.
virtual Gtk::TreeModel::~TreeModel | ( | ) | [virtual] |
static void Gtk::TreeModel::add_interface | ( | GType | gtype_implementer | ) | [static] |
Children Gtk::TreeModel::children | ( | ) | const |
This returns an STL-like container API, for iterating over the rows.
Children Gtk::TreeModel::children | ( | ) |
This returns an STL-like container API, for iterating over the rows.
void Gtk::TreeModel::foreach | ( | const SlotForeachPathAndIter& | slot | ) |
Calls a callback slot on each node in the model in a depth-first fashion.
If the callback function returns true, then the tree ceases to be walked, and foreach() returns.
slot | The function to call for each selected node. |
void Gtk::TreeModel::foreach_iter | ( | const SlotForeachIter& | slot | ) |
Calls a callback slot on each node in the model in a depth-first fashion.
If the callback function returns true, then the tree ceases to be walked, and foreach() returns.
slot | The function to call for each selected node. |
void Gtk::TreeModel::foreach_path | ( | const SlotForeachPath& | slot | ) |
Calls a callback slot on each node in the model in a depth-first fashion.
If the callback function returns true, then the tree ceases to be walked, and foreach() returns.
slot | The function to call for each selected node. |
GType Gtk::TreeModel::get_column_type | ( | int | index | ) | const |
Returns the type of the column.
index | The column index. |
TreeModelFlags Gtk::TreeModel::get_flags | ( | ) | const |
Returns a set of flags supported by this interface.
The flags are a bitwise combination of Gtk::TreeModelFlags. The flags supported should not change during the lifecycle of the tree_model.
iterator Gtk::TreeModel::get_iter | ( | const Glib::ustring & | path_string | ) |
Returns a valid iterator pointing to path_string.
path_string | The path, as a string representation. |
Returns a valid iterator pointing to path.
path | The Gtk::TreeModel::Path. |
int Gtk::TreeModel::get_n_columns | ( | ) | const |
Returns the number of columns supported by tree_model .
TreeModel::Path Gtk::TreeModel::get_path | ( | const iterator& | iter | ) | const |
Returns a Gtk::TreePath referenced by iter .
iter | The Gtk::TreeIter. |
Glib::ustring Gtk::TreeModel::get_string | ( | const iterator& | iter | ) | const |
Generates a string representation of the iter.
This string is a ':' separated list of numbers. For example, "4:10:0:3" would be an acceptable return value for this string.
newin2p2
iter | An Gtk::TreeIter. |
virtual void Gtk::TreeModel::get_value_impl | ( | const iterator& | row, | |
int | column, | |||
Glib::ValueBase & | value | |||
) | const [protected, virtual] |
const GtkTreeModel* Gtk::TreeModel::gobj | ( | ) | const [inline] |
Provides access to the underlying C GObject.
Reimplemented in Gtk::ListStore, Gtk::TreeModelFilter, Gtk::TreeModelSort, and Gtk::TreeStore.
GtkTreeModel* Gtk::TreeModel::gobj | ( | ) | [inline] |
Provides access to the underlying C GObject.
Reimplemented in Gtk::ListStore, Gtk::TreeModelFilter, Gtk::TreeModelSort, and Gtk::TreeStore.
virtual bool Gtk::TreeModel::iter_is_valid | ( | const iterator& | iter | ) | const [protected, virtual] |
Override and implement this in a derived TreeModel class.
Reimplemented in Gtk::ListStore, Gtk::TreeModelSort, and Gtk::TreeStore.
Emits the "row_changed" signal on tree_model .
path | A Gtk::TreePath pointing to the changed row. | |
iter | A valid Gtk::TreeIter pointing to the changed row. |
void Gtk::TreeModel::row_deleted | ( | const Path& | path | ) |
Emits the "row_deleted" signal on tree_model .
This should be called by models after a row has been removed. The location pointed to by path should be the location that the row previously was at. It may not be a valid location anymore.
path | A Gtk::TreePath pointing to the previous location of the deleted row. |
Emits the "row_has_child_toggled" signal on tree_model .
This should be called by models after the child state of a node changes.
path | A Gtk::TreePath pointing to the changed row. | |
iter | A valid Gtk::TreeIter pointing to the changed row. |
Emits the "row_inserted" signal on tree_model.
path | A Gtk::TreePath pointing to the inserted row. | |
iter | A valid Gtk::TreeIter pointing to the inserted row. |
Emits the "rows_reordered" signal on tree_model .
This should be called by models when their rows have been reordered.
path | A Gtk::TreePath pointing to the tree node whose children have been reordered. | |
iter | A valid Gtk::TreeIter pointing to the node whose children have been reordered, or 0 if the depth of path is 0. | |
new_order | An array of integers mapping the current position of each child to its old position before the re-ordering, i.e. new_order [newpos] = oldpos . |
void Gtk::TreeModel::rows_reordered | ( | const Path& | path, | |
const iterator& | iter, | |||
const Glib::ArrayHandle< int > & | new_order | |||
) |
virtual void Gtk::TreeModel::set_value_impl | ( | const iterator& | row, | |
int | column, | |||
const Glib::ValueBase & | value | |||
) | [protected, virtual] |
Override and implement this in a derived TreeModel class, so that Row::operator() and Row::set_value() work.
You can probably just implement this by calling set_value_vfunc(). Your implementation of set_value_impl() should also call set_row_changed() after changing the value.
Reimplemented in Gtk::ListStore, Gtk::TreeModelFilter, Gtk::TreeModelSort, and Gtk::TreeStore.
Glib::SignalProxy2<void,const TreeModel::Path&,const TreeModel::iterator&> Gtk::TreeModel::signal_row_changed | ( | ) |
Glib::SignalProxy1<void,const TreeModel::Path&> Gtk::TreeModel::signal_row_deleted | ( | ) |
Glib::SignalProxy2<void,const TreeModel::Path&,const TreeModel::iterator&> Gtk::TreeModel::signal_row_has_child_toggled | ( | ) |
Glib::SignalProxy2<void,const TreeModel::Path&,const TreeModel::iterator&> Gtk::TreeModel::signal_row_inserted | ( | ) |
Glib::SignalProxy3<void,const TreeModel::Path&,const TreeModel::iterator&,int*> Gtk::TreeModel::signal_rows_reordered | ( | ) |
void rows_reordered(const TreeModel::Path& path, const TreeModel::iterator& iter, int* new_order)
friend class Gtk::TreeIter [friend] |
friend class Gtk::TreeModelSort [friend] |
friend class Gtk::TreeRow [friend] |
Glib::RefPtr<Gtk::TreeModel> wrap | ( | GtkTreeModel * | object, | |
bool | take_copy = false | |||
) | [related] |
object | The C instance |
take_copy | False if the result should take ownership of the C instance. True if it should take a new copy or ref. |