00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "TGo4Browser.h"
00015
00016 #include <QFileDialog>
00017 #include <QInputDialog>
00018 #include <QTimer>
00019 #include <QApplication>
00020 #include <QToolTip>
00021 #include <QMenu>
00022 #include <QSignalMapper>
00023 #include <QHeaderView>
00024 #include <QDrag>
00025 #include <QMimeData>
00026
00027 #include "Riostream.h"
00028 #include "TClass.h"
00029 #include "TClassTable.h"
00030 #include "TROOT.h"
00031 #include "TObjString.h"
00032 #include "TCanvas.h"
00033 #include "TGo4LockGuard.h"
00034 #include "TGo4Proxy.h"
00035 #include "TGo4Slot.h"
00036 #include "TGo4Iter.h"
00037 #include "TGo4BrowserProxy.h"
00038 #include "QGo4BrowserTreeWidget.h"
00039 #include "TGo4AnalysisProxy.h"
00040 #include "TGo4HServProxy.h"
00041 #include "TGo4DabcProxy.h"
00042 #include "TGo4QSettings.h"
00043 #include "TGo4ViewPanel.h"
00044
00045
00046 const int NColumns = 7;
00047 const int ColumnWidths[NColumns] = { 150, 40, 120, 90, 60, 100, 50 };
00048 const char* ColumnNames[NColumns] = { "Name", "Flags", "Info", "Date", "Time", "Class", "Size" };
00049 const int ColumnAllign[NColumns] = { Qt::AlignLeft, Qt::AlignLeft, Qt::AlignLeft, Qt::AlignLeft, Qt::AlignLeft, Qt::AlignLeft, Qt::AlignRight };
00050
00051 QTreeWidgetItem* nextSibling(QTreeWidgetItem* item)
00052 {
00053 if (item==0) return 0;
00054
00055 QTreeWidgetItem* prnt = item->parent();
00056 if (prnt==0) prnt = item->treeWidget()->invisibleRootItem();
00057 if (prnt==0) return 0;
00058
00059 int indx = prnt->indexOfChild(item) + 1;
00060 if (indx >= prnt->childCount()) return 0;
00061 return prnt->child(indx);
00062 }
00063
00064
00065 TGo4Browser::TGo4Browser(QWidget *parent, const char* name) :
00066 QGo4Widget(parent,name)
00067 {
00068 setupUi(this);
00069
00070 setAcceptDrops(false);
00071 setCanDestroyWidget(false);
00072
00073 fbUpdateTimerActive = false;
00074
00075 ListView->setSortingEnabled(false);
00076 ListView->setSelectionMode(QAbstractItemView::ExtendedSelection);
00077 ListView->setAcceptDrops(false);
00078 ListView->viewport()->setAcceptDrops(true);
00079
00080 ListView->setRootIsDecorated(false);
00081
00082
00083
00084 for(int indx=0;indx<NColumns;indx++) {
00085 int width = -1;
00086 if ((indx==0) || (indx==2)) width = ColumnWidths[indx];
00087 width = go4sett->getBrowserColumn(ColumnNames[indx], width);
00088 fVisibleColumns[indx] = width>0;
00089
00090 ListView->headerItem()->setText(indx, ColumnNames[indx]);
00091
00092 ListView->header()->setSectionHidden(indx, ! fVisibleColumns[indx]);
00093 ListView->headerItem()->setTextAlignment(indx, ColumnAllign[indx]);
00094
00095 ListView->header()->resizeSection(indx, width>0 ? width : ColumnWidths[indx]);
00096 }
00097
00098
00099 connect(ListView, SIGNAL(RequestDragObject(QDrag**)),
00100 this, SLOT(RequestDragObjectSlot(QDrag**)));
00101
00102
00103
00104
00105 connect(ListView, SIGNAL(ItemDropProcess(void*, void*)),
00106 this, SLOT(ItemDropProcessSlot(void*, void*)));
00107
00108 connect(ListView->header(), SIGNAL(sectionResized(int, int, int)),
00109 this, SLOT(HeaderSectionResizedSlot(int, int, int)));
00110
00111 connect(ListView->header(), SIGNAL(customContextMenuRequested(const QPoint &)),
00112 this, SLOT(Header_customContextMenuRequested(const QPoint &)));
00113
00114 ListView->header()->setToolTip(
00115 QString("You can change selected browser columns\n") +
00116 "by activating RMB. Flags has following meaning\n" +
00117 "m - monitored,\ns - static,\n" +
00118 "d - can be deleted,\np - protected against delete\n" +
00119 "r - can not be reset (read only),\nw - can be reset");
00120
00121 ListView->setContextMenuPolicy(Qt::CustomContextMenu);
00122 ListView->header()->setContextMenuPolicy(Qt::CustomContextMenu);
00123 }
00124
00125
00126 void TGo4Browser::StartWorking()
00127 {
00128 AddLink("","Browser");
00129 ShootUpdateTimer();
00130 }
00131
00132 void TGo4Browser::linkedObjectUpdated(const char* linkname, TObject* obj)
00133 {
00134 if (strcmp(linkname,"Browser")==0) {
00135 ShootUpdateTimer();
00136 } else
00137
00138 if (strcmp(linkname,"TGo4Slot::evSubslotUpdated")==0) {
00139 TGo4Slot* itemslot = dynamic_cast<TGo4Slot*> (obj);
00140 if (itemslot!=0)
00141 SetViewItemProperties(itemslot, FindItemFor(itemslot));
00142 }
00143 }
00144
00145
00146 void TGo4Browser::RequestDragObjectSlot(QDrag** res)
00147 {
00148 *res = 0;
00149
00150 if (ListView->currentItem()==0) return;
00151
00152 QString fullname = FullItemName(ListView->currentItem());
00153
00154 *res = new QDrag(this);
00155 QMimeData *mimeData = new QMimeData;
00156 mimeData->setText(fullname);
00157
00158 (*res)->setMimeData(mimeData);
00159 }
00160
00161 void TGo4Browser::ItemDropAcceptSlot(void* item, void* d, bool* res)
00162 {
00163 *res = false;
00164 QString tgtname = FullItemName((QTreeWidgetItem*) item);
00165 const QMimeData* mime = (const QMimeData*) d;
00166 if (!mime->hasText()) return;
00167
00168 QString dropname = mime->text();
00169
00170 TGo4Slot* tgtslot = Browser()->ItemSlot(tgtname.toLatin1().constData());
00171 TGo4Slot* dropslot = Browser()->ItemSlot(dropname.toLatin1().constData());
00172
00173 if ((tgtslot==0) || (dropslot==0)) return;
00174 if (Browser()->ItemKind(tgtslot)!=TGo4Access::kndFolder) return;
00175
00176 if (dropslot->GetParent()==tgtslot) return;
00177
00178 *res = true;
00179 }
00180
00181 void TGo4Browser::ItemDropProcessSlot(void* item, void* d)
00182 {
00183 QString tgtname = FullItemName((QTreeWidgetItem*) item);
00184 const QMimeData* mime = (const QMimeData*) d;
00185 if (!mime->hasText()) return;
00186 Browser()->ProduceExplicitCopy(mime->text().toLatin1().constData(), tgtname.toLatin1().constData(), go4sett->getFetchDataWhenCopy());
00187 }
00188
00189 void TGo4Browser::ResetWidget()
00190 {
00191 }
00192
00193 TGo4BrowserProxy* TGo4Browser::BrowserProxy()
00194 {
00195 return (TGo4BrowserProxy*) GetLinked("Browser", 0);
00196 }
00197
00198 QString TGo4Browser::FullItemName(QTreeWidgetItem* item)
00199 {
00200 QString name;
00201 if (item!=0) {
00202 name = item->text(0);
00203 while (item->parent()!=0) {
00204 item = item->parent();
00205 name = item->text(0) + "/" + name;
00206 }
00207 }
00208 return name;
00209 }
00210
00211 QTreeWidgetItem* TGo4Browser::FindItemFor(TGo4Slot* slot)
00212 {
00213 TGo4BrowserProxy* br = BrowserProxy();
00214 if (br==0) return 0;
00215
00216 TString itemname;
00217 if (!br->BrowserItemName(slot, itemname)) return 0;
00218 QString iname = itemname.Data();
00219
00220 QTreeWidgetItemIterator it(ListView);
00221 for ( ; *it; ++it ) {
00222 QString fullname = FullItemName(*it);
00223 if (fullname == iname) return *it;
00224 }
00225 return 0;
00226 }
00227
00228 void TGo4Browser::SetViewItemProperties(TGo4Slot* itemslot, QTreeWidgetItem* item)
00229 {
00230 if ((itemslot==0) || (item==0)) return;
00231
00232 TGo4BrowserProxy* br = BrowserProxy();
00233
00234 bool mon = br->IsItemMonitored(itemslot);
00235 bool remote = br->IsItemRemote(itemslot);
00236 int kind = br->ItemKind(itemslot);
00237 int cando = br->ItemCanDo(itemslot);
00238 const char* iteminfo = TGo4BrowserProxy::ItemInfo(itemslot);
00239 const char* classname = TGo4BrowserProxy::ItemClassName(itemslot);
00240
00241 bool visible = false;
00242
00243 switch (br->GetItemFilter()) {
00244 case 1: visible = (itemslot->GetAssignedObject()!=0); break;
00245 case 2: visible = mon; break;
00246 default: visible = true;
00247 }
00248
00249 if (TGo4BrowserProxy::CanDragItem(cando))
00250 item->setFlags(item->flags() | Qt::ItemIsDragEnabled);
00251 else
00252 item->setFlags(item->flags() & ~Qt::ItemIsDragEnabled);
00253
00254 item->setFlags(item->flags() & ~Qt::ItemIsDropEnabled);
00255 if (kind==TGo4Access::kndFolder) {
00256 TGo4Slot* memslot = br->BrowserMemorySlot();
00257 if (itemslot->IsParent(memslot) || (itemslot==memslot))
00258 item->setFlags(item->flags() | Qt::ItemIsDropEnabled);
00259 }
00260
00261 if (visible)
00262 item->setText(NColumns,"visible");
00263 else
00264 item->setText(NColumns,"hidden");
00265
00266
00267 if (visible && (br->GetItemFilter()>0)) {
00268 QTreeWidgetItem* parent = item->parent();
00269 while (parent!=0) {
00270 parent->setText(NColumns, "visible");
00271 parent = parent->parent();
00272 }
00273 }
00274
00275 QString flags;
00276
00277
00278
00279
00280
00281
00282
00283 if (remote && (kind == TGo4Access::kndObject)) {
00284 if (mon) flags+="m";
00285 else flags+="s";
00286 Int_t delprot, clearprot;
00287 br->GetProtectionBits(itemslot, delprot, clearprot);
00288
00289 switch (delprot) {
00290 case 0: flags+="d"; break;
00291 case 1: flags+="p"; break;
00292 default: flags+="-"; break;
00293 }
00294
00295 switch (clearprot) {
00296 case 0: flags+="w"; break;
00297 case 1: flags+="r"; break;
00298 default: flags+="-"; break;
00299 }
00300 }
00301 item->setText(1, flags);
00302 item->setText(2, iteminfo);
00303 item->setText(3, br->ItemDate(itemslot));
00304 item->setText(4, br->ItemTime(itemslot));
00305 item->setText(5, classname);
00306 QString sizelbl = "";
00307 int sizeinfo = br->ItemSizeInfo(itemslot);
00308 int calcsize = br->GetCalcSize(itemslot);
00309 if (sizeinfo>0) sizelbl = QString::number(sizeinfo); else
00310 if (calcsize>0) sizelbl = QString("= ") + QString::number(calcsize);
00311 item->setText(6, sizelbl);
00312 }
00313
00314 void TGo4Browser::updateListViewItems()
00315 {
00316 TGo4LockGuard lock(0,true);
00317
00318 fbUpdateTimerActive = false;
00319
00320
00321
00322 for(int indx=0;indx<NColumns;indx++)
00323 ListView->header()->setSectionHidden(indx, !fVisibleColumns[indx]);
00324
00325 TGo4BrowserProxy* br = BrowserProxy();
00326 if (br==0) return;
00327
00328 ServiceCall("UpdateGuiLayout");
00329
00330 TGo4Slot* topslot = br->BrowserTopSlot();
00331 if (topslot==0) return;
00332
00333 checkVisisbilityFlags(true);
00334
00335
00336
00337 QTreeWidgetItem* curfold = 0;
00338 QTreeWidgetItem* curitem = ListView->topLevelItem(0);
00339 QTreeWidgetItem* previtem = 0;
00340
00341 TGo4Iter iter(topslot, kTRUE);
00342
00343 TObjArray testedClasses;
00344
00345 while (true) {
00346 Bool_t res = iter.next();
00347
00348
00349 Int_t levelchange = iter.levelchange();
00350 while (levelchange++<0) {
00351
00352 while (curitem!=0) {
00353 QTreeWidgetItem* next = nextSibling(curitem);
00354 delete curitem;
00355 curitem = next;
00356 }
00357
00358 if (curfold==0) break;
00359
00360 curitem = nextSibling(curfold);
00361 previtem = curfold;
00362 curfold = curfold->parent();
00363 }
00364
00365 if (!res) break;
00366
00367
00368 while ((curitem!=0) && (strcmp(iter.getname(), curitem->text(0).toLatin1().constData())!=0)) {
00369 QTreeWidgetItem* next = nextSibling(curitem);
00370 delete curitem;
00371 curitem = next;
00372 }
00373
00374 TGo4Slot* curslot = iter.getslot();
00375 if (curslot==0) {
00376 std::cerr << "************* ERROR in gui slots ****************** " << std::endl;
00377 return;
00378 }
00379
00380 const char* classname = br->ItemClassName(curslot);
00381 Int_t itemkind = br->ItemKind(curslot);
00382 TClass* itemclass = 0;
00383
00384 if ((classname!=0) && (strlen(classname)>0) && (testedClasses.FindObject(classname)==0)) {
00385
00386 itemclass = gROOT->GetClass(classname, kFALSE);
00387
00388
00389 if ((itemclass==0) && TClassTable::GetDict(classname))
00390 itemclass = gROOT->LoadClass(classname);
00391
00392 if (itemclass==0)
00393 testedClasses.Add(new TNamed(classname,""));
00394 }
00395
00396 TString pixmap;
00397 int cando = TGo4BrowserProxy::DefineItemProperties(itemkind, itemclass, pixmap);
00398 if (pixmap.Length()>0) pixmap = TString(":/icons/") + pixmap;
00399 TGo4BrowserProxy::SetItemCanDo(curslot, cando);
00400
00401 if (curitem==0) {
00402 if (curfold==0)
00403 curitem = new QTreeWidgetItem(ListView, previtem);
00404 else
00405 curitem = new QTreeWidgetItem(curfold, previtem);
00406 }
00407
00408 curitem->setText(0, iter.getname());
00409
00410 if ((pixmap.Length()>0) && curitem->icon(0).isNull())
00411 curitem->setIcon(0, QIcon(pixmap.Data()));
00412
00413 if ((curitem->text(0).contains(".TGo4EventElement") && (itemkind==TGo4Access::kndTreeBranch)) ||
00414 ((curitem->text(0)=="TGo4EventElement") && (itemkind==TGo4Access::kndFolder))) {
00415 curitem->setHidden(go4sett->getHideTGo4EventElement());
00416 }
00417
00418 SetViewItemProperties(curslot, curitem);
00419
00420 if (iter.isfolder()) {
00421 curfold = curitem;
00422 curitem = curfold->child(0);
00423 previtem = 0;
00424 } else {
00425
00426 while (curitem->child(0)!=0)
00427 delete curitem->child(0);
00428 previtem = curitem;
00429 curitem = nextSibling(curitem);
00430 }
00431 }
00432
00433 while (curitem!=0) {
00434 QTreeWidgetItem* next = nextSibling(curitem);
00435 delete curitem;
00436 curitem = next;
00437 }
00438
00439 if (br->GetItemFilter()>0)
00440 checkVisisbilityFlags(false);
00441
00442 ListView->update();
00443 ListView->viewport()->update();
00444
00445 testedClasses.Delete();
00446 }
00447
00448 void TGo4Browser::checkVisisbilityFlags(bool showall)
00449 {
00450 QTreeWidgetItemIterator it(ListView);
00451 for ( ; *it; ++it ) {
00452 QTreeWidgetItem* item = *it;
00453 if (showall || (item->parent()==0))
00454 item->setHidden(false);
00455 else
00456 item->setHidden(item->text(NColumns)!="visible");
00457 }
00458 }
00459
00460 void TGo4Browser::DisplaySelectedItems()
00461 {
00462
00463 TGo4BrowserProxy* br = BrowserProxy();
00464
00465 int npads = 0;
00466
00467 {
00468 QTreeWidgetItemIterator it(ListView);
00469 for ( ; *it; ++it )
00470 if ((*it)->isSelected() &&
00471 canDrawItem(*it)) npads++;
00472 }
00473
00474 if (npads==0) return;
00475
00476 TGo4ViewPanel* newpanel = CreateViewPanel(npads);
00477 TPad* subpad = 0;
00478
00479 int cnt = 0;
00480 QTreeWidgetItemIterator it(ListView);
00481 for ( ; *it; ++it )
00482 if ( (*it)->isSelected() && canDrawItem(*it)) {
00483 QString itemname = FullItemName(*it);
00484
00485 subpad = newpanel->GetSubPad(newpanel->GetCanvas(), cnt++, true);
00486
00487 DrawItem(itemname, newpanel, subpad, false);
00488 }
00489 newpanel->ShootRepaintTimer();
00490
00491 }
00492
00493
00494 void TGo4Browser::SuperImposeSelectedItems()
00495 {
00496 TGo4ViewPanel* newpanel = 0;
00497
00498 QTreeWidgetItemIterator it(ListView);
00499 for ( ; *it; ++it )
00500 if ( (*it)->isSelected() && canDrawItem(*it)) {
00501 if (newpanel==0) {
00502 newpanel = CreateViewPanel();
00503 newpanel->SetPadSuperImpose(newpanel->GetCanvas(), true);
00504 }
00505
00506 QString itemname = FullItemName(*it);
00507
00508 DrawItem(itemname, newpanel, newpanel->GetCanvas(), false);
00509 }
00510 if (newpanel!=0)
00511 newpanel->ShootRepaintTimer();
00512 }
00513
00514 void TGo4Browser::ListView_doubleClicked(QTreeWidgetItem* item, int ncol)
00515 {
00516 if (item==0) return;
00517
00518 QString fullname = FullItemName(item);
00519
00520 TGo4BrowserProxy* br = BrowserProxy();
00521
00522 int cando = br->ItemCanDo(fullname.toLatin1().constData());
00523 TGo4Slot* itemslot = br->ItemSlot(fullname.toLatin1().constData());
00524
00525 if (go4sett->getDrawOnceFlag()) {
00526 TGo4ViewPanel* panel = WhereItemDrawn(fullname.toLatin1().constData());
00527
00528 QWidget* mdi = panel ? panel->parentWidget() : 0;
00529
00530 if (mdi!=0) {
00531 if (mdi->isMinimized()) mdi->showNormal();
00532 mdi->activateWindow();
00533 mdi->raise();
00534 mdi->show();
00535 mdi->setFocus();
00536 }
00537
00538 if (panel!=0) return;
00539 }
00540
00541 if (TGo4BrowserProxy::CanDrawItem(cando))
00542 DrawItem(fullname, 0, 0, true);
00543 else
00544 if (TGo4BrowserProxy::CanEditItem(cando))
00545 EditItem(fullname);
00546
00547
00548
00549
00550 }
00551
00552 void TGo4Browser::Header_customContextMenuRequested(const QPoint & pos)
00553 {
00554 QMenu menu;
00555 QSignalMapper map;
00556
00557 for(int indx=1;indx<NColumns;indx++)
00558 AddIdAction(&menu, &map,
00559 ColumnNames[indx], indx, true, fVisibleColumns[indx]);
00560 connect(&map, SIGNAL(mapped(int)), this, SLOT(ColumnToggled(int)));
00561
00562 menu.exec(ListView->header()->mapToGlobal(pos));
00563 }
00564
00565
00566 void TGo4Browser::ListView_customContextMenuRequested(const QPoint& pos)
00567 {
00568 QTreeWidgetItem* item = ListView->itemAt(pos);
00569
00570 int col = ListView->header()->logicalIndexAt(pos);
00571
00572 QMenu menu;
00573 QSignalMapper map;
00574
00575 if (col!=0) {
00576 for(int indx=1;indx<NColumns;indx++)
00577 AddIdAction(&menu, &map,
00578 ColumnNames[indx], indx, true, fVisibleColumns[indx]);
00579 connect(&map, SIGNAL(mapped(int)), this, SLOT(ColumnToggled(int)));
00580
00581 menu.exec(ListView->viewport()->mapToGlobal(pos));
00582 return;
00583 }
00584
00585 TGo4BrowserProxy* br = BrowserProxy();
00586 TGo4Slot* memslot = br->BrowserMemorySlot();
00587 TGo4Slot* analslot = br->FindAnalysisSlot(false);
00588
00589 int nitems = 0;
00590 int nmemory = 0;
00591 bool istopmemory = false;
00592 int nclose = 0;
00593 int ndraw = 0;
00594 int nsuperimpose = 0;
00595 int si_kind = -1;
00596 int nremote = 0;
00597 int nanalysis = 0;
00598 int ndabc = 0;
00599 int nmonitor = 0;
00600 int nclear = 0;
00601 int nclearlocal = 0;
00602 int nclearproton = 0;
00603 int nclearprotoff = 0;
00604 int ndelprotoff = 0;
00605 int nobjects = 0;
00606 int nfolders = 0;
00607 int nedits = 0;
00608 int ninfo = 0;
00609 int nexport = 0;
00610 int ndelete = 0;
00611 int nassigned = 0;
00612
00613 QTreeWidgetItemIterator it(ListView);
00614 for ( ; *it; ++it )
00615 if ((*it)->isSelected()) {
00616 QString fullname = FullItemName(*it);
00617 TGo4Slot* itemslot = br->ItemSlot(fullname.toLatin1().constData());
00618 if (itemslot==0) continue;
00619 nitems++;
00620
00621 int cando = br->ItemCanDo(itemslot);
00622 int kind = br->ItemKind(itemslot);
00623 const char* itemclassname = br->ItemClassName(itemslot);
00624
00625 bool ismemitem = itemslot->IsParent(memslot);
00626
00627 if (br->IsCanDelete(itemslot) || ismemitem)
00628 ndelete++;
00629
00630 if (kind==TGo4Access::kndObject)
00631 nobjects++;
00632
00633 if (kind==TGo4Access::kndFolder)
00634 nfolders++;
00635
00636 if (TGo4BrowserProxy::CanDrawItem(cando)) {
00637 ndraw++;
00638 TClass* cl = gROOT->GetClass(itemclassname);
00639 if (cl!=0)
00640 if (cl->InheritsFrom("TH1")) {
00641 if (!cl->InheritsFrom("TH2") && !cl->InheritsFrom("TH3")) {
00642 if ((si_kind<0) || (si_kind==1)) {
00643 si_kind=1;
00644 nsuperimpose++;
00645 }
00646 }
00647 } else
00648 if (cl->InheritsFrom("TGraph")) {
00649 if ((si_kind<0) || (si_kind==2)) {
00650 si_kind=2;
00651 nsuperimpose++;
00652 }
00653 }
00654 }
00655
00656 if (TGo4BrowserProxy::CanEditItem(cando))
00657 nedits++;
00658
00659 if (TGo4BrowserProxy::CanCloseItem(cando))
00660 nclose++;
00661
00662 if (TGo4BrowserProxy::CanInfoItem(cando))
00663 ninfo++;
00664
00665 istopmemory = (itemslot==memslot);
00666
00667 if (ismemitem || istopmemory)
00668 nmemory++;
00669
00670 if (ismemitem && TGo4BrowserProxy::CanClearItem(cando))
00671 nclearlocal++;
00672
00673 if ((kind==TGo4Access::kndObject) && (itemslot->GetAssignedObject()!=0)) {
00674 nassigned++;
00675 if (TGo4BrowserProxy::CanExportItem(cando))
00676 nexport++;
00677 }
00678
00679 bool isanalysisitem = (itemslot==analslot) || itemslot->IsParent(analslot);
00680
00681 if (isanalysisitem)
00682 nanalysis++;
00683
00684 if ((itemclassname!=0) && (strcmp(itemclassname,"TGo4DabcProxy")==0))
00685 { ndabc++; nremote++; }
00686
00687 if (br->IsItemRemote(itemslot)) {
00688 nremote++;
00689
00690 if (isanalysisitem) {
00691
00692 if (kind==TGo4Access::kndObject) {
00693 Int_t delprot, clearprot;
00694 br->GetProtectionBits(itemslot, delprot, clearprot);
00695 if (clearprot==1) nclearproton++; else
00696 if (clearprot==0) nclearprotoff++;
00697 if (delprot==0) ndelprotoff++;
00698 }
00699
00700 if (TGo4BrowserProxy::CanClearItem(cando) ||
00701 (kind==TGo4Access::kndFolder))
00702 nclear++;
00703 }
00704 }
00705
00706 if (br->IsItemMonitored(itemslot)) nmonitor++;
00707 }
00708
00709 AddIdAction(&menu, &map, QIcon(":/icons/chart.png"),
00710 "Plot", 11, (ndraw>0));
00711
00712 AddIdAction(&menu, &map, QIcon(":/icons/superimpose.png"),
00713 "Superimpose", 12, (ndraw>1) && (nsuperimpose==ndraw));
00714
00715 AddIdAction(&menu, &map, QIcon(":/icons/right.png"),
00716 "Fetch item(s)", 18, (nfolders>0) || (nobjects>0));
00717
00718 AddIdAction(&menu, &map, QIcon(":/icons/saveall.png"),
00719 "Save selected...", 13, (nobjects>0) || ((nfolders==1) && (nitems==1)));
00720
00721
00722 if (nexport>0) {
00723
00724 QMenu* expmenu = menu.addMenu(QIcon(":/icons/export.png"), "Export to");
00725
00726 AddIdAction(expmenu, &map, "ASCII", 141);
00727 AddIdAction(expmenu, &map, "Radware", 142);
00728
00729 } else {
00730 AddIdAction(&menu, &map, QIcon(":/icons/export.png"),
00731 "Export to", 14, false);
00732 }
00733
00734 AddIdAction(&menu, &map, QIcon(":/icons/info.png"),
00735 "Info...", 15, (ninfo>0));
00736
00737 AddIdAction(&menu, &map, QIcon(":/icons/control.png"),
00738 "Edit..", 16, (nedits>0));
00739
00740 QString dellabel = "Delete item";
00741 QString delbutton = ":/icons/delete.png";
00742 if ((nclose>0) && (ndelete==0)) {
00743 dellabel = "Close item";
00744 if (nclose>1) dellabel+="s";
00745 delbutton=":/icons/close.png";
00746 } else
00747 if ((nclose==0) && (ndelete>0)) {
00748 dellabel = "Delete item";
00749 if (ndelete>1) dellabel+="s";
00750 } else
00751 if ((nclose>0) && (ndelete>0)) {
00752 dellabel = "Close/delete items";
00753 }
00754
00755 AddIdAction(&menu, &map, QIcon(delbutton),
00756 dellabel, 17, (nclose>0) || (ndelete>0));
00757
00758 AddIdAction(&menu, &map, QIcon(":/icons/copyws.png"),
00759 "Copy to Workspace", 19, (nobjects>0) || ((nfolders==1) && (nitems==1)));
00760
00761 AddIdAction(&menu, &map, QIcon(":/icons/editcopy.png"),
00762 "Copy to clipboard", 20, (nobjects>0) || (nfolders>0));
00763
00764 if ((nremote>0) || (nanalysis>0)) {
00765
00766 menu.addSeparator();
00767
00768 AddIdAction(&menu, &map, QIcon(":/icons/monitor.png"),
00769 "Monitor item(s)", 21, ((nobjects>0) && (nremote>0) && (nmonitor<nremote)) || ((nfolders==1) && (nitems==1)));
00770
00771 AddIdAction(&menu, &map, QIcon(":/icons/Stop.png"),
00772 "Stop item(s) monitoring", 22, ((nobjects>0) && (nremote>0) && (nmonitor>0)) || ((nfolders==1) && (nitems==1)));
00773
00774 AddIdAction(&menu, &map, QIcon( ":/icons/clear.png" ),
00775 "Clear (Reset to 0)", 23, (nclear>0));
00776
00777 AddIdAction(&menu, &map, QIcon( ":/icons/clear_nok.png" ),
00778 "Set Clear protection", 24, (nclearprotoff>0));
00779
00780 AddIdAction(&menu, &map, QIcon( ":/icons/clear_ok.png" ),
00781 "Unset Clear protection", 25, (nclearproton>0));
00782
00783 AddIdAction(&menu, &map, QIcon( ":/icons/delete.png" ),
00784 "Delete from analysis", 26, (ndelprotoff>0));
00785
00786 AddIdAction(&menu, &map, QIcon( ":/icons/refresh.png" ),
00787 "Refresh namelist", 27, true);
00788 }
00789
00790 if ((nmemory>0) && (nmemory==nitems)) {
00791 menu.addSeparator();
00792
00793 AddIdAction(&menu, &map, QIcon(":/icons/crefolder.png"),
00794 "Create folder", 41, (nmemory==1) && (nfolders==1));
00795
00796 AddIdAction(&menu, &map, QIcon(":/icons/rename.png"),
00797 "Rename object", 42, (nmemory==1) && !istopmemory);
00798
00799 AddIdAction(&menu, &map, QIcon(":/icons/clear.png"),
00800 "Clear object(s)", 44, (nclearlocal>0));
00801
00802 AddIdAction(&menu, &map, QIcon(":/icons/editpaste.png"),
00803 "Paste from clipboard", 43, br->IsClipboard() && (nmemory==1) && (nfolders==1));
00804 }
00805
00806 connect(&map, SIGNAL(mapped(int)), this, SLOT(ContextMenuActivated(int)));
00807
00808 menu.exec(ListView->viewport()->mapToGlobal(pos));
00809 }
00810
00811 void TGo4Browser::ColumnToggled(int indx)
00812 {
00813 if ((indx<=0) || (indx>=NColumns)) return;
00814 fVisibleColumns[indx] = !fVisibleColumns[indx];
00815
00816 HeaderSectionResizedSlot(0, 0, 0);
00817
00818 ShootUpdateTimer();
00819 }
00820
00821 void TGo4Browser::HeaderSectionResizedSlot(int, int, int)
00822 {
00823 int ncolumn = 0;
00824 for(int indx=0;indx<NColumns;indx++) {
00825 int width = -1;
00826 if (fVisibleColumns[indx]) {
00827 width = ListView->columnWidth(ncolumn++);
00828 if (width==0) width = ColumnWidths[indx];
00829 }
00830 go4sett->setBrowserColumn(ColumnNames[indx], width);
00831 }
00832 }
00833
00834 void TGo4Browser::ContextMenuActivated(int id)
00835 {
00836 switch (id) {
00837 case 11: DisplaySelectedItems(); return;
00838 case 12: SuperImposeSelectedItems(); return;
00839 case 13: SaveSelectedItems(); return;
00840 case 141: ExportSelectedItems("ASCII format"); return;
00841 case 142: ExportSelectedItems("Radware format"); return;
00842 }
00843
00844 TGo4BrowserProxy* br = BrowserProxy();
00845
00846 TGo4AnalysisProxy* anrefresh = 0;
00847 TGo4HServProxy* hservrefresh = 0;
00848 TGo4DabcProxy* dabcprrefresh = 0;
00849
00850 if (id==20) br->ClearClipboard();
00851
00852 if (id==19)
00853 QApplication::setOverrideCursor(Qt::WaitCursor);
00854
00855 QTreeWidgetItemIterator it(ListView);
00856 for ( ; *it; ++it )
00857 if ((*it)->isSelected()) {
00858 QString itemname = FullItemName(*it);
00859 TGo4Slot* itemslot = br->ItemSlot(itemname.toLatin1().constData());
00860 if (itemslot==0) continue;
00861 int cando = br->ItemCanDo(itemslot);
00862 int kind = br->ItemKind(itemslot);
00863
00864 switch(id) {
00865 case 15: {
00866 if (TGo4BrowserProxy::CanInfoItem(cando)) {
00867 ShowItemInfo(itemname);
00868 return;
00869 }
00870 break;
00871 }
00872
00873 case 16: {
00874 if (TGo4BrowserProxy::CanEditItem(cando)) {
00875 EditItem(itemname);
00876 return;
00877 }
00878 break;
00879 }
00880
00881 case 17: {
00882 br->DeleteDataSource(itemslot);
00883 break;
00884 }
00885
00886 case 18: {
00887 br->FetchItem(itemname.toLatin1().constData());
00888 break;
00889 }
00890
00891 case 19: {
00892 br->ProduceExplicitCopy(itemname.toLatin1().constData(), 0, go4sett->getFetchDataWhenCopy());
00893 break;
00894 }
00895
00896 case 20: {
00897 br->AddToClipboard(itemname.toLatin1().constData());
00898 break;
00899 }
00900
00901 case 21:
00902 case 22: {
00903 br->SetItemMonitored(itemslot, id==21);
00904 ShootUpdateTimer();
00905 break;
00906 }
00907
00908 case 23: {
00909 TString objname;
00910 TGo4AnalysisProxy* an = br->DefineAnalysisObject(itemname.toLatin1().constData(), objname);
00911 if (an!=0) {
00912 an->ClearAnalysisObject(objname.Data());
00913
00914 if (kind==TGo4Access::kndFolder) {
00915 TGo4Iter iter(itemslot, kTRUE);
00916 while (iter.next()) {
00917 TGo4Slot* subslot = iter.getslot();
00918 if (subslot->GetAssignedObject()!=0)
00919 subslot->Update(kFALSE);
00920 }
00921 } else
00922 if (itemslot->GetAssignedObject()!=0)
00923 itemslot->Update(kFALSE);
00924 }
00925 break;
00926 }
00927
00928 case 24:
00929 case 25: {
00930 TString objname;
00931 TGo4AnalysisProxy* an = br->DefineAnalysisObject(itemname.toLatin1().constData(), objname);
00932 if (an!=0) {
00933 an->ChageObjectProtection(objname.Data(), (id == 24 ? "+C" : "-C"));
00934 anrefresh = an;
00935 }
00936 break;
00937 }
00938
00939 case 26: {
00940 TString objname;
00941 TGo4AnalysisProxy* an = br->DefineAnalysisObject(itemname.toLatin1().constData(), objname);
00942 if (an!=0) {
00943 an->RemoveObjectFromAnalysis(objname.Data(), br->ItemClass(itemslot));
00944 anrefresh = an;
00945 }
00946 break;
00947 }
00948
00949 case 27: {
00950 TString objname;
00951 TGo4AnalysisProxy* an = br->DefineAnalysisObject(itemname.toLatin1().constData(), objname);
00952 if (an!=0) anrefresh = an;
00953 TGo4HServProxy* hserv = br->DefineHServerProxy(itemname.toLatin1().constData());
00954 if (hserv!=0) hservrefresh = hserv;
00955 TGo4DabcProxy* dabcpr = br->DefineDabcProxy(itemname.toLatin1().constData());
00956 if (dabcpr!=0) dabcprrefresh = dabcpr;
00957 break;
00958 }
00959
00960 case 41: {
00961 bool ok = false;
00962 QString folder =
00963 QInputDialog::getText(this,
00964 "Create folder in workspace",
00965 "Input folder name",
00966 QLineEdit::Normal,
00967 QString::null,
00968 &ok);
00969 if (ok) br->CreateMemorySubfolder(itemname.toLatin1().constData(), folder.toLatin1().constData());
00970 break;
00971 }
00972
00973 case 42: {
00974 bool ok = false;
00975 QString newname =
00976 QInputDialog::getText(this,
00977 "Rename item in workspace",
00978 "Input new item name",
00979 QLineEdit::Normal,
00980 QString::null,
00981 &ok);
00982 if (ok) br->RenameMemoryItem(itemname.toLatin1().constData(), newname.toLatin1().constData());
00983 break;
00984 }
00985
00986 case 43: {
00987 br->CopyClipboard(itemname.toLatin1().constData(), go4sett->getFetchDataWhenCopy());
00988 br->ClearClipboard();
00989 break;
00990 }
00991
00992 case 44: {
00993 br->ClearMemoryItem(itemname.toLatin1().constData());
00994 break;
00995 }
00996 }
00997 }
00998
00999 if (anrefresh!=0)
01000 anrefresh->RefreshNamesList();
01001
01002 if (hservrefresh!=0)
01003 hservrefresh->RequestHistosList();
01004
01005 if (dabcprrefresh!=0)
01006 dabcprrefresh->RefreshNamesList();
01007
01008 if (id==19)
01009 QApplication::restoreOverrideCursor();
01010 }
01011
01012 bool TGo4Browser::canDrawItem(QTreeWidgetItem* item)
01013 {
01014 if (item==0) return false;
01015 int cando = BrowserProxy()->ItemCanDo(FullItemName(item).toLatin1().constData());
01016 return TGo4BrowserProxy::CanDrawItem(cando);
01017 }
01018
01019 void TGo4Browser::ShootUpdateTimer()
01020 {
01021 if (fbUpdateTimerActive) return;
01022
01023 fbUpdateTimerActive = true;
01024
01025 QTimer::singleShot(1, this, SLOT(updateListViewItems()));
01026 }
01027
01028 void TGo4Browser::SaveSelectedItems()
01029 {
01030 QFileDialog fd(this, "Save selected objects to file", QString(),
01031 "ROOT (*.root);;ROOT XML (*.xml)");
01032 fd.setFileMode( QFileDialog::AnyFile);
01033 fd.setAcceptMode(QFileDialog::AcceptSave);
01034
01035 if (fd.exec() != QDialog::Accepted) return;
01036
01037 QStringList flst = fd.selectedFiles();
01038 if (flst.isEmpty()) return;
01039
01040 QString fname = flst[0];
01041 QString title;
01042
01043 if (fd.selectedNameFilter() == "ROOT (*.root)") {
01044 bool ok = false;
01045 title = QInputDialog::getText(this,
01046 "Save slected objects to file", "Provide file title",
01047 QLineEdit::Normal, QString::null, &ok);
01048 if (!ok) return;
01049 if (fname.indexOf(".root", 0, Qt::CaseInsensitive)<0) fname+=".root";
01050 } else {
01051 if (fname.indexOf(".xml", 0, Qt::CaseInsensitive)<0) fname+=".xml";
01052 }
01053
01054 ExportSelectedItems(fname.toLatin1().constData(),
01055 QFileInfo(fname).absolutePath().toLatin1().constData(),
01056 fd.selectedNameFilter().toLatin1().constData(),
01057 title.toLatin1().constData());
01058 }
01059
01060 void TGo4Browser::ExportSelectedItems(const char* filtername)
01061 {
01062 QFileDialog fd(this, QString("Select directory to export to ") + filtername);
01063 fd.setFileMode(QFileDialog::DirectoryOnly);
01064
01065 if (fd.exec() != QDialog::Accepted) return;
01066
01067 QStringList flst = fd.selectedFiles();
01068 if (flst.isEmpty()) return;
01069
01070 ExportSelectedItems("null",
01071 flst[0].toLatin1().constData(),
01072 filtername,
01073 "Export of selected items");
01074 }
01075
01076 void TGo4Browser::ExportSelectedItems(const char* filename, const char* filedir, const char* format, const char* description)
01077 {
01078 TObjArray items;
01079 QTreeWidgetItemIterator it(ListView);
01080 for ( ; *it; ++it )
01081 if ((*it)->isSelected()) {
01082 QString fullname = FullItemName(*it);
01083 items.Add(new TObjString(fullname.toLatin1().constData()));
01084 }
01085
01086 BrowserProxy()->ExportItemsTo(&items, go4sett->getFetchDataWhenSave(), filename, filedir, format, description);
01087
01088 items.Delete();
01089 }