16 #include <QFileDialog>
17 #include <QInputDialog>
19 #include <QApplication>
22 #include <QSignalMapper>
23 #include <QHeaderView>
27 #include "Riostream.h"
29 #include "TClassTable.h"
31 #include "TObjString.h"
33 #include "TGo4LockGuard.h"
49 const int ColumnAllign[
NColumns] = { Qt::AlignLeft, Qt::AlignLeft, Qt::AlignLeft, Qt::AlignLeft, Qt::AlignLeft, Qt::AlignLeft, Qt::AlignRight };
53 if (item==0)
return 0;
55 QTreeWidgetItem* prnt = item->parent();
56 if (prnt==0) prnt = item->treeWidget()->invisibleRootItem();
57 if (prnt==0)
return 0;
59 int indx = prnt->indexOfChild(item) + 1;
60 if (indx >= prnt->childCount())
return 0;
61 return prnt->child(indx);
70 setAcceptDrops(
false);
75 ListView->setSortingEnabled(
false);
76 ListView->setSelectionMode(QAbstractItemView::ExtendedSelection);
77 ListView->setAcceptDrops(
false);
78 ListView->viewport()->setAcceptDrops(
true);
80 ListView->setRootIsDecorated(
false);
84 for(
int indx=0;indx<
NColumns;indx++) {
90 ListView->headerItem()->setText(indx,
ColumnNames[indx]);
93 ListView->headerItem()->setTextAlignment(indx,
ColumnAllign[indx]);
95 ListView->header()->resizeSection(indx, width>0 ? width :
ColumnWidths[indx]);
99 connect(ListView, SIGNAL(RequestDragObject(QDrag**)),
105 connect(ListView, SIGNAL(ItemDropProcess(
void*,
void*)),
108 connect(ListView->header(), SIGNAL(sectionResized(
int,
int,
int)),
111 connect(ListView->header(), SIGNAL(customContextMenuRequested(
const QPoint &)),
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");
121 ListView->setContextMenuPolicy(Qt::CustomContextMenu);
122 ListView->header()->setContextMenuPolicy(Qt::CustomContextMenu);
134 if (strcmp(linkname,
"Browser")==0) {
138 if (strcmp(linkname,
"TGo4Slot::evSubslotUpdated")==0) {
150 if (ListView->currentItem()==0)
return;
152 QString fullname =
FullItemName(ListView->currentItem());
154 *res =
new QDrag(
this);
155 QMimeData *mimeData =
new QMimeData;
156 mimeData->setText(fullname);
158 (*res)->setMimeData(mimeData);
164 QString tgtname =
FullItemName((QTreeWidgetItem*) item);
165 const QMimeData* mime = (
const QMimeData*) d;
166 if (!mime->hasText())
return;
168 QString dropname = mime->text();
173 if ((tgtslot==0) || (dropslot==0))
return;
176 if (dropslot->
GetParent()==tgtslot)
return;
183 QString tgtname =
FullItemName((QTreeWidgetItem*) item);
184 const QMimeData* mime = (
const QMimeData*) d;
185 if (!mime->hasText())
return;
202 name = item->text(0);
203 while (item->parent()!=0) {
204 item = item->parent();
205 name = item->text(0) +
"/" + name;
218 QString iname = itemname.Data();
220 QTreeWidgetItemIterator it(ListView);
221 for ( ; *it; ++it ) {
223 if (fullname == iname)
return *it;
230 if ((itemslot==0) || (item==0))
return;
241 bool visible =
false;
245 case 2: visible = mon;
break;
246 default: visible =
true;
250 item->setFlags(item->flags() | Qt::ItemIsDragEnabled);
252 item->setFlags(item->flags() & ~
Qt::ItemIsDragEnabled);
254 item->setFlags(item->flags() & ~
Qt::ItemIsDropEnabled);
257 if (itemslot->
IsParent(memslot) || (itemslot==memslot))
258 item->setFlags(item->flags() | Qt::ItemIsDropEnabled);
268 QTreeWidgetItem* parent = item->parent();
270 parent->setText(
NColumns,
"visible");
271 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==0)
return;
337 QTreeWidgetItem* curfold = 0;
338 QTreeWidgetItem* curitem = ListView->topLevelItem(0);
339 QTreeWidgetItem* previtem = 0;
343 TObjArray testedClasses;
346 Bool_t res = iter.
next();
350 while (levelchange++<0) {
358 if (curfold==0)
break;
362 curfold = curfold->parent();
368 while ((curitem!=0) && (strcmp(iter.
getname(), curitem->text(0).toLatin1().constData())!=0)) {
376 std::cerr <<
"************* ERROR in gui slots ****************** " << std::endl;
381 Int_t itemkind = br->
ItemKind(curslot);
382 TClass* itemclass = 0;
384 if ((classname!=0) && (strlen(classname)>0) && (testedClasses.FindObject(classname)==0)) {
386 itemclass = gROOT->GetClass(classname, kFALSE);
389 if ((itemclass==0) && TClassTable::GetDict(classname))
390 itemclass = gROOT->LoadClass(classname);
393 testedClasses.Add(
new TNamed(classname,
""));
398 if (pixmap.Length()>0) pixmap = TString(
":/icons/") + pixmap;
403 curitem =
new QTreeWidgetItem(ListView, previtem);
405 curitem =
new QTreeWidgetItem(curfold, previtem);
408 curitem->setText(0, iter.
getname());
410 if ((pixmap.Length()>0) && curitem->icon(0).isNull())
411 curitem->setIcon(0, QIcon(pixmap.Data()));
422 curitem = curfold->child(0);
426 while (curitem->child(0)!=0)
427 delete curitem->child(0);
443 ListView->viewport()->update();
445 testedClasses.Delete();
450 QTreeWidgetItemIterator it(ListView);
451 for ( ; *it; ++it ) {
452 QTreeWidgetItem* item = *it;
453 if (showall || (item->parent()==0))
454 item->setHidden(
false);
456 item->setHidden(item->text(
NColumns)!=
"visible");
468 QTreeWidgetItemIterator it(ListView);
470 if ((*it)->isSelected() &&
474 if (npads==0)
return;
480 QTreeWidgetItemIterator it(ListView);
487 DrawItem(itemname, newpanel, subpad,
false);
498 QTreeWidgetItemIterator it(ListView);
522 int cando = br->
ItemCanDo(fullname.toLatin1().constData());
528 QWidget* mdi = panel ? panel->parentWidget() : 0;
531 if (mdi->isMinimized()) mdi->showNormal();
532 mdi->activateWindow();
538 if (panel!=0)
return;
548 item->setExpanded(
true);
566 for(
int indx=1;indx<
NColumns;indx++)
569 connect(&map, SIGNAL(mapped(
int)),
this, SLOT(
ColumnToggled(
int)));
571 menu.exec(ListView->header()->mapToGlobal(pos));
577 QTreeWidgetItem* item = ListView->itemAt(pos);
579 int col = ListView->header()->logicalIndexAt(pos);
585 for(
int indx=1;indx<
NColumns;indx++)
588 connect(&map, SIGNAL(mapped(
int)),
this, SLOT(
ColumnToggled(
int)));
590 menu.exec(ListView->viewport()->mapToGlobal(pos));
598 bool istopmemory =
false;
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);
605 QTreeWidgetItemIterator it(ListView);
607 if ((*it)->isSelected()) {
610 if (itemslot==0)
continue;
617 bool ismemitem = itemslot->
IsParent(memslot);
634 TClass* cl = gROOT->GetClass(itemclassname);
636 if (cl->InheritsFrom(
"TH1")) {
637 if (!cl->InheritsFrom(
"TH2") && !cl->InheritsFrom(
"TH3")) {
638 if ((si_kind<0) || (si_kind==1)) {
644 if (cl->InheritsFrom(
"TGraph")) {
645 if ((si_kind<0) || (si_kind==2)) {
652 if (cl->InheritsFrom(
"TF1")) {
653 if ((si_kind<0) || (si_kind==3)) {
671 istopmemory = (itemslot==memslot);
673 if (ismemitem || istopmemory)
685 bool isanalysisitem = (itemslot==analslot) || itemslot->
IsParent(analslot);
687 if (isanalysisitem) nanalysis++;
689 if ((itemclassname!=0) && (strcmp(itemclassname,
"TGo4DabcProxy")==0)) nremote++;
691 if ((itemclassname!=0) && (strcmp(itemclassname,
"TGo4ServerProxy")==0)) nremote++;
696 if (isanalysisitem) {
699 Int_t delprot, clearprot;
701 if (clearprot==1) nclearproton++;
else
702 if (clearprot==0) nclearprotoff++;
703 if (delprot==0) ndelprotoff++;
714 AddIdAction(&menu, &map, QIcon(
":/icons/chart.png"),
715 "Plot", 11, (ndraw>0));
717 AddIdAction(&menu, &map, QIcon(
":/icons/superimpose.png"),
718 "Superimpose", 12, (ndraw>1) && (nsuperimpose==ndraw));
721 AddIdAction(&menu, &map, QIcon(
":/icons/zoomlim.png"),
"Expand", 28,
true);
724 AddIdAction(&menu, &map, QIcon(
":/icons/zoomlim.png"),
"Execute", 29,
true);
726 AddIdAction(&menu, &map, QIcon(
":/icons/right.png"),
727 "Fetch item(s)", 18, (nfolders>0) || (nobjects>0));
729 AddIdAction(&menu, &map, QIcon(
":/icons/saveall.png"),
730 "Save selected...", 13, (nobjects>0) || ((nfolders==1) && (nitems==1)));
735 QMenu* expmenu = menu.addMenu(QIcon(
":/icons/export.png"),
"Export to");
741 AddIdAction(&menu, &map, QIcon(
":/icons/export.png"),
742 "Export to", 14,
false);
745 AddIdAction(&menu, &map, QIcon(
":/icons/info.png"),
746 "Info...", 15, (ninfo>0));
748 AddIdAction(&menu, &map, QIcon(
":/icons/control.png"),
749 "Edit..", 16, (nedits>0));
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";
758 if ((nclose==0) && (ndelete>0)) {
759 dellabel =
"Delete item";
760 if (ndelete>1) dellabel+=
"s";
762 if ((nclose>0) && (ndelete>0)) {
763 dellabel =
"Close/delete items";
767 dellabel, 17, (nclose>0) || (ndelete>0));
769 AddIdAction(&menu, &map, QIcon(
":/icons/copyws.png"),
770 "Copy to Workspace", 19, (nobjects>0) || ((nfolders==1) && (nitems==1)));
772 AddIdAction(&menu, &map, QIcon(
":/icons/editcopy.png"),
773 "Copy to clipboard", 20, (nobjects>0) || (nfolders>0));
775 if ((nremote>0) || (nanalysis>0)) {
779 AddIdAction(&menu, &map, QIcon(
":/icons/monitor.png"),
780 "Monitor item(s)", 21, ((nobjects>0) && (nremote>0) && (nmonitor<nremote)) || ((nfolders==1) && (nitems==1)));
782 AddIdAction(&menu, &map, QIcon(
":/icons/Stop.png"),
783 "Stop item(s) monitoring", 22, ((nobjects>0) && (nremote>0) && (nmonitor>0)) || ((nfolders==1) && (nitems==1)));
785 AddIdAction(&menu, &map, QIcon(
":/icons/clear.png" ),
786 "Clear (Reset to 0)", 23, (nclear>0));
788 AddIdAction(&menu, &map, QIcon(
":/icons/clear_nok.png" ),
789 "Set Clear protection", 24, (nclearprotoff>0));
791 AddIdAction(&menu, &map, QIcon(
":/icons/clear_ok.png" ),
792 "Unset Clear protection", 25, (nclearproton>0));
794 AddIdAction(&menu, &map, QIcon(
":/icons/delete.png" ),
795 "Delete from analysis", 26, (ndelprotoff>0));
797 AddIdAction(&menu, &map, QIcon(
":/icons/refresh.png" ),
798 "Refresh namelist", 27,
true);
801 if ((nmemory>0) && (nmemory==nitems)) {
804 AddIdAction(&menu, &map, QIcon(
":/icons/crefolder.png"),
805 "Create folder", 41, (nmemory==1) && (nfolders==1));
807 AddIdAction(&menu, &map, QIcon(
":/icons/rename.png"),
808 "Rename object", 42, (nmemory==1) && !istopmemory);
810 AddIdAction(&menu, &map, QIcon(
":/icons/clear.png"),
811 "Clear object(s)", 44, (nclearlocal>0));
813 AddIdAction(&menu, &map, QIcon(
":/icons/editpaste.png"),
814 "Paste from clipboard", 43, br->
IsClipboard() && (nmemory==1) && (nfolders==1));
819 menu.exec(ListView->viewport()->mapToGlobal(pos));
824 if ((indx<=0) || (indx>=
NColumns))
return;
835 for(
int indx=0;indx<
NColumns;indx++) {
838 width = ListView->columnWidth(ncolumn++);
863 QApplication::setOverrideCursor(Qt::WaitCursor);
865 QTreeWidgetItemIterator it(ListView);
867 if ((*it)->isSelected()) {
870 if (itemslot==0)
continue;
897 br->
FetchItem(itemname.toLatin1().constData());
926 while (iter.
next()) {
962 if (an!=0) anrefresh = an;
964 if (serv!=0) servrefresh = serv;
970 (*it)->setExpanded(
true);
985 QInputDialog::getText(
this,
986 "Create folder in workspace",
997 QString shortitemname=itemname.section(
"/",-1);
999 QInputDialog::getText(
this,
1000 "Rename item in workspace",
1001 "Input new item name",
1005 if (ok) br->
RenameMemoryItem(itemname.toLatin1().constData(), newname.toLatin1().constData());
1029 QApplication::restoreOverrideCursor();
1034 if (item==0)
return false;
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);
1055 if (fd.exec() != QDialog::Accepted)
return;
1057 QStringList flst = fd.selectedFiles();
1058 if (flst.isEmpty())
return;
1060 QString fname = flst[0];
1063 if (fd.selectedNameFilter() ==
"ROOT (*.root)") {
1065 title = QInputDialog::getText(
this,
1066 "Save slected objects to file",
"Provide file title",
1067 QLineEdit::Normal, QString::null, &ok);
1069 if (fname.indexOf(
".root", 0, Qt::CaseInsensitive)<0) fname+=
".root";
1071 if (fname.indexOf(
".xml", 0, Qt::CaseInsensitive)<0) fname+=
".xml";
1075 QFileInfo(fname).absolutePath().toLatin1().constData(),
1076 fd.selectedNameFilter().toLatin1().constData(),
1077 title.toLatin1().constData());
1082 QFileDialog fd(
this, QString(
"Select directory to export to ") + filtername);
1083 fd.setFileMode(QFileDialog::DirectoryOnly);
1085 if (fd.exec() != QDialog::Accepted)
return;
1087 QStringList flst = fd.selectedFiles();
1088 if (flst.isEmpty())
return;
1091 flst[0].toLatin1().constData(),
1093 "Export of selected items");
1099 QTreeWidgetItemIterator it(ListView);
1101 if ((*it)->isSelected()) {
1103 items.Add(
new TObjString(fullname.toLatin1().constData()));
1118 TString objname, arg1, arg2, arg3;
1122 if ((serv==0) || (objname.Length()==0))
return;
1125 if (nargs<0)
return;
1127 for (Int_t n=0;n<nargs;n++) {
1130 QInputDialog::getText(0,
"Input command arguments",
1131 QString(
"Arg%1:").arg(n+1), QLineEdit::Normal,
"", &ok);
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();
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));
1140 StatusMessage(QString(
" Command execution:") + objname + QString(
" result = ") + (res ?
"TRUE" :
"FALSE"));
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)
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()
virtual Int_t NumCommandArgs(const char *name)
Bool_t IsItemRemote(const char *name)
static bool CanDrawItem(int cando)
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
void checkVisisbilityFlags(bool showall)
Bool_t DeleteDataSource(TGo4Slot *itemslot)
TGo4ServerProxy * DefineServerObject(const char *itemname, TString *objname=0, Bool_t onlyanalysis=kTRUE)
static bool CanExecuteItem(int cando)
static bool CanExpandItem(int cando)
const int ColumnAllign[NColumns]
void DisplaySelectedItems()
virtual Bool_t RefreshNamesList()
TGo4Slot * FindServerSlot(Bool_t databranch, Int_t kind=0)
void CreateMemorySubfolder(const char *itemname, const char *newfoldername)
QTreeWidgetItem * nextSibling(QTreeWidgetItem *item)
virtual void ClearAnalysisObject(const char *fullpath)
void updateListViewItems()
static const char * ItemInfo(TGo4Slot *slot)
static bool CanDragItem(int cando)
TObject * GetAssignedObject()
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
void SetViewItemProperties(TGo4Slot *itemslot, QTreeWidgetItem *item)
bool canDrawItem(QTreeWidgetItem *item)
void setBrowserColumn(const char *name, int width)
void ItemDropAcceptSlot(void *item, void *mime, bool *res)
void HeaderSectionResizedSlot(int, int, int)
void ClearMemoryItem(const char *itemname)
TGo4Slot * GetParent() const
Int_t ItemSizeInfo(TGo4Slot *slot)
virtual void Update(Bool_t strong=kFALSE)
Int_t GetItemFilter() const
static const char * ItemDate(TGo4Slot *slot)
QString FullItemName(QTreeWidgetItem *item)
const char * ItemClassName(const char *name)
bool getFetchDataWhenSave()
void AddToClipboard(const char *itemname)
const char * ColumnNames[NColumns]
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)
Int_t levelchange() const
void ListView_customContextMenuRequested(const QPoint &)
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)
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]
TGo4Slot * ItemSlot(const char *itemname)
static Int_t DefineItemProperties(Int_t kind, TClass *cl, TString &pixmap)
Bool_t next(Bool_t goesinto=kTRUE)