The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

App::Chart::Gtk2::Ex::ListModelPos -- position within a list type tree model

SYNOPSIS

 use App::Chart::Gtk2::Ex::ListModelPos;
 my $listpos = App::Chart::Gtk2::Ex::ListModelPos->new (model => $my_model);

 my $index = $listpos->next_index;

OBJECT HIERARCHY

App::Chart::Gtk2::Ex::ListModelPos is a subclass of Glib::Object,

    Glib::Object
      App::Chart::Gtk2::Ex::ListModelPos

DESCRIPTION

A App::Chart::Gtk2::Ex::ListModelPos object keeps track of a position in a list type TreeModel (meaning any Glib::Object implementing the Gtk2::TreeModel interface). It's intended to track a user's position in a list of files, documents, etc.

The position can be "at" a given row, or "before" or "after" one. The position adjusts with inserts, deletes and reordering to follow that row. Special positions "start" and "end" are the ends of the list, not following any row.

A row data "key" scheme allows a row to be followed across a delete and re-insert done by TreeView drag-and-drop, or by a user delete and undo, or re-add.

TreeRowReference

Gtk2::TreeRowReference does a similar thing to ListModelPos, but a TreeRowReference is oriented towards tracking just a particular row. If its row is deleted then a TreeRowReference points nowhere, whereas ListModelPos remembers a position in between remaining rows.

FUNCTIONS

$listpos = App::Chart::Gtk2::Ex::ListModelPos->new (key => value, ...)

Create and return a new ListModelPos object. Optional key/value pairs set initial properties as per Glib::Object->new(). Eg.

    my $listpos = App::Chart::Gtk2::Ex::ListModelPos->new (model => $my_model,
                                                           key_column => 2);
$index = $listpos->model()
$index = $listpos->type()
$index = $listpos->index()

Return the model, type and index properties per "PROPERTIES" below.

$index = $listpos->iter()

Return a Gtk2::TreeIter which is the current row. If $listpos is not type "at" or its index is out of range then the return is undef.

$index = $listpos->next_index()
$index = $listpos->prev_index()
$iter = $listpos->next_iter()
$iter = $listpos->prev_iter()

Move $listpos to the next or previous row from its current position and return an integer index or Gtk2::TreeIter for the new position. If there's no more rows in the respective direction (including if the model is empty) then the return is undef instead.

$listpos->goto ($index)
$listpos->goto ($index, $type)

Move $listpos to the given $index row. The $type parameter defaults to "at", or you can give "before" or "after" instead.

    $listpos->goto (4, 'before');

goto is the same as setting the respective property values (but changed in one operation).

$listpos->goto_start()
$listpos->goto_end()

Move $listpos to the start or end of its model, so that next returns the first row or prev the last row (respectively). These functions are the same as setting the type property to "start" or "end", respectively.

PROPERTIES

model (Glib::Object implementing Gtk2::TreeModel interface)

The model to operate on.

type (Gtk2::Ex::ListModelPos::Type enum, default "start")

Enum values "at", "before", "after", "start", "end".

The default type is "start", but you can Initialize to a particular row explicitly,

    my $listpos = App::Chart::Gtk2::Ex::ListModelPos->new (model => $my_model,
                                               type  => 'at',
                                               index => 3);
index (integer, default 0)

Current row number in the model. When type is "start" or "end" the index value is unused.

key_column (integer, default -1)

Column number of row key data. The default -1 means no key column.

key_func (coderef, default undef)

Function to extract a key from a row. When set it's called

    $str = &$key_func ($model, $iter)
key_equal (coderef, default undef)

Row key equality function. The default undef means use eq. When set it's called as

    $bool = &$key_equal ($value1, $value2)

with values from the key_func or key_column.

OTHER NOTES

When a ListModelPos is "at" a given row and that row is deleted there's a choice between becoming "after" the previous row, or "before" the next row. This can make a difference in a reorder if the two rows move to different places. The current code always uses "after the previous", or if the first row is deleted then "start".

SEE ALSO

Gtk2::TreeModel, Gtk2::TreeRowReference