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