Reference Manual
Inti Logo
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

Inti::Gtk::ListStore Class Reference

A GtkListStore C++ wrapper class. More...

#include <inti/gtk/liststore.h>

Inheritance diagram for Inti::Gtk::ListStore:

Inti::G::Object Inti::Gtk::TreeModel Inti::Gtk::TreeSortable Inti::G::TypeInstance Inti::MemoryHandler Inti::G::TypeInterface Inti::G::TypeInterface Inti::ReferencedBase Inti::G::TypeInstance Inti::G::TypeInstance Inti::ReferencedBase Inti::ReferencedBase List of all members.

Public Member Functions

Constructors
Accessors
Methods
Templates

Protected Member Functions

Constructors

Detailed Description

A GtkListStore C++ wrapper class.

The ListStore object is a list 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.

Example: Creating a simple list store.

    #include <inti/main.h>
    #include <inti/gtk/window.h>
    #include "inti/gtk/liststore.h"
    #include <inti/gtk/treeview.h>
    #include "inti/gtk/cellrenderer.h"
   
    using namespace Inti;
   
    class ListStoreWindow : public Gtk::Window
    {
        Pointer<Gtk::ListStore> list_store;
        Gtk::TreeView *tree_view;
    public:
        ListStoreWindow();
    };
   
    enum
    {
        COLUMN_STRING,
        COLUMN_INT,
        COLUMN_BOOLEAN,
        N_COLUMNS
    };
   
    ListStoreWindow::ListStoreWindow()
    {
        list_store = new Gtk::ListStore(N_COLUMNS, G_TYPE_STRING, G_TYPE_INT, G_TYPE_BOOLEAN);
   
        Gtk::TreeIter iter;
        for (int i = 0; i < 10; i++)
        {
                // Add a new row to the model
                iter = list_store->append();
                list_store->set_value(iter, COLUMN_STRING, "Some Data");
                list_store->set_value(iter, COLUMN_INT, i);
                list_store->set_value(iter, COLUMN_BOOLEAN, false);
        }
   
        // Modify a particular row
        Pointer<Gtk::TreePath> path = new Gtk::TreePath("4");
        list_store->get_iter(iter, *path);
        list_store->set_value(iter, COLUMN_BOOLEAN, true);
   
        // Create a TreeView
        tree_view = new Gtk::TreeView(*list_store);
   
        // Create first column, associating the "text" attribute of the cell_renderer
        // with the first column of the list_store. Add column to TreeView.
        Gtk::CellRendererText *renderer = new Gtk::CellRendererText;
        renderer->prop_foreground().set("red");
        Gtk::TreeViewColumn *column = new Gtk::TreeViewColumn("Text", renderer, "text", COLUMN_STRING, 0);
        tree_view->append_column(*column);
   
        // Create second column, associating the "text" attribute of the cell_renderer
        // with the second column of the list_store. Add column to TreeView.
        renderer = new Gtk::CellRendererText;
        renderer->prop_foreground().set("blue");
        column = new Gtk::TreeViewColumn("Number", renderer, "text", COLUMN_INT, 0);
        tree_view->append_column(*column);
   
        // Create third column, associating the "active" attribute of the toggle cell_renderer
        // with the second column of the list_store. Add column to TreeView. To update checkbox
        // when toggled you must connect to the "toggled_signal".
        Gtk::CellRendererToggle *toggle_renderer = new Gtk::CellRendererToggle;
        column = new Gtk::TreeViewColumn("Boolean", toggle_renderer, "active", COLUMN_BOOLEAN, 0);
        tree_view->append_column(*column);
   
        add(*tree_view);
        show_all();
    }
   
    int main (int argc, char *argv[])
    {
        using namespace Main;
   
        init(&argc, &argv);
   
        ListStoreWindow window;
        window.sig_destroy().connect(slot(&Inti::Main::quit));
   
        run();
        return 0;
    }


Constructor & Destructor Documentation

Inti::Gtk::ListStore::ListStore GtkListStore *  list_store,
bool  reference = true
[explicit, protected]
 

Construct a new ListStore from an existing GtkListStore.

Parameters:
list_store A pointer to a GtkListStore.
reference Set false if the initial reference count is floating, set true if it's not.

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

Inti::Gtk::ListStore::ListStore int  n_columns,
... 
 

Construct a list 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 list store.
... All the GType types for the columns, from first to last.

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

Inti::Gtk::ListStore::ListStore const std::vector< GType > &  types  ) 
 

Construct a list 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::ListStore::append  ) 
 

Appends a new row to a ListStore.

Returns:
An unset TreeIter set to the appended row.

The row will be empty after this method is called. To fill in values, you need to call set_value(), set_object() or set_pointer().

TreeIter Inti::Gtk::ListStore::insert int  position  ) 
 

Inserts a new row at position.

Parameters:
position The position to insert the new row.
Returns:
An unset TreeIter set to the inserted row.

If position is larger than the number of rows on the list, then the new row will be appended to the list.The row will be empty after this method is called. To fill in values, you need to call set_value(), set_object() or set_pointer().

TreeIter Inti::Gtk::ListStore::insert_after TreeIter sibling  ) 
 

Inserts a new row after sibling.

Parameters:
sibling A valid TreeIter.
Returns:
An unset TreeIter set to the inserted row.

The row will be empty after this method is called. To fill in values, you need to call set_value(), set_object() or set_pointer().

TreeIter Inti::Gtk::ListStore::insert_before TreeIter sibling  ) 
 

Inserts a new row before sibling.

Parameters:
sibling A valid TreeIter.
Returns:
An unset TreeIter set to the inserted row.

The row will be empty after this method is called. To fill in values, you need to call set_value(), set_object() or set_pointer().

bool Inti::Gtk::ListStore::iter_is_valid const TreeIter iter  )  const
 

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

Parameters:
iter A TreeIter.
Returns:
true if the iter is valid, false if it's not.

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

void Inti::Gtk::ListStore::move_after const TreeIter iter,
const TreeIter position
 

Moves iter in the list store to the position after position.

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 list.

void Inti::Gtk::ListStore::move_before const TreeIter iter,
const TreeIter position
 

Moves iter in the list store to the position before position.

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 list.

TreeIter Inti::Gtk::ListStore::prepend  ) 
 

Prepends a new row to a ListStore.

Returns:
An unset TreeIter set to the prepended row.

The row will be empty after this method is called. To fill in values, you need to call set_value(), set_object() or set_pointer().

bool Inti::Gtk::ListStore::remove TreeIter iter  ) 
 

Removes the given row from the list store.

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

After being removed, iter is set to be the next valid row, or invalidated if it pointed to the last row in list_store.

void Inti::Gtk::ListStore::reorder int *  new_order  ) 
 

Reorders the list store to follow the order indicated by new_order.

Parameters:
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::ListStore::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::ListStore::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::ListStore::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::ListStore::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::ListStore::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::ListStore::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::ListStore::swap const TreeIter a,
const TreeIter b
 

Swaps a and b in the list 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: Main Page - Footer


Generated on Sun Sep 14 20:08:16 2003 for Inti by doxygen 1.3.2 written by Dimitri van Heesch, © 1997-2002