Diana Software
QGWindow.cc
Go to the documentation of this file.
1 #include "QGWindow.hh"
2 #include <algorithm>
3 #include <sstream>
4 #include "QGPlot.hh"
6 #include "QGPlotEditWindow.hh"
7 #include "TApplication.h"
8 
10 
11 using std::flush;
12 using std::list;
13 using std::string;
14 using std::stringstream;
15 
16 list<QGWindow*> QGWindow::fWindows;
17 
18 QGWindow::QGWindow(const TGWindow *p, UInt_t w, UInt_t h) :
19 TGMainFrame(p, w, h),
20 fWidth(w), fHeight(h)
21 {
22  SetWindowName();
23  fWindows.push_back(this);
24  SetCleanup(kDeepCleanup);
25 }
26 
28 {
29  if (find(fWindows.begin(), fWindows.end(), this) != fWindows.end()) {
30  fWindows.erase(find(fWindows.begin(), fWindows.end(), this));
31  }
33  Cleanup();
34  if (fWindows.size() == 0) {
35  gApplication->Terminate(0);
36  }
37 }
38 
39 QGWindow *QGWindow::GetWindowByName(const string& name)
40 {
41  QGWindow *window = 0;
42  list<QGWindow*>::const_iterator windowIter;
43  for (windowIter = fWindows.begin(); windowIter != fWindows.end(); ++windowIter) {
44  if ((*windowIter)->GetWindowName() == name) {
45  window = *windowIter;
46  break;
47  }
48  }
49  return window;
50 }
51 
52 void QGWindow::SetWindowName(const char *name)
53 {
54  if (name) {
55  string oldName = GetWindowName();
56  string newName = name;
57  if (newName != oldName) {
58  if (IsNameInUse(name)) {
59  TGMainFrame::SetWindowName(GenerateWindowName(newName).c_str());
60  } else {
61  TGMainFrame::SetWindowName(newName.c_str());
62  }
63  }
64  } else {
65  SetWindowName(GenerateWindowName("Diana GUI: Window ").c_str());
66  }
67 }
68 
69 bool QGWindow::IsNameInUse(string name)
70 {
71  bool inUse = false;
72  list<QGWindow*>::const_iterator windowIter;
73  for (windowIter = fWindows.begin(); windowIter != fWindows.end(); ++windowIter) {
74  if ((*windowIter)->GetWindowName() == name) {
75  inUse = true;
76  break;
77  }
78  }
79  return inUse;
80 }
81 
82 string QGWindow::GenerateWindowName(string baseName)
83 {
84  string name;
85  int i = 0;
86  do {
87  ++i;
88  stringstream index;
89  index << i << flush;
90  name = baseName + index.str();
91  } while (IsNameInUse(name));
92  return name;
93 }
94 
96 {
97  list<QGPlot*>::const_iterator plotIter;
98  for (plotIter = QGPlot::GetPlots().begin(); plotIter != QGPlot::GetPlots().end(); ++plotIter) {
99  if ((*plotIter)->GetEditWindow()) {
100  (*plotIter)->GetEditWindow()->GetButtonsFrame()->FillWindowDropDownBox();
101  }
102  }
103 }
104 
ClassImp(QObject)
static const std::list< QGPlot * > & GetPlots()
Get collection of plots.
Definition: QGPlot.hh:84
Base class for GUI windows.
Definition: QGWindow.hh:15
static std::list< QGWindow * > fWindows
Collection of pointers to all open QGWindows.
Definition: QGWindow.hh:49
static bool IsNameInUse(std::string name)
Check whether string is the name of any window.
Definition: QGWindow.cc:69
static std::string GenerateWindowName(std::string baseName)
Generate a name for the window.
Definition: QGWindow.cc:82
static void UpdateWindowDropDownBoxes()
Update window drop down boxes.
Definition: QGWindow.cc:95
static QGWindow * GetWindowByName(const std::string &name)
Get pointer to window with a given name.
Definition: QGWindow.cc:39
virtual void SetWindowName(const char *name=0)
Set name of window.
Definition: QGWindow.cc:52
QGWindow(const TGWindow *p=0, UInt_t w=100, UInt_t h=100)
Constructor.
Definition: QGWindow.cc:18
virtual ~QGWindow()
Destructor.
Definition: QGWindow.cc:27