Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "TGo4TreeViewer.h"
00015 #include "TObjArray.h"
00016 #include "TObjString.h"
00017
00018 #include <QApplication>
00019 #include <QToolTip>
00020
00021 #include "TH1.h"
00022 #include "TClass.h"
00023 #include "TGo4Slot.h"
00024 #include "TGo4BrowserProxy.h"
00025
00026 TGo4TreeViewer::TGo4TreeViewer(QWidget *parent, const char* name)
00027 : QGo4Widget(parent, name)
00028 {
00029 setupUi(this);
00030
00031 fxTreeName = "";
00032 TreeDrawBtn->setEnabled(false);
00033 setAcceptDrops(false);
00034 setToolTip("Tree is not selected. Drag and drop leaf item from browser to X, Y or Z field");
00035 }
00036
00037 void TGo4TreeViewer::ResetWidget()
00038 {
00039 QGo4Widget::ResetWidget();
00040 XFieldEdt->clear();
00041 YFieldEdt->clear();
00042 ZFieldEdt->clear();
00043 HistNameEdt->clear();
00044 CutEdt->clear();
00045 TreeDrawBtn->setEnabled(false);
00046 fxTreeName = "";
00047 setToolTip("Tree is not selected. Drag and drop leaf item from browser to X, Y or Z field");
00048 }
00049
00050 void TGo4TreeViewer::WorkWithLeaf(const char* itemname)
00051 {
00052 ResetWidget();
00053 XFieldEdt->setText(itemname);
00054 ProcessDropEvent(XFieldEdt, true);
00055 }
00056
00057 void TGo4TreeViewer::XFieldEdt_dropped()
00058 {
00059 ProcessDropEvent(XFieldEdt, true);
00060 }
00061
00062 void TGo4TreeViewer::YFieldEdt_dropped()
00063 {
00064 ProcessDropEvent(YFieldEdt, true);
00065 }
00066
00067 void TGo4TreeViewer::ZFieldEdt_dropped()
00068 {
00069 ProcessDropEvent(ZFieldEdt, true);
00070 }
00071
00072 void TGo4TreeViewer::cutEdit_dropped()
00073 {
00074 ProcessDropEvent(CutEdt, false);
00075 }
00076
00077 void TGo4TreeViewer::ProcessDropEvent(QGo4LineEdit* edt, bool caninit)
00078 {
00079 QString value = edt->text();
00080
00081 TGo4BrowserProxy* br = Browser();
00082 if (br==0) return;
00083
00084 if (fxTreeName.length()==0) {
00085 if (!caninit) {
00086 StatusMessage("First drop something on X, Y or Z field");
00087 edt->setText("");
00088 return;
00089 }
00090
00091 TString treename;
00092 if (!br->DefineTreeName(value.toLatin1().constData(), treename)) {
00093 StatusMessage(QString("Invalid tree ") + value);
00094 edt->setText("");
00095 return;
00096 }
00097 fxTreeName = treename.Data();
00098 setToolTip(QString("Selected tree: ") + fxTreeName);
00099
00100 TreeDrawBtn->setEnabled(true);
00101 AddLink(treename.Data(), "Tree");
00102 }
00103
00104 TString leafname;
00105 if (!br->DefineLeafName(value.toLatin1().constData(), fxTreeName.toLatin1().constData(), leafname)) {
00106 edt->setText("");
00107 StatusMessage(QString("Invalid leaf name ") + value);
00108 return;
00109 }
00110
00111
00112 TObjArray* it=leafname.Tokenize("[");
00113 leafname=((TObjString *)it->First())->GetName();
00114 for(Int_t i=1;i<it->GetEntriesFast();i++) leafname.Append("[]");
00115 edt->setText(leafname.Data());
00116 edt->setFocus();
00117 it->Delete();
00118 }
00119
00120 void TGo4TreeViewer::TreeDrawBtn_clicked()
00121 {
00122 if (fxTreeName.isEmpty()) {
00123 StatusMessage("No tree specified");
00124 return;
00125 }
00126
00127 if(XFieldEdt->text().isEmpty()) {
00128 StatusMessage("Treedraw without x coordinate expression");
00129 return;
00130 }
00131
00132 TGo4BrowserProxy* br = Browser();
00133 if (br==0) return;
00134
00135 QApplication::setOverrideCursor(Qt::WaitCursor);
00136
00137 TString createdh;
00138
00139 br->PerformTreeDraw(fxTreeName.toLatin1().constData(),
00140 XFieldEdt->text().toLatin1().constData(),
00141 YFieldEdt->text().toLatin1().constData(),
00142 ZFieldEdt->text().toLatin1().constData(),
00143 CutEdt->text().toLatin1().constData(),
00144 HistNameEdt->text().toLatin1().constData(),
00145 createdh);
00146
00147 if (createdh.Length()>0) {
00148 HistNameEdt->setText(createdh.Data());
00149 DrawItem(createdh.Data());
00150 } else {
00151 if (WhereItemDrawn(HistNameEdt->text().toLatin1().constData())==0)
00152 DrawItem(HistNameEdt->text());
00153 else
00154 br->RequestBrowserObject(HistNameEdt->text().toLatin1().constData());
00155 }
00156
00157 QApplication::restoreOverrideCursor();
00158 }
00159
00160 void TGo4TreeViewer::TreeClearBtn_clicked()
00161 {
00162 ResetWidget();
00163 }
00164
00165 void TGo4TreeViewer::NewHistBtn_clicked()
00166 {
00167 if (fxTreeName.length()>0)
00168 AskToCreateObject(TH1::Class(), BrowserItemRemote(fxTreeName.toLatin1().constData()) ? 1 : 0);
00169 }
00170
00171 void TGo4TreeViewer::requestedObjectCreated(const char* itemname, TClass* cl)
00172 {
00173 if ((cl!=0) && cl->InheritsFrom(TH1::Class()))
00174 HistNameEdt->setText(itemname);
00175 }