GSI Object Oriented Online Offline (Go4)  GO4-6.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4Browser.cpp
Go to the documentation of this file.
1 // $Id: TGo4Browser.cpp 3118 2021-03-30 07:20:28Z 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 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 "TGo4Browser.h"
15 
16 #include <iostream>
17 
18 #include <QFileDialog>
19 #include <QInputDialog>
20 #include <QTimer>
21 #include <QApplication>
22 #include <QMenu>
23 #include <QSignalMapper>
24 #include <QHeaderView>
25 #include <QDrag>
26 #include <QMimeData>
27 
28 #include "TClass.h"
29 #include "TClassTable.h"
30 #include "TROOT.h"
31 #include "TObjString.h"
32 #include "TCanvas.h"
33 #include "TGo4LockGuard.h"
34 #include "TGo4Slot.h"
35 #include "TGo4Iter.h"
36 #include "TGo4BrowserProxy.h"
37 #include "TGo4ServerProxy.h"
38 #include "TGo4QSettings.h"
39 #include "TGo4ViewPanel.h"
40 
41 const int NColumns = 7;
42 const int ColumnWidths[NColumns] = { 150, 40, 120, 90, 60, 100, 50 };
43 const char* ColumnNames[NColumns] = { "Name", "Flags", "Info", "Date", "Time", "Class", "Size" };
44 const int ColumnAllign[NColumns] = { Qt::AlignLeft, Qt::AlignLeft, Qt::AlignLeft, Qt::AlignLeft, Qt::AlignLeft, Qt::AlignLeft, Qt::AlignRight };
45 
46 QTreeWidgetItem* nextSibling(QTreeWidgetItem* item)
47 {
48  if (item==0) return 0;
49 
50  QTreeWidgetItem* prnt = item->parent();
51  if (prnt==0) prnt = item->treeWidget()->invisibleRootItem();
52  if (prnt==0) return 0;
53 
54  int indx = prnt->indexOfChild(item) + 1;
55  if (indx >= prnt->childCount()) return 0;
56  return prnt->child(indx);
57 }
58 
59 
60 TGo4Browser::TGo4Browser(QWidget *parent, const char* name) :
61  QGo4Widget(parent,name)
62 {
63  setupUi(this);
64 
65  QObject::connect(ListView, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)), this, SLOT(ListView_doubleClicked(QTreeWidgetItem*, int)));
66  QObject::connect(ListView, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(ListView_customContextMenuRequested(const QPoint &)));
67 
68  setAcceptDrops(false);
69  setCanDestroyWidget(false);
70 
71  fbUpdateTimerActive = false;
72 
73  ListView->setSortingEnabled(false);
74  ListView->setSelectionMode(QAbstractItemView::ExtendedSelection);
75  ListView->setAcceptDrops(false);
76  ListView->viewport()->setAcceptDrops(true);
77 
78  ListView->setRootIsDecorated(false);
79 
80  // ListView->setDragEnabled(true);
81 
82  for(int indx=0;indx<NColumns;indx++) {
83  int width = -1;
84  if ((indx==0) || (indx==2)) width = ColumnWidths[indx];
85  width = go4sett->getBrowserColumn(ColumnNames[indx], width);
86  fVisibleColumns[indx] = width>0;
87 
88  ListView->headerItem()->setText(indx, ColumnNames[indx]);
89 
90  ListView->header()->setSectionHidden(indx, ! fVisibleColumns[indx]);
91  ListView->headerItem()->setTextAlignment(indx, ColumnAllign[indx]);
92 
93  ListView->header()->resizeSection(indx, width>0 ? width : ColumnWidths[indx]);
94  }
95 
96  // not in .ui file while designer brakes this connection
97  connect(ListView, SIGNAL(RequestDragObject(QDrag**)),
98  this, SLOT(RequestDragObjectSlot(QDrag**)));
99 
100 // connect(ListView, SIGNAL(ItemDropAccept(void*, void*, bool*)),
101 // this, SLOT(ItemDropAcceptSlot(void*, void*, bool*)));
102 
103  connect(ListView, SIGNAL(ItemDropProcess(void*, void*)),
104  this, SLOT(ItemDropProcessSlot(void*, void*)));
105 
106  connect(ListView->header(), SIGNAL(sectionResized(int, int, int)),
107  this, SLOT(HeaderSectionResizedSlot(int, int, int)));
108 
109  connect(ListView->header(), SIGNAL(customContextMenuRequested(const QPoint &)),
110  this, SLOT(Header_customContextMenuRequested(const QPoint &)));
111 
112  ListView->header()->setToolTip(
113  QString("You can change selected browser columns\n") +
114  "by activating RMB. Flags has following meaning\n" +
115  "m - monitored,\ns - static,\n" +
116  "d - can be deleted,\np - protected against delete\n" +
117  "r - can not be reset (read only),\nw - can be reset");
118 
119  ListView->setContextMenuPolicy(Qt::CustomContextMenu);
120  ListView->header()->setContextMenuPolicy(Qt::CustomContextMenu);
121 }
122 
123 
125 {
126  AddLink("","Browser");
128 }
129 
130 void TGo4Browser::linkedObjectUpdated(const char* linkname, TObject* obj)
131 {
132  if (strcmp(linkname,"Browser")==0) {
134  } else
135 
136  if (strcmp(linkname,"TGo4Slot::evSubslotUpdated")==0) {
137  TGo4Slot* itemslot = dynamic_cast<TGo4Slot*> (obj);
138  if (itemslot!=0)
139  SetViewItemProperties(itemslot, FindItemFor(itemslot));
140  }
141 }
142 
143 
145 {
146  *res = 0;
147 
148  if (ListView->currentItem()==0) return;
149 
150  QString fullname = FullItemName(ListView->currentItem());
151 
152  *res = new QDrag(this);
153  QMimeData *mimeData = new QMimeData;
154  mimeData->setText(fullname);
155 
156  (*res)->setMimeData(mimeData);
157 }
158 
159 void TGo4Browser::ItemDropAcceptSlot(void* item, void* d, bool* res)
160 {
161  *res = false;
162  QString tgtname = FullItemName((QTreeWidgetItem*) item);
163  const QMimeData* mime = (const QMimeData*) d;
164  if (!mime->hasText()) return;
165 
166  QString dropname = mime->text();
167 
168  TGo4Slot* tgtslot = Browser()->ItemSlot(tgtname.toLatin1().constData());
169  TGo4Slot* dropslot = Browser()->ItemSlot(dropname.toLatin1().constData());
170 
171  if ((tgtslot==0) || (dropslot==0)) return;
172  if (Browser()->ItemKind(tgtslot)!=TGo4Access::kndFolder) return;
173 
174  if (dropslot->GetParent()==tgtslot) return;
175 
176  *res = true;
177 }
178 
179 void TGo4Browser::ItemDropProcessSlot(void* item, void* d)
180 {
181  QString tgtname = FullItemName((QTreeWidgetItem*) item);
182  const QMimeData* mime = (const QMimeData*) d;
183  if (!mime->hasText()) return;
184  Browser()->ProduceExplicitCopy(mime->text().toLatin1().constData(), tgtname.toLatin1().constData(), go4sett->getFetchDataWhenCopy());
185 }
186 
188 {
189 }
190 
192 {
193  return (TGo4BrowserProxy*) GetLinked("Browser", 0);
194 }
195 
196 QString TGo4Browser::FullItemName(QTreeWidgetItem* item)
197 {
198  QString name;
199  if (item!=0) {
200  name = item->text(0);
201  while (item->parent()!=0) {
202  item = item->parent();
203  name = item->text(0) + "/" + name;
204  }
205  }
206  return name;
207 }
208 
209 QTreeWidgetItem* TGo4Browser::FindItemFor(TGo4Slot* slot)
210 {
212  if (br==0) return 0;
213 
214  TString itemname;
215  if (!br->BrowserItemName(slot, itemname)) return 0;
216  QString iname = itemname.Data();
217 
218  QTreeWidgetItemIterator it(ListView);
219  for ( ; *it; ++it ) {
220  QString fullname = FullItemName(*it);
221  if (fullname == iname) return *it;
222  }
223  return 0;
224 }
225 
226 void TGo4Browser::SetViewItemProperties(TGo4Slot* itemslot, QTreeWidgetItem* item)
227 {
228  if ((itemslot==0) || (item==0)) return;
229 
231 
232  bool mon = br->IsItemMonitored(itemslot);
233  bool remote = br->IsItemRemote(itemslot);
234  int kind = br->ItemKind(itemslot);
235  int cando = br->ItemCanDo(itemslot);
236  const char* iteminfo = TGo4BrowserProxy::ItemInfo(itemslot);
237  const char* classname = TGo4BrowserProxy::ItemClassName(itemslot);
238 
239  bool visible = false;
240 
241  switch (br->GetItemFilter()) {
242  case 1: visible = (itemslot->GetAssignedObject()!=0); break;
243  case 2: visible = mon; break;
244  default: visible = true;
245  }
246 
248  item->setFlags(item->flags() | Qt::ItemIsDragEnabled);
249  else
250  item->setFlags(item->flags() & ~Qt::ItemIsDragEnabled);
251 
252  item->setFlags(item->flags() & ~Qt::ItemIsDropEnabled);
253  if (kind==TGo4Access::kndFolder) {
254  TGo4Slot* memslot = br->BrowserMemorySlot();
255  if (itemslot->IsParent(memslot) || (itemslot==memslot))
256  item->setFlags(item->flags() | Qt::ItemIsDropEnabled);
257  }
258 
259  if (visible)
260  item->setText(NColumns,"visible");
261  else
262  item->setText(NColumns,"hidden");
263 
264  // make visible all folders, where item is located
265  if (visible && (br->GetItemFilter()>0)) {
266  QTreeWidgetItem* parent = item->parent();
267  while (parent!=0) {
268  parent->setText(NColumns, "visible");
269  parent = parent->parent();
270  }
271  }
272 
273  QString flags;
274 
275 // if (kind == TGo4Access::kndObject)
276 // if (itemslot->GetAssignedObject()!=0)
277 // flags += "c";
278 // else
279 // flags += "a";
280 
281  if (remote && (kind == TGo4Access::kndObject)) {
282  if (mon) flags+="m";
283  else flags+="s";
284  Int_t delprot, clearprot;
285  br->GetProtectionBits(itemslot, delprot, clearprot);
286 
287  switch (delprot) {
288  case 0: flags+="d"; break;
289  case 1: flags+="p"; break;
290  default: flags+="-"; break;
291  }
292 
293  switch (clearprot) {
294  case 0: flags+="w"; break;
295  case 1: flags+="r"; break;
296  default: flags+="-"; break;
297  }
298  }
299  item->setText(1, flags);
300  item->setText(2, iteminfo);
301  item->setText(3, br->ItemDate(itemslot));
302  item->setText(4, br->ItemTime(itemslot));
303  item->setText(5, classname);
304  QString sizelbl = "";
305  int sizeinfo = br->ItemSizeInfo(itemslot);
306  int calcsize = br->GetCalcSize(itemslot);
307  if (sizeinfo>0) sizelbl = QString::number(sizeinfo); else
308  if (calcsize>0) sizelbl = QString("= ") + QString::number(calcsize);
309  item->setText(6, sizelbl);
310 }
311 
313 {
314  TGo4LockGuard lock;
315 
316  fbUpdateTimerActive = false;
317 
318  // first update list of visible columns
319 
320  for(int indx=0;indx<NColumns;indx++)
321  ListView->header()->setSectionHidden(indx, !fVisibleColumns[indx]);
322 
324  if (br==0) return;
325 
326  ServiceCall("UpdateGuiLayout");
327 
328  TGo4Slot* topslot = br->BrowserTopSlot();
329  if (topslot==0) return;
330 
331  checkVisisbilityFlags(true);
332 
333 // slot->Print("");
334 
335  QTreeWidgetItem* curfold = 0;
336  QTreeWidgetItem* curitem = ListView->topLevelItem(0);
337  QTreeWidgetItem* previtem = 0;
338 
339  TGo4Iter iter(topslot, kTRUE);
340 
341  TObjArray testedClasses;
342 
343  while (true) {
344  Bool_t res = iter.next();
345 
346  // go to top folders and remove rest items
347  Int_t levelchange = iter.levelchange();
348  while (levelchange++<0) {
349 
350  while (curitem!=0) {
351  QTreeWidgetItem* next = nextSibling(curitem);
352  delete curitem;
353  curitem = next;
354  }
355 
356  if (curfold==0) break;
357 
358  curitem = nextSibling(curfold);
359  previtem = curfold;
360  curfold = curfold->parent();
361  }
362 
363  if (!res) break;
364 
365  // delete all slots in folder, which has another name
366  while ((curitem!=0) && (strcmp(iter.getname(), curitem->text(0).toLatin1().constData())!=0)) {
367  QTreeWidgetItem* next = nextSibling(curitem);
368  delete curitem;
369  curitem = next;
370  }
371 
372  TGo4Slot* curslot = iter.getslot();
373  if (curslot==0) {
374  std::cerr << "************* ERROR in gui slots ****************** " << std::endl;
375  return;
376  }
377 
378  const char* classname = br->ItemClassName(curslot);
379  Int_t itemkind = br->ItemKind(curslot);
380  TClass* itemclass = 0;
381 
382  if ((classname!=0) && (strlen(classname)>0) && (testedClasses.FindObject(classname)==0)) {
383 
384  itemclass = gROOT->GetClass(classname, kFALSE);
385 
386  // if dictionary existing (library is loaded) force creation of TClass object
387  if ((itemclass==0) && TClassTable::GetDict(classname))
388  itemclass = gROOT->LoadClass(classname);
389 
390  if (itemclass==0)
391  testedClasses.Add(new TNamed(classname,""));
392  }
393 
394  TString pixmap;
395  int cando = TGo4BrowserProxy::DefineItemProperties(itemkind, itemclass, pixmap);
396  if (pixmap.Length()>0) pixmap = TString(":/icons/") + pixmap;
397  TGo4BrowserProxy::SetItemCanDo(curslot, cando);
398 
399  if (curitem==0) {
400  if (curfold==0)
401  curitem = new QTreeWidgetItem(ListView, previtem);
402  else
403  curitem = new QTreeWidgetItem(curfold, previtem);
404  }
405 
406  curitem->setText(0, iter.getname());
407 
408  if ((pixmap.Length()>0) && curitem->icon(0).isNull())
409  curitem->setIcon(0, QIcon(pixmap.Data()));
410 
411  if ((curitem->text(0).contains(".TGo4EventElement") && (itemkind==TGo4Access::kndTreeBranch)) ||
412  ((curitem->text(0)=="TGo4EventElement") && (itemkind==TGo4Access::kndFolder))) {
413  curitem->setHidden(go4sett->getHideTGo4EventElement());
414  }
415 
416  SetViewItemProperties(curslot, curitem);
417 
418  if (iter.isfolder()) {
419  curfold = curitem;
420  curitem = curfold->child(0);
421  previtem = 0;
422  } else {
423  // remove any substructures if any
424  while (curitem->child(0)!=0)
425  delete curitem->child(0);
426  previtem = curitem;
427  curitem = nextSibling(curitem);
428  }
429  }
430 
431  while (curitem!=0) {
432  QTreeWidgetItem* next = nextSibling(curitem);
433  delete curitem;
434  curitem = next;
435  }
436 
437  if (br->GetItemFilter()>0)
438  checkVisisbilityFlags(false);
439 
440  ListView->update();
441  ListView->viewport()->update();
442 
443  testedClasses.Delete();
444 }
445 
447 {
448  QTreeWidgetItemIterator it(ListView);
449  for ( ; *it; ++it ) {
450  QTreeWidgetItem* item = *it;
451  if (showall || (item->parent()==0))
452  item->setHidden(false);
453  else
454  item->setHidden(item->text(NColumns)!="visible");
455  }
456 }
457 
459 {
460 
462 
463  int npads = 0;
464 
465  {
466  QTreeWidgetItemIterator it(ListView);
467  for ( ; *it; ++it )
468  if ((*it)->isSelected() &&
469  canDrawItem(*it)) npads++;
470  }
471 
472  if (npads==0) return;
473 
474  TGo4ViewPanel* newpanel = CreateViewPanel(npads);
475  TPad* subpad = 0;
476 
477  int cnt = 0;
478  QTreeWidgetItemIterator it(ListView);
479  for ( ; *it; ++it )
480  if ( (*it)->isSelected() && canDrawItem(*it)) {
481  QString itemname = FullItemName(*it);
482 
483  subpad = newpanel->GetSubPad(newpanel->GetCanvas(), cnt++, true);
484 
485  DrawItem(itemname, newpanel, subpad, false);
486  }
487  newpanel->ShootRepaintTimer();
488 // newpanel->SetActivePad(subpad);
489 }
490 
491 
493 {
494  TGo4ViewPanel* newpanel = 0;
495 
496  QTreeWidgetItemIterator it(ListView);
497  for ( ; *it; ++it )
498  if ( (*it)->isSelected() && canDrawItem(*it)) {
499  if (newpanel==0) {
500  newpanel = CreateViewPanel();
501  newpanel->SetPadSuperImpose(newpanel->GetCanvas(), true);
502  }
503 
504  QString itemname = FullItemName(*it);
505 
506  DrawItem(itemname, newpanel, newpanel->GetCanvas(), false);
507  }
508  if (newpanel!=0)
509  newpanel->ShootRepaintTimer();
510 }
511 
512 void TGo4Browser::ListView_doubleClicked(QTreeWidgetItem* item, int ncol)
513 {
514  if (item==0) return;
515 
516  QString fullname = FullItemName(item);
517 
519 
520  int cando = br->ItemCanDo(fullname.toLatin1().constData());
521  TGo4Slot* itemslot = br->ItemSlot(fullname.toLatin1().constData());
522 
523  if (go4sett->getDrawOnceFlag()) {
524  TGo4ViewPanel* panel = WhereItemDrawn(fullname.toLatin1().constData());
525 
526  QWidget* mdi = panel ? panel->parentWidget() : 0;
527 
528  if (mdi!=0) {
529  if (mdi->isMinimized()) mdi->showNormal();
530  mdi->activateWindow();
531  mdi->raise();
532  mdi->show();
533  mdi->setFocus();
534  }
535 
536  if (panel!=0) return;
537  }
538 
540  DrawItem(fullname, 0, 0, true);
541  else
543  EditItem(fullname);
544  else
545  if (TGo4BrowserProxy::CanExpandItem(cando)) {
546  item->setExpanded(true);
547  ExpandItem(fullname);
548  } else
550  ExecuteItem(fullname);
551  }
552 
553 // else
554 // ShowItemInfo(fullname);
555 
556 // SetViewItemProperties(itemslot, item);
557 }
558 
560 {
561  QMenu menu;
562  QSignalMapper map;
563 
564  for(int indx=1;indx<NColumns;indx++)
565  AddIdAction(&menu, &map,
566  ColumnNames[indx], indx, true, fVisibleColumns[indx]);
567  connect(&map, SIGNAL(mapped(int)), this, SLOT(ColumnToggled(int)));
568 
569  menu.exec(ListView->header()->mapToGlobal(pos));
570 }
571 
572 
574 {
575  QTreeWidgetItem* item = ListView->itemAt(pos);
576 
577  int col = ListView->header()->logicalIndexAt(pos);
578 
579  QMenu menu;
580  QSignalMapper map;
581 
582  if (col!=0) {
583  for(int indx=1;indx<NColumns;indx++)
584  AddIdAction(&menu, &map,
585  ColumnNames[indx], indx, true, fVisibleColumns[indx]);
586  connect(&map, SIGNAL(mapped(int)), this, SLOT(ColumnToggled(int)));
587 
588  menu.exec(ListView->viewport()->mapToGlobal(pos));
589  return;
590  }
591 
593  TGo4Slot* memslot = br->BrowserMemorySlot();
594  TGo4Slot* analslot = br->FindServerSlot(false, 1);
595 
596  bool istopmemory = false;
597 
598  int nitems(0), nmemory(0), nclose(0), ndraw(0), nsuperimpose(0), si_kind(-1),
599  nremote(0), nanalysis(0), nmonitor(0), nclear(0), nclearlocal(0), nclearproton(0),
600  nclearprotoff(0), ndelprotoff(0), nobjects(0), nfolders(0), nedits(0), ninfo(0),
601  nexport(0), ndelete(0), nassigned(0), nexpand(0), nexecute(0);
602 
603  QTreeWidgetItemIterator it(ListView);
604  for ( ; *it; ++it )
605  if ((*it)->isSelected()) {
606  QString fullname = FullItemName(*it);
607  TGo4Slot* itemslot = br->ItemSlot(fullname.toLatin1().constData());
608  if (itemslot==0) continue;
609  nitems++;
610 
611  int cando = br->ItemCanDo(itemslot);
612  int kind = br->ItemKind(itemslot);
613  const char* itemclassname = br->ItemClassName(itemslot);
614 
615  bool ismemitem = itemslot->IsParent(memslot);
616 
617  if (br->IsCanDelete(itemslot) || ismemitem)
618  ndelete++;
619 
620  if (kind==TGo4Access::kndObject)
621  nobjects++;
622 
623  if (kind==TGo4Access::kndFolder)
624  nfolders++;
625 
626  if (TGo4BrowserProxy::CanExpandItem(cando)) nexpand++;
627 
628  if (TGo4BrowserProxy::CanExecuteItem(cando)) nexecute++;
629 
630  if (TGo4BrowserProxy::CanDrawItem(cando)) {
631  ndraw++;
632  TClass* cl = gROOT->GetClass(itemclassname);
633  if (cl!=0) {
634  if (cl->InheritsFrom("TH1")) {
635  if (!cl->InheritsFrom("TH2") && !cl->InheritsFrom("TH3")) {
636  if ((si_kind<0) || (si_kind==1)) {
637  si_kind=1;
638  nsuperimpose++;
639  }
640  }
641  } else
642  if (cl->InheritsFrom("TGraph")) {
643  if ((si_kind<0) || (si_kind==2)) {
644  si_kind=2;
645  nsuperimpose++;
646  }
647  }
648  // JAM test for TF1:
649  else
650  if (cl->InheritsFrom("TF1")) {
651  if ((si_kind<0) || (si_kind==3)) {
652  si_kind=3;
653  nsuperimpose++;
654  }
655  }
656  }
657  }
658 
660  nedits++;
661 
663  nclose++;
664 
666  ninfo++;
667 
668  istopmemory = (itemslot==memslot);
669 
670  if (ismemitem || istopmemory)
671  nmemory++;
672 
673  if (ismemitem && TGo4BrowserProxy::CanClearItem(cando))
674  nclearlocal++;
675 
676  if ((kind==TGo4Access::kndObject) && (itemslot->GetAssignedObject()!=0)) {
677  nassigned++;
679  nexport++;
680  }
681 
682  bool isanalysisitem = (itemslot==analslot) || itemslot->IsParent(analslot);
683 
684  if (isanalysisitem) nanalysis++;
685 
686  if ((itemclassname!=0) && (strcmp(itemclassname,"TGo4DabcProxy")==0)) nremote++;
687 
688  if ((itemclassname!=0) && (strcmp(itemclassname,"TGo4ServerProxy")==0)) nremote++;
689 
690  if (br->IsItemRemote(itemslot)) {
691  nremote++;
692 
693  if (isanalysisitem) {
694 
695  if (kind==TGo4Access::kndObject) {
696  Int_t delprot, clearprot;
697  br->GetProtectionBits(itemslot, delprot, clearprot);
698  if (clearprot==1) nclearproton++; else
699  if (clearprot==0) nclearprotoff++;
700  if (delprot==0) ndelprotoff++;
701  }
702 
704  nclear++;
705  }
706  }
707 
708  if (br->IsItemMonitored(itemslot)) nmonitor++;
709  }
710 
711  AddIdAction(&menu, &map, QIcon(":/icons/chart.png"),
712  "Plot", 11, (ndraw>0));
713 
714  AddIdAction(&menu, &map, QIcon(":/icons/superimpose.png"),
715  "Superimpose", 12, (ndraw>1) && (nsuperimpose==ndraw));
716 
717  if (nexpand > 0)
718  AddIdAction(&menu, &map, QIcon(":/icons/zoomlim.png"), "Expand", 28, true);
719 
720  if (nexecute == 1)
721  AddIdAction(&menu, &map, QIcon(":/icons/zoomlim.png"), "Execute", 29, true);
722 
723  AddIdAction(&menu, &map, QIcon(":/icons/right.png"),
724  "Fetch item(s)", 18, (nfolders>0) || (nobjects>0));
725 
726  AddIdAction(&menu, &map, QIcon(":/icons/saveall.png"),
727  "Save selected...", 13, (nobjects>0) || ((nfolders==1) && (nitems==1)));
728 
729  // organize export submenu
730  if (nexport>0) {
731 
732  QMenu* expmenu = menu.addMenu(QIcon(":/icons/export.png"), "Export to");
733 
734  AddIdAction(expmenu, &map, "ASCII", 141);
735  AddIdAction(expmenu, &map, "Radware", 142);
736 
737  } else {
738  AddIdAction(&menu, &map, QIcon(":/icons/export.png"),
739  "Export to", 14, false);
740  }
741 
742  AddIdAction(&menu, &map, QIcon(":/icons/info.png"),
743  "Info...", 15, (ninfo>0));
744 
745  AddIdAction(&menu, &map, QIcon(":/icons/control.png"),
746  "Edit..", 16, (nedits>0));
747 
748  QString dellabel = "Delete item";
749  QString delbutton = ":/icons/delete.png";
750  if ((nclose>0) && (ndelete==0)) {
751  dellabel = "Close item";
752  if (nclose>1) dellabel+="s";
753  delbutton=":/icons/close.png";
754  } else
755  if ((nclose==0) && (ndelete>0)) {
756  dellabel = "Delete item";
757  if (ndelete>1) dellabel+="s";
758  } else
759  if ((nclose>0) && (ndelete>0)) {
760  dellabel = "Close/delete items";
761  }
762 
763  AddIdAction(&menu, &map, QIcon(delbutton),
764  dellabel, 17, (nclose>0) || (ndelete>0));
765 
766  AddIdAction(&menu, &map, QIcon(":/icons/copyws.png"),
767  "Copy to Workspace", 19, (nobjects>0) || ((nfolders==1) && (nitems==1)));
768 
769  AddIdAction(&menu, &map, QIcon(":/icons/editcopy.png"),
770  "Copy to clipboard", 20, (nobjects>0) || (nfolders>0));
771 
772  if ((nremote>0) || (nanalysis>0)) {
773 
774  menu.addSeparator();
775 
776  AddIdAction(&menu, &map, QIcon(":/icons/monitor.png"),
777  "Monitor item(s)", 21, ((nobjects>0) && (nremote>0) && (nmonitor<nremote)) || ((nfolders==1) && (nitems==1)));
778 
779  AddIdAction(&menu, &map, QIcon(":/icons/Stop.png"),
780  "Stop item(s) monitoring", 22, ((nobjects>0) && (nremote>0) && (nmonitor>0)) || ((nfolders==1) && (nitems==1)));
781 
782  AddIdAction(&menu, &map, QIcon( ":/icons/clear.png" ),
783  "Clear (Reset to 0)", 23, (nclear>0));
784 
785  AddIdAction(&menu, &map, QIcon( ":/icons/clear_nok.png" ),
786  "Set Clear protection", 24, (nclearprotoff>0));
787 
788  AddIdAction(&menu, &map, QIcon( ":/icons/clear_ok.png" ),
789  "Unset Clear protection", 25, (nclearproton>0));
790 
791  AddIdAction(&menu, &map, QIcon( ":/icons/delete.png" ),
792  "Delete from analysis", 26, (ndelprotoff>0));
793 
794  AddIdAction(&menu, &map, QIcon( ":/icons/refresh.png" ),
795  "Refresh namelist", 27, true);
796  }
797 
798  if ((nmemory>0) && (nmemory==nitems)) {
799  menu.addSeparator();
800 
801  AddIdAction(&menu, &map, QIcon(":/icons/crefolder.png"),
802  "Create folder", 41, (nmemory==1) && (nfolders==1));
803 
804  AddIdAction(&menu, &map, QIcon(":/icons/rename.png"),
805  "Rename object", 42, (nmemory==1) && !istopmemory);
806 
807  AddIdAction(&menu, &map, QIcon(":/icons/clear.png"),
808  "Clear object(s)", 44, (nclearlocal>0));
809 
810  AddIdAction(&menu, &map, QIcon(":/icons/editpaste.png"),
811  "Paste from clipboard", 43, br->IsClipboard() && (nmemory==1) && (nfolders==1));
812  }
813 
814  connect(&map, SIGNAL(mapped(int)), this, SLOT(ContextMenuActivated(int)));
815 
816  menu.exec(ListView->viewport()->mapToGlobal(pos));
817 }
818 
820 {
821  if ((indx<=0) || (indx>=NColumns)) return;
822  fVisibleColumns[indx] = !fVisibleColumns[indx];
823 
824  HeaderSectionResizedSlot(0, 0, 0);
825 
827 }
828 
830 {
831  int ncolumn = 0;
832  for(int indx=0;indx<NColumns;indx++) {
833  int width = -1;
834  if (fVisibleColumns[indx]) {
835  width = ListView->columnWidth(ncolumn++);
836  if (width==0) width = ColumnWidths[indx];
837  }
838  go4sett->setBrowserColumn(ColumnNames[indx], width);
839  }
840 }
841 
843 {
844  switch (id) {
845  case 11: DisplaySelectedItems(); return;
846  case 12: SuperImposeSelectedItems(); return;
847  case 13: SaveSelectedItems(); return;
848  case 141: ExportSelectedItems("ASCII format"); return;
849  case 142: ExportSelectedItems("Radware format"); return;
850  }
851 
853 
854  TGo4ServerProxy* anrefresh = 0;
855  TGo4ServerProxy* servrefresh = 0;
856 
857  if (id==20) br->ClearClipboard();
858 
859  if (id==19)
860  QApplication::setOverrideCursor(Qt::WaitCursor);
861 
862  QTreeWidgetItemIterator it(ListView);
863  for ( ; *it; ++it )
864  if ((*it)->isSelected()) {
865  QString itemname = FullItemName(*it);
866  TGo4Slot* itemslot = br->ItemSlot(itemname.toLatin1().constData());
867  if (itemslot==0) continue;
868  int cando = br->ItemCanDo(itemslot);
869  int kind = br->ItemKind(itemslot);
870 
871  switch(id) {
872  case 15: {
873  if (TGo4BrowserProxy::CanInfoItem(cando)) {
874  ShowItemInfo(itemname);
875  return;
876  }
877  break;
878  }
879 
880  case 16: {
881  if (TGo4BrowserProxy::CanEditItem(cando)) {
882  EditItem(itemname);
883  return;
884  }
885  break;
886  }
887 
888  case 17: {
889  br->DeleteDataSource(itemslot);
890  break;
891  }
892 
893  case 18: { // fetch item from the data source
894  br->FetchItem(itemname.toLatin1().constData());
895  break;
896  }
897 
898  case 19: {
899  br->ProduceExplicitCopy(itemname.toLatin1().constData(), 0, go4sett->getFetchDataWhenCopy());
900  break;
901  }
902 
903  case 20: {
904  br->AddToClipboard(itemname.toLatin1().constData());
905  break;
906  }
907 
908  case 21: // toggle monitor on
909  case 22: { // toggle monitor off
910  br->SetItemMonitored(itemslot, id==21);
912  break;
913  }
914 
915  case 23: { // clear
916  TString objname;
917  TGo4ServerProxy* an = br->DefineAnalysisObject(itemname.toLatin1().constData(), objname);
918  if (an!=0) {
919  an->ClearAnalysisObject(objname.Data());
920  // if clear folder, request all objects which were requested before
921  if (kind==TGo4Access::kndFolder) {
922  TGo4Iter iter(itemslot, kTRUE);
923  while (iter.next()) {
924  TGo4Slot* subslot = iter.getslot();
925  if (subslot->GetAssignedObject()!=0)
926  subslot->Update(kFALSE);
927  }
928  } else
929  if (itemslot->GetAssignedObject()!=0)
930  itemslot->Update(kFALSE);
931  }
932  break;
933  }
934 
935  case 24: // set clear protect
936  case 25: { // unset clear protect
937  TString objname;
938  TGo4ServerProxy* an = br->DefineAnalysisObject(itemname.toLatin1().constData(), objname);
939  if (an!=0) {
940  an->ChageObjectProtection(objname.Data(), (id == 24 ? "+C" : "-C"));
941  anrefresh = an;
942  }
943  break;
944  }
945 
946  case 26: { // delete remote object
947  TString objname;
948  TGo4ServerProxy* an = br->DefineAnalysisObject(itemname.toLatin1().constData(), objname);
949  if (an!=0) {
950  an->RemoveObjectFromAnalysis(objname.Data());
951  anrefresh = an;
952  }
953  break;
954  }
955 
956  case 27: { // refresh
957  TString objname;
958  TGo4ServerProxy* an = br->DefineAnalysisObject(itemname.toLatin1().constData(), objname);
959  if (an!=0) anrefresh = an;
960  TGo4ServerProxy* serv = br->DefineServerProxy(itemname.toLatin1().constData());
961  if (serv!=0) servrefresh = serv;
962  break;
963  }
964 
965  case 28: { // expand
966  if (TGo4BrowserProxy::CanExpandItem(cando)) {
967  (*it)->setExpanded(true);
968  ExpandItem(itemname);
969  }
970  break;
971  }
972 
973  case 29: { // execute
975  ExecuteItem(itemname);
976  break;
977  }
978 
979  case 41: { // create folder in memory
980  bool ok = false;
981  QString folder =
982  QInputDialog::getText(this,
983  "Create folder in workspace",
984  "Input folder name",
985  QLineEdit::Normal,
986  QString(),
987  &ok);
988  if (ok) br->CreateMemorySubfolder(itemname.toLatin1().constData(), folder.toLatin1().constData());
989  break;
990  }
991 
992  case 42: { // rename memory item
993  bool ok = false;
994  QString shortitemname=itemname.section("/",-1);
995  QString newname =
996  QInputDialog::getText(this,
997  "Rename item in workspace",
998  "Input new item name",
999  QLineEdit::Normal,
1000  shortitemname,
1001  &ok);
1002  if (ok) br->RenameMemoryItem(itemname.toLatin1().constData(), newname.toLatin1().constData());
1003  break;
1004  }
1005 
1006  case 43: { // paste items from clipboard
1007  br->CopyClipboard(itemname.toLatin1().constData(), go4sett->getFetchDataWhenCopy());
1008  br->ClearClipboard();
1009  break;
1010  }
1011 
1012  case 44: { // clear memory item
1013  br->ClearMemoryItem(itemname.toLatin1().constData());
1014  break;
1015  }
1016  }
1017  }
1018 
1019  if (anrefresh!=0)
1020  anrefresh->RefreshNamesList();
1021 
1022  if (servrefresh!=0)
1023  servrefresh->RefreshNamesList();
1024 
1025  if (id==19)
1026  QApplication::restoreOverrideCursor();
1027 }
1028 
1029 bool TGo4Browser::canDrawItem(QTreeWidgetItem* item)
1030 {
1031  if (item==0) return false;
1032  int cando = BrowserProxy()->ItemCanDo(FullItemName(item).toLatin1().constData());
1033  return TGo4BrowserProxy::CanDrawItem(cando);
1034 }
1035 
1037 {
1038  if (fbUpdateTimerActive) return;
1039 
1040  fbUpdateTimerActive = true;
1041 
1042  QTimer::singleShot(1, this, SLOT(updateListViewItems()));
1043 }
1044 
1046 {
1047  QFileDialog fd(this, "Save selected objects to file", QString(),
1048  "ROOT (*.root);;ROOT XML (*.xml)");
1049  fd.setFileMode( QFileDialog::AnyFile);
1050  fd.setAcceptMode(QFileDialog::AcceptSave);
1051 
1052  if (fd.exec() != QDialog::Accepted) return;
1053 
1054  QStringList flst = fd.selectedFiles();
1055  if (flst.isEmpty()) return;
1056 
1057  QString fname = flst[0];
1058  QString title;
1059 
1060  if (fd.selectedNameFilter() == "ROOT (*.root)") {
1061  bool ok = false;
1062  title = QInputDialog::getText(this,
1063  "Save slected objects to file", "Provide file title",
1064  QLineEdit::Normal, QString(), &ok);
1065  if (!ok) return;
1066  if (fname.indexOf(".root", 0, Qt::CaseInsensitive)<0) fname+=".root";
1067  } else {
1068  if (fname.indexOf(".xml", 0, Qt::CaseInsensitive)<0) fname+=".xml";
1069  }
1070 
1071  ExportSelectedItems(fname.toLatin1().constData(),
1072  QFileInfo(fname).absolutePath().toLatin1().constData(),
1073  fd.selectedNameFilter().toLatin1().constData(),
1074  title.toLatin1().constData());
1075 }
1076 
1077 void TGo4Browser::ExportSelectedItems(const char* filtername)
1078 {
1079  QFileDialog fd(this, QString("Select directory to export to ") + filtername);
1080  fd.setOption(QFileDialog::ShowDirsOnly, true);
1081 
1082  if (fd.exec() != QDialog::Accepted) return;
1083 
1084  QStringList flst = fd.selectedFiles();
1085  if (flst.isEmpty()) return;
1086 
1087  ExportSelectedItems("null",
1088  flst[0].toLatin1().constData(),
1089  filtername,
1090  "Export of selected items");
1091 }
1092 
1093 void TGo4Browser::ExportSelectedItems(const char* filename, const char* filedir, const char* format, const char* description)
1094 {
1095  TObjArray items;
1096  QTreeWidgetItemIterator it(ListView);
1097  for ( ; *it; ++it )
1098  if ((*it)->isSelected()) {
1099  QString fullname = FullItemName(*it);
1100  items.Add(new TObjString(fullname.toLatin1().constData()));
1101  }
1102 
1103  BrowserProxy()->ExportItemsTo(&items, go4sett->getFetchDataWhenSave(), filename, filedir, format, description);
1104 
1105  items.Delete();
1106 }
1107 
1108 void TGo4Browser::ExpandItem(const QString& itemname)
1109 {
1110  BrowserProxy()->GetBrowserObject(itemname.toLatin1().constData(), 100);
1111 }
1112 
1113 void TGo4Browser::ExecuteItem(const QString& itemname)
1114 {
1115  TString objname, arg1, arg2, arg3;
1116 
1117  TGo4ServerProxy* serv = BrowserProxy()->DefineServerObject(itemname.toLatin1().constData(), &objname, kFALSE);
1118 
1119  if ((serv==0) || (objname.Length()==0)) return;
1120 
1121  Int_t nargs = serv->NumCommandArgs(objname);
1122  if (nargs<0) return;
1123 
1124  for (Int_t n=0;n<nargs;n++) {
1125  bool ok = false;
1126  QString value =
1127  QInputDialog::getText(0, "Input command arguments",
1128  QString("Arg%1:").arg(n+1), QLineEdit::Normal, "", &ok);
1129  if (!ok) return;
1130  if (n==0) arg1 = value.toLatin1().constData(); else
1131  if (n==1) arg2 = value.toLatin1().constData(); else
1132  if (n==2) arg3 = value.toLatin1().constData();
1133  }
1134 
1135  Bool_t res = serv->SubmitCommand(objname, 3, (arg1.Length() > 0 ? arg1.Data() : 0), (arg2.Length() > 0 ? arg2.Data() : 0), (arg3.Length() > 0 ? arg3.Data() : 0));
1136 
1137  StatusMessage(QString(" Command execution:") + objname + QString(" result = ") + (res ? "TRUE" : "FALSE"));
1138 }
static bool CanClearItem(int cando)
virtual void ShootRepaintTimer()
void SuperImposeSelectedItems()
void ExecuteItem(const QString &itemname)
void ContextMenuActivated(int id)
void ListView_doubleClicked(QTreeWidgetItem *item, int ncol)
Bool_t IsItemMonitored(TGo4Slot *slot)
bool getDrawOnceFlag()
TObject * GetBrowserObject(const char *name, Int_t update=0)
virtual void ChageObjectProtection(const char *fullpath, const char *flags)
void ExportItemsTo(TObjArray *items, Bool_t fetchitems, const char *filename, const char *filedir, const char *format, const char *description)
void linkedObjectUpdated(const char *linkname, TObject *obj)
Int_t ItemKind(const char *name)
bool getFetchDataWhenCopy()
Bool_t isfolder()
Definition: TGo4Iter.cxx:108
virtual Int_t NumCommandArgs(const char *name)
Bool_t IsItemRemote(const char *name)
void SaveSelectedItems()
static bool CanDrawItem(int cando)
TObject * GetLinked(const char *linkname, int updatelevel)
Definition: QGo4Widget.cpp:177
virtual void RemoveObjectFromAnalysis(const char *fullpath)
void ColumnToggled(int indx)
void RenameMemoryItem(const char *itemname, const char *newname)
Int_t ItemCanDo(const char *name)
TGo4Slot * getslot() const
Definition: TGo4Iter.cxx:166
void checkVisisbilityFlags(bool showall)
Bool_t DeleteDataSource(TGo4Slot *itemslot)
TGo4ServerProxy * DefineServerObject(const char *itemname, TString *objname=0, Bool_t onlyanalysis=kTRUE)
void setCanDestroyWidget(bool on=true)
Definition: QGo4Widget.h:200
static bool CanExecuteItem(int cando)
void ShootUpdateTimer()
static bool CanExpandItem(int cando)
const int ColumnAllign[NColumns]
Definition: TGo4Browser.cpp:44
void DisplaySelectedItems()
virtual Bool_t RefreshNamesList()
const int NColumns
Definition: TGo4Browser.cpp:41
bool fVisibleColumns[7]
Definition: TGo4Browser.h:30
TGo4Slot * FindServerSlot(Bool_t databranch, Int_t kind=0)
TGo4BrowserProxy * Browser()
Definition: QGo4Widget.cpp:224
void EditItem(const QString &itemname)
Definition: QGo4Widget.cpp:352
void CreateMemorySubfolder(const char *itemname, const char *newfoldername)
QTreeWidgetItem * nextSibling(QTreeWidgetItem *item)
Definition: TGo4Browser.cpp:46
virtual void ClearAnalysisObject(const char *fullpath)
TGo4ViewPanel * CreateViewPanel(int ndiv=0)
Definition: QGo4Widget.cpp:304
void updateListViewItems()
static const char * ItemInfo(TGo4Slot *slot)
static bool CanDragItem(int cando)
TObject * GetAssignedObject()
Definition: TGo4Slot.cxx:370
virtual TPad * GetSubPad(TPad *toppad, int num, bool onlytoplevel)
Bool_t IsCanDelete(TGo4Slot *slot)
void CopyClipboard(const char *tgtpath, Bool_t forcerequest=kFALSE)
static bool CanExportItem(int cando)
Bool_t IsParent(const TGo4Slot *slot) const
Definition: TGo4Slot.cxx:194
void ShowItemInfo(const QString &itemname)
Definition: QGo4Widget.cpp:299
void StatusMessage(const QString &message)
Definition: QGo4Widget.cpp:245
void SetViewItemProperties(TGo4Slot *itemslot, QTreeWidgetItem *item)
bool canDrawItem(QTreeWidgetItem *item)
void setBrowserColumn(const char *name, int width)
void ResetWidget()
void ItemDropAcceptSlot(void *item, void *mime, bool *res)
void HeaderSectionResizedSlot(int, int, int)
void ClearMemoryItem(const char *itemname)
TGo4Slot * GetParent() const
Definition: TGo4Slot.h:58
Int_t ItemSizeInfo(TGo4Slot *slot)
virtual void Update(Bool_t strong=kFALSE)
Definition: TGo4Slot.cxx:375
Int_t GetItemFilter() const
static const char * ItemDate(TGo4Slot *slot)
TGo4ViewPanel * DrawItem(const QString &itemname, TGo4ViewPanel *panel=0, TPad *pad=0, bool activate=true, int updatelevel=-1)
Definition: QGo4Widget.cpp:312
QString FullItemName(QTreeWidgetItem *item)
void ServiceCall(const char *name, void *par=0)
Definition: QGo4Widget.cpp:405
void StartWorking()
TGo4QSettings * go4sett
const char * ItemClassName(const char *name)
bool getFetchDataWhenSave()
void AddToClipboard(const char *itemname)
const char * getname()
Definition: TGo4Iter.cxx:114
const char * ColumnNames[NColumns]
Definition: TGo4Browser.cpp:43
void FetchItem(const char *itemname, Int_t wait_time=0)
Int_t GetCalcSize(TGo4Slot *slot)
void SetItemMonitored(TGo4Slot *slot, Bool_t on=kTRUE)
TGo4Slot * BrowserMemorySlot()
Bool_t ProduceExplicitCopy(const char *itemname, const char *tgtpath=0, Bool_t forcerequest=kFALSE)
void ItemDropProcessSlot(void *item, void *e)
void ExpandItem(const QString &itemname)
static bool CanCloseItem(int cando)
void GetProtectionBits(TGo4Slot *slot, Int_t &delprot, Int_t &clearprot)
TGo4ServerProxy * DefineServerProxy(const char *itemname)
static QAction * AddIdAction(QMenu *menu, QSignalMapper *map, const QString &text, int id, int enabled=-1, int checked=-1)
Definition: QGo4Widget.cpp:422
static void SetItemCanDo(TGo4Slot *slot, Int_t cando)
void Header_customContextMenuRequested(const QPoint &)
TGo4Browser(QWidget *parent=0, const char *name=0)
Definition: TGo4Browser.cpp:60
Int_t levelchange() const
Definition: TGo4Iter.h:41
void ListView_customContextMenuRequested(const QPoint &)
TGo4ViewPanel * WhereItemDrawn(const char *itemname)
Definition: QGo4Widget.cpp:323
TGo4Slot * BrowserTopSlot()
virtual void SetPadSuperImpose(TPad *pad, bool on)
void ExportSelectedItems(const char *filtername)
void RequestDragObjectSlot(QDrag **)
static bool CanInfoItem(int cando)
QTreeWidgetItem * FindItemFor(TGo4Slot *slot)
TGo4ServerProxy * DefineAnalysisObject(const char *itemname, TString &analysisname)
void AddLink(const char *itemname, const char *linkname)
Definition: QGo4Widget.cpp:122
int getBrowserColumn(const char *name, int defwidth)
virtual Bool_t SubmitCommand(const char *name, Int_t waitres=-1, const char *arg1=0, const char *arg2=0, const char *arg3=0)
bool getHideTGo4EventElement()
static const char * ItemTime(TGo4Slot *slot)
virtual TCanvas * GetCanvas()
TGo4BrowserProxy * BrowserProxy()
static bool CanEditItem(int cando)
Bool_t BrowserItemName(TGo4Slot *itemslot, TString &res)
const int ColumnWidths[NColumns]
Definition: TGo4Browser.cpp:42
TGo4Slot * ItemSlot(const char *itemname)
static Int_t DefineItemProperties(Int_t kind, TClass *cl, TString &pixmap)
bool fbUpdateTimerActive
Definition: TGo4Browser.h:29
Bool_t next(Bool_t goesinto=kTRUE)
Definition: TGo4Iter.cxx:44