2012-03-28 15:13:34 -04:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* OpenSQLManager
|
|
|
|
*
|
|
|
|
* Free Database manager for Open Source Databases
|
|
|
|
*
|
|
|
|
* @author Timothy J. Warren
|
|
|
|
* @copyright Copyright (c) 2012
|
|
|
|
* @link https://github.com/aviat4ion/OpenSQLManager
|
|
|
|
* @license http://philsturgeon.co.uk/code/dbad-license
|
|
|
|
*/
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
*Class to simplify dealing with GtkTreeView
|
|
|
|
*/
|
|
|
|
class Data_Grid extends GtkTreeView {
|
|
|
|
|
|
|
|
protected $model;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create the object
|
2012-03-29 16:26:50 -04:00
|
|
|
*
|
|
|
|
* @param object $model
|
2012-03-28 15:13:34 -04:00
|
|
|
*/
|
2012-03-29 16:26:50 -04:00
|
|
|
public function __construct($model = null)
|
2012-03-28 15:13:34 -04:00
|
|
|
{
|
2012-03-29 16:26:50 -04:00
|
|
|
$this->model = ( ! is_null($model))
|
|
|
|
? $model
|
|
|
|
: new GtkTreeStore(Gobject::TYPE_PHP_VALUE, Gobject::TYPE_PHP_VALUE);
|
|
|
|
|
2012-03-28 15:13:34 -04:00
|
|
|
parent::__construct($this->model);
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
2012-03-30 13:09:38 -04:00
|
|
|
* Get the value of the model for the current selection
|
2012-03-28 15:13:34 -04:00
|
|
|
*
|
2012-03-30 13:09:38 -04:00
|
|
|
* @param int pos
|
2012-03-28 15:13:34 -04:00
|
|
|
* @return mixed
|
|
|
|
*/
|
2012-03-30 13:09:38 -04:00
|
|
|
public function get($pos = 0)
|
2012-03-28 15:13:34 -04:00
|
|
|
{
|
2012-03-30 13:09:38 -04:00
|
|
|
// Get the selection object of the row
|
|
|
|
$sel = $this->get_selection();
|
|
|
|
|
|
|
|
// Get the model and iterator for the selected row
|
|
|
|
list($model, $iter) = $sel->get_selected();
|
|
|
|
|
|
|
|
// Get the data from the model
|
|
|
|
return $model->get_value($iter, $pos);
|
2012-03-28 15:13:34 -04:00
|
|
|
}
|
2012-03-29 16:26:50 -04:00
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the value of the cell at the provided coordinate array
|
|
|
|
*
|
|
|
|
* @param array $coord
|
|
|
|
* @param mixed $val
|
|
|
|
*/
|
|
|
|
public function set(array $coord, $val)
|
|
|
|
{
|
|
|
|
// @todo implement
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
2012-03-29 19:57:10 -04:00
|
|
|
* Empty the model
|
2012-03-29 16:26:50 -04:00
|
|
|
*/
|
2012-03-30 13:09:38 -04:00
|
|
|
public function reset()
|
2012-03-29 16:26:50 -04:00
|
|
|
{
|
2012-03-29 19:57:10 -04:00
|
|
|
$this->model->clear();
|
2012-03-30 10:13:16 -04:00
|
|
|
|
|
|
|
$cols = $this->get_columns();
|
|
|
|
|
|
|
|
foreach($cols as $c)
|
|
|
|
{
|
|
|
|
$this->remove_column($c);
|
|
|
|
}
|
2012-03-29 16:26:50 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// End of data_grid.php
|