Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
simpleTableTest.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_gui
3/// This TableTest class is a simple example of how to use a TGSimpleTable that creates and owns it's own TGSimpleTableInterface.
4/// TableTest inherits from TGMainFrame to create a top level frame to embed the TGTable in.
5/// First the data needed is created. Then the TGSimpleTable is created using this data.
6/// In the end, the table is added to the TGMainFrame that is the TableTest and the necessary calls to correctly draw the window are made.
7/// For more information about the use of TGSimpleTable see it's documentation.
8///
9/// \macro_code
10///
11/// \author Roel Aaij 13/07/2007
12
13#include <iostream>
14#include <TApplication.h>
15#include <TGClient.h>
16#include <TGButton.h>
17#include <TGFrame.h>
18#include <TGLayout.h>
19#include <TGWindow.h>
20#include <TGLabel.h>
21#include <TGNumberEntry.h>
22#include <TString.h>
23#include <TGButtonGroup.h>
24#include <TGMenu.h>
25#include <TGSimpleTable.h>
26
27// A little class to automatically handle the generation of unique
28// widget ids.
29class IDList {
30private:
31 Int_t nID ; // Generates unique widget IDs.
32public:
33 IDList() : nID(0) {}
34 ~IDList() {}
35 Int_t GetUnID(void) { return ++nID ; }
36} ;
37
38class TableTest : public TGMainFrame {
39
40private:
41 IDList IDs ; // Generator for unique widget IDs.
42 Double_t **fData;
43 UInt_t fNDataRows;
44 UInt_t fNDataColumns;
45 UInt_t fNTableRows;
46 UInt_t fNTableColumns;
47 TGSimpleTable *fSimpleTable;
48
49public:
50 TableTest(const TGWindow *p, UInt_t ndrows, UInt_t ndcols,
51 UInt_t ntrows, UInt_t ntcols, UInt_t w = 100, UInt_t h = 100) ;
52 virtual ~TableTest() ;
53
54 void DoExit() ;
55
56 TGSimpleTable *GetTable() { return fSimpleTable; }
57
58 ClassDef(TableTest, 0)
59};
60
61TableTest::TableTest(const TGWindow *p, UInt_t ndrows, UInt_t ndcols,
62 UInt_t ntrows, UInt_t ntcols, UInt_t w, UInt_t h)
63 : TGMainFrame(p, w, h), fData(0), fNDataRows(ndrows), fNDataColumns(ndcols),
64 fNTableRows(ntrows), fNTableColumns(ntcols), fSimpleTable(0)
65{
66 SetCleanup(kDeepCleanup) ;
67 Connect("CloseWindow()", "TableTest", this, "DoExit()") ;
68 DontCallClose() ;
69
70 // Create the needed data.
71 Int_t i = 0, j = 0;
72 fData = new Double_t*[fNDataRows];
73 for (i = 0; i < (Int_t)fNDataRows; i++) {
74 fData[i] = new Double_t[fNDataColumns];
75 for (j = 0; j < (Int_t)fNDataColumns; j++) {
76 fData[i][j] = 10 * i + j;
77 }
78 }
79
80 // Create the table and add it to the TableTest that is a TGMainFrame.
81 fSimpleTable = new TGSimpleTable(this, IDs.GetUnID(), fData, fNTableRows,
82 fNTableColumns);
83 AddFrame(fSimpleTable, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
84
85 // Calls to layout and draw the TableTest that is a TGMainFrame.
86 SetWindowName("TGSimpleTable Test") ;
87 MapSubwindows() ;
88 Layout();
89 Resize(GetDefaultWidth()+20, 600) ;
90 MapWindow() ;
91
92} ;
93
94TableTest::~TableTest()
95{
96 // Destructor
97 UInt_t i = 0;
98 for (i = 0; i < fNDataRows; i++) {
99 delete[] fData[i];
100 }
101 delete[] fData;
102 Cleanup() ;
103 }
104
105 void TableTest::DoExit()
106{
107 // Exit this application via the Exit button or Window Manager.
108 // Use one of the both lines according to your needs.
109 // Please note to re-run this macro in the same ROOT session,
110 // you have to compile it to get signals/slots 'on place'.
111
112 DeleteWindow(); // to stay in the ROOT session
113 // gApplication->Terminate(); // to exit and close the ROOT session
114}
115
116TGSimpleTable *simpleTableTest(UInt_t ndrows = 500, UInt_t ndcols = 20,
117 UInt_t ntrows = 50, UInt_t ntcols = 10) {
118 TableTest *test = new TableTest(0, ndrows, ndcols, ntrows, ntcols, 500, 200);
119 return test->GetTable();
120}
#define h(i)
Definition RSha256.hxx:106
int Int_t
Definition RtypesCore.h:45
unsigned int UInt_t
Definition RtypesCore.h:46
double Double_t
Definition RtypesCore.h:59
#define ClassDef(name, id)
Definition Rtypes.h:325
@ kDeepCleanup
Definition TGFrame.h:50
@ kLHintsExpandY
Definition TGLayout.h:38
@ kLHintsExpandX
Definition TGLayout.h:37
RooCmdArg Layout(Double_t xmin, Double_t xmax=0.99, Double_t ymin=0.95)
Definition test.py:1