GSI Object Oriented Online Offline (Go4)  GO4-6.3.0
TGo4TreeViewer.cpp
Go to the documentation of this file.
1 // $Id$
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, &QPushButton::clicked, this, &TGo4TreeViewer::TreeDrawBtn_clicked);
31  QObject::connect(TreeClearBtn, &QPushButton::clicked, this, &TGo4TreeViewer::TreeClearBtn_clicked);
32  QObject::connect(NewHistBtn, &QPushButton::clicked, this, &TGo4TreeViewer::NewHistBtn_clicked);
33  QObject::connect(XFieldEdt, &QGo4LineEdit::textDropped, this, &TGo4TreeViewer::XFieldEdt_dropped);
34  QObject::connect(XFieldEdt, &QGo4LineEdit::returnPressed, this, &TGo4TreeViewer::TreeDrawBtn_clicked);
35  QObject::connect(YFieldEdt, &QGo4LineEdit::textDropped, this, &TGo4TreeViewer::YFieldEdt_dropped);
36  QObject::connect(YFieldEdt, &QGo4LineEdit::returnPressed, this, &TGo4TreeViewer::TreeDrawBtn_clicked);
37  QObject::connect(ZFieldEdt, &QGo4LineEdit::textDropped, this, &TGo4TreeViewer::ZFieldEdt_dropped);
38  QObject::connect(ZFieldEdt, &QGo4LineEdit::returnPressed, this, &TGo4TreeViewer::TreeDrawBtn_clicked);
39  QObject::connect(CutEdt, &QGo4LineEdit::textDropped, this, &TGo4TreeViewer::cutEdit_dropped);
40  QObject::connect(CutEdt, &QGo4LineEdit::returnPressed, this, &TGo4TreeViewer::TreeDrawBtn_clicked);
41  QObject::connect(HistNameEdt, &QGo4LineEdit::returnPressed, this, &TGo4TreeViewer::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) return;
95 
96  if (fxTreeName.isEmpty()) {
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) 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()))
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 && 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)
TGo4ViewPanel * DrawItem(const QString &itemname, TGo4ViewPanel *panel=nullptr, TPad *pad=nullptr, bool activate=true, int updatelevel=-1)
Definition: QGo4Widget.cpp:305
TGo4BrowserProxy * Browser()
Definition: QGo4Widget.cpp:219
void requestedObjectCreated(const char *itemname, TClass *cl) override
virtual void TreeDrawBtn_clicked()
virtual void ProcessDropEvent(QGo4LineEdit *edt, bool caninit)
bool BrowserItemRemote(const char *itemname)
Definition: QGo4Widget.cpp:212
void StatusMessage(const QString &message)
Definition: QGo4Widget.cpp:239
virtual void ZFieldEdt_dropped()
void textDropped()
void ResetWidget() override
Bool_t DefineTreeName(const char *itemname, TString &treename)
void AskToCreateObject(TClass *cl, int isremote)
Definition: QGo4Widget.cpp:275
TGo4ViewPanel * WhereItemDrawn(const char *itemname)
Definition: QGo4Widget.cpp:316
virtual void cutEdit_dropped()
void AddLink(const char *itemname, const char *linkname)
Definition: QGo4Widget.cpp:117
TGo4TreeViewer(QWidget *parent=nullptr, const char *name=nullptr)