Diana Software
QGCanvasWindow.cc
Go to the documentation of this file.
1 #include "QGCanvasWindow.hh"
2 #include <algorithm>
3 #include <iostream>
4 #include "QGCanvasSetupFrame.hh"
6 #include "QGFileHandler.hh"
7 #include "QStyle.hh"
8 #include "QGHistogram.hh"
9 #include "QGPlot.hh"
10 #include "QGPlotEditWindow.hh"
11 #include "QGPlotFrame.hh"
12 #include "QGSessionHandler.hh"
13 #include "TCanvas.h"
14 #include "TGButton.h"
15 #include "TGLabel.h"
16 #include "TRootEmbeddedCanvas.h"
17 #include "TInterpreter.h"
18 
20 
21 using std::cout;
22 using std::endl;
23 using std::list;
24 using std::string;
25 using std::vector;
26 
27 TStyle* QStyle = 0;
28 
29 QGCanvasWindow::QGCanvasWindow(const TGWindow *p, UInt_t w, UInt_t h) :
30 QGWindow(p, w, h),
31 fFileHandler(0), fPlotFrame(0), fSetupFrame(0)
32 {
33  if(!QStyle) new QStyles;
34 
35  gInterpreter->ProcessLine("using namespace Diana;");
37 
38  fSetupFrame = new QGCanvasSetupFrame(this, w, h);
39  AddFrame(fSetupFrame, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY, 2, 2, 2, 0));
40 
41  fPlotFrame = new QGPlotFrame(this, w, h);
42  AddFrame(fPlotFrame, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 2, 2, 2, 0));
43 
44  fFilenameLabel = new TGLabel(this, "File: ");
45  AddFrame(fFilenameLabel, new TGLayoutHints(kLHintsLeft, 2, 2, 2, 0));
46 
48  AddFrame(fButtonsFrame, new TGLayoutHints(kLHintsBottom, 2, 2, 2, 2));
49 
50  Resize(w, h);
51  MapSubwindows();
55  MapWindow();
56 
58 }
59 
61 {
62  // disassociate plots from this canvas window
63  while (fPlots.begin() != fPlots.end()) {
64  (*fPlots.begin())->SetCanvasWindow(0); // removes this plot from the list
65  }
66  delete fFileHandler;
67 }
68 
70 {
71  if (plot == 0) {
72  cout << "QGCanvasWindow::AddPlot(QGPlot *plot) Warning: plot == 0" << endl;
73  } else if (find(fPlots.begin(), fPlots.end(), plot) == fPlots.end()) {
74  fPlots.push_back(plot);
75  }
76 }
77 
79 {
80  if (plot == 0) {
81  cout << "QGCanvasWindow::AddToDrawnPlots(QGPlot *plot) Warning: plot == 0" << endl;
82  } else if (find(fDrawnPlots.begin(), fDrawnPlots.end(), plot) == fDrawnPlots.end()) {
83  fDrawnPlots.push_back(plot);
84  }
85 }
86 
88 {
89  fDrawnPlots.clear();
90 }
91 
93 {
94  HideFrame(fSetupFrame);
95  ShowFrame(fPlotFrame);
96  ShowFrame(fFilenameLabel);
97  if (fFileHandler->IsFileOpen()) {
98  ShowFrame(fFilenameLabel);
99  } else {
100  HideFrame(fFilenameLabel);
101  }
103 }
104 
106 {
107  HideFrame(fPlotFrame);
109  ShowFrame(fSetupFrame);
110  if (fFileHandler->IsFileOpen()) {
111  ShowFrame(fFilenameLabel);
112  } else {
113  HideFrame(fFilenameLabel);
114  }
116 }
117 
119 {
120  if (find(fDrawnPlots.begin(), fDrawnPlots.end(), plot) != fDrawnPlots.end()) {
121  fDrawnPlots.erase(find(fDrawnPlots.begin(), fDrawnPlots.end(), plot));
122  }
123 }
124 
126 {
127  if (find(fPlots.begin(), fPlots.end(), plot) != fPlots.end()) {
128  fPlots.erase(find(fPlots.begin(), fPlots.end(), plot));
129  }
130  RemoveFromDrawnPlots(plot);
131 }
132 
134 {
135  list<QGPlot*>::const_iterator plotIter;
136  for (plotIter = fPlots.begin(); plotIter != fPlots.end(); ++plotIter) {
137  (*plotIter)->SetRegenerate();
138  }
139 }
140 
141 void QGCanvasWindow::SetProperty(string key, string value)
142 {
143  if (key == FILE_KEY) {
144  GetFileHandler()->OpenFile(value);
145  if (GetFileHandler()->IsFileOpen()) {
147  UpdateFileLabel();
148  }
151  }
152 }
153 
155 {
156  if (GetFileHandler()->IsFileOpen()) {
157  string label = "File: ";
158  vector<string> filenames = GetFileHandler()->GetFilenames();
159  if (filenames.size() == 1) {
160  string::size_type pos = filenames[0].find("/");
161  if (pos == string::npos) {
162  label += filenames[0];
163  } else {
164  label += filenames[0].substr(filenames[0].rfind("/") + 1);
165  }
166  } else if (filenames.size() > 1) {
167  label += "Multiple files";
168  }
169  fFilenameLabel->SetText(label.c_str());
170  fFilenameLabel->Resize();
171  }
172 }
173 
175 {
176  list<QGPlot*>::const_iterator plotIter;
177  for (plotIter = fPlots.begin(); plotIter != fPlots.end(); ++plotIter) {
178  if ((*plotIter)->GetEditWindow()) {
179  (*plotIter)->GetEditWindow()->FillVariablesDropDownBoxes();
180  }
181  }
182 }
183 
#define FILE_KEY
ClassImp(QObject)
Part of a canvas window for doing setup tasks.
void SetDisplay()
Set the display based on the current state.
Part of a canvas window containing control buttons.
void ShowSetupWindowDisplay()
Show setup window display, hide everything except back-to-plots button.
void ShowDefaultDisplay()
Show default display, hide certain elements.
Window containing a ROOT canvas.
TGLabel * fFilenameLabel
Filename label.
QGCanvasSetupFrame * fSetupFrame
Setup frame.
void RemovePlot(QGPlot *plot)
Remove pointer to a plot from the list of plots associated with this window.
std::list< QGPlot * > fDrawnPlots
Collection of currently drawn plots in this window.
void RemoveFromDrawnPlots(QGPlot *plot)
Remove pointer to a plot from the list of drawn plots.
void DisplayPlotFrame()
Display the plot frame.
QGCanvasWindow(const TGWindow *p=0, UInt_t w=600, UInt_t h=450)
Constructor.
QGCanvasWindowButtonsFrame * fButtonsFrame
Buttons frame.
QGFileHandler * fFileHandler
File handler.
void AddToDrawnPlots(QGPlot *plot)
Add pointer to a plot to the list of drawn plots.
void DisplaySetupFrame()
Display the setup frame.
void AddPlot(QGPlot *plot)
Add pointer to a plot to the list of plots associated with this window.
QGPlotFrame * fPlotFrame
Plot frame.
virtual ~QGCanvasWindow()
Destructor.
void SetProperty(std::string key, std::string value)
Set property (used for opening a session)
void SetPlotsToRegenerate()
Set regenerate for each plot associated with this window.
QGFileHandler * GetFileHandler() const
Get pointer to file handler.
std::list< QGPlot * > fPlots
Collection of plots associated with this window.
void ClearDrawnPlots()
Clears the collection of drawn plots.
void UpdateVariablesDropDownBoxes()
Update variables drop down boxes for plots associated with this window.
void UpdateFileLabel()
Update the file label.
Class to handle ROOT files.
bool IsFileOpen()
Check whether a file is open.
void OpenFile()
Pop up a file open dialog.
std::vector< std::string > GetFilenames()
Get a vector containing the names of the open files.
Part of a canvas window containing the ROOT canvas.
Definition: QGPlotFrame.hh:17
Base class for GUI plots including histograms, scatter plots, pulses, and graphical cuts.
Definition: QGPlot.hh:21
Base class for GUI windows.
Definition: QGWindow.hh:15
static void UpdateWindowDropDownBoxes()
Update window drop down boxes.
Definition: QGWindow.cc:95
Definition: QStyle.hh:6
std::string Resize(const std::string &s, size_t len)
resize a string to len, adding spaces if necessary