19#include <QInputDialog>
21#include <QApplication>
28#include "TClassTable.h"
30#include "TObjString.h"
32#include "TGo4LockGuard.h"
43#if QT_VERSION < QT_VERSION_CHECK(5,15,0)
52 if (!item)
return nullptr;
54 QTreeWidgetItem* prnt = item->parent();
55 if (!prnt) prnt = item->treeWidget()->invisibleRootItem();
56 if (!prnt)
return nullptr;
58 int indx = prnt->indexOfChild(item) + 1;
59 if (indx >= prnt->childCount())
return nullptr;
60 return prnt->child(indx);
72 setAcceptDrops(
false);
77 ListView->setSortingEnabled(
false);
78 ListView->setSelectionMode(QAbstractItemView::ExtendedSelection);
79 ListView->setAcceptDrops(
false);
80 ListView->viewport()->setAcceptDrops(
true);
82 ListView->setRootIsDecorated(
false);
86 for(
int indx = 0; indx <
NColumns; indx++) {
88 if ((indx == 0) || (indx == 2)) width =
ColumnWidths[indx];
92 ListView->headerItem()->setText(indx,
ColumnNames[indx]);
95 ListView->headerItem()->setTextAlignment(indx,
ColumnAllign[indx]);
97 ListView->header()->resizeSection(indx, width>0 ? width :
ColumnWidths[indx]);
111 ListView->header()->setToolTip(
112 "You can change selected browser columns\n"
113 "by activating RMB. Flags has following meaning:\n"
116 "d - can be deleted,\n"
117 "p - protected against delete,\n"
118 "r - can not be reset (read only),\n"
121 ListView->setContextMenuPolicy(Qt::CustomContextMenu);
122 ListView->header()->setContextMenuPolicy(Qt::CustomContextMenu);
134 if (strcmp(linkname,
"Browser") == 0) {
136 }
else if (strcmp(linkname,
"TGo4Slot::evSubslotUpdated") == 0) {
148 if (!ListView->currentItem())
return;
150 QString fullname =
FullItemName(ListView->currentItem());
152 *res =
new QDrag(
this);
153 QMimeData *mimeData =
new QMimeData;
154 mimeData->setText(fullname);
156 (*res)->setMimeData(mimeData);
162 QString tgtname =
FullItemName((QTreeWidgetItem*) item);
163 const QMimeData* mime = (
const QMimeData*) d;
164 if (!mime->hasText())
return;
166 QString dropname = mime->text();
171 if (!tgtslot || !dropslot)
return;
174 if (dropslot->
GetParent() == tgtslot)
return;
181 QString tgtname =
FullItemName((QTreeWidgetItem*) item);
182 const QMimeData* mime = (
const QMimeData*) d;
183 if (!mime->hasText())
return;
200 name = item->text(0);
201 while (item->parent()) {
202 item = item->parent();
203 name = item->text(0) +
"/" + name;
212 if (!br)
return nullptr;
216 QString iname = itemname.Data();
218 QTreeWidgetItemIterator it(ListView);
219 for ( ; *it; ++it ) {
221 if (fullname == iname)
return *it;
228 if (!itemslot || !item)
return;
239 bool visible =
false;
243 case 2: visible = mon;
break;
244 default: visible =
true;
248 item->setFlags(item->flags() | Qt::ItemIsDragEnabled);
250 item->setFlags(item->flags() & ~Qt::ItemIsDragEnabled);
252 item->setFlags(item->flags() & ~Qt::ItemIsDropEnabled);
255 if (itemslot->
IsParent(memslot) || (itemslot==memslot))
256 item->setFlags(item->flags() | Qt::ItemIsDropEnabled);
266 QTreeWidgetItem* parent = item->parent();
268 parent->setText(
NColumns,
"visible");
269 parent = parent->parent();
286 Int_t delprot, clearprot;
290 case 0: flags+=
"d";
break;
291 case 1: flags+=
"p";
break;
292 default: flags+=
"-";
break;
296 case 0: flags+=
"w";
break;
297 case 1: flags+=
"r";
break;
298 default: flags+=
"-";
break;
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 =
"";
309 if (sizeinfo>0) sizelbl = QString::number(sizeinfo);
else
310 if (calcsize>0) sizelbl = QString(
"= ") + QString::number(calcsize);
311 item->setText(6, sizelbl);
322 for (
int indx = 0; indx <
NColumns; indx++)
331 if (!topslot)
return;
335 QTreeWidgetItem* curfold =
nullptr;
336 QTreeWidgetItem* curitem = ListView->topLevelItem(0);
337 QTreeWidgetItem* previtem =
nullptr;
341 TObjArray testedClasses;
344 Bool_t res = iter.
next();
348 while (levelchange++ < 0) {
360 curfold = curfold->parent();
366 while (curitem && (strcmp(iter.
getname(), curitem->text(0).toLatin1().constData()) != 0)) {
374 std::cerr <<
"************* ERROR in gui slots ****************** " << std::endl;
379 Int_t itemkind = br->
ItemKind(curslot);
380 TClass *itemclass =
nullptr;
382 if (classname && (strlen(classname) > 0) && (testedClasses.FindObject(classname) ==
nullptr)) {
384 itemclass = gROOT->GetClass(classname, kFALSE);
387 if (!itemclass && TClassTable::GetDict(classname))
388 itemclass = gROOT->LoadClass(classname);
391 testedClasses.Add(
new TNamed(classname,
""));
396 if (pixmap.Length()>0) pixmap = TString(
":/icons/") + pixmap;
401 curitem =
new QTreeWidgetItem(ListView, previtem);
403 curitem =
new QTreeWidgetItem(curfold, previtem);
406 curitem->setText(0, iter.
getname());
408 if ((pixmap.Length()>0) && curitem->icon(0).isNull())
409 curitem->setIcon(0, QIcon(pixmap.Data()));
413 curitem->setHidden(
go4sett->getHideTGo4EventElement());
420 curitem = curfold->child(0);
424 while (curitem->child(0))
425 delete curitem->child(0);
441 ListView->viewport()->update();
443 testedClasses.Delete();
448 QTreeWidgetItemIterator it(ListView);
449 for ( ; *it; ++it ) {
450 QTreeWidgetItem* item = *it;
451 if (showall || !item->parent())
452 item->setHidden(
false);
454 item->setHidden(item->text(
NColumns)!=
"visible");
463 QTreeWidgetItemIterator it(ListView);
465 if ((*it)->isSelected() &&
469 if (npads == 0)
return;
472 TPad *subpad =
nullptr;
475 QTreeWidgetItemIterator it(ListView);
482 DrawItem(itemname, newpanel, subpad,
false);
492 QTreeWidgetItemIterator it(ListView);
516 int cando = br->
ItemCanDo(fullname.toLatin1().constData());
518 if (
go4sett->getDrawOnceFlag()) {
521 QWidget *mdi = panel ? panel->parentWidget() :
nullptr;
524 if (mdi->isMinimized()) mdi->showNormal();
525 mdi->activateWindow();
535 DrawItem(fullname,
nullptr,
nullptr,
true);
539 item->setExpanded(
true);
550 for(
int indx = 1; indx <
NColumns; indx++)
554 menu.exec(ListView->header()->mapToGlobal(pos));
560 if (ListView->header()->logicalIndexAt(pos) != 0) {
571 bool istopmemory =
false;
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, nassigned = 0, nexpand = 0, nexecute = 0;
578 QTreeWidgetItemIterator it(ListView);
580 if ((*it)->isSelected()) {
583 if (!itemslot)
continue;
590 bool ismemitem = itemslot->
IsParent(memslot);
607 TClass *cl = gROOT->GetClass(itemclassname);
609 if (cl->InheritsFrom(
"TH1")) {
610 if (!cl->InheritsFrom(
"TH2") && !cl->InheritsFrom(
"TH3")) {
611 if ((si_kind < 0) || (si_kind == 1)) {
617 if (cl->InheritsFrom(
"TGraph")) {
618 if ((si_kind<0) || (si_kind==2)) {
625 if (cl->InheritsFrom(
"TF1")) {
626 if ((si_kind<0) || (si_kind==3)) {
643 istopmemory = (itemslot==memslot);
645 if (ismemitem || istopmemory)
657 bool isanalysisitem = (itemslot==analslot) || itemslot->
IsParent(analslot);
659 if (isanalysisitem) nanalysis++;
661 if (itemclassname && (strcmp(itemclassname,
"TGo4DabcProxy") == 0)) nremote++;
663 if (itemclassname && (strcmp(itemclassname,
"TGo4ServerProxy") == 0)) nremote++;
668 if (isanalysisitem) {
671 Int_t delprot, clearprot;
675 else if (clearprot == 0)
689 auto addAct = [
this, &menu](
const QString& iconname,
const QString& text,
int id,
bool enabled =
true, QMenu *submenu =
nullptr) {
690 auto act = iconname.isEmpty() ?
new QAction(text, &menu)
691 :
new QAction(QIcon(QString(
":/icons/") + iconname), text, &menu);
692 act->setEnabled(enabled);
694 submenu->addAction(act);
700 addAct(
"chart.png",
"Plot", 11, ndraw > 0);
702 addAct(
"superimpose.png",
"Superimpose", 12, (ndraw>1) && (nsuperimpose==ndraw));
705 addAct(
"zoomlim.png",
"Expand", 28);
708 addAct(
"zoomlim.png",
"Execute", 29);
710 addAct(
"right.png",
"Fetch item(s)", 18, (nfolders > 0) || (nobjects > 0));
712 addAct(
"saveall.png",
"Save selected...", 13, (nobjects > 0) || ((nfolders == 1) && (nitems == 1)));
717 QMenu* expmenu = menu.addMenu(QIcon(
":/icons/export.png"),
"Export to");
719 addAct(
"",
"ASCII", 141,
true, expmenu);
720 addAct(
"",
"Radware", 142,
true, expmenu);
723 addAct(
"export.png",
"Export to", 14,
false);
726 addAct(
"info.png",
"Info...", 15, (ninfo > 0));
728 addAct(
"control.png",
"Edit...", 16, (nedits > 0));
730 QString dellabel =
"Delete item";
731 QString delbutton =
"delete.png";
732 if ((nclose > 0) && (ndelete == 0)) {
733 dellabel =
"Close item";
736 delbutton =
"close.png";
737 }
else if ((nclose == 0) && (ndelete > 0)) {
738 dellabel =
"Delete item";
741 }
else if ((nclose > 0) && (ndelete > 0)) {
742 dellabel =
"Close/delete items";
745 addAct(delbutton, dellabel, 17, (nclose > 0) || (ndelete > 0));
747 addAct(
"copyws.png",
"Copy to Workspace", 19, (nobjects > 0) || ((nfolders == 1) && (nitems == 1)));
749 addAct(
"editcopy.png",
"Copy to clipboard", 20, (nobjects>0) || (nfolders>0));
751 if ((nremote > 0) || (nanalysis > 0)) {
755 addAct(
"monitor.png",
"Monitor item(s)", 21, ((nobjects>0) && (nremote>0) && (nmonitor<nremote)) || ((nfolders==1) && (nitems==1)));
757 addAct(
"Stop.png",
"Stop item(s) monitoring", 22, ((nobjects>0) && (nremote>0) && (nmonitor>0)) || ((nfolders==1) && (nitems==1)));
759 addAct(
"clear.png",
"Clear (Reset to 0)", 23, (nclear > 0));
761 addAct(
"clear_nok.png",
"Set Clear protection", 24, (nclearprotoff > 0));
763 addAct(
"clear_ok.png",
"Unset Clear protection", 25, (nclearproton > 0));
765 addAct(
"delete.png",
"Delete from analysis", 26, (ndelprotoff > 0));
767 addAct(
"refresh.png",
"Refresh namelist", 27);
770 if ((nmemory > 0) && (nmemory == nitems)) {
773 addAct(
"crefolder.png",
"Create folder", 41, (nmemory==1) && (nfolders==1));
775 addAct(
"rename.png",
"Rename object", 42, (nmemory==1) && !istopmemory);
777 addAct(
"clear.png",
"Clear object(s)", 44, (nclearlocal > 0));
779 addAct(
":/icons/editpaste.png",
"Paste from clipboard", 43, br->
IsClipboard() && (nmemory==1) && (nfolders==1));
782 menu.exec(ListView->viewport()->mapToGlobal(pos));
787 if ((indx <= 0) || (indx >=
NColumns))
return;
798 for (
int indx = 0; indx <
NColumns; indx++) {
801 width = ListView->columnWidth(ncolumn++);
826 QApplication::setOverrideCursor(Qt::WaitCursor);
828 QTreeWidgetItemIterator it(ListView);
830 if ((*it)->isSelected()) {
833 if (!itemslot)
continue;
860 br->
FetchItem(itemname.toLatin1().constData());
889 while (iter.
next()) {
925 if (an) anrefresh = an;
927 if (serv) servrefresh = serv;
933 (*it)->setExpanded(
true);
948 QInputDialog::getText(
this,
949 "Create folder in workspace",
960 QString shortitemname=itemname.section(
"/",-1);
962 QInputDialog::getText(
this,
963 "Rename item in workspace",
964 "Input new item name",
968 if (ok) br->
RenameMemoryItem(itemname.toLatin1().constData(), newname.toLatin1().constData());
992 QApplication::restoreOverrideCursor();
997 if (!item)
return false;
1013 QFileDialog fd(
this,
"Save selected objects to file", QString(),
1014 "ROOT (*.root);;ROOT XML (*.xml)");
1015 fd.setFileMode( QFileDialog::AnyFile);
1016 fd.setAcceptMode(QFileDialog::AcceptSave);
1018 if (fd.exec() != QDialog::Accepted)
return;
1020 QStringList flst = fd.selectedFiles();
1021 if (flst.isEmpty())
return;
1023 QString fname = flst[0];
1026 if (fd.selectedNameFilter() ==
"ROOT (*.root)") {
1028 title = QInputDialog::getText(
this,
1029 "Save slected objects to file",
"Provide file title",
1030 QLineEdit::Normal, QString(), &ok);
1032 if (fname.indexOf(
".root", 0, Qt::CaseInsensitive)<0) fname+=
".root";
1034 if (fname.indexOf(
".xml", 0, Qt::CaseInsensitive)<0) fname+=
".xml";
1038 QFileInfo(fname).absolutePath().toLatin1().constData(),
1039 fd.selectedNameFilter().toLatin1().constData(),
1040 title.toLatin1().constData());
1045 QFileDialog fd(
this, QString(
"Select directory to export to ") + filtername);
1046 fd.setOption(QFileDialog::ShowDirsOnly,
true);
1047 fd.setFileMode(QFileDialog::Directory);
1048 fd.setOption(QFileDialog::DontUseNativeDialog);
1050 if (fd.exec() != QDialog::Accepted)
return;
1052 QStringList flst = fd.selectedFiles();
1053 if (flst.isEmpty())
return;
1056 flst[0].toLatin1().constData(),
1058 "Export of selected items");
1064 QTreeWidgetItemIterator it(ListView);
1066 if ((*it)->isSelected()) {
1068 items.Add(
new TObjString(fullname.toLatin1().constData()));
1083 TString objname, arg1, arg2, arg3;
1087 if (!serv || objname.IsNull())
return;
1090 if (nargs < 0)
return;
1092 for (Int_t n = 0; n < nargs; n++) {
1095 QInputDialog::getText(
nullptr,
"Input command arguments",
1096 QString(
"Arg%1:").arg(n+1), QLineEdit::Normal,
"", &ok);
1099 arg1 = value.toLatin1().constData();
1101 arg2 = value.toLatin1().constData();
1103 arg3 = value.toLatin1().constData();
1106 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));
1108 StatusMessage(QString(
" Command execution:") + objname + QString(
" result = ") + (res ?
"TRUE" :
"FALSE"));
const int ColumnWidths[TGo4Browser::NColumns]
QTreeWidgetItem * nextSibling(QTreeWidgetItem *item)
const char * ColumnNames[TGo4Browser::NColumns]
const Qt::Alignment ColumnAllign[TGo4Browser::NColumns]
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 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 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)
QString FullItemName(QTreeWidgetItem *item)
void ListView_doubleClicked(QTreeWidgetItem *item, int ncol)
void ResetWidget() override
void ItemDropProcessSlot(void *item, void *e)
TGo4BrowserProxy * BrowserProxy()
void ListView_customContextMenuRequested(const QPoint &)
bool fVisibleColumns[NColumns]
Bool_t next(Bool_t goesinto=kTRUE)
TGo4Slot * getslot() const
Int_t levelchange() const
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
virtual void Update(Bool_t strong=kFALSE)
Bool_t IsParent(const TGo4Slot *slot) const
TObject * GetAssignedObject()
virtual void ShootRepaintTimer()
virtual void SetPadSuperImpose(TPad *pad, bool on)
virtual TCanvas * GetCanvas()
virtual TPad * GetSubPad(TPad *toppad, int num, bool onlytoplevel)