NAME
Gtk2::Ex::ListModelConcat -- concatenated list models
SYNOPSIS
use Gtk2::Ex::ListModelConcat;
my $model = Gtk2::Ex::ListModelConcat->new (models => [$m1,$m2]);
OBJECT HIERARCHY
Gtk2::Ex::ListModelConcat is a subclass of Glib::Object.
Glib::Object
Gtk2::Ex::ListModelConcat
and implements the interfaces
Gtk2::TreeModel
Gtk2::TreeDragSource
Gtk2::TreeDragDest
DESCRIPTION
Gtk2::Ex::ListModelConcat presents a set of list type TreeModels concatenated together as a single list. A Concat doesn't hold any data itself, it just presents the sub-models' content. Gtk2::ListStore objects are suitable as the sub-models, but any similar list-type model can be used.
Changes in the sub-models are reported up through the Concat with the usual row-changed etc signals. Conversely change methods are implemented by Concat in the style of Gtk2::ListStore and if the sub-models have those functions too (eg. if they're ListStores) then changes on the Concat are applied down to the sub-models.
The sub-models should all have the same number of columns and the same column types (or compatible types), though currently ListModelConcat doesn't try to enforce that. It works to put one Concat inside another, except of course it cannot be inside itself (directly or indirectly).
Drag and Drop
ListModelConcat implements TreeDragSource and TreeDragDest, allowing rows to be moved by dragging in a Gtk2::TreeView or similar. The actual operations are delgated to the submodels, so a row can be dragged if the originating submodel is a TreeDragSource, and a location is a drop point if the submodel there is a TreeDragDest.
It's worth noting the standard Gtk2::ListStore models only accept drops of their own rows, ie. a re-ordering, not movement of rows between different models. This is reasonable if different models might have different natures, but you might want to subclass or use a wrapper for a more liberal policy between compatible models.
PROPERTIES
models(array reference, default empty[])-
Arrayref of sub-models to concatenate. The sub-models can be any object implementing the
Gtk2::TreeModelinterface. They should belist-onlytype, though currently ListModelConcat doesn't enforce that.Currently when the
modelsproperty is changed there's norow-inserted/row-deletedetc signals emitted by the Concat to announce the new or altered data presented. Perhaps this will change. The disadvantage would be that adding or removing a big model could generate thousands of fairly pointless signals. The suggestion is to treatmodelsas if it were "construct-only" and make a new Concat for a new set of models.
FUNCTIONS
$concat = Gtk2::Ex::ListModelConcat->new (key=>value,...)-
Create and return a new Concat object. Optional key/value pairs set initial properties as per
Glib::Object->new. Eg.my $concat = Gtk2::Ex::ListModelConcat->new (models => [$m1,$m2]);
LISTSTORE METHODS
The following functions are implemented in the style of Gtk2::ListStore and they call down to corresponding functions in the sub-models. Those sub-models don't have to be Gtk2::ListStore objects, they can be some other class implementing the same methods.
$concat->clear$concat->set_column_types-
These are applied to all sub-models, so
clearclears all the models orset_column_typessets the types in all the models.In the current implementation Concat doesn't keep column types itself, but asks the sub-models when required (using the first sub-model, curently).
$iter = $concat->append$iter = $concat->insert ($pos)$iter = $concat->insert_with_values ($pos, $col,$val, ...)$iter = $concat->insert_after ($iter)$iter = $concat->insert_before ($iter)bool = $concat->iter_is_valid ($iter)$concat->move_after ($iter, $iter_from, $iter_to)$concat->move_before ($iter, $iter_from, $iter_to)$iter = $concat->prependbool = $concat->remove ($iter)$concat->reorder (@neworder)$concat->swap ($iter_a, $iter_b)$concat->set ($iter, $col,$val, ...)$concat->set_value ($iter, $col, $val)-
These are per the
Gtk2::ListStoremethods.Note
setoverrides thesetinGlib::Objectwhich normally sets object properties. You can use theset_propertyname instead.$model->set_property ('propname' => $value);
SIGNALS
The TreeModel interface implemented by ListModelConcat provides the following usual signals
row-changed ($concat, $path, $iter, $userdata)
row-inserted ($concat, $path, $iter, $userdata)
row-deleted ($concat, $path, $userdata)
rows-reordered ($concat, $path, $iter, $arrayref, $userdata)
Because ListModelConcat is list-only, the path to row-changed, row-inserted and row-deleted is always depth 1, and the path to rows-reordered is always depth 0 and the iter there always undef.
When a change occurs in a sub-model the corresponding signal is reported up through Concat. The path and iter are of course reported by the Concat in its "concatenated" coordinates and iters, not the sub-model's.
BUGS
ref_node and unref_node are no-ops. The intention is to apply them down on the sub-models, but hopefully without needing lots of bookkeeping in the Concat as to what's currently reffed.
It mostly works to have a sub-model appear more than once in a Concat. The only outright bug is in the remove method which doesn't update its iter correctly when removing a row from a second or subsequent copy of a submodel. The row-deleted and row-inserted signals are emitted on the Concat the right number of times, but the multiple inserts/deletes are all present in the data as of the first emit, which might confuse handler code. (The idea could be some sort of temporary index mapping to make the changes seem one-at-a-time for the handlers.)
What does work fine is to have multiple TreeModelFilters selecting different parts of a single underlying model. As long as a given row only appears once it doesn't matter where the ultimate storage location is.
SEE ALSO
Gtk2::TreeModel, Gtk2::TreeDragSource, Gtk2::TreeDragDest, Gtk2::ListStore, Glib::Object
HOME PAGE
http://www.geocities.com/user42_kevin/gtk2-ex-listmodelconcat/
COPYRIGHT
Copyright 2008 Kevin Ryde
Gtk2-Ex-ListModelConcat is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.
Gtk2-Ex-ListModelConcat is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Gtk2-Ex-ListModelConcat. If not, see http://www.gnu.org/licenses/.