18 #include <QFileDialog>
19 #include <QInputDialog>
21 #include <QApplication>
23 #include <QSignalMapper>
24 #include <QHeaderView>
29 #include "TClassTable.h"
31 #include "TObjString.h"
33 #include "TGo4LockGuard.h"
44 const int ColumnAllign[
NColumns] = { Qt::AlignLeft, Qt::AlignLeft, Qt::AlignLeft, Qt::AlignLeft, Qt::AlignLeft, Qt::AlignLeft, Qt::AlignRight };
48 if (item==0)
return 0;
50 QTreeWidgetItem* prnt = item->parent();
51 if (prnt==0) prnt = item->treeWidget()->invisibleRootItem();
52 if (prnt==0)
return 0;
54 int indx = prnt->indexOfChild(item) + 1;
55 if (indx >= prnt->childCount())
return 0;
56 return prnt->child(indx);
65 QObject::connect(ListView, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,
int)),
this, SLOT(
ListView_doubleClicked(QTreeWidgetItem*,
int)));
68 setAcceptDrops(
false);
73 ListView->setSortingEnabled(
false);
74 ListView->setSelectionMode(QAbstractItemView::ExtendedSelection);
75 ListView->setAcceptDrops(
false);
76 ListView->viewport()->setAcceptDrops(
true);
78 ListView->setRootIsDecorated(
false);
82 for(
int indx=0;indx<
NColumns;indx++) {
88 ListView->headerItem()->setText(indx,
ColumnNames[indx]);
91 ListView->headerItem()->setTextAlignment(indx,
ColumnAllign[indx]);
93 ListView->header()->resizeSection(indx, width>0 ? width :
ColumnWidths[indx]);
97 connect(ListView, SIGNAL(RequestDragObject(QDrag**)),
103 connect(ListView, SIGNAL(ItemDropProcess(
void*,
void*)),
106 connect(ListView->header(), SIGNAL(sectionResized(
int,
int,
int)),
109 connect(ListView->header(), SIGNAL(customContextMenuRequested(
const QPoint &)),
112 ListView->header()->setToolTip(
113 QString(
"You can change selected browser columns\n") +
114 "by activating RMB. Flags has following meaning\n" +
115 "m - monitored,\ns - static,\n" +
116 "d - can be deleted,\np - protected against delete\n" +
117 "r - can not be reset (read only),\nw - can be reset");
119 ListView->setContextMenuPolicy(Qt::CustomContextMenu);
120 ListView->header()->setContextMenuPolicy(Qt::CustomContextMenu);
132 if (strcmp(linkname,
"Browser")==0) {
136 if (strcmp(linkname,
"TGo4Slot::evSubslotUpdated")==0) {
148 if (ListView->currentItem()==0)
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==0) || (dropslot==0))
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()!=0) {
202 item = item->parent();
203 name = item->text(0) +
"/" + name;
216 QString iname = itemname.Data();
218 QTreeWidgetItemIterator it(ListView);
219 for ( ; *it; ++it ) {
221 if (fullname == iname)
return *it;
228 if ((itemslot==0) || (item==0))
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();
284 Int_t delprot, clearprot;
288 case 0: flags+=
"d";
break;
289 case 1: flags+=
"p";
break;
290 default: flags+=
"-";
break;
294 case 0: flags+=
"w";
break;
295 case 1: flags+=
"r";
break;
296 default: flags+=
"-";
break;
299 item->setText(1, flags);
300 item->setText(2, iteminfo);
301 item->setText(3, br->
ItemDate(itemslot));
302 item->setText(4, br->
ItemTime(itemslot));
303 item->setText(5, classname);
304 QString sizelbl =
"";
307 if (sizeinfo>0) sizelbl = QString::number(sizeinfo);
else
308 if (calcsize>0) sizelbl = QString(
"= ") + QString::number(calcsize);
309 item->setText(6, sizelbl);
320 for(
int indx=0;indx<
NColumns;indx++)
329 if (topslot==0)
return;
335 QTreeWidgetItem* curfold = 0;
336 QTreeWidgetItem* curitem = ListView->topLevelItem(0);
337 QTreeWidgetItem* previtem = 0;
341 TObjArray testedClasses;
344 Bool_t res = iter.
next();
348 while (levelchange++<0) {
356 if (curfold==0)
break;
360 curfold = curfold->parent();
366 while ((curitem!=0) && (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 = 0;
382 if ((classname!=0) && (strlen(classname)>0) && (testedClasses.FindObject(classname)==0)) {
384 itemclass = gROOT->GetClass(classname, kFALSE);
387 if ((itemclass==0) && 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()));
420 curitem = curfold->child(0);
424 while (curitem->child(0)!=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()==0))
452 item->setHidden(
false);
454 item->setHidden(item->text(
NColumns)!=
"visible");
466 QTreeWidgetItemIterator it(ListView);
468 if ((*it)->isSelected() &&
472 if (npads==0)
return;
478 QTreeWidgetItemIterator it(ListView);
485 DrawItem(itemname, newpanel, subpad,
false);
496 QTreeWidgetItemIterator it(ListView);
520 int cando = br->
ItemCanDo(fullname.toLatin1().constData());
526 QWidget* mdi = panel ? panel->parentWidget() : 0;
529 if (mdi->isMinimized()) mdi->showNormal();
530 mdi->activateWindow();
536 if (panel!=0)
return;
546 item->setExpanded(
true);
564 for(
int indx=1;indx<
NColumns;indx++)
567 connect(&map, SIGNAL(mapped(
int)),
this, SLOT(
ColumnToggled(
int)));
569 menu.exec(ListView->header()->mapToGlobal(pos));
575 QTreeWidgetItem* item = ListView->itemAt(pos);
577 int col = ListView->header()->logicalIndexAt(pos);
583 for(
int indx=1;indx<
NColumns;indx++)
586 connect(&map, SIGNAL(mapped(
int)),
this, SLOT(
ColumnToggled(
int)));
588 menu.exec(ListView->viewport()->mapToGlobal(pos));
596 bool istopmemory =
false;
598 int nitems(0), nmemory(0), nclose(0), ndraw(0), nsuperimpose(0), si_kind(-1),
599 nremote(0), nanalysis(0), nmonitor(0), nclear(0), nclearlocal(0), nclearproton(0),
600 nclearprotoff(0), ndelprotoff(0), nobjects(0), nfolders(0), nedits(0), ninfo(0),
601 nexport(0), ndelete(0), nassigned(0), nexpand(0), nexecute(0);
603 QTreeWidgetItemIterator it(ListView);
605 if ((*it)->isSelected()) {
608 if (itemslot==0)
continue;
615 bool ismemitem = itemslot->
IsParent(memslot);
632 TClass* cl = gROOT->GetClass(itemclassname);
634 if (cl->InheritsFrom(
"TH1")) {
635 if (!cl->InheritsFrom(
"TH2") && !cl->InheritsFrom(
"TH3")) {
636 if ((si_kind<0) || (si_kind==1)) {
642 if (cl->InheritsFrom(
"TGraph")) {
643 if ((si_kind<0) || (si_kind==2)) {
650 if (cl->InheritsFrom(
"TF1")) {
651 if ((si_kind<0) || (si_kind==3)) {
668 istopmemory = (itemslot==memslot);
670 if (ismemitem || istopmemory)
682 bool isanalysisitem = (itemslot==analslot) || itemslot->
IsParent(analslot);
684 if (isanalysisitem) nanalysis++;
686 if ((itemclassname!=0) && (strcmp(itemclassname,
"TGo4DabcProxy")==0)) nremote++;
688 if ((itemclassname!=0) && (strcmp(itemclassname,
"TGo4ServerProxy")==0)) nremote++;
693 if (isanalysisitem) {
696 Int_t delprot, clearprot;
698 if (clearprot==1) nclearproton++;
else
699 if (clearprot==0) nclearprotoff++;
700 if (delprot==0) ndelprotoff++;
711 AddIdAction(&menu, &map, QIcon(
":/icons/chart.png"),
712 "Plot", 11, (ndraw>0));
714 AddIdAction(&menu, &map, QIcon(
":/icons/superimpose.png"),
715 "Superimpose", 12, (ndraw>1) && (nsuperimpose==ndraw));
718 AddIdAction(&menu, &map, QIcon(
":/icons/zoomlim.png"),
"Expand", 28,
true);
721 AddIdAction(&menu, &map, QIcon(
":/icons/zoomlim.png"),
"Execute", 29,
true);
723 AddIdAction(&menu, &map, QIcon(
":/icons/right.png"),
724 "Fetch item(s)", 18, (nfolders>0) || (nobjects>0));
726 AddIdAction(&menu, &map, QIcon(
":/icons/saveall.png"),
727 "Save selected...", 13, (nobjects>0) || ((nfolders==1) && (nitems==1)));
732 QMenu* expmenu = menu.addMenu(QIcon(
":/icons/export.png"),
"Export to");
738 AddIdAction(&menu, &map, QIcon(
":/icons/export.png"),
739 "Export to", 14,
false);
742 AddIdAction(&menu, &map, QIcon(
":/icons/info.png"),
743 "Info...", 15, (ninfo>0));
745 AddIdAction(&menu, &map, QIcon(
":/icons/control.png"),
746 "Edit..", 16, (nedits>0));
748 QString dellabel =
"Delete item";
749 QString delbutton =
":/icons/delete.png";
750 if ((nclose>0) && (ndelete==0)) {
751 dellabel =
"Close item";
752 if (nclose>1) dellabel+=
"s";
753 delbutton=
":/icons/close.png";
755 if ((nclose==0) && (ndelete>0)) {
756 dellabel =
"Delete item";
757 if (ndelete>1) dellabel+=
"s";
759 if ((nclose>0) && (ndelete>0)) {
760 dellabel =
"Close/delete items";
764 dellabel, 17, (nclose>0) || (ndelete>0));
766 AddIdAction(&menu, &map, QIcon(
":/icons/copyws.png"),
767 "Copy to Workspace", 19, (nobjects>0) || ((nfolders==1) && (nitems==1)));
769 AddIdAction(&menu, &map, QIcon(
":/icons/editcopy.png"),
770 "Copy to clipboard", 20, (nobjects>0) || (nfolders>0));
772 if ((nremote>0) || (nanalysis>0)) {
776 AddIdAction(&menu, &map, QIcon(
":/icons/monitor.png"),
777 "Monitor item(s)", 21, ((nobjects>0) && (nremote>0) && (nmonitor<nremote)) || ((nfolders==1) && (nitems==1)));
779 AddIdAction(&menu, &map, QIcon(
":/icons/Stop.png"),
780 "Stop item(s) monitoring", 22, ((nobjects>0) && (nremote>0) && (nmonitor>0)) || ((nfolders==1) && (nitems==1)));
782 AddIdAction(&menu, &map, QIcon(
":/icons/clear.png" ),
783 "Clear (Reset to 0)", 23, (nclear>0));
785 AddIdAction(&menu, &map, QIcon(
":/icons/clear_nok.png" ),
786 "Set Clear protection", 24, (nclearprotoff>0));
788 AddIdAction(&menu, &map, QIcon(
":/icons/clear_ok.png" ),
789 "Unset Clear protection", 25, (nclearproton>0));
791 AddIdAction(&menu, &map, QIcon(
":/icons/delete.png" ),
792 "Delete from analysis", 26, (ndelprotoff>0));
794 AddIdAction(&menu, &map, QIcon(
":/icons/refresh.png" ),
795 "Refresh namelist", 27,
true);
798 if ((nmemory>0) && (nmemory==nitems)) {
801 AddIdAction(&menu, &map, QIcon(
":/icons/crefolder.png"),
802 "Create folder", 41, (nmemory==1) && (nfolders==1));
804 AddIdAction(&menu, &map, QIcon(
":/icons/rename.png"),
805 "Rename object", 42, (nmemory==1) && !istopmemory);
807 AddIdAction(&menu, &map, QIcon(
":/icons/clear.png"),
808 "Clear object(s)", 44, (nclearlocal>0));
810 AddIdAction(&menu, &map, QIcon(
":/icons/editpaste.png"),
811 "Paste from clipboard", 43, br->
IsClipboard() && (nmemory==1) && (nfolders==1));
816 menu.exec(ListView->viewport()->mapToGlobal(pos));
821 if ((indx<=0) || (indx>=
NColumns))
return;
832 for(
int indx=0;indx<
NColumns;indx++) {
835 width = ListView->columnWidth(ncolumn++);
860 QApplication::setOverrideCursor(Qt::WaitCursor);
862 QTreeWidgetItemIterator it(ListView);
864 if ((*it)->isSelected()) {
867 if (itemslot==0)
continue;
894 br->
FetchItem(itemname.toLatin1().constData());
923 while (iter.
next()) {
959 if (an!=0) anrefresh = an;
961 if (serv!=0) servrefresh = serv;
967 (*it)->setExpanded(
true);
982 QInputDialog::getText(
this,
983 "Create folder in workspace",
994 QString shortitemname=itemname.section(
"/",-1);
996 QInputDialog::getText(
this,
997 "Rename item in workspace",
998 "Input new item name",
1002 if (ok) br->
RenameMemoryItem(itemname.toLatin1().constData(), newname.toLatin1().constData());
1026 QApplication::restoreOverrideCursor();
1031 if (item==0)
return false;
1047 QFileDialog fd(
this,
"Save selected objects to file", QString(),
1048 "ROOT (*.root);;ROOT XML (*.xml)");
1049 fd.setFileMode( QFileDialog::AnyFile);
1050 fd.setAcceptMode(QFileDialog::AcceptSave);
1052 if (fd.exec() != QDialog::Accepted)
return;
1054 QStringList flst = fd.selectedFiles();
1055 if (flst.isEmpty())
return;
1057 QString fname = flst[0];
1060 if (fd.selectedNameFilter() ==
"ROOT (*.root)") {
1062 title = QInputDialog::getText(
this,
1063 "Save slected objects to file",
"Provide file title",
1064 QLineEdit::Normal, QString(), &ok);
1066 if (fname.indexOf(
".root", 0, Qt::CaseInsensitive)<0) fname+=
".root";
1068 if (fname.indexOf(
".xml", 0, Qt::CaseInsensitive)<0) fname+=
".xml";
1072 QFileInfo(fname).absolutePath().toLatin1().constData(),
1073 fd.selectedNameFilter().toLatin1().constData(),
1074 title.toLatin1().constData());
1079 QFileDialog fd(
this, QString(
"Select directory to export to ") + filtername);
1080 fd.setOption(QFileDialog::ShowDirsOnly,
true);
1082 if (fd.exec() != QDialog::Accepted)
return;
1084 QStringList flst = fd.selectedFiles();
1085 if (flst.isEmpty())
return;
1088 flst[0].toLatin1().constData(),
1090 "Export of selected items");
1096 QTreeWidgetItemIterator it(ListView);
1098 if ((*it)->isSelected()) {
1100 items.Add(
new TObjString(fullname.toLatin1().constData()));
1115 TString objname, arg1, arg2, arg3;
1119 if ((serv==0) || (objname.Length()==0))
return;
1122 if (nargs<0)
return;
1124 for (Int_t n=0;n<nargs;n++) {
1127 QInputDialog::getText(0,
"Input command arguments",
1128 QString(
"Arg%1:").arg(n+1), QLineEdit::Normal,
"", &ok);
1130 if (n==0) arg1 = value.toLatin1().constData();
else
1131 if (n==1) arg2 = value.toLatin1().constData();
else
1132 if (n==2) arg3 = value.toLatin1().constData();
1135 Bool_t res = serv->
SubmitCommand(objname, 3, (arg1.Length() > 0 ? arg1.Data() : 0), (arg2.Length() > 0 ? arg2.Data() : 0), (arg3.Length() > 0 ? arg3.Data() : 0));
1137 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)