GSI Object Oriented Online Offline (Go4)  GO4-5.3.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4TreeViewer.cpp
Go to the documentation of this file.
1 // $Id: TGo4TreeViewer.cpp 1134 2014-01-22 14:53:40Z 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 für 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 #include "TObjArray.h"
16 #include "TObjString.h"
17 
18 #include <QApplication>
19 #include <QToolTip>
20 
21 #include "TH1.h"
22 #include "TClass.h"
23 #include "TGo4Slot.h"
24 #include "TGo4BrowserProxy.h"
25 
26 TGo4TreeViewer::TGo4TreeViewer(QWidget *parent, const char* name)
27  : QGo4Widget(parent, name)
28 {
29  setupUi(this);
30 
31  fxTreeName = "";
32  TreeDrawBtn->setEnabled(false);
33  setAcceptDrops(false);
34  setToolTip("Tree is not selected. Drag and drop leaf item from browser to X, Y or Z field");
35 }
36 
38 {
40  XFieldEdt->clear();
41  YFieldEdt->clear();
42  ZFieldEdt->clear();
43  HistNameEdt->clear();
44  CutEdt->clear();
45  TreeDrawBtn->setEnabled(false);
46  fxTreeName = "";
47  setToolTip("Tree is not selected. Drag and drop leaf item from browser to X, Y or Z field");
48 }
49 
50 void TGo4TreeViewer::WorkWithLeaf(const char* itemname)
51 {
52  ResetWidget();
53  XFieldEdt->setText(itemname);
54  ProcessDropEvent(XFieldEdt, true);
55 }
56 
58 {
59  ProcessDropEvent(XFieldEdt, true);
60 }
61 
63 {
64  ProcessDropEvent(YFieldEdt, true);
65 }
66 
68 {
69  ProcessDropEvent(ZFieldEdt, true);
70 }
71 
73 {
74  ProcessDropEvent(CutEdt, false);
75 }
76 
78 {
79  QString value = edt->text();
80 
81  TGo4BrowserProxy* br = Browser();
82  if (br==0) return;
83 
84  if (fxTreeName.length()==0) {
85  if (!caninit) {
86  StatusMessage("First drop something on X, Y or Z field");
87  edt->setText("");
88  return;
89  }
90 
91  TString treename;
92  if (!br->DefineTreeName(value.toLatin1().constData(), treename)) {
93  StatusMessage(QString("Invalid tree ") + value);
94  edt->setText("");
95  return;
96  }
97  fxTreeName = treename.Data();
98  setToolTip(QString("Selected tree: ") + fxTreeName);
99 
100  TreeDrawBtn->setEnabled(true);
101  AddLink(treename.Data(), "Tree");
102  }
103 
104  TString leafname;
105  if (!br->DefineLeafName(value.toLatin1().constData(), fxTreeName.toLatin1().constData(), leafname)) {
106  edt->setText("");
107  StatusMessage(QString("Invalid leaf name ") + value);
108  return;
109  }
110  // count number of [ and replace by []
111  // this means, by default accumulate over all members
112  TObjArray* it=leafname.Tokenize("[");
113  leafname=((TObjString *)it->First())->GetName();
114  for(Int_t i=1;i<it->GetEntriesFast();i++) leafname.Append("[]");
115  edt->setText(leafname.Data());
116  edt->setFocus();
117  it->Delete();
118 }
119 
121 {
122  if (fxTreeName.isEmpty()) {
123  StatusMessage("No tree specified");
124  return;
125  }
126 
127  if(XFieldEdt->text().isEmpty()) {
128  StatusMessage("Treedraw without x coordinate expression");
129  return;
130  }
131 
132  TGo4BrowserProxy* br = Browser();
133  if (br==0) return;
134 
135  QApplication::setOverrideCursor(Qt::WaitCursor);
136 
137  TString createdh;
138 
139  br->PerformTreeDraw(fxTreeName.toLatin1().constData(),
140  XFieldEdt->text().toLatin1().constData(),
141  YFieldEdt->text().toLatin1().constData(),
142  ZFieldEdt->text().toLatin1().constData(),
143  CutEdt->text().toLatin1().constData(),
144  HistNameEdt->text().toLatin1().constData(),
145  createdh);
146 
147  if (createdh.Length()>0) {
148  HistNameEdt->setText(createdh.Data());
149  DrawItem(createdh.Data());
150  } else {
151  if (WhereItemDrawn(HistNameEdt->text().toLatin1().constData())==0)
152  DrawItem(HistNameEdt->text());
153  else
154  br->RequestBrowserObject(HistNameEdt->text().toLatin1().constData());
155  }
156 
157  QApplication::restoreOverrideCursor();
158 }
159 
161 {
162  ResetWidget();
163 }
164 
166 {
167  if (fxTreeName.length()>0)
168  AskToCreateObject(TH1::Class(), BrowserItemRemote(fxTreeName.toLatin1().constData()) ? 1 : 0);
169 }
170 
171 void TGo4TreeViewer::requestedObjectCreated(const char* itemname, TClass* cl)
172 {
173  if ((cl!=0) && cl->InheritsFrom(TH1::Class()))
174  HistNameEdt->setText(itemname);
175 }
virtual void ResetWidget()
Definition: QGo4Widget.cpp:51
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:223
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:216
void StatusMessage(const QString &message)
Definition: QGo4Widget.cpp:244
virtual void ZFieldEdt_dropped()
TGo4ViewPanel * DrawItem(const QString &itemname, TGo4ViewPanel *panel=0, TPad *pad=0, bool activate=true, int updatelevel=-1)
Definition: QGo4Widget.cpp:311
Bool_t DefineTreeName(const char *itemname, TString &treename)
void AskToCreateObject(TClass *cl, int isremote)
Definition: QGo4Widget.cpp:281
virtual void ResetWidget()
TGo4ViewPanel * WhereItemDrawn(const char *itemname)
Definition: QGo4Widget.cpp:322
virtual void cutEdit_dropped()
void AddLink(const char *itemname, const char *linkname)
Definition: QGo4Widget.cpp:121