00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "TGo4EditDynEntry.h"
00015
00016 #include <QMessageBox>
00017 #include <QToolTip>
00018
00019 #include "TClass.h"
00020 #include "TH1.h"
00021 #include "TTree.h"
00022 #include "QGo4LineEdit.h"
00023 #include "TGo4TreeHistogramEntry.h"
00024 #include "TGo4HistogramEntry.h"
00025 #include "TGo4DynamicEntry.h"
00026 #include "TGo4Condition.h"
00027 #include "TGo4Slot.h"
00028 #include "TGo4BrowserProxy.h"
00029 #include "TGo4AnalysisProxy.h"
00030
00031
00032 TGo4EditDynEntry::TGo4EditDynEntry(QWidget *parent, const char* name)
00033 : QGo4Widget(parent, name)
00034 {
00035 setupUi(this);
00036
00037 fbTypingMode = true;
00038 fiSelectedType = entry_None;
00039 ResetWidget();
00040 }
00041
00042 bool TGo4EditDynEntry::IsAcceptDrag(const char* itemname, TClass* cl, int kind)
00043 {
00044 if (cl==0) return false;
00045
00046 return cl->InheritsFrom(TGo4DynamicEntry::Class()) ||
00047 cl->InheritsFrom(TH1::Class()) ||
00048 cl->InheritsFrom(TTree::Class()) ||
00049 cl->InheritsFrom(TGo4Condition::Class());
00050 }
00051
00052 void TGo4EditDynEntry::DropItem(const char* itemname, TClass* cl, int kind)
00053 {
00054 if (cl==0) return;
00055
00056 if (cl->InheritsFrom(TGo4DynamicEntry::Class()))
00057 WorkWithEntry(itemname);
00058 else
00059 if (cl->InheritsFrom(TH1::Class()))
00060 DropHistogram(itemname);
00061 else
00062 if (cl->InheritsFrom(TGo4Condition::Class()))
00063 DropCondition(itemname);
00064 else
00065 if (cl->InheritsFrom(TTree::Class()))
00066 DropTree(itemname);
00067 }
00068
00069 void TGo4EditDynEntry::linkedObjectUpdated(const char* linkname, TObject* obj)
00070 {
00071 if (strcmp(linkname, "Entry")==0)
00072 SetPleaseUpdate(false);
00073
00074 RefreshWidget();
00075 }
00076
00077 void TGo4EditDynEntry::RefreshWidget()
00078 {
00079 TGo4DynamicEntry* entry =
00080 dynamic_cast<TGo4DynamicEntry*>(GetLinked("Entry", 0));
00081
00082 TGo4BrowserProxy* br = Browser();
00083
00084 if ((entry==0) || (br==0)) return;
00085
00086 fiSelectedType = entry_None;
00087
00088 fbTypingMode = false;
00089
00090 EntryBox->setTitle(QString("Entry: ") + entry->ClassName());
00091 EntryEnabledButton->setChecked(entry->IsEnabledProcessing());
00092
00093 EntryBox->setEnabled(true);
00094 HistogramBox->setEnabled(true);
00095 EntryTabs->setEnabled(true);
00096
00097 TGo4HistogramEntry* hentry = dynamic_cast<TGo4HistogramEntry*> (entry);
00098 TGo4TreeHistogramEntry* tentry = dynamic_cast<TGo4TreeHistogramEntry*> (entry);
00099
00100 const char* entryitem = GetLinkedName("Entry");
00101
00102 if (hentry!=0) {
00103 fiSelectedType = entry_Histogram;
00104
00105 EntryTabs->setTabEnabled(EntryTabs->indexOf(EventTab), true);
00106 EntryTabs->setTabEnabled(EntryTabs->indexOf(ConditionTab), true);
00107 EntryTabs->setTabEnabled(EntryTabs->indexOf(TreeTab), false);
00108 EntryTabs->setCurrentIndex(EntryTabs->indexOf(EventTab));
00109
00110 TString hitemname;
00111 if (!br->DefineRelatedObject(entryitem,
00112 hentry->GetHistogramName(), hitemname))
00113 hitemname = hentry->GetHistogramName();
00114 HistoNameLbl->setText(hitemname.Data());
00115 DrawButton->setVisible(hitemname.Length()>0);
00116 ClearButton->setVisible(hitemname.Length()>0);
00117
00118 QString fname = hentry->GetHistEventName(0);
00119 if (fname.length()>0) fname += "/";
00120 fname += hentry->GetHistVarName(0);
00121 EvXnameEdit->setText(fname);
00122
00123 fname = hentry->GetHistEventName(1);
00124 if (fname.length()>0) fname += "/";
00125 fname += hentry->GetHistVarName(1);
00126 EvYnameEdit->setText(fname);
00127
00128 fname = hentry->GetHistEventName(2);
00129 if (fname.length()>0) fname += "/";
00130 fname += hentry->GetHistVarName(2);
00131 EvZnameEdit->setText(fname);
00132
00133 TString citemname;
00134 if (!br->DefineRelatedObject(entryitem,
00135 hentry->GetConditionName(), citemname))
00136 citemname = hentry->GetConditionName();
00137 CondNameLbl->setText(citemname.Data());
00138
00139 fname = hentry->GetConEventName(0);
00140 if (fname.length()>0) fname += "/";
00141 fname += hentry->GetConVarName(0);
00142 ConXnameEdit->setText(fname);
00143
00144 fname = hentry->GetConEventName(1);
00145 if (fname.length()>0) fname += "/";
00146 fname += hentry->GetConVarName(1);
00147 ConYnameEdit->setText(fname);
00148 } else
00149 if (tentry!=0) {
00150 fiSelectedType = entry_Tree;
00151
00152 EntryTabs->setTabEnabled(EntryTabs->indexOf(EventTab), false);
00153 EntryTabs->setTabEnabled(EntryTabs->indexOf(ConditionTab), false);
00154 EntryTabs->setTabEnabled(EntryTabs->indexOf(TreeTab), true);
00155 EntryTabs->setCurrentIndex(EntryTabs->indexOf(TreeTab));
00156
00157 TString hitemname;
00158 if (!br->DefineRelatedObject(entryitem,
00159 tentry->GetHistogramName(), hitemname))
00160 hitemname = tentry->GetHistogramName();
00161 HistoNameLbl->setText(hitemname.Data());
00162 DrawButton->setVisible(hitemname.Length()>0);
00163 ClearButton->setVisible(hitemname.Length()>0);
00164
00165 TString titemname;
00166 if (!br->DefineRelatedObject(entryitem,
00167 tentry->GetTreeName(), titemname))
00168 titemname = tentry->GetTreeName();
00169 TreeNameLbl->setText(titemname.Data());
00170
00171 DrawExprEdit->setText(tentry->GetVarExp());
00172 CutExprEdit->setText(tentry->GetCutExp());
00173 DynIntervalSpin->setValue(tentry->GetDynListInterval());
00174 }
00175
00176 fbTypingMode = true;
00177 }
00178
00179 QString TGo4EditDynEntry::GetEventName(const QString& itemname)
00180 {
00181 TString folder, name;
00182 TGo4Slot::ProduceFolderAndName(itemname.toLatin1().constData(), folder, name);
00183
00184
00185
00186
00187 return QString(folder.Data());
00188 }
00189
00190 QString TGo4EditDynEntry::GetEventMember(const QString& itemname)
00191 {
00192 TString folder, name;
00193 TGo4Slot::ProduceFolderAndName(itemname.toLatin1().constData(), folder, name);
00194 return QString(name.Data());
00195 }
00196
00197 void TGo4EditDynEntry::WorkWithEntry(const char* itemname)
00198 {
00199 TGo4DynamicEntry* entry =
00200 dynamic_cast<TGo4DynamicEntry*>(GetLinked("Entry", 0));
00201 const char* oldname = GetLinkedName("Entry");
00202
00203 if ((entry!=0) && (oldname!=0) && PleaseUpdateLabel->isVisible()) {
00204
00205 int res = QMessageBox::warning(this, "Dynamic list entry editor",
00206 QString("Current entry ")+oldname+" is modified!\n New entry" +
00207 itemname+ " selected.",
00208 QString("Continue with current"),
00209 QString("Start with new"), QString::null, 0);
00210
00211 if (res==0) return;
00212
00213 }
00214
00215 ResetWidget();
00216
00217 AddLink(itemname, "Entry");
00218
00219 EntryNameLbl->setText(itemname);
00220
00221 QString iconname = ":/icons/right.png";
00222 QString tooltip = "Refresh dynamic entry from analysis";
00223 if (!BrowserItemRemote(itemname)) {
00224 iconname = ":/icons/refresh.png";
00225 tooltip = "Refresh dynamic entry from source";
00226 }
00227 RefreshButton->setIcon( QIcon(iconname) );
00228 RefreshButton->setToolTip(tooltip);
00229
00230 GetLinked("Entry", 2);
00231 RefreshWidget();
00232
00233 SetPleaseUpdate(false);
00234 parentWidget()->adjustSize();
00235 parentWidget()->setFocus();
00236 }
00237
00238 void TGo4EditDynEntry::DropHistogram(const char * itemname)
00239 {
00240 if (itemname==0) return;
00241
00242 EntryChangedSlot();
00243
00244 HistoNameLbl->setText(itemname);
00245 DrawButton->setVisible(true);
00246 ClearButton->setVisible(true);
00247
00248 TGo4DynamicEntry* entry =
00249 dynamic_cast<TGo4DynamicEntry*>(GetLinked("Entry", 0));
00250
00251 TGo4HistogramEntry* hentry = dynamic_cast<TGo4HistogramEntry*> (entry);
00252 TGo4TreeHistogramEntry* tentry = dynamic_cast<TGo4TreeHistogramEntry*> (entry);
00253 if (hentry!=0)
00254 hentry->SetHistogramName(itemname);
00255 if (tentry!=0)
00256 tentry->SetHistogramName(itemname);
00257 }
00258
00259 void TGo4EditDynEntry::DropCondition( const char * itemname )
00260 {
00261 if (fiSelectedType != entry_Histogram) return;
00262
00263 EntryChangedSlot();
00264
00265 CondNameLbl->setText(itemname);
00266
00267 EntryTabs->setCurrentIndex(EntryTabs->indexOf(ConditionTab));
00268 TGo4HistogramEntry* hentry =
00269 dynamic_cast<TGo4HistogramEntry*> (GetLinked("Entry", 0));
00270 if (hentry!=0)
00271 hentry->SetConditionName(itemname);
00272 }
00273
00274 void TGo4EditDynEntry::DropTree( const char * itemname )
00275 {
00276 if (fiSelectedType != entry_Tree) return;
00277
00278 EntryChangedSlot();
00279
00280 TreeNameLbl->setText(itemname);
00281
00282 TGo4TreeHistogramEntry* tentry =
00283 dynamic_cast<TGo4TreeHistogramEntry*> (GetLinked("Entry", 0));
00284 if (tentry!=0)
00285 tentry->SetTreeName(itemname);
00286 }
00287
00288 void TGo4EditDynEntry::ResetWidget()
00289 {
00290 QGo4Widget::ResetWidget();
00291
00292 fiSelectedType = entry_None;
00293
00294 EntryNameLbl->setText("");
00295 EntryBox->setTitle(QString("Entry: "));
00296
00297 EntryBox->setEnabled(false);
00298 HistogramBox->setEnabled(false);
00299 EntryTabs->setEnabled(false);
00300
00301 DrawButton->setVisible(false);
00302
00303 RefreshButton->setIcon( QIcon(":/icons/right.png" ) );
00304
00305 SetPleaseUpdate(false);
00306 }
00307
00308 void TGo4EditDynEntry::RefreshClicked()
00309 {
00310 GetLinked("Entry", 2);
00311 RefreshWidget();
00312 }
00313
00314 void TGo4EditDynEntry::ApplyClicked()
00315 {
00316 if (!PrepareEntryForAnalysis()) return;
00317
00318 if (UpdateItemInAnalysis(GetLinkedName("Entry"))) {
00319 SetPleaseUpdate(false);
00320 RefreshWidget();
00321 }
00322 }
00323
00324 void TGo4EditDynEntry::SetPleaseUpdate( bool on )
00325 {
00326 PleaseUpdateLabel->setVisible(on);
00327 ensurePolished();
00328 update();
00329 show();
00330 }
00331
00332 void TGo4EditDynEntry::EntryChangedSlot()
00333 {
00334 if(!PleaseUpdateLabel->isVisible())
00335 SetPleaseUpdate(true);
00336 }
00337
00338 void TGo4EditDynEntry::SaveEntrySlot()
00339 {
00340 if (!PrepareEntryForAnalysis()) return;
00341
00342 if (SaveItemToFile(GetLinkedName("Entry"), "DynamicLists"))
00343 SetPleaseUpdate(false);
00344 }
00345
00346 void TGo4EditDynEntry::EvXnameEdit_dropped()
00347 {
00348 ProcessDropEvent(EvXnameEdit);
00349 }
00350
00351 void TGo4EditDynEntry::EvYnameEdit_dropped()
00352 {
00353 ProcessDropEvent(EvYnameEdit);
00354 }
00355
00356 void TGo4EditDynEntry::EvZnameEdit_dropped()
00357 {
00358 ProcessDropEvent(EvZnameEdit);
00359 }
00360
00361 void TGo4EditDynEntry::ConXnameEdit_dropped()
00362 {
00363 ProcessDropEvent(ConXnameEdit);
00364 }
00365
00366 void TGo4EditDynEntry::ConYnameEdit_dropped()
00367 {
00368 ProcessDropEvent(ConYnameEdit);
00369 }
00370
00371 void TGo4EditDynEntry::DrawExprEdit_dropped()
00372 {
00373 ProcessTreeDropEvent(DrawExprEdit);
00374 }
00375
00376 void TGo4EditDynEntry::CutExprEdit_dropped()
00377 {
00378 ProcessTreeDropEvent(CutExprEdit);
00379 }
00380
00381 void TGo4EditDynEntry::ProcessDropEvent(QGo4LineEdit* edt)
00382 {
00383 if ((edt==0) || (Browser()==0)) return;
00384
00385 QString value = edt->text();
00386
00387 EntryChangedSlot();
00388
00389 Int_t kind = Browser()->ItemKind(value.toLatin1().constData());
00390 if (kind!=TGo4Access::kndDataMember) {
00391 edt->setText("");
00392 return;
00393 }
00394
00395 QString serachfor("EventObjects/Events/");
00396 int pos = value.indexOf(serachfor);
00397 if (pos<0) {
00398 edt->setText("");
00399 return;
00400 }
00401
00402 value.remove(0, pos+serachfor.length());
00403
00404 edt->setText(value);
00405 }
00406
00407 void TGo4EditDynEntry::ProcessTreeDropEvent(QGo4LineEdit* edt)
00408 {
00409 if ((edt==0) || (Browser()==0)) return;
00410
00411 QString value = edt->text();
00412
00413 TGo4BrowserProxy* br = Browser();
00414
00415 EntryChangedSlot();
00416
00417 int kind = br->ItemKind(value.toLatin1().constData());
00418 if (kind!=TGo4Access::kndTreeLeaf) {
00419 edt->setText("");
00420 return;
00421 }
00422
00423 TString treename;
00424 if (br->DefineTreeName(value.toLatin1().constData(), treename))
00425 DropTree(treename.Data());
00426
00427 TString lfolder, lname;
00428 TGo4Slot::ProduceFolderAndName(value.toLatin1().constData(), lfolder, lname);
00429 edt->setText(lname.Data());
00430 }
00431
00432
00433 void TGo4EditDynEntry::HisCreateButton_clicked()
00434 {
00435 AskToCreateObject(TH1::Class(), 1);
00436 }
00437
00438
00439 void TGo4EditDynEntry::HisInfoButton_clicked()
00440 {
00441 ShowItemInfo(HistoNameLbl->text());
00442 }
00443
00444 void TGo4EditDynEntry::ConNewButton_clicked()
00445 {
00446 AskToCreateObject(TGo4Condition::Class(), 1);
00447 }
00448
00449 void TGo4EditDynEntry::ConInfoButton_clicked()
00450 {
00451 EditItem(CondNameLbl->text());
00452 }
00453
00454 void TGo4EditDynEntry::requestedObjectCreated(const char* itemname, TClass* cl)
00455 {
00456 if ((cl==0) || (fiSelectedType==entry_None)) return;
00457 if (cl->InheritsFrom(TH1::Class()))
00458 DropHistogram(itemname);
00459 else
00460 if (cl->InheritsFrom(TGo4Condition::Class()))
00461 DropCondition(itemname);
00462 }
00463
00464 bool TGo4EditDynEntry::PrepareEntryForAnalysis()
00465 {
00466 TGo4DynamicEntry* entry =
00467 dynamic_cast<TGo4DynamicEntry*>(GetLinked("Entry", 0));
00468
00469 if (entry==0) return false;
00470
00471 TGo4HistogramEntry* hentry = dynamic_cast<TGo4HistogramEntry*> (entry);
00472 TGo4TreeHistogramEntry* tentry = dynamic_cast<TGo4TreeHistogramEntry*> (entry);
00473
00474 if (hentry!=0) {
00475 TString folder, name;
00476
00477 TGo4Slot::ProduceFolderAndName(hentry->GetHistogramName(), folder, name);
00478 hentry->SetHistogramName(name.Data());
00479
00480 TGo4Slot::ProduceFolderAndName(hentry->GetConditionName(), folder, name);
00481 hentry->SetConditionName(name.Data());
00482
00483 return true;
00484 }
00485
00486 if (tentry!=0) {
00487 TString folder, name;
00488
00489 TGo4Slot::ProduceFolderAndName(tentry->GetHistogramName(), folder, name);
00490 tentry->SetHistogramName(name.Data());
00491
00492 TGo4Slot::ProduceFolderAndName(tentry->GetTreeName(), folder, name);
00493 tentry->SetTreeName(name.Data());
00494 return true;
00495 }
00496
00497 return false;
00498 }
00499
00500
00501 void TGo4EditDynEntry::EntryEnabledButton_toggled( bool on)
00502 {
00503 TGo4DynamicEntry* entry =
00504 dynamic_cast<TGo4DynamicEntry*>(GetLinked("Entry", 0));
00505 if ((entry==0) || !fbTypingMode) return;
00506 entry->EnableProcessing(on);
00507 EntryChangedSlot();
00508 }
00509
00510
00511 void TGo4EditDynEntry::EvXnameEdit_textChanged( const QString & xname)
00512 {
00513 TGo4HistogramEntry* hentry =
00514 dynamic_cast<TGo4HistogramEntry*> (GetLinked("Entry", 0));
00515 if ((hentry==0) || !fbTypingMode) return;
00516
00517 hentry->SetHisEventName(0, GetEventName(xname).toLatin1().constData());
00518 hentry->SetHisVarName(0, GetEventMember(xname).toLatin1().constData());
00519 }
00520
00521
00522 void TGo4EditDynEntry::EvYnameEdit_textChanged( const QString & yname)
00523 {
00524 TGo4HistogramEntry* hentry =
00525 dynamic_cast<TGo4HistogramEntry*> (GetLinked("Entry", 0));
00526 if ((hentry==0) || !fbTypingMode) return;
00527
00528 hentry->SetHisEventName(1, GetEventName(yname).toLatin1().constData());
00529 hentry->SetHisVarName(1, GetEventMember(yname).toLatin1().constData());
00530 }
00531
00532
00533 void TGo4EditDynEntry::EvZnameEdit_textChanged( const QString & zname)
00534 {
00535 TGo4HistogramEntry* hentry =
00536 dynamic_cast<TGo4HistogramEntry*> (GetLinked("Entry", 0));
00537 if ((hentry==0) || !fbTypingMode) return;
00538
00539 hentry->SetHisEventName(2, GetEventName(zname).toLatin1().constData());
00540 hentry->SetHisVarName(2, GetEventMember(zname).toLatin1().constData());
00541 }
00542
00543
00544 void TGo4EditDynEntry::ConXnameEdit_textChanged( const QString & xname)
00545 {
00546 TGo4HistogramEntry* hentry =
00547 dynamic_cast<TGo4HistogramEntry*> (GetLinked("Entry", 0));
00548 if ((hentry==0) || !fbTypingMode) return;
00549
00550 hentry->SetConEventName(0, GetEventName(xname).toLatin1().constData());
00551 hentry->SetConVarName(0, GetEventMember(xname).toLatin1().constData());
00552 }
00553
00554
00555 void TGo4EditDynEntry::ConYnameEdit_textChanged( const QString & yname)
00556 {
00557 TGo4HistogramEntry* hentry =
00558 dynamic_cast<TGo4HistogramEntry*> (GetLinked("Entry", 0));
00559 if ((hentry==0) || !fbTypingMode) return;
00560
00561 hentry->SetConEventName(1, GetEventName(yname).toLatin1().constData());
00562 hentry->SetConVarName(1, GetEventMember(yname).toLatin1().constData());
00563 }
00564
00565
00566 void TGo4EditDynEntry::DrawExprEdit_textChanged( const QString & value)
00567 {
00568 TGo4TreeHistogramEntry* tentry =
00569 dynamic_cast<TGo4TreeHistogramEntry*> (GetLinked("Entry", 0));
00570 if ((tentry==0) || !fbTypingMode) return;
00571 tentry->SetVarExp(value.toLatin1().constData());
00572 }
00573
00574 void TGo4EditDynEntry::CutExprEdit_textChanged( const QString & value)
00575 {
00576 TGo4TreeHistogramEntry* tentry =
00577 dynamic_cast<TGo4TreeHistogramEntry*> (GetLinked("Entry", 0));
00578 if ((tentry==0) || !fbTypingMode) return;
00579 tentry->SetCutExp(value.toLatin1().constData());
00580 }
00581
00582 void TGo4EditDynEntry::DynIntervalSpin_valueChanged( int value)
00583 {
00584 TGo4TreeHistogramEntry* tentry =
00585 dynamic_cast<TGo4TreeHistogramEntry*> (GetLinked("Entry", 0));
00586 if ((tentry==0) || !fbTypingMode) return;
00587 tentry->SetDynListInterval(value);
00588 }
00589
00590
00591 void TGo4EditDynEntry::DrawButton_clicked()
00592 {
00593 DrawItem(HistoNameLbl->text());
00594 }
00595
00596 void TGo4EditDynEntry::ClearHistogramClicked()
00597 {
00598 TString objname;
00599 TGo4AnalysisProxy* an = Browser()->DefineAnalysisObject(HistoNameLbl->text().toLatin1().constData(), objname);
00600 if (an!=0) {
00601 an->ClearAnalysisObject(objname.Data());
00602 if (dynamic_cast<TGo4TreeHistogramEntry*>(GetLinked("Entry",0))!=0)
00603 an->ExecuteLine("@ResetBackStores();");
00604 Browser()->GetBrowserObject(HistoNameLbl->text().toLatin1().constData(), 2);
00605 }
00606 }
00607
00608 void TGo4EditDynEntry::PrintDynList()
00609 {
00610 TString objname;
00611 TGo4AnalysisProxy* an = Browser()->DefineAnalysisObject(GetLinkedName("Entry"), objname);
00612
00613 if (an!=0)
00614 an->PrintDynListEntry(objname.Data());
00615 }
00616
00617 void TGo4EditDynEntry::ConRemoveButton_clicked()
00618 {
00619 DropCondition("");
00620 }