Diana Software
QGHistogramParametersFrame.cc
Go to the documentation of this file.
2 #include <sstream>
3 #include "QGDropDownBox.hh"
5 #include "QGTextEntry.hh"
6 #include <TGLabel.h>
7 #include <TGTextEntry.h>
8 #include <TString.h>
9 
11 
12 using std::flush;
13 using std::string;
14 using std::stringstream;
15 
17 TGCompositeFrame(p, w, h),
18 fHistogramEditWindow(p)
19 {
20  SetCleanup(kDeepCleanup);
21 
22  fXFrame = new TGHorizontalFrame(this, w, 25);
23  AddFrame(fXFrame, new TGLayoutHints(kLHintsExpandX | kLHintsCenterY, 0, 0, 0, 0));
24 
25  fXLabel = new TGLabel(fXFrame, "X:");
26  fXFrame->AddFrame(fXLabel, new TGLayoutHints(kLHintsCenterY, 0, 0, 0, 0));
27 
29  fXFrame->AddFrame(fXDropDownBox, new TGLayoutHints(kLHintsExpandX | kLHintsCenterY, 2, 0, 0, 0));
31  fXDropDownBox->Resize(GetDefaultWidth(), 25);
32  fXDropDownBox->GetTextEntry()->SetToolTipText("Enter x-axis variable");
33  //fXDropDownBox->GetTextEntry()->Connect("ProcessedEvent(Event_t*)", "QGHistogramParametersFrame", this, "HandleXVariableEvent(Event_t*)");
34 
36  fXFrame->AddFrame(fXUnitsBox, new TGLayoutHints(kLHintsCenterY, 0, 0, 0, 0));
37  fXUnitsBox->Resize(50, 25);
38  fXUnitsBox->SetToolTipText("Enter x-axis units");
39  //fXUnitsBox->Connect("ProcessedEvent(Event_t*)", "QGHistogramParametersFrame", this, "HandleXUnitsEvent(Event_t*)");
40 
41  fMinMaxFrame = new TGHorizontalFrame(this, w, 25);
42  AddFrame(fMinMaxFrame, new TGLayoutHints(kLHintsExpandX | kLHintsCenterY, 0, 0, 2, 0));
43 
44  fXMinLabel = new TGLabel(fMinMaxFrame, "Min:");
45  fMinMaxFrame->AddFrame(fXMinLabel, new TGLayoutHints(kLHintsCenterY, 0, 0, 0, 0));
46 
48  fMinMaxFrame->AddFrame(fXMinBox, new TGLayoutHints(kLHintsExpandX | kLHintsCenterY, 2, 0, 0, 0));
49  fXMinBox->Resize(GetDefaultWidth(), 25);
50  fXMinBox->SetToolTipText("Enter x-axis minimum");
51  fXMinBox->Connect("ProcessedEvent(Event_t*)", "QGHistogramParametersFrame", this, "HandleXMinEvent(Event_t*)");
52 
53  fXMaxLabel = new TGLabel(fMinMaxFrame, "Max:");
54  fMinMaxFrame->AddFrame(fXMaxLabel, new TGLayoutHints(kLHintsCenterY, 10, 0, 0, 0));
55 
57  fMinMaxFrame->AddFrame(fXMaxBox, new TGLayoutHints(kLHintsExpandX | kLHintsCenterY, 2, 0, 0, 0));
58  fXMaxBox->Resize(GetDefaultWidth(), 25);
59  fXMaxBox->SetToolTipText("Enter x-axis maximum");
60  fXMaxBox->Connect("ProcessedEvent(Event_t*)", "QGHistogramParametersFrame", this, "HandleXMaxEvent(Event_t*)");
61 
62  fBinsFrame = new TGHorizontalFrame(this, w, 25);
63  AddFrame(fBinsFrame, new TGLayoutHints(kLHintsExpandX | kLHintsCenterY, 0, 0, 2, 0));
64 
65  fNumberOfBinsLabel = new TGLabel(fBinsFrame, "# of bins:");
66  fBinsFrame->AddFrame(fNumberOfBinsLabel, new TGLayoutHints(kLHintsCenterY, 0, 0, 0, 0));
67 
69  fBinsFrame->AddFrame(fNumberOfBinsBox, new TGLayoutHints(kLHintsExpandX | kLHintsCenterY, 2, 0, 0, 0));
70  fNumberOfBinsBox->Resize(GetDefaultWidth(), 25);
71  fNumberOfBinsBox->SetToolTipText("Enter number of bins");
72  fNumberOfBinsBox->Connect("ProcessedEvent(Event_t*)", "QGHistogramParametersFrame", this, "HandleNumberOfBinsEvent(Event_t*)");
73 
74  fBinWidthLabel = new TGLabel(fBinsFrame, "Bin width:");
75  fBinsFrame->AddFrame(fBinWidthLabel, new TGLayoutHints(kLHintsCenterY, 10, 0, 0, 0));
76 
78  fBinsFrame->AddFrame(fBinWidthBox, new TGLayoutHints(kLHintsExpandX | kLHintsCenterY, 2, 0, 0, 0));
79  fBinWidthBox->Resize(GetDefaultWidth(), 25);
80  fBinWidthBox->SetToolTipText("Enter bin width");
81  fBinWidthBox->Connect("ProcessedEvent(Event_t*)", "QGHistogramParametersFrame", this, "HandleBinWidthEvent(Event_t*)");
82 
83  fSuperimposeBox = new TGCheckButton(this, "Superimpose");
84  AddFrame(fSuperimposeBox, new TGLayoutHints(kLHintsLeft, 0, 0, 2, 0));
85  fSuperimposeBox->SetToolTipText("Check to superimpose histogram on existing histograms");
86 
92 }
93 
95 {
96  Cleanup();
97 }
98 
100 {
101  if (IsXMinSet() && IsXMaxSet() && IsNumberOfBinsSet()) {
102  if (GetXMax() > GetXMin() && GetNumberOfBins() > 0) {
104  }
105  }
106 }
107 
109 {
110  if (IsXMinSet() && IsXMaxSet() && IsBinWidthSet()) {
111  if (GetXMax() > GetXMin() && GetBinWidth() > 0) {
112  Int_t nBins = (Int_t) ((GetXMax() - GetXMin()) / GetBinWidth() + 0.5);
113  if (nBins == 0) {
114  nBins = 1;
115  }
116  SetNumberOfBins(nBins);
117  }
118  }
119 }
120 
122 {
123  Double_t width = 0;
124  if (IsBinWidthSet()) {
125  width = fBinWidthBox->GetDisplayText().Atof();
126  }
127  return width;
128 }
129 
131 {
132  Int_t nbins = 0;
133  if (fNumberOfBinsBox->GetDisplayText().IsDigit()) {
134  nbins = fNumberOfBinsBox->GetDisplayText().Atoi();
135  } else if (fNumberOfBinsBox->GetDisplayText().IsFloat()) {
136  nbins = (Int_t) fNumberOfBinsBox->GetDisplayText().Atof();
137  }
138  return nbins;
139 }
140 
142 {
143  Double_t xmax = 0;
144  if (IsXMaxSet()) {
145  xmax = fXMaxBox->GetDisplayText().Atof();
146  }
147  return xmax;
148 }
149 
151 {
152  Double_t xmin = 0;
153  if (IsXMinSet()) {
154  xmin = fXMinBox->GetDisplayText().Atof();
155  }
156  return xmin;
157 }
158 
160 {
161  return fXUnitsBox->GetText();
162 }
163 
165 {
166  return fXDropDownBox->GetTextEntry()->GetText();
167 }
168 
170 {
171  if (event->fType == kGKeyPress) { // key pressed
173  } else if (event->fType == kFocusOut) {
174  // fBinWidthBox->Deselect();
175  AutoSetBinWidth();
176  }
177 }
178 
180 {
181  if (event->fType == kGKeyPress) { // key pressed
182  AutoSetBinWidth();
183  }
184 }
185 
187 {
188  if (event->fType == kGKeyPress) { // key pressed
190  }
191 }
192 
194 {
195  if (event->fType == kGKeyPress) { // key pressed
197  }
198 }
199 
201 {
202  return fBinWidthBox->GetDisplayText().IsFloat();
203 }
204 
206 {
207  return fNumberOfBinsBox->GetDisplayText().IsFloat();
208 }
209 
211 {
212  return fSuperimposeBox->IsOn();
213 }
214 
216 {
217  return fXMaxBox->GetDisplayText().IsFloat();
218 }
219 
221 {
222  return fXMinBox->GetDisplayText().IsFloat();
223 }
224 
226 {
227  stringstream ss;
228  ss.precision(4);
229  ss << width << flush;
230  fBinWidthBox->SetText(ss.str().c_str());
231 }
232 
234 {
235  stringstream ss;
236  ss << n << flush;
237  fNumberOfBinsBox->SetText(ss.str().c_str());
238 }
239 
241 {
242  if (flag == true) {
243  fSuperimposeBox->SetState(kButtonDown);
244  } else {
245  fSuperimposeBox->SetState(kButtonUp);
246  }
247 }
248 
250 {
251  stringstream ss;
252  ss.precision(12);
253  ss << max << flush;
254  fXMaxBox->SetText(ss.str().c_str());
256  AutoSetBinWidth();
257 }
258 
260 {
261  stringstream ss;
262  ss.precision(12);
263  ss << min << flush;
264  fXMinBox->SetText(ss.str().c_str());
266  AutoSetBinWidth();
267 }
268 
269 void QGHistogramParametersFrame::SetXUnits(const string& units)
270 {
271  fXUnitsBox->SetText(units.c_str());
272 }
273 
275 {
276  fXDropDownBox->GetTextEntry()->SetText(x.c_str());
277 }
double max
Definition: CheckOF.C:53
ClassImp(QObject)
double min(const Diana::QVector &v)
Definition: QVector.cc:878
Drop down box with tab-complete.
void SetReturnTarget(TGTextEntry *textBox)
Set return target.
void EnableTabCompletion()
Enable tab completion.
Class for histogram edit window.
Part of a histogram edit window for inputting parameters.
TGHorizontalFrame * fXFrame
Horizontal frame for x-axis variable.
QGTextEntry * fNumberOfBinsBox
Number of bins box.
TGHorizontalFrame * fMinMaxFrame
Horizontal frame for x-axis minimum and maximum.
Double_t GetXMax()
Get x-axis maximum.
void SetNumberOfBins(Int_t n)
Set the number of bins.
QGTextEntry * fXMaxBox
X-axis maximum box.
void HandleXMinEvent(Event_t *event)
Handle event in x-axis minimum box.
void SetXMin(Double_t min)
Set the x-axis minimum.
TGHorizontalFrame * fBinsFrame
Horizontal frame for bins parameters.
void AutoSetBinWidth()
Set bin width automatically.
void HandleNumberOfBinsEvent(Event_t *event)
Handle event in number of bins box.
void SetXVariable(const std::string &x)
Set the x-axis variable.
std::string GetXUnits()
Get x-axis units.
QGHistogramParametersFrame(QGHistogramEditWindow *p=0, UInt_t w=100, UInt_t h=100)
Constructor.
QGDropDownBox * fXDropDownBox
X-axis variable drop down box.
void SetSuperimpose(bool flag=true)
Set whether the superimpose box is checked.
void HandleXMaxEvent(Event_t *event)
Handle event in x-axis maximum box.
void SetBinWidth(Double_t width)
Set the bin width.
bool IsXMaxSet()
Return true if x-axis maximum is set.
Int_t GetNumberOfBins()
Get number of bins.
void SetXUnits(const std::string &units)
Set the x-axis units.
TGCheckButton * fSuperimposeBox
Superimpose check box.
Double_t GetXMin()
Get x-axis minimum.
bool IsBinWidthSet()
Handle event in x-axis units box.
QGTextEntry * fBinWidthBox
Bin width box.
void HandleBinWidthEvent(Event_t *event)
Handle event in bin width box.
virtual ~QGHistogramParametersFrame()
Destructor.
bool IsNumberOfBinsSet()
Return true if number of bins is set.
void SetXMax(Double_t max)
Set the x-axis maximum.
QGTextEntry * fXMinBox
X-axis minimum box.
QGTextEntry * fXUnitsBox
X-axis units box.
bool IsSuperimposeSet()
Return true if superimpose box is checked.
bool IsXMinSet()
Return true if x-axis minimum is set.
std::string GetXVariable()
Get x-axis variable.
Double_t GetBinWidth()
Get bin width.
void AutoSetNumberOfBins()
Set number of bins automatically.
TGLabel * fBinWidthLabel
Bin width label.
TGLabel * fNumberOfBinsLabel
Number of bins label.
Extension of ROOT's basic text box TGTextEntry.
Definition: QGTextEntry.hh:13
void SetTabTarget(TGTextEntry *textBox)
Set text box to tab to.
Definition: QGTextEntry.cc:47