Gtk2::Ex::DbLinker::Datasheet - a module that display data from a database in a tabular format using a treeview
See Version in Gtk2::Ex::DbLinker
This display a table having to 6 columns: 3 text entries, 2 combo, 1 toogle, we have to create a dataManager object for each combo, and a dataManager for the table itself. The example here use Rose::DB::Object to access the tables.
This gets the Rose::DB::Object::Manager (we could have use plain sql command, or DBIx::Class object)
my $datasheet_rows = Rdb::Vtlsfm::Manager->get_vtlsfm(sort_by => 'nofm');
This object is used to instanciante a RdbDataManager, that will be used in the datasheet constructor.
my $dman = Gtk2::Ex::DbLinker::RdbDataManager->new({data => $datasheet_rows, meta => Rdb::Vtlsfm->meta });
We create the RdbDataManager for the combo rows
my $biblio_data = Rdb::Biblio::Manager->get_biblio( select => [qw/t1.id t1.nom/], sort_by => 'nom'); my $dman_combo_biblio = Gtk2::Ex::DbLinker::RdbDataManager->new({data => $biblio_data, meta => Rdb::Biblio->meta}); my $ed_data = Rdb::Ed::Manager->get_ed( sort_by => 'nom'); my $dman_combo_ed = Gtk2::Ex::DbLinker::RdbDataManager->new({ data =>$ed_data, meta => Rdb::Ed->meta, });
We create the Datasheet object with the columns description
my $treeview = Gtk2::TreeView->new(); $self->{datasheet} = Gtk2::Ex::DbLinker::Datasheet->new({ treeview => $treeview, fields => [{name=>"nofm", renderer=>"text"}, {name=>"reroid"}, {name=>"url", renderer=>"text", custom_render_functions => [sub {display_url (@_, $self);},]}, {name => 'biblio', renderer => 'combo', data_manager => $dman_combo_biblio, fieldnames=>["id", "nom"]}, {name => 'ed', renderer => 'combo', data_manager=> $dman_combo_ed, fieldnames=>["id", "nom"]}, {name => 'idle', renderer => 'toggle'}, ], data_manager => $dman, });
To change a set of rows in the table when we navigate between records for example. The primary key of the current record is hold in $primarykey_value :
my $data = Rdb::Vtlsfm::Manager->get_vtlsfm(query =>[nofm =>{eq=> $primarykey_value}], sort_by => 'primarykey'); $self->{dataseet}->get_data_manager->query($data); $self->{datasheet}->update();
This module automates the process of setting up a model and treeview based on field definitions you pass it. An additional column named _status_column_ is added in front of a the other fields. It holds icons that shows if a row is beeing edited, mark for deletion or is added.
Steps for use:
Instanciate a xxxDataManager that will fetch a set of rows.
Create a 'bare' Gtk2::TreeView.
Create a xxxDataManager holding the rows to display, if the datasheet has combo box, create the corresponding DataManager that hold the combo box content.
Create a Gtk2::Ex::DbLinker::Datasheet object and pass it your TreeView and DataManagers objects.
You would then typically connect some buttons to methods such as inserting, deleting, etc.
The new() method expects a hash reference of key / value pairs.
new()
data_manager a instance of a xxxDataManager object.
data_manager
tree a Gtk2::TreeView
tree
fields a reference to an array of hash. Each hash has the following key / value pairs.
fields
name / id of the field to display.
name
renderer / one of "text combo toggle hidden image".
renderer
if the renderer is a combo the following key / values are needed in the same hash reference:
data_manager / an instance holding the rows.
fieldnames / a reference to an array of the fields that populate the combo. The first one is the return value.
fieldnames
update();
Reflect in the user interface the changes made after the data manager has been queried, or on the datasheet creation.
get_data_manager();
Returns the data manager to be queried.
insert();
Displays an empty rows.
delete();
Marks the current row to be deleted. The delele itself will be done on apply.
apply();
Save a new row, save changes on an existing row, or delete the row(s) marked for deletion.
undo();
Revert the row to the original state in displaying the values fetch from the database.
Any Gk2::Ex::DbLinker questions or problems can be posted to the the mailing list. To subscribe to the list or view the archives, go here: http://groups.google.com/group/gtk2-ex-dblinker. You may also send emails to gtk2-ex-dblinker@googlegroups.com.
The current state of the source can be extract using Mercurial from http://code.google.com/p/gtk2-ex-dblinker/.
François Rappaz <rappazf@gmail.com>
Copyright (c) 2014 by François Rappaz. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Gtk2::Ex::Datasheet::DBI
Daniel Kasak, whose modules initiate this work.
To install Gtk2::Ex::DbLinker, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Gtk2::Ex::DbLinker
CPAN shell
perl -MCPAN -e shell install Gtk2::Ex::DbLinker
For more information on module installation, please visit the detailed CPAN module installation guide.