Diana Software
QGPlotListEntryFrame.cc
Go to the documentation of this file.
2 #include <string>
3 #include <typeinfo>
4 #include "QGGraphicalCut.hh"
5 #include "QGHistogram.hh"
6 #include "QGPlot.hh"
7 #include "QGPlotEditWindow.hh"
8 #include "QGPulse.hh"
9 #include "QGScatterPlot.hh"
10 #include <TCanvas.h>
11 #include <TColor.h>
12 #include <TGButton.h>
13 #include <TGPicture.h>
14 #include <TGTextEntry.h>
15 #include <TRootEmbeddedCanvas.h>
16 #include <TTimer.h>
17 
18 // Images
19 #include "ImageDelete.xpm"
20 #include "ImageDraw.xpm"
21 #include "ImageEdit.xpm"
22 
24 
25 using std::string;
26 
27 QGPlotListEntryFrame::QGPlotListEntryFrame(TGWindow *p, UInt_t w, UInt_t h) :
28 TGHorizontalFrame(p, w, h)
29 {
30  SetCleanup(kDeepCleanup);
31  SetBackgroundColor(TColor::RGB2Pixel(110, 110, 110));
32 }
33 
35 {
36  Cleanup();
37 }
38 
40 {
41  if (fPlot) {
42  fPlot->Erase();
43  delete fPlot; // deleting fPlot will result in this QGPlotListEntryFrame being deleted as well
44  fPlot = 0;
45  }
46 }
47 
49 {
50  TTimer::SingleShot(50, "QGPlotListEntryFrame", this, "DeletePlot()");
51  // The reason for this timer is to allow the Delete button to emit all its signals
52  // before the button is deleted. If the "Clicked" signal of the Delete button were
53  // connected directly to the DeletePlot() method without the timer, the button
54  // itself would be deleted possibly before finishing emitting all its signals,
55  // causing a crash.
56 }
57 
59 {
60  if (fPlot) {
61  fPlot->Plot();
62  }
63 }
64 
66 {
67  if (fPlot) {
69  }
70 }
71 
73 {
74  if (plot) {
75  fPlot = plot;
76 
77  fEmbeddedCanvas = new TRootEmbeddedCanvas("Canvas", this, 40, 40);
78  fEmbeddedCanvas->GetCanvas()->SetBorderMode(0);
79  fEmbeddedCanvas->GetCanvas()->cd();
80  AddFrame(fEmbeddedCanvas, new TGLayoutHints(kLHintsCenterY, 5, 0, 0, 0));
81 
82  fNameBox = new TGTextEntry(this);
83  fNameBox->Resize(fNameBox->GetDefaultWidth(), 25);
84  fNameBox->SetAlignment(kTextCenterX);
85  fNameBox->SetText(plot->GetName());
86  fNameBox->SetEnabled(kFALSE);
87  AddFrame(fNameBox, new TGLayoutHints(kLHintsExpandX | kLHintsCenterY, 5, 0, 0, 0));
88 
89  fDrawButton = new TGPictureButton(this, gClient->GetPicturePool()->GetPicture("Draw", (char**)ImageDraw));
90  fDrawButton->Connect("Clicked()", "QGPlotListEntryFrame", this, "HandleDrawButton()");
91  fDrawButton->SetToolTipText("Draw the plot");
92 
93  fDeleteButton = new TGPictureButton(this, gClient->GetPicturePool()->GetPicture("Delete", (char**)ImageDelete));
94  fDeleteButton->Connect("Clicked()", "QGPlotListEntryFrame", this, "HandleDeleteButton()");
95 
96  if (QGHistogram *histogram = dynamic_cast<QGHistogram*>(plot)) {
97  histogram->DrawStyleHistogram();
98  fEmbeddedCanvas->GetCanvas()->Update();
99  fEditButton = new TGPictureButton(this, gClient->GetPicturePool()->GetPicture("Edit", (char**)ImageEdit));
100  fEditButton->Connect("Clicked()", "QGPlotListEntryFrame", this, "HandleEditButton()");
101  fEditButton->SetToolTipText("Display histogram edit window");
102  fDeleteButton->SetToolTipText("Delete the histogram");
103  AddFrame(fDrawButton, new TGLayoutHints(kLHintsCenterY, 5, 0, 0, 0));
104  AddFrame(fEditButton, new TGLayoutHints(kLHintsCenterY, 0, 0, 0, 0));
105  AddFrame(fDeleteButton, new TGLayoutHints(kLHintsCenterY, 0, 5, 0, 0));
106  } else if (QGScatterPlot *scatterPlot = dynamic_cast<QGScatterPlot*>(plot)) {
107  scatterPlot->DrawStyleScatterPlot();
108  fEmbeddedCanvas->GetCanvas()->Update();
109  fEditButton = new TGPictureButton(this, gClient->GetPicturePool()->GetPicture("Edit", (char**)ImageEdit));
110  fEditButton->Connect("Clicked()", "QGPlotListEntryFrame", this, "HandleEditButton()");
111  fEditButton->SetToolTipText("Display scatter plot edit window");
112  fDeleteButton->SetToolTipText("Delete the scatter plot");
113  AddFrame(fDrawButton, new TGLayoutHints(kLHintsCenterY, 5, 0, 0, 0));
114  AddFrame(fEditButton, new TGLayoutHints(kLHintsCenterY, 0, 0, 0, 0));
115  AddFrame(fDeleteButton, new TGLayoutHints(kLHintsCenterY, 0, 5, 0, 0));
116  } else if (QGPulse *pulse = dynamic_cast<QGPulse*>(plot)) {
117  pulse->DrawStylePulse();
118  fEmbeddedCanvas->GetCanvas()->Update();
119  fEditButton = new TGPictureButton(this, gClient->GetPicturePool()->GetPicture("Edit", (char**)ImageEdit));
120  fEditButton->Connect("Clicked()", "QGPlotListEntryFrame", this, "HandleEditButton()");
121  fEditButton->SetToolTipText("Display pulse edit window");
122  fDeleteButton->SetToolTipText("Delete the pulse plot");
123  AddFrame(fDrawButton, new TGLayoutHints(kLHintsCenterY, 5, 0, 0, 0));
124  AddFrame(fEditButton, new TGLayoutHints(kLHintsCenterY, 0, 0, 0, 0));
125  AddFrame(fDeleteButton, new TGLayoutHints(kLHintsCenterY, 0, 5, 0, 0));
126  } else if (typeid(*plot) == typeid(QGGraphicalCut)) {
127  AddFrame(fDrawButton, new TGLayoutHints(kLHintsCenterY, 5, 0, 0, 0));
128  fDeleteButton->SetToolTipText("Delete the graphical cut");
129  AddFrame(fDeleteButton, new TGLayoutHints(kLHintsCenterY, 0, 5, 0, 0));
130  }
131  fEmbeddedCanvas->GetCanvas()->Update();
132  fEmbeddedCanvas->GetCanvas()->SetEditable(kFALSE);
133  }
134 }
ClassImp(QObject)
Class for graphical cuts.
Class for GUI histograms.
Definition: QGHistogram.hh:19
Class for entries in the plot list.
TGPictureButton * fDrawButton
Draw button.
void HandleDrawButton()
Handle draw button.
virtual ~QGPlotListEntryFrame()
Destructor.
void HandleDeleteButton()
Handle delete button.
TGTextEntry * fNameBox
Box for plot name.
TGPictureButton * fDeleteButton
Delete button.
QGPlot * fPlot
Plot represented by this entry.
TRootEmbeddedCanvas * fEmbeddedCanvas
Embedded canvas for style preview.
void HandleEditButton()
Handle edit button.
void DeletePlot()
Delete associated plot.
TGPictureButton * fEditButton
Edit button.
void SetPlot(QGPlot *plot)
Set plot that this entry represents.
QGPlotListEntryFrame(TGWindow *p=0, UInt_t w=10, UInt_t h=10)
Constructor.
Base class for GUI plots including histograms, scatter plots, pulses, and graphical cuts.
Definition: QGPlot.hh:21
virtual const char * GetName() const
Get plot name, should be overridden by derived classes.
Definition: QGPlot.cc:144
virtual void Plot()
Plot this in the associated canvas window, generating it if necessary.
Definition: QGPlot.cc:195
virtual void DisplayEditWindow()
Display edit window for the plot, should be overridden by derived classes.
Definition: QGPlot.cc:77
virtual void Erase()
Erase plot, should be overridden by derived classes.
Definition: QGPlot.cc:88
Class for GUI pulse plots.
Definition: QGPulse.hh:18
Class for GUI scatter plots.