GSI Object Oriented Online Offline (Go4)  GO4-6.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4TreeViewer.cpp
Go to the documentation of this file.
1 // $Id: TGo4TreeViewer.cpp 3129 2021-03-30 09:46:41Z linev $
2 //-----------------------------------------------------------------------
3 // The GSI Online Offline Object Oriented (Go4) Project
4 // Experiment Data Processing at EE department, GSI
5 //-----------------------------------------------------------------------
6 // Copyright (C) 2000- GSI Helmholtzzentrum fuer Schwerionenforschung GmbH
7 // Planckstr. 1, 64291 Darmstadt, Germany
8 // Contact: http://go4.gsi.de
9 //-----------------------------------------------------------------------
10 // This software can be used under the license agreements as stated
11 // in Go4License.txt file which is part of the distribution.
12 //-----------------------------------------------------------------------
13 
14 #include "TGo4TreeViewer.h"
15 
16 #include "TObjArray.h"
17 #include "TObjString.h"
18 #include "TH1.h"
19 #include "TClass.h"
20 
21 #include <QApplication>
22 
23 #include "TGo4BrowserProxy.h"
24 
25 TGo4TreeViewer::TGo4TreeViewer(QWidget *parent, const char* name)
26  : QGo4Widget(parent, name)
27 {
28  setupUi(this);
29 
30  QObject::connect(TreeDrawBtn, SIGNAL(clicked()), this, SLOT(TreeDrawBtn_clicked()));
31  QObject::connect(TreeClearBtn, SIGNAL(clicked()), this, SLOT(TreeClearBtn_clicked()));
32  QObject::connect(NewHistBtn, SIGNAL(clicked()), this, SLOT(NewHistBtn_clicked()));
33  QObject::connect(XFieldEdt, SIGNAL(textDropped()), this, SLOT(XFieldEdt_dropped()));
34  QObject::connect(XFieldEdt, SIGNAL(returnPressed()), this, SLOT(TreeDrawBtn_clicked()));
35  QObject::connect(YFieldEdt, SIGNAL(textDropped()), this, SLOT(YFieldEdt_dropped()));
36  QObject::connect(YFieldEdt, SIGNAL(returnPressed()), this, SLOT(TreeDrawBtn_clicked()));
37  QObject::connect(ZFieldEdt, SIGNAL(textDropped()), this, SLOT(ZFieldEdt_dropped()));
38  QObject::connect(ZFieldEdt, SIGNAL(returnPressed()), this, SLOT(TreeDrawBtn_clicked()));
39  QObject::connect(CutEdt, SIGNAL(textDropped()), this, SLOT(cutEdit_dropped()));
40  QObject::connect(CutEdt, SIGNAL(returnPressed()), this, SLOT(TreeDrawBtn_clicked()));
41  QObject::connect(HistNameEdt, SIGNAL(returnPressed()), this, SLOT(TreeDrawBtn_clicked()));
42 
43  fxTreeName = "";
44  TreeDrawBtn->setEnabled(false);
45  setAcceptDrops(false);
46  setToolTip("Tree is not selected. Drag and drop leaf item from browser to X, Y or Z field");
47 }
48 
50 {
52  XFieldEdt->clear();
53  YFieldEdt->clear();
54  ZFieldEdt->clear();
55  HistNameEdt->clear();
56  CutEdt->clear();
57  TreeDrawBtn->setEnabled(false);
58  fxTreeName = "";
59  setToolTip("Tree is not selected. Drag and drop leaf item from browser to X, Y or Z field");
60 }
61 
62 void TGo4TreeViewer::WorkWithLeaf(const char* itemname)
63 {
64  ResetWidget();
65  XFieldEdt->setText(itemname);
66  ProcessDropEvent(XFieldEdt, true);
67 }
68 
70 {
71  ProcessDropEvent(XFieldEdt, true);
72 }
73 
75 {
76  ProcessDropEvent(YFieldEdt, true);
77 }
78 
80 {
81  ProcessDropEvent(ZFieldEdt, true);
82 }
83 
85 {
86  ProcessDropEvent(CutEdt, false);
87 }
88 
90 {
91  QString value = edt->text();
92 
93  TGo4BrowserProxy* br = Browser();
94  if (br==0) return;
95 
96  if (fxTreeName.length()==0) {
97  if (!caninit) {
98  StatusMessage("First drop something on X, Y or Z field");
99  edt->setText("");
100  return;
101  }
102 
103  TString treename;
104  if (!br->DefineTreeName(value.toLatin1().constData(), treename)) {
105  StatusMessage(QString("Invalid tree ") + value);
106  edt->setText("");
107  return;
108  }
109  fxTreeName = treename.Data();
110  setToolTip(QString("Selected tree: ") + fxTreeName);
111 
112  TreeDrawBtn->setEnabled(true);
113  AddLink(treename.Data(), "Tree");
114  }
115 
116  TString leafname;
117  if (!br->DefineLeafName(value.toLatin1().constData(), fxTreeName.toLatin1().constData(), leafname)) {
118  edt->setText("");
119  StatusMessage(QString("Invalid leaf name ") + value);
120  return;
121  }
122  // count number of [ and replace by []
123  // this means, by default accumulate over all members
124  TObjArray* it=leafname.Tokenize("[");
125  leafname=((TObjString *)it->First())->GetName();
126  for(Int_t i=1;i<it->GetEntriesFast();i++) leafname.Append("[]");
127  edt->setText(leafname.Data());
128  edt->setFocus();
129  it->Delete();
130 }
131 
133 {
134  if (fxTreeName.isEmpty()) {
135  StatusMessage("No tree specified");
136  return;
137  }
138 
139  if(XFieldEdt->text().isEmpty()) {
140  StatusMessage("Treedraw without x coordinate expression");
141  return;
142  }
143 
144  TGo4BrowserProxy* br = Browser();
145  if (br==0) return;
146 
147  QApplication::setOverrideCursor(Qt::WaitCursor);
148 
149  TString createdh;
150 
151  br->PerformTreeDraw(fxTreeName.toLatin1().constData(),
152  XFieldEdt->text().toLatin1().constData(),
153  YFieldEdt->text().toLatin1().constData(),
154  ZFieldEdt->text().toLatin1().constData(),
155  CutEdt->text().toLatin1().constData(),
156  HistNameEdt->text().toLatin1().constData(),
157  createdh);
158 
159  if (createdh.Length()>0) {
160  HistNameEdt->setText(createdh.Data());
161  DrawItem(createdh.Data());
162  } else {
163  if (WhereItemDrawn(HistNameEdt->text().toLatin1().constData())==0)
164  DrawItem(HistNameEdt->text());
165  else
166  br->RequestBrowserObject(HistNameEdt->text().toLatin1().constData());
167  }
168 
169  QApplication::restoreOverrideCursor();
170 }
171 
173 {
174  ResetWidget();
175 }
176 
178 {
179  if (fxTreeName.length()>0)
180  AskToCreateObject(TH1::Class(), BrowserItemRemote(fxTreeName.toLatin1().constData()) ? 1 : 0);
181 }
182 
183 void TGo4TreeViewer::requestedObjectCreated(const char* itemname, TClass* cl)
184 {
185  if ((cl!=0) && cl->InheritsFrom(TH1::Class()))
186  HistNameEdt->setText(itemname);
187 }
virtual void ResetWidget()
Definition: QGo4Widget.cpp:52
virtual void NewHistBtn_clicked()
virtual void WorkWithLeaf(const char *itemname)
virtual void XFieldEdt_dropped()
Bool_t DefineLeafName(const char *itemname, const char *treename, TString &leafname)
virtual void YFieldEdt_dropped()
void PerformTreeDraw(const char *treename, const char *Xexp, const char *Yexp, const char *Zexp, const char *cutcond, const char *hname, TString &createdhistoname)
QString fxTreeName
virtual void TreeClearBtn_clicked()
Int_t RequestBrowserObject(const char *name, Int_t wait_time=0)
TGo4BrowserProxy * Browser()
Definition: QGo4Widget.cpp:224
TGo4TreeViewer(QWidget *parent=0, const char *name=0)
virtual void TreeDrawBtn_clicked()
virtual void requestedObjectCreated(const char *itemname, TClass *cl)
virtual void ProcessDropEvent(QGo4LineEdit *edt, bool caninit)
bool BrowserItemRemote(const char *itemname)
Definition: QGo4Widget.cpp:217
void StatusMessage(const QString &message)
Definition: QGo4Widget.cpp:245
virtual void ZFieldEdt_dropped()
TGo4ViewPanel * DrawItem(const QString &itemname, TGo4ViewPanel *panel=0, TPad *pad=0, bool activate=true, int updatelevel=-1)
Definition: QGo4Widget.cpp:312
Bool_t DefineTreeName(const char *itemname, TString &treename)
void AskToCreateObject(TClass *cl, int isremote)
Definition: QGo4Widget.cpp:282
virtual void ResetWidget()
TGo4ViewPanel * WhereItemDrawn(const char *itemname)
Definition: QGo4Widget.cpp:323
virtual void cutEdit_dropped()
void AddLink(const char *itemname, const char *linkname)
Definition: QGo4Widget.cpp:122