GSI Object Oriented Online Offline (Go4) GO4-6.4.5
Loading...
Searching...
No Matches
TGo4Browser.cpp
Go to the documentation of this file.
1// $Id$
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 <QHeaderView>
24#include <QDrag>
25#include <QMimeData>
26
27#include "TClass.h"
28#include "TClassTable.h"
29#include "TROOT.h"
30#include "TObjString.h"
31#include "TCanvas.h"
32#include "TGo4LockGuard.h"
33#include "TGo4Slot.h"
34#include "TGo4Iter.h"
35#include "TGo4BrowserProxy.h"
36#include "TGo4ServerProxy.h"
37#include "TGo4QSettings.h"
38#include "TGo4ViewPanel.h"
39
40const int ColumnWidths[TGo4Browser::NColumns] = { 150, 40, 120, 90, 60, 100, 50 };
41const char *ColumnNames[TGo4Browser::NColumns] = { "Name", "Flags", "Info", "Date", "Time", "Class", "Size" };
42
43#if QT_VERSION < QT_VERSION_CHECK(5,15,0)
44const int
45#else
46const Qt::Alignment
47#endif
48 ColumnAllign[TGo4Browser::NColumns] = { Qt::AlignLeft, Qt::AlignLeft, Qt::AlignLeft, Qt::AlignLeft, Qt::AlignLeft, Qt::AlignLeft, Qt::AlignRight };
49
50QTreeWidgetItem* nextSibling(QTreeWidgetItem* item)
51{
52 if (!item) return nullptr;
53
54 QTreeWidgetItem* prnt = item->parent();
55 if (!prnt) prnt = item->treeWidget()->invisibleRootItem();
56 if (!prnt) return nullptr;
57
58 int indx = prnt->indexOfChild(item) + 1;
59 if (indx >= prnt->childCount()) return nullptr;
60 return prnt->child(indx);
61}
62
63
64TGo4Browser::TGo4Browser(QWidget *parent, const char *name) :
65 QGo4Widget(parent,name)
66{
67 setupUi(this);
68
69 QObject::connect(ListView, &QGo4BrowserTreeWidget::itemDoubleClicked, this, &TGo4Browser::ListView_doubleClicked);
70 QObject::connect(ListView, &QGo4BrowserTreeWidget::customContextMenuRequested, this, &TGo4Browser::ListView_customContextMenuRequested);
71
72 setAcceptDrops(false);
74
75 fbUpdateTimerActive = false;
76
77 ListView->setSortingEnabled(false);
78 ListView->setSelectionMode(QAbstractItemView::ExtendedSelection);
79 ListView->setAcceptDrops(false);
80 ListView->viewport()->setAcceptDrops(true);
81
82 ListView->setRootIsDecorated(false);
83
84 // ListView->setDragEnabled(true);
85
86 for(int indx = 0; indx < NColumns; indx++) {
87 int width = -1;
88 if ((indx == 0) || (indx == 2)) width = ColumnWidths[indx];
89 width = go4sett->getBrowserColumn(ColumnNames[indx], width);
90 fVisibleColumns[indx] = width > 0;
91
92 ListView->headerItem()->setText(indx, ColumnNames[indx]);
93
94 ListView->header()->setSectionHidden(indx, ! fVisibleColumns[indx]);
95 ListView->headerItem()->setTextAlignment(indx, ColumnAllign[indx]);
96
97 ListView->header()->resizeSection(indx, width>0 ? width : ColumnWidths[indx]);
98 }
99
100 // not in .ui file while designer brakes this connection
102
103// QObject::connect(ListView, &QGo4BrowserTreeWidget::ItemDropAccept, this, &TGo4Browser::ItemDropAcceptSlot);
104
106
107 QObject::connect(ListView->header(), &QHeaderView::sectionResized, this, &TGo4Browser::HeaderSectionResizedSlot);
108
109 QObject::connect(ListView->header(), &QHeaderView::customContextMenuRequested, this, &TGo4Browser::Header_customContextMenuRequested);
110
111 ListView->header()->setToolTip(
112 "You can change selected browser columns\n"
113 "by activating RMB. Flags has following meaning:\n"
114 "m - monitored,\n"
115 "s - static,\n"
116 "d - can be deleted,\n"
117 "p - protected against delete,\n"
118 "r - can not be reset (read only),\n"
119 "w - can be reset");
120
121 ListView->setContextMenuPolicy(Qt::CustomContextMenu);
122 ListView->header()->setContextMenuPolicy(Qt::CustomContextMenu);
123}
124
125
127{
128 AddLink("","Browser");
130}
131
132void TGo4Browser::linkedObjectUpdated(const char *linkname, TObject *obj)
133{
134 if (strcmp(linkname,"Browser") == 0) {
136 } else if (strcmp(linkname,"TGo4Slot::evSubslotUpdated") == 0) {
137 TGo4Slot *itemslot = dynamic_cast<TGo4Slot *> (obj);
138 if (itemslot)
139 SetViewItemProperties(itemslot, FindItemFor(itemslot));
140 }
141}
142
143
145{
146 *res = nullptr;
147
148 if (!ListView->currentItem()) 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
159void 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 || !dropslot) return;
172 if (Browser()->ItemKind(tgtslot) != TGo4Access::kndFolder) return;
173
174 if (dropslot->GetParent() == tgtslot) return;
175
176 *res = true;
177}
178
179void 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
190
195
196QString TGo4Browser::FullItemName(QTreeWidgetItem* item)
197{
198 QString name;
199 if (item) {
200 name = item->text(0);
201 while (item->parent()) {
202 item = item->parent();
203 name = item->text(0) + "/" + name;
204 }
205 }
206 return name;
207}
208
209QTreeWidgetItem* TGo4Browser::FindItemFor(TGo4Slot *slot)
210{
212 if (!br) return nullptr;
213
214 TString itemname;
215 if (!br->BrowserItemName(slot, itemname)) return nullptr;
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 nullptr;
224}
225
226void TGo4Browser::SetViewItemProperties(TGo4Slot *itemslot, QTreeWidgetItem* item)
227{
228 if (!itemslot || !item) 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() != nullptr); 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) {
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())
277// flags += "c";
278// else
279// flags += "a";
280
281 if (remote && (kind == TGo4Access::kndObject)) {
282 if (mon)
283 flags += "m";
284 else
285 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) return;
327
328 ServiceCall("UpdateGuiLayout");
329
330 TGo4Slot *topslot = br->BrowserTopSlot();
331 if (!topslot) return;
332
334
335 QTreeWidgetItem* curfold = nullptr;
336 QTreeWidgetItem* curitem = ListView->topLevelItem(0);
337 QTreeWidgetItem* previtem = nullptr;
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) {
351 QTreeWidgetItem* next = nextSibling(curitem);
352 delete curitem;
353 curitem = next;
354 }
355
356 if (!curfold) 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 && (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) {
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 = nullptr;
381
382 if (classname && (strlen(classname) > 0) && (testedClasses.FindObject(classname) == nullptr)) {
383
384 itemclass = gROOT->GetClass(classname, kFALSE);
385
386 // if dictionary existing (library is loaded) force creation of TClass object
387 if (!itemclass && TClassTable::GetDict(classname))
388 itemclass = gROOT->LoadClass(classname);
389
390 if (!itemclass)
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) {
400 if (!curfold)
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 = nullptr;
422 } else {
423 // remove any substructures if any
424 while (curitem->child(0))
425 delete curitem->child(0);
426 previtem = curitem;
427 curitem = nextSibling(curitem);
428 }
429 }
430
431 while (curitem) {
432 QTreeWidgetItem* next = nextSibling(curitem);
433 delete curitem;
434 curitem = next;
435 }
436
437 if (br->GetItemFilter() > 0)
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())
452 item->setHidden(false);
453 else
454 item->setHidden(item->text(NColumns)!="visible");
455 }
456}
457
459{
460 int npads = 0;
461
462 {
463 QTreeWidgetItemIterator it(ListView);
464 for ( ; *it; ++it )
465 if ((*it)->isSelected() &&
466 canDrawItem(*it)) npads++;
467 }
468
469 if (npads == 0) return;
470
471 TGo4ViewPanel *newpanel = CreateViewPanel(npads);
472 TPad *subpad = nullptr;
473
474 int cnt = 0;
475 QTreeWidgetItemIterator it(ListView);
476 for ( ; *it; ++it )
477 if ( (*it)->isSelected() && canDrawItem(*it)) {
478 QString itemname = FullItemName(*it);
479
480 subpad = newpanel->GetSubPad(newpanel->GetCanvas(), cnt++, true);
481
482 DrawItem(itemname, newpanel, subpad, false);
483 }
484 newpanel->ShootRepaintTimer();
485}
486
487
489{
490 TGo4ViewPanel *newpanel = nullptr;
491
492 QTreeWidgetItemIterator it(ListView);
493 for ( ; *it; ++it )
494 if ( (*it)->isSelected() && canDrawItem(*it)) {
495 if (!newpanel) {
496 newpanel = CreateViewPanel();
497 newpanel->SetPadSuperImpose(newpanel->GetCanvas(), true);
498 }
499
500 QString itemname = FullItemName(*it);
501
502 DrawItem(itemname, newpanel, newpanel->GetCanvas(), false);
503 }
504 if (newpanel)
505 newpanel->ShootRepaintTimer();
506}
507
508void TGo4Browser::ListView_doubleClicked(QTreeWidgetItem* item, int ncol)
509{
510 if (!item) return;
511
512 QString fullname = FullItemName(item);
513
515
516 int cando = br->ItemCanDo(fullname.toLatin1().constData());
517
518 if (go4sett->getDrawOnceFlag()) {
519 TGo4ViewPanel *panel = WhereItemDrawn(fullname.toLatin1().constData());
520
521 QWidget *mdi = panel ? panel->parentWidget() : nullptr;
522
523 if (mdi) {
524 if (mdi->isMinimized()) mdi->showNormal();
525 mdi->activateWindow();
526 mdi->raise();
527 mdi->show();
528 mdi->setFocus();
529 }
530
531 if (panel) return;
532 }
533
535 DrawItem(fullname, nullptr, nullptr, true);
536 } else if (TGo4BrowserProxy::CanEditItem(cando)) {
537 EditItem(fullname);
538 } else if (TGo4BrowserProxy::CanExpandItem(cando)) {
539 item->setExpanded(true);
540 ExpandItem(fullname);
541 } else if (TGo4BrowserProxy::CanExecuteItem(cando)) {
542 ExecuteItem(fullname);
543 }
544}
545
547{
548 QMenu menu;
549
550 for(int indx = 1; indx < NColumns; indx++)
551 QObject::connect(CreateChkAction(&menu, ColumnNames[indx], fVisibleColumns[indx]),
552 &QAction::toggled, [this,indx]() { ColumnToggled(indx); });
553
554 menu.exec(ListView->header()->mapToGlobal(pos));
555}
556
557
559{
560 if (ListView->header()->logicalIndexAt(pos) != 0) {
562 return;
563 }
564
565 QMenu menu;
566
568 TGo4Slot *memslot = br->BrowserMemorySlot();
569 TGo4Slot *analslot = br->FindServerSlot(false, 1);
570
571 bool istopmemory = false;
572
573 int nitems = 0, nmemory = 0, nclose = 0, ndraw = 0, nsuperimpose = 0, si_kind = -1,
574 nremote = 0, nanalysis = 0, nmonitor = 0, nclear = 0, nclearlocal = 0, nclearproton = 0,
575 nclearprotoff = 0, ndelprotoff = 0, nobjects = 0, nfolders = 0, nedits = 0, ninfo = 0,
576 nexport = 0, ndelete = 0, nexpand = 0, nexecute = 0;
577
578 QTreeWidgetItemIterator it(ListView);
579 for ( ; *it; ++it )
580 if ((*it)->isSelected()) {
581 QString fullname = FullItemName(*it);
582 TGo4Slot *itemslot = br->ItemSlot(fullname.toLatin1().constData());
583 if (!itemslot) continue;
584 nitems++;
585
586 int cando = br->ItemCanDo(itemslot);
587 int kind = br->ItemKind(itemslot);
588 const char *itemclassname = br->ItemClassName(itemslot);
589
590 bool ismemitem = itemslot->IsParent(memslot);
591
592 if (br->IsCanDelete(itemslot) || ismemitem)
593 ndelete++;
594
595 if (kind==TGo4Access::kndObject)
596 nobjects++;
597
598 if (kind==TGo4Access::kndFolder)
599 nfolders++;
600
601 if (TGo4BrowserProxy::CanExpandItem(cando)) nexpand++;
602
603 if (TGo4BrowserProxy::CanExecuteItem(cando)) nexecute++;
604
606 ndraw++;
607 TClass *cl = gROOT->GetClass(itemclassname);
608 if (cl) {
609 if (cl->InheritsFrom("TH1")) {
610 if (!cl->InheritsFrom("TH2") && !cl->InheritsFrom("TH3")) {
611 if ((si_kind < 0) || (si_kind == 1)) {
612 si_kind=1;
613 nsuperimpose++;
614 }
615 }
616 } else
617 if (cl->InheritsFrom("TGraph")) {
618 if ((si_kind<0) || (si_kind==2)) {
619 si_kind=2;
620 nsuperimpose++;
621 }
622 }
623 // JAM test for TF1:
624 else
625 if (cl->InheritsFrom("TF1")) {
626 if ((si_kind<0) || (si_kind==3)) {
627 si_kind=3;
628 nsuperimpose++;
629 }
630 }
631 }
632 }
633
635 nedits++;
636
638 nclose++;
639
641 ninfo++;
642
643 istopmemory = (itemslot == memslot);
644
645 if (ismemitem || istopmemory)
646 nmemory++;
647
648 if (ismemitem && TGo4BrowserProxy::CanClearItem(cando))
649 nclearlocal++;
650
651 if ((kind == TGo4Access::kndObject) && itemslot->GetAssignedObject()) {
653 nexport++;
654 }
655
656 bool isanalysisitem = (itemslot == analslot) || itemslot->IsParent(analslot);
657
658 if (isanalysisitem)
659 nanalysis++;
660
661 if (itemclassname && (strcmp(itemclassname,"TGo4DabcProxy") == 0))
662 nremote++;
663
664 if (itemclassname && (strcmp(itemclassname,"TGo4ServerProxy") == 0))
665 nremote++;
666
667 if (br->IsItemRemote(itemslot)) {
668 nremote++;
669
670 if (isanalysisitem) {
671
672 if (kind==TGo4Access::kndObject) {
673 Int_t delprot, clearprot;
674 br->GetProtectionBits(itemslot, delprot, clearprot);
675 if (clearprot == 1)
676 nclearproton++;
677 else if (clearprot == 0)
678 nclearprotoff++;
679 if (delprot == 0)
680 ndelprotoff++;
681 }
682
684 nclear++;
685 }
686 }
687
688 if (br->IsItemMonitored(itemslot)) nmonitor++;
689 }
690
691 auto addAct = [this, &menu](const QString& iconname, const QString& text, int id, bool enabled = true, QMenu *submenu = nullptr) {
692 auto act = iconname.isEmpty() ? new QAction(text, &menu)
693 : new QAction(QIcon(QString(":/icons/") + iconname), text, &menu);
694 act->setEnabled(enabled);
695 if (submenu)
696 submenu->addAction(act);
697 else
698 menu.addAction(act);
699 QObject::connect(act, &QAction::triggered, [this, id]() { ContextMenuActivated(id); });
700 };
701
702 addAct("chart.png", "Plot", 11, ndraw > 0);
703
704 addAct("superimpose.png", "Superimpose", 12, (ndraw>1) && (nsuperimpose==ndraw));
705
706 if (nexpand > 0)
707 addAct("zoomlim.png", "Expand", 28);
708
709 if (nexecute == 1)
710 addAct("zoomlim.png", "Execute", 29);
711
712 addAct("right.png", "Fetch item(s)", 18, (nfolders > 0) || (nobjects > 0));
713
714 addAct("saveall.png", "Save selected...", 13, (nobjects > 0) || ((nfolders == 1) && (nitems == 1)));
715
716 // organize export submenu
717 if (nexport > 0) {
718
719 QMenu* expmenu = menu.addMenu(QIcon(":/icons/export.png"), "Export to");
720
721 addAct("", "ASCII", 141, true, expmenu);
722 addAct("", "Radware", 142, true, expmenu);
723
724 } else {
725 addAct("export.png", "Export to", 14, false);
726 }
727
728 addAct("info.png", "Info...", 15, (ninfo > 0));
729
730 addAct("control.png", "Edit...", 16, (nedits > 0));
731
732 QString dellabel = "Delete item";
733 QString delbutton = "delete.png";
734 if ((nclose > 0) && (ndelete == 0)) {
735 dellabel = "Close item";
736 if (nclose > 1)
737 dellabel += "s";
738 delbutton = "close.png";
739 } else if ((nclose == 0) && (ndelete > 0)) {
740 dellabel = "Delete item";
741 if (ndelete > 1)
742 dellabel += "s";
743 } else if ((nclose > 0) && (ndelete > 0)) {
744 dellabel = "Close/delete items";
745 }
746
747 addAct(delbutton, dellabel, 17, (nclose > 0) || (ndelete > 0));
748
749 addAct("copyws.png", "Copy to Workspace", 19, (nobjects > 0) || ((nfolders == 1) && (nitems == 1)));
750
751 addAct("editcopy.png", "Copy to clipboard", 20, (nobjects>0) || (nfolders>0));
752
753 if ((nremote > 0) || (nanalysis > 0)) {
754
755 menu.addSeparator();
756
757 addAct("monitor.png", "Monitor item(s)", 21, ((nobjects>0) && (nremote>0) && (nmonitor<nremote)) || ((nfolders==1) && (nitems==1)));
758
759 addAct("Stop.png", "Stop item(s) monitoring", 22, ((nobjects>0) && (nremote>0) && (nmonitor>0)) || ((nfolders==1) && (nitems==1)));
760
761 addAct("clear.png", "Clear (Reset to 0)", 23, (nclear > 0));
762
763 addAct("clear_nok.png", "Set Clear protection", 24, (nclearprotoff > 0));
764
765 addAct("clear_ok.png", "Unset Clear protection", 25, (nclearproton > 0));
766
767 addAct("delete.png", "Delete from analysis", 26, (ndelprotoff > 0));
768
769 addAct("refresh.png", "Refresh namelist", 27);
770 }
771
772 if ((nmemory > 0) && (nmemory == nitems)) {
773 menu.addSeparator();
774
775 addAct("crefolder.png", "Create folder", 41, (nmemory==1) && (nfolders==1));
776
777 addAct("rename.png", "Rename object", 42, (nmemory==1) && !istopmemory);
778
779 addAct("clear.png", "Clear object(s)", 44, (nclearlocal > 0));
780
781 addAct(":/icons/editpaste.png", "Paste from clipboard", 43, br->IsClipboard() && (nmemory==1) && (nfolders==1));
782 }
783
784 menu.exec(ListView->viewport()->mapToGlobal(pos));
785}
786
788{
789 if ((indx <= 0) || (indx >= NColumns)) return;
790 fVisibleColumns[indx] = !fVisibleColumns[indx];
791
793
795}
796
798{
799 int ncolumn = 0;
800 for (int indx = 0; indx < NColumns; indx++) {
801 int width = -1;
802 if (fVisibleColumns[indx]) {
803 width = ListView->columnWidth(ncolumn++);
804 if (width == 0) width = ColumnWidths[indx];
805 }
806 go4sett->setBrowserColumn(ColumnNames[indx], width);
807 }
808}
809
811{
812 switch (id) {
813 case 11: DisplaySelectedItems(); return;
814 case 12: SuperImposeSelectedItems(); return;
815 case 13: SaveSelectedItems(); return;
816 case 141: ExportSelectedItems("ASCII format"); return;
817 case 142: ExportSelectedItems("Radware format"); return;
818 }
819
821
822 TGo4ServerProxy *anrefresh = nullptr;
823 TGo4ServerProxy *servrefresh = nullptr;
824
825 if (id == 20) br->ClearClipboard();
826
827 if (id == 19)
828 QApplication::setOverrideCursor(Qt::WaitCursor);
829
830 QTreeWidgetItemIterator it(ListView);
831 for ( ; *it; ++it )
832 if ((*it)->isSelected()) {
833 QString itemname = FullItemName(*it);
834 TGo4Slot *itemslot = br->ItemSlot(itemname.toLatin1().constData());
835 if (!itemslot) continue;
836 int cando = br->ItemCanDo(itemslot);
837 int kind = br->ItemKind(itemslot);
838
839 switch(id) {
840 case 15: {
842 ShowItemInfo(itemname);
843 return;
844 }
845 break;
846 }
847
848 case 16: {
850 EditItem(itemname);
851 return;
852 }
853 break;
854 }
855
856 case 17: {
857 br->DeleteDataSource(itemslot);
858 break;
859 }
860
861 case 18: { // fetch item from the data source
862 br->FetchItem(itemname.toLatin1().constData());
863 break;
864 }
865
866 case 19: {
867 br->ProduceExplicitCopy(itemname.toLatin1().constData(), nullptr, go4sett->getFetchDataWhenCopy());
868 break;
869 }
870
871 case 20: {
872 br->AddToClipboard(itemname.toLatin1().constData());
873 break;
874 }
875
876 case 21: // toggle monitor on
877 case 22: { // toggle monitor off
878 br->SetItemMonitored(itemslot, id==21);
880 break;
881 }
882
883 case 23: { // clear
884 TString objname;
885 TGo4ServerProxy *an = br->DefineAnalysisObject(itemname.toLatin1().constData(), objname);
886 if (an) {
887 an->ClearAnalysisObject(objname.Data());
888 // if clear folder, request all objects which were requested before
889 if (kind==TGo4Access::kndFolder) {
890 TGo4Iter iter(itemslot, kTRUE);
891 while (iter.next()) {
892 TGo4Slot *subslot = iter.getslot();
893 if (subslot->GetAssignedObject())
894 subslot->Update(kFALSE);
895 }
896 } else
897 if (itemslot->GetAssignedObject())
898 itemslot->Update(kFALSE);
899 }
900 break;
901 }
902
903 case 24: // set clear protect
904 case 25: { // unset clear protect
905 TString objname;
906 TGo4ServerProxy *an = br->DefineAnalysisObject(itemname.toLatin1().constData(), objname);
907 if (an) {
908 an->ChageObjectProtection(objname.Data(), (id == 24 ? "+C" : "-C"));
909 anrefresh = an;
910 }
911 break;
912 }
913
914 case 26: { // delete remote object
915 TString objname;
916 TGo4ServerProxy *an = br->DefineAnalysisObject(itemname.toLatin1().constData(), objname);
917 if (an) {
918 an->RemoveObjectFromAnalysis(objname.Data());
919 anrefresh = an;
920 }
921 break;
922 }
923
924 case 27: { // refresh
925 TString objname;
926 TGo4ServerProxy *an = br->DefineAnalysisObject(itemname.toLatin1().constData(), objname);
927 if (an) anrefresh = an;
928 TGo4ServerProxy *serv = br->DefineServerProxy(itemname.toLatin1().constData());
929 if (serv) servrefresh = serv;
930 break;
931 }
932
933 case 28: { // expand
935 (*it)->setExpanded(true);
936 ExpandItem(itemname);
937 }
938 break;
939 }
940
941 case 29: { // execute
943 ExecuteItem(itemname);
944 break;
945 }
946
947 case 41: { // create folder in memory
948 bool ok = false;
949 QString folder =
950 QInputDialog::getText(this,
951 "Create folder in workspace",
952 "Input folder name",
953 QLineEdit::Normal,
954 QString(),
955 &ok);
956 if (ok) br->CreateMemorySubfolder(itemname.toLatin1().constData(), folder.toLatin1().constData());
957 break;
958 }
959
960 case 42: { // rename memory item
961 bool ok = false;
962 QString shortitemname=itemname.section("/",-1);
963 QString newname =
964 QInputDialog::getText(this,
965 "Rename item in workspace",
966 "Input new item name",
967 QLineEdit::Normal,
968 shortitemname,
969 &ok);
970 if (ok) br->RenameMemoryItem(itemname.toLatin1().constData(), newname.toLatin1().constData());
971 break;
972 }
973
974 case 43: { // paste items from clipboard
975 br->CopyClipboard(itemname.toLatin1().constData(), go4sett->getFetchDataWhenCopy());
976 br->ClearClipboard();
977 break;
978 }
979
980 case 44: { // clear memory item
981 br->ClearMemoryItem(itemname.toLatin1().constData());
982 break;
983 }
984 }
985 }
986
987 if (anrefresh)
988 anrefresh->RefreshNamesList();
989
990 if (servrefresh)
991 servrefresh->RefreshNamesList();
992
993 if (id == 19)
994 QApplication::restoreOverrideCursor();
995}
996
997bool TGo4Browser::canDrawItem(QTreeWidgetItem* item)
998{
999 if (!item) return false;
1000 int cando = BrowserProxy()->ItemCanDo(FullItemName(item).toLatin1().constData());
1001 return TGo4BrowserProxy::CanDrawItem(cando);
1002}
1003
1005{
1006 if (fbUpdateTimerActive) return;
1007
1008 fbUpdateTimerActive = true;
1009
1010 QTimer::singleShot(1, this, &TGo4Browser::updateListViewItems);
1011}
1012
1014{
1015 QFileDialog fd(this, "Save selected objects to file", QString(),
1016 "ROOT (*.root);;ROOT XML (*.xml)");
1017 fd.setFileMode( QFileDialog::AnyFile);
1018 fd.setAcceptMode(QFileDialog::AcceptSave);
1019
1020 if (fd.exec() != QDialog::Accepted) return;
1021
1022 QStringList flst = fd.selectedFiles();
1023 if (flst.isEmpty()) return;
1024
1025 QString fname = flst[0];
1026 QString title;
1027
1028 if (fd.selectedNameFilter() == "ROOT (*.root)") {
1029 bool ok = false;
1030 title = QInputDialog::getText(this,
1031 "Save slected objects to file", "Provide file title",
1032 QLineEdit::Normal, QString(), &ok);
1033 if (!ok) return;
1034 if (fname.indexOf(".root", 0, Qt::CaseInsensitive)<0) fname+=".root";
1035 } else {
1036 if (fname.indexOf(".xml", 0, Qt::CaseInsensitive)<0) fname+=".xml";
1037 }
1038
1039 ExportSelectedItems(fname.toLatin1().constData(),
1040 QFileInfo(fname).absolutePath().toLatin1().constData(),
1041 fd.selectedNameFilter().toLatin1().constData(),
1042 title.toLatin1().constData());
1043}
1044
1045void TGo4Browser::ExportSelectedItems(const char *filtername)
1046{
1047 QFileDialog fd(this, QString("Select directory to export to ") + filtername);
1048 fd.setOption(QFileDialog::ShowDirsOnly, true);
1049 fd.setFileMode(QFileDialog::Directory);
1050 fd.setOption(QFileDialog::DontUseNativeDialog);
1051
1052 if (fd.exec() != QDialog::Accepted) return;
1053
1054 QStringList flst = fd.selectedFiles();
1055 if (flst.isEmpty()) return;
1056
1057 ExportSelectedItems("null",
1058 flst[0].toLatin1().constData(),
1059 filtername,
1060 "Export of selected items");
1061}
1062
1063void TGo4Browser::ExportSelectedItems(const char *filename, const char *filedir, const char *format, const char *description)
1064{
1065 TObjArray items;
1066 QTreeWidgetItemIterator it(ListView);
1067 for ( ; *it; ++it )
1068 if ((*it)->isSelected()) {
1069 QString fullname = FullItemName(*it);
1070 items.Add(new TObjString(fullname.toLatin1().constData()));
1071 }
1072
1073 BrowserProxy()->ExportItemsTo(&items, go4sett->getFetchDataWhenSave(), filename, filedir, format, description);
1074
1075 items.Delete();
1076}
1077
1078void TGo4Browser::ExpandItem(const QString& itemname)
1079{
1080 BrowserProxy()->GetBrowserObject(itemname.toLatin1().constData(), 100);
1081}
1082
1083void TGo4Browser::ExecuteItem(const QString& itemname)
1084{
1085 TString objname, arg1, arg2, arg3;
1086
1087 TGo4ServerProxy *serv = BrowserProxy()->DefineServerObject(itemname.toLatin1().constData(), &objname, kFALSE);
1088
1089 if (!serv || objname.IsNull()) return;
1090
1091 Int_t nargs = serv->NumCommandArgs(objname);
1092 if (nargs < 0) return;
1093
1094 for (Int_t n = 0; n < nargs; n++) {
1095 bool ok = false;
1096 QString value =
1097 QInputDialog::getText(nullptr, "Input command arguments",
1098 QString("Arg%1:").arg(n+1), QLineEdit::Normal, "", &ok);
1099 if (!ok) return;
1100 if (n == 0)
1101 arg1 = value.toLatin1().constData();
1102 else if (n == 1)
1103 arg2 = value.toLatin1().constData();
1104 else if (n == 2)
1105 arg3 = value.toLatin1().constData();
1106 }
1107
1108 Bool_t res = serv->SubmitCommand(objname, 3, (arg1.Length() > 0 ? arg1.Data() : nullptr), (arg2.Length() > 0 ? arg2.Data() : nullptr), (arg3.Length() > 0 ? arg3.Data() : nullptr));
1109
1110 StatusMessage(QString(" Command execution:") + objname + QString(" result = ") + (res ? "TRUE" : "FALSE"));
1111}
#define TGo4LockGuard
const int ColumnWidths[TGo4Browser::NColumns]
QTreeWidgetItem * nextSibling(QTreeWidgetItem *item)
const char * ColumnNames[TGo4Browser::NColumns]
const Qt::Alignment ColumnAllign[TGo4Browser::NColumns]
void RequestDragObject(QDrag **)
void ItemDropProcess(void *, void *)
T * GetLinkedCast(const char *linkname, int updatelevel=0)
Definition QGo4Widget.h:157
void ShowItemInfo(const QString &itemname)
static QAction * CreateChkAction(QMenu *menu, const QString &text, bool checked, bool enabled=true)
void setCanDestroyWidget(bool on=true)
Definition QGo4Widget.h:201
TGo4ViewPanel * DrawItem(const QString &itemname, TGo4ViewPanel *panel=nullptr, TPad *pad=nullptr, bool activate=true, int updatelevel=-1)
QGo4Widget(QWidget *parent=nullptr, const char *name=nullptr, Qt::WindowFlags f=Qt::Widget)
void AddLink(const char *itemname, const char *linkname)
create link for item with name linkname
void StatusMessage(const QString &message)
TGo4ViewPanel * WhereItemDrawn(const char *itemname)
void ServiceCall(const char *name, void *par=nullptr)
TGo4BrowserProxy * Browser()
void EditItem(const QString &itemname)
TGo4ViewPanel * CreateViewPanel(int ndiv=0)
@ kndTreeBranch
Definition TGo4Proxy.h:37
void RenameMemoryItem(const char *itemname, const char *newname)
static bool CanExportItem(int cando)
Bool_t IsCanDelete(TGo4Slot *slot) const
TGo4Slot * FindServerSlot(Bool_t databranch, Int_t kind=0)
Bool_t DeleteDataSource(TGo4Slot *itemslot)
static bool CanCloseItem(int cando)
TGo4ServerProxy * DefineServerProxy(const char *itemname)
TGo4Slot * BrowserTopSlot()
TGo4ServerProxy * DefineAnalysisObject(const char *itemname, TString &analysisname)
TGo4Slot * ItemSlot(const char *itemname)
static bool CanExecuteItem(int cando)
Int_t ItemSizeInfo(TGo4Slot *slot)
Bool_t ProduceExplicitCopy(const char *itemname, const char *tgtpath=nullptr, Bool_t forcerequest=kFALSE)
TObject * GetBrowserObject(const char *name, Int_t update=0)
void CreateMemorySubfolder(const char *itemname, const char *newfoldername)
static bool CanExpandItem(int cando)
static void SetItemCanDo(TGo4Slot *slot, Int_t cando)
static bool CanClearItem(int cando)
Int_t ItemCanDo(const char *name)
void ExportItemsTo(TObjArray *items, Bool_t fetchitems, const char *filename, const char *filedir, const char *format, const char *description)
Int_t ItemKind(const char *name)
Int_t GetCalcSize(TGo4Slot *slot)
TGo4Slot * BrowserMemorySlot()
void GetProtectionBits(TGo4Slot *slot, Int_t &delprot, Int_t &clearprot)
static const char * ItemTime(TGo4Slot *slot)
void FetchItem(const char *itemname, Int_t wait_time=0)
void SetItemMonitored(TGo4Slot *slot, Bool_t on=kTRUE)
void CopyClipboard(const char *tgtpath, Bool_t forcerequest=kFALSE)
void ClearMemoryItem(const char *itemname)
static const char * ItemInfo(TGo4Slot *slot)
Bool_t BrowserItemName(TGo4Slot *itemslot, TString &res)
static Int_t DefineItemProperties(Int_t kind, TClass *cl, TString &pixmap)
void AddToClipboard(const char *itemname)
Bool_t IsItemRemote(const char *name)
static bool CanInfoItem(int cando)
static bool CanEditItem(int cando)
static const char * ItemDate(TGo4Slot *slot)
static bool CanDrawItem(int cando)
const char * ItemClassName(const char *name)
TGo4ServerProxy * DefineServerObject(const char *itemname, TString *objname=nullptr, Bool_t onlyanalysis=kTRUE)
Bool_t IsItemMonitored(TGo4Slot *slot) const
Bool_t IsClipboard() const
static bool CanDragItem(int cando)
Int_t GetItemFilter() const
void RequestDragObjectSlot(QDrag **)
void SuperImposeSelectedItems()
TGo4Browser(QWidget *parent=nullptr, const char *name=nullptr)
void checkVisisbilityFlags(bool showall)
void ColumnToggled(int indx)
void ContextMenuActivated(int id)
void ShootUpdateTimer()
void updateListViewItems()
bool canDrawItem(QTreeWidgetItem *item)
void DisplaySelectedItems()
void ItemDropAcceptSlot(void *item, void *mime, bool *res)
void Header_customContextMenuRequested(const QPoint &)
void ExecuteItem(const QString &itemname)
QTreeWidgetItem * FindItemFor(TGo4Slot *slot)
void SaveSelectedItems()
void linkedObjectUpdated(const char *linkname, TObject *obj) override
void HeaderSectionResizedSlot(int, int, int)
void ExpandItem(const QString &itemname)
void SetViewItemProperties(TGo4Slot *itemslot, QTreeWidgetItem *item)
void ExportSelectedItems(const char *filtername)
void StartWorking()
QString FullItemName(QTreeWidgetItem *item)
void ListView_doubleClicked(QTreeWidgetItem *item, int ncol)
void ResetWidget() override
void ItemDropProcessSlot(void *item, void *e)
bool fVisibleColumns[NColumns]
Definition TGo4Browser.h:91
TGo4BrowserProxy * BrowserProxy()
bool fbUpdateTimerActive
Definition TGo4Browser.h:90
void ListView_customContextMenuRequested(const QPoint &)
Bool_t isfolder()
Definition TGo4Iter.cxx:109
Bool_t next(Bool_t goesinto=kTRUE)
Definition TGo4Iter.cxx:44
const char * getname()
Definition TGo4Iter.cxx:115
TGo4Slot * getslot() const
Definition TGo4Iter.cxx:166
Int_t levelchange() const
Definition TGo4Iter.h:41
special base class for remote data servers like DABC, HTTP, hist server
virtual Int_t NumCommandArgs(const char *name)
virtual void ChageObjectProtection(const char *fullpath, const char *flags)
virtual Bool_t SubmitCommand(const char *name, Int_t waitres=-1, const char *arg1=nullptr, const char *arg2=nullptr, const char *arg3=nullptr)
virtual void RemoveObjectFromAnalysis(const char *fullpath)
virtual Bool_t RefreshNamesList()
virtual void ClearAnalysisObject(const char *fullpath)
TGo4Slot * GetParent() const
Definition TGo4Slot.h:58
virtual void Update(Bool_t strong=kFALSE)
Definition TGo4Slot.cxx:361
Bool_t IsParent(const TGo4Slot *slot) const
Definition TGo4Slot.cxx:178
TObject * GetAssignedObject()
Definition TGo4Slot.cxx:356
virtual void ShootRepaintTimer()
virtual void SetPadSuperImpose(TPad *pad, bool on)
virtual TCanvas * GetCanvas()
virtual TPad * GetSubPad(TPad *toppad, int num, bool onlytoplevel)
TGo4QSettings * go4sett