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
4/// TGSimpleTableInterface. 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
7/// the window are made. 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, UInt_t ntrows, UInt_t ntcols, UInt_t w = 100,
51 UInt_t h = 100);
52 ~TableTest() override;
53
54 void DoExit();
55
56 TGSimpleTable *GetTable() { return fSimpleTable; }
57
58 ClassDefOverride(TableTest, 0)
59};
60
61TableTest::TableTest(const TGWindow *p, UInt_t ndrows, UInt_t ndcols, UInt_t ntrows, UInt_t ntcols, UInt_t w, UInt_t h)
62 : TGMainFrame(p, w, h),
63 fData(nullptr),
64 fNDataRows(ndrows),
65 fNDataColumns(ndcols),
66 fNTableRows(ntrows),
67 fNTableColumns(ntcols),
68 fSimpleTable(nullptr)
69{
70 SetCleanup(kDeepCleanup);
71 Connect("CloseWindow()", "TableTest", this, "DoExit()");
72 DontCallClose();
73
74 // Create the needed data.
75 Int_t i = 0, j = 0;
76 fData = new Double_t *[fNDataRows];
77 for (i = 0; i < (Int_t)fNDataRows; i++) {
78 fData[i] = new Double_t[fNDataColumns];
79 for (j = 0; j < (Int_t)fNDataColumns; j++) {
80 fData[i][j] = 10 * i + j;
81 }
82 }
83
84 // Create the table and add it to the TableTest that is a TGMainFrame.
85 fSimpleTable = new TGSimpleTable(this, IDs.GetUnID(), fData, fNTableRows, fNTableColumns);
86 AddFrame(fSimpleTable, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
87
88 // Calls to layout and draw the TableTest that is a TGMainFrame.
89 SetWindowName("TGSimpleTable Test");
91 Layout();
92 Resize(GetDefaultWidth() + 20, 600);
93 MapWindow();
94};
95
96TableTest::~TableTest()
97{
98 // Destructor
99 UInt_t i = 0;
100 for (i = 0; i < fNDataRows; i++) {
101 delete[] fData[i];
102 }
103 delete[] fData;
104 Cleanup();
105}
106
107void TableTest::DoExit()
108{
109 // Exit this application via the Exit button or Window Manager.
110 // Use one of the both lines according to your needs.
111 // Please note to re-run this macro in the same ROOT session,
112 // you have to compile it to get signals/slots 'on place'.
113
114 DeleteWindow(); // to stay in the ROOT session
115 // gApplication->Terminate(); // to exit and close the ROOT session
116}
117
118TGSimpleTable *simpleTableTest(UInt_t ndrows = 500, UInt_t ndcols = 20, UInt_t ntrows = 50, UInt_t ntcols = 10)
119{
120 TableTest *test = new TableTest(nullptr, ndrows, ndcols, ntrows, ntcols, 500, 200);
121 return test->GetTable();
122}
#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 ClassDefOverride(name, id)
Definition Rtypes.h:346
@ kDeepCleanup
Definition TGFrame.h:42
@ kLHintsExpandY
Definition TGLayout.h:31
@ kLHintsExpandX
Definition TGLayout.h:30
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize MapSubwindows
This class describes layout hints used by the layout classes.
Definition TGLayout.h:50
Defines top level windows that interact with the system Window Manager.
Definition TGFrame.h:397
To provide a simple class to visualize an array of doubles, the class TGSimpleTable is provided.
ROOT GUI Window base class.
Definition TGWindow.h:23
RooCmdArg Layout(double xmin, double xmax=0.99, double ymin=0.95)