vdk 2.4.0
Public Member Functions | List of all members
VDKTreeViewModel Class Reference

Provides a wrapper for GtkTreeModel basically it stores data to be viewed with a VDKTreeView. More...

#include <vdktreeview.h>

Inheritance diagram for VDKTreeViewModel:
Inheritance graph
[legend]
Collaboration diagram for VDKTreeViewModel:
Collaboration graph
[legend]

Public Member Functions

GtkTreeStore * GtkModel ()
 
 VDKTreeViewModel (GType *types, int ncol)
 
 ~VDKTreeViewModel ()
 
void AppendBlank (GtkTreeIter *iter, GtkTreeIter *parent=NULL)
 
void PrependBlank (GtkTreeIter *iter, GtkTreeIter *parent=NULL)
 
void InsertTuple (GtkTreeIter *iter, VDKTreeViewModelTuple &tuple, GtkTreeIter *parent=NULL, bool recurse=false)
 
void Clear ()
 
void Remove (GtkTreeIter *i)
 
void SetData (GtkTreeIter *node,...)
 
void SetCell (GtkTreeIter *node, int column, const char *value)
 
char * GetCell (GtkTreeIter *node, int column)
 
void GetTuple (GtkTreeIter *node, VDKTreeViewModelTuple &tuple)
 
bool HasChild ()
 
void operator++ ()
 
void operator++ (int)
 

Detailed Description

Provides a wrapper for GtkTreeModel basically it stores data to be viewed with a VDKTreeView.

Constructor & Destructor Documentation

§ VDKTreeViewModel()

VDKTreeViewModel::VDKTreeViewModel ( GType *  types,
int  ncol 
)

constructor

Parameters
typesa GType array
ncolthe number of columns into the model

§ ~VDKTreeViewModel()

VDKTreeViewModel::~VDKTreeViewModel ( )

destructor

Member Function Documentation

§ AppendBlank()

void VDKTreeViewModel::AppendBlank ( GtkTreeIter *  iter,
GtkTreeIter *  parent = NULL 
)

Appends a new blank tree row

Parameters
itera not initialized iter address that will be filled with newly constructed tree row
parentif not NULL the row will appended as a child otherwise it will be appended as a sibling. TIP:
  • appending all rows as sibling will degenerate the tree into a list
    GtkTreeIter iter;
    model->AppendBlank();
    model->SetData(&iter,...);

§ Clear()

void VDKTreeViewModel::Clear ( )

Clears the tree store

§ GetCell()

char * VDKTreeViewModel::GetCell ( GtkTreeIter *  node,
int  column 
)

Get data from a cell, data type will be converted into their string representation accordlying with GType.

Parameters
nodeiterator to be retrieved
columncell column

Supported GType's:

  • G_TYPE_CHAR
  • G_TYPE_STRING
  • G_TYPE_BOOLEAN
  • G_TYPE_INT
  • G_TYPE_UINT
  • G_TYPE_LONG
  • G_TYPE_ULONG
  • G_TYPE_FLOAT
  • G_TYPE_DOUBLE

Tip: Returned buffer address should be freed by user if not NULL.

//signal response method
bool
TvForm::OnTreeViewSelectRow(VDKObject* sender)
{
// gets selections
treeview->GetSelections();
// disregard multiple selections
if(treeview->Selections().size() == 1)
{
VDKTreeViewModel* model = treeview->Model;
// gets iter position from selections list
GtkTreeIter iter = treeview->Selections()[0];
char* firstname = model->GetCell(&iter,0); // extract from iter position at column 0
char* lastname = model->GetCell(&iter,1);
if(firstname && lastname) // GetCell() returns NULL on failure
{
printf("\n[%s %s]",firstname,lastname);
fflush(stdout);
delete[] firstname;
delete[] lastname;
}
}
treeview->Selections().flush();
return true;
}

§ GetTuple()

void VDKTreeViewModel::GetTuple ( GtkTreeIter *  node,
VDKTreeViewModelTuple tuple 
)

Gets and fill a tuple with row data converted into their string representation

Parameters
nodeiterator to be retrieved
tuplea tuple reference (tuple can be empty since it will be resized and filled by the method

§ GtkModel()

GtkTreeStore* VDKTreeViewModel::GtkModel ( )
inline

Return underlying GtkTreeStore object

§ HasChild()

bool VDKTreeViewModel::HasChild ( )

Move iterator to root node

Parameters
itera not initialized iter address that will be filled with root node pointer
GtkTreeIter iter;
if(model->Root(&iter))
{
char* cell = model->GetCell(&iter,0);
if(cell)
{
// ..
delete[] cell;
}
}
/
bool Root(GtkTreeIter* iter);
bool Next(GtkTreeIter* iter);
bool HasChild(GtkTreeIter* iter)
{ return gtk_tree_model_iter_has_child (GTK_TREE_MODEL(model), iter); }
bool Child(GtkTreeIter* iter,GtkTreeIter* parent);
bool Find(GtkTreeIter* iter,int column, char* value);
};
class VDKTreeViewModelIterator
{
GtkTreeIter iter, *internal_iter;
public:
VDKTreeViewModelIterator(): model(NULL),internal_iter(NULL) {}
VDKTreeViewModelIterator(VDKTreeViewModel* model,GtkTreeIter* parent = NULL);
GtkTreeIter* current() { return internal_iter; }
operator int() { return internal_iter != NULL; }

§ InsertTuple()

void VDKTreeViewModel::InsertTuple ( GtkTreeIter *  iter,
VDKTreeViewModelTuple tuple,
GtkTreeIter *  parent = NULL,
bool  recurse = false 
)

Insert a tuple into model, tuple will be inserted in order.

Parameters
itera not initialized iter address that will be filled with newly constructed tree row
tupleto be inserted
parentif is NULL tuple will be inserted in order into top level nodes list otherwise will be inserted in order into parent children list
recurseif true scans children/sibling list recursively to search insertion position

§ operator++() [1/2]

void VDKTreeViewModel::operator++ ( )

Incremental operator (postfix), visit next sibling node

§ operator++() [2/2]

void VDKTreeViewModel::operator++ ( int  )

Incremental operator (infix), visit next sibling node

§ PrependBlank()

void VDKTreeViewModel::PrependBlank ( GtkTreeIter *  iter,
GtkTreeIter *  parent = NULL 
)

Prepends a new blank tree row

Parameters
itera not initialized iter address that will be filled with newly constructed tree row
parentif not NULL the row will prepended as a child otherwise it will be prepended as a sibling. TIP:
  • prepending all rows as sibling will degenerate the tree into a list
GtkTreeIter iter;
model->PrependBlank();
model->SetData(&iter,...);

§ Remove()

void VDKTreeViewModel::Remove ( GtkTreeIter *  i)

Removes the row at iter

Parameters
ithe iter to be removed

§ SetCell()

void VDKTreeViewModel::SetCell ( GtkTreeIter *  node,
int  column,
const char *  value 
)

Sets data into a cell

Parameters
nodethe iterator to be set
columncell column
valuea string representation of GType value that will be converted into a GType accordlying with the model
GtkTreeIter *iter = model->PrependBlank();
model->SetCell(iter,0, "test");
model->SetCell(iter,1, "true");

Supported GType's:

  • G_TYPE_CHAR
  • G_TYPE_STRING
  • G_TYPE_BOOLEAN
  • G_TYPE_INT
  • G_TYPE_UINT
  • G_TYPE_LONG
  • G_TYPE_ULONG
  • G_TYPE_FLOAT
  • G_TYPE_DOUBLE

§ SetData()

void VDKTreeViewModel::SetData ( GtkTreeIter *  node,
  ... 
)

Sets data into a row

Parameters
nodethe iterator to be set
alist of pairs <column ordinal number,type value> the list must be -1 terminated.
GtkTreeIter iter;
model->AppendBlank();
model->SetData(&iter, 0, "This is row 1", 1, FALSE, 2, NULL, -1);

The documentation for this class was generated from the following files: