TGTable
TGTable implements a table widget to display data in rows and
columns. The data is supplied by a TVirtualTableInterface.
The table is a TGCanvas to make use of already available viewport
functionality and drawing optimizations.
The top left cell in a table has coordinates (0,0)
A TObjArray is used internally to ensure little overhead and fast
acces to cells.
If the data source has more rows than the default 50 rows of cells in
memory, buttons at the bottom of the table can be used to load the
next or previous chunk of data.
At the top of the table, a frame is visible that shows the coordinates
of the top left cell currently in memmory in row,column. The amount of
rows and columns is also shown in rows x columns. These values can be
edited to move to a different area of the data source or to resize the
table. Tab will switch between the enties, return will move to the
currently entered range and resize the table if needed. Clicking the
goto button has the same effect.
A TGTable is created by first creating an appropriate
TVirtualTableInterface from the data that needs visualization and
then creating the TGTable using this interface.
A simple macro to use a TGTable with a TGSimpleTableInterface:
{
Int_t i = 0, j = 0;
UInt_t nrows = 6, ncolumns = 5;
Double_t** data = new Double_t*[nrows];
for (i = 0; i < nrows; i++) {
data[i] = new Double_t[ncolumns];
for (j = 0; j < ncolumns; j++) {
data[i][j] = 10 * i + j;
}
}
TGMainFrame* mainframe = new TGMainFrame(0, 400, 200);
mainframe->SetCleanup(kDeepCleanup) ;
TGSimpleTableInterface *iface = new TGSimpleTableInterface(data, 6, 5);
TGTable *table = new TGTable(mainframe, 999, iface);
mainframe->AddFrame(table, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
data[5][1] = 3.01;
table->Update();
mainframe->SetWindowName("Tree Table Test") ;
mainframe->MapSubwindows() ;
mainframe->Layout();
mainframe->Resize() ;
mainframe->MapWindow() ;
return mainframe;
}
It is also possible to visualise data from a tree. A simple macro
showing the use of a TTreeTableInterface follows.
{
TFile *file = new TFile("$ROOTSYS/tutorials/hsimple.root");
TNtuple *ntuple = (TNtuple *)file.Get("ntuple");
TTreeTableInterface *iface = new TTreeTableInterface(ntuple);
TGMainFrame* mainframe = new TGMainFrame(0, 400, 200);
mainframe->SetCleanup(kDeepCleanup) ;
TGTable *table = new TGTable(mainframe, 999, iface, 10, 6);
mainframe->AddFrame(table, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
iface->SetSelection("px > 0.");
iface->AddColumn("(px+py)/(px-py)", 0);
table->Update();
mainframe->SetWindowName("Tree Table Test") ;
mainframe->MapSubwindows() ;
mainframe->Layout();
mainframe->Resize() ;
mainframe->MapWindow() ;
return mainframe;
}