GSI Object Oriented Online Offline (Go4) GO4-6.4.0
Loading...
Searching...
No Matches
QGo4Widget.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 "QGo4Widget.h"
15
16#include <QtCore/QTimer>
17#include <QAction>
18#include <QMenu>
19#include <QtCore/QSignalMapper>
20
21#include <QDragMoveEvent>
22#include <QCloseEvent>
23#include <QDragEnterEvent>
24
25QGo4Widget::QGo4Widget(QWidget *parent, const char *name, Qt::WindowFlags f) :
26 QWidget(parent, f),
30 fBlockUpdate(false),
31 fBrowserProxy(nullptr)
32{
33 setObjectName(name);
34 setAcceptDrops(true);
35}
36
41
42void QGo4Widget::ObjectCreatedByWidget(const char *itemname, TClass *cl)
43{
44 // this method calls by main gui when object created by one of editor
45
48 requestedObjectCreated(itemname, cl);
49 }
50}
51
53{
54 // we set fResetWidgetShooted to prevent in any situation of ShootResetWidget() again
58 fResetWidgetShooted = false;
59}
60
62{
63 if (fResetWidgetShooted) return;
64
66
67 QTimer::singleShot(0, this, &QGo4Widget::ResetWidget);
68}
69
70void QGo4Widget::ShootCloseWidget(bool closeparent)
71{
72 if (fResetWidgetShooted) return;
73
75
76 QTimer::singleShot(0, closeparent ? parentWidget() : this, &QWidget::close);
77}
78
83
84bool QGo4Widget::IsAcceptDrag(const char *, TClass *, int)
85{
86 return false;
87}
88
89void QGo4Widget::DropItem(const char *, TClass *, int)
90{
91}
92
93void QGo4Widget::closeEvent(QCloseEvent *e)
94{
96 e->accept();
97 } else {
98 e->ignore();
99 }
100}
101
102void QGo4Widget::dragEnterEvent(QDragEnterEvent *e)
103{
104 emit widgetService(this, service_DragEnter, nullptr, dynamic_cast<QDragMoveEvent *> (e));
105}
106
107void QGo4Widget::dragMoveEvent(QDragMoveEvent* e)
108{
109 emit widgetService(this, service_DragEnter, "", e);
110}
111
112void QGo4Widget::dropEvent(QDropEvent* e)
113{
114 emit widgetService(this, service_DropEvent, nullptr, e);
115}
116
117void QGo4Widget::AddLink(const char *itemname, const char *linkname)
118{
119 emit widgetService(this, service_AddEditorLink, linkname, (void *) itemname);
120}
121
122void QGo4Widget::AddLink(TGo4Slot *slot, const char *linkname)
123{
124 emit widgetService(this, service_AddDirectLink, linkname, (void *) slot);
125}
126
127TGo4Slot *QGo4Widget::AddLink(const char *itemname, TGo4Slot *parent)
128{
129 TGo4Slot *res = parent;
130 emit widgetService(this, service_AddLinkInSlot, itemname, (void *) &res);
131 return res;
132}
133
135{
136 TGo4Slot *res = nullptr;
137 emit widgetService(this, service_GetTopSlot, force ? "force" : "normal", (void *) &res);
138 return res;
139}
140
141TGo4Slot *QGo4Widget::AddSlot(const char *slotname)
142{
143 TGo4Slot *res = nullptr;
144 emit widgetService(this, service_AddEditorSlot, slotname, (void *) &res);
145 return res;
146}
147
148void QGo4Widget::SetLinkedName(TGo4Slot *slot, const char *itemname)
149{
150 emit widgetService(this, service_SetLinkedName, itemname, (void *) slot);
151}
152
153const char *QGo4Widget::GetLinkedName(const char *linkname)
154{
155 const char *res = nullptr;
156
157 emit widgetService(this, service_GetLinkedName, linkname, (void *) &res);
158
159 return res;
160}
161
163{
164 void *res = slot;
165
166 emit widgetService(this, service_GetLinkedName2, "", (void *) &res);
167
168 return (const char *) res;
169}
170
171
172TObject *QGo4Widget::GetLinked(const char *linkname, int updatelevel)
173{
174 TObject *res = nullptr;
175 int func = 0;
176 switch (updatelevel) {
177 case 0: func = service_GetLinked0; break;
178 case 1: func = service_GetLinked1; break;
179 case 2: func = service_GetLinked2; break;
180 default: func = service_GetLinked1; break;
181 }
182
183 emit widgetService(this, func, linkname, (void *) &res);
184
185 return res;
186}
187
188void QGo4Widget::RemoveLink(const char *linkname, bool blockreset)
189{
190 bool oldvalue = fBlockUpdate;
191 if (blockreset) fBlockUpdate = true;
192 emit widgetService(this, service_RemoveLink, linkname, nullptr);
193 fBlockUpdate = oldvalue;
194}
195
196void QGo4Widget::RemoveAllLinks(bool blockreset)
197{
198 bool oldvalue = fBlockUpdate;
199 if (blockreset) fBlockUpdate = true;
200 emit widgetService(this, service_RemoveAllLinks, nullptr, nullptr);
201 fBlockUpdate = oldvalue;
202}
203
204void QGo4Widget::RemoveLinksMasked(const char *startedwith, bool blockreset)
205{
206 bool oldvalue = fBlockUpdate;
207 if (blockreset) fBlockUpdate = true;
208 emit widgetService(this, service_RemoveAllLinks, startedwith, nullptr);
209 fBlockUpdate = oldvalue;
210}
211
212bool QGo4Widget::BrowserItemRemote(const char *itemname)
213{
214 bool isremote = false;
215 emit widgetService(this, service_BrowserItemRemote, itemname, (void *) &isremote);
216 return isremote;
217}
218
220{
221 if (fBrowserProxy) return fBrowserProxy;
222
223 TGo4BrowserProxy *br = nullptr;
224 emit widgetService(this, service_Browser, "", (void *) &br);
225 fBrowserProxy = br;
226 return br;
227}
228
230{
231 emit widgetService(this, service_ConnectPad, "", (void *) pad);
232}
233
234void QGo4Widget::CallPanelFunc(int func, TPad *pad)
235{
236 emit widgetService(this, func, "", (void *) pad);
237}
238
239void QGo4Widget::StatusMessage(const QString& message)
240{
241 emit widgetService(this, service_StatusMessage, message.toLatin1().constData(), nullptr);
242}
243
244void QGo4Widget::ProcessSignal(const char *linkname, bool assigned, TObject *obj, TGo4Slot *slot)
245{
246 if (assigned) {
247 linkedUpdated(slot, obj);
248 linkedObjectUpdated(linkname, obj);
249 } else
250 // inform widget only if deletion caused not by widget itself by RemoveAllLinks() call
251 if (!IsUpdateBlocked()) {
252 linkedRemoved(slot, obj);
253 linkedObjectRemoved(linkname);
254 }
255}
256
257void QGo4Widget::linkedObjectUpdated(const char * /* linkname */, TObject * /* obj */)
258{
259}
260
261void QGo4Widget::linkedObjectRemoved(const char * /* linkname */)
262{
263 // reset editor if any watched object is removed
265}
266
267void QGo4Widget::linkedUpdated(TGo4Slot */* slot */, TObject */* obj */ )
268{
269}
270
271void QGo4Widget::linkedRemoved(TGo4Slot */* slot */, TObject */* obj */)
272{
273}
274
275void QGo4Widget::AskToCreateObject(TClass *cl, int isremote)
276{
277 fWaitsForObjectCreation = (isremote >= 0);
278 QString str = QString::number(isremote);
279 emit widgetService(this, service_CreateItem, str.toLatin1().constData(), (void *) cl);
280}
281
282void QGo4Widget::InformThatObjectCreated(const char *itemname, TClass *cl)
283{
284 emit widgetService(this, service_ObjectCreated, itemname, cl);
285}
286
287// this function should be reimplemented in editor that asks to create object
288void QGo4Widget::requestedObjectCreated(const char * /* itemname */, TClass * /* cl */)
289{
290}
291
292void QGo4Widget::ShowItemInfo(const QString& itemname)
293{
294 emit widgetService(this, service_ShowInfo, itemname.toLatin1().constData(), nullptr);
295}
296
298{
299 QString str = QString::number(ndiv);
300 TGo4ViewPanel *res = nullptr;
301 emit widgetService(this, service_CreateViewPanel, str.toLatin1().constData(), (void *)&res);
302 return res;
303}
304
305TGo4ViewPanel *QGo4Widget::DrawItem(const QString& itemname, TGo4ViewPanel *panel, TPad *pad, bool activate, int updatelevel)
306{
307 void *res[4];
308 res[0] = panel;
309 res[1] = pad;
310 res[2] = &activate;
311 res[3] = &updatelevel;
312 emit widgetService(this, service_DrawItem, itemname.toLatin1().constData(), res);
313 return (TGo4ViewPanel *) res[0];
314}
315
317{
318 TGo4ViewPanel *res = nullptr;
319 emit widgetService(this, service_WhereItemDrawn, itemname, &res);
320 return res;
321}
322
323void QGo4Widget::UndrawItem(const char *itemname)
324{
325 emit widgetService(this, service_UndrawItem, itemname, nullptr);
326}
327
328void QGo4Widget::HelpWindow(const char *filename, const char *msg)
329{
330 emit widgetService(this, service_HelpWindow, filename, (void *)msg);
331}
332
333void QGo4Widget::StartHotstart(const char *filename)
334{
335 emit widgetService(this, service_HotStart, filename, nullptr);
336}
337
339{
340 TGo4ViewPanel *res = nullptr;
341 emit widgetService(this, service_LastActivePanel, "", (void *)&res);
342 return res;
343}
344
345void QGo4Widget::EditItem(const QString& itemname)
346{
347 emit widgetService(this, service_EditItem, itemname.toLatin1().constData(), nullptr);
348}
349
351{
352 emit widgetService(this, service_EditInSlot, "", (void *) slot);
353}
354
355QString QGo4Widget::SaveObjectInMemory(const char *foldername, TObject *obj)
356{
357 void *par = obj;
358 emit widgetService(this, service_SaveToMemory, foldername, (void *) &par);
359 QString itemname = "";
360 if ((par != obj) && par) {
361 QString* res = (QString*) par;
362 itemname = *res;
363 delete res;
364 }
365 return itemname;
366}
367
368bool QGo4Widget::SaveItemToFile(const char *itemname, const char *subfolder)
369{
370 char buf[1000];
371 if (!subfolder)
372 strcpy(buf, "");
373 else
374 strncpy(buf, subfolder, sizeof(buf));
375 emit widgetService(this, service_SaveItem, itemname, (void *) buf);
376 return buf[0] != 0;
377}
378
379bool QGo4Widget::UpdateItemInAnalysis(const char *itemname, TObject *obj)
380{
381 TObject *res = obj;
382 emit widgetService(this, service_UpdateAnalysisItem, itemname, (void *) &res);
383 return res != nullptr;
384}
385
387{
388 TGo4ServerProxy *res = nullptr;
389 emit widgetService(this, service_GetAnalysis, itemname, (void *) &res);
390 return res;
391}
392
393void QGo4Widget::CallServiceFunc(int func, const char *str, void *par)
394{
395 emit widgetService(this, func, str, par);
396}
397
398void QGo4Widget::ServiceCall(const char *name, void *par)
399{
401}
402
403QAction* QGo4Widget::CreateChkAction(QMenu* menu, const QString& text, bool checked, bool enabled)
404{
405 QAction* act = new QAction(text, menu);
406 act->setCheckable(true);
407 act->setChecked(checked);
408 act->setEnabled(enabled);
409 menu->addAction(act);
410 return act;
411}
412
413QAction* QGo4Widget::AddIdAction(QMenu* menu, QSignalMapper* map,
414 const QString& text, int id, int enabled, int checked)
415{
416 auto oldact = map->mapping(id);
417 if (oldact) map->removeMappings(oldact);
418
419 QAction* act = new QAction(text, menu);
420 if (checked!=-1) {
421 act->setCheckable(true);
422 act->setChecked(checked > 0);
423 }
424 if (enabled!=-1)
425 act->setEnabled(enabled > 0);
426
427 QObject::connect(act, &QAction::triggered, [id, map]() {
428#if QT_VERSION < QT_VERSION_CHECK(5,15,0)
429 map->mapped(id);
430#else
431 map->mappedInt(id);
432#endif
433 });
434
435 menu->addAction(act);
436 map->setMapping(act, id);
437 return act;
438}
439
440QAction* QGo4Widget::SetIdAction(QSignalMapper* map, int id, int enabled, int checked)
441{
442 QAction* act = (QAction*) map->mapping(id);
443 if (!act) return nullptr;
444 if (checked!=-1) {
445 act->setCheckable(true);
446 act->setChecked(checked > 0);
447 }
448 if (enabled!=-1)
449 act->setEnabled(enabled > 0);
450 return act;
451}
452
453QAction* QGo4Widget::AddIdAction(QMenu* menu, QSignalMapper* map,
454 const QIcon& icon, const QString& text, int id, int enabled, int checked)
455{
456 auto oldact = map->mapping(id);
457 if (oldact) map->removeMappings(oldact);
458
459 QAction* act = new QAction(icon, text, menu);
460 if (checked != -1) {
461 act->setCheckable(true);
462 act->setChecked(checked > 0);
463 }
464 if (enabled!=-1)
465 act->setEnabled(enabled > 0);
466
467 QObject::connect(act, &QAction::triggered, [id, map]() {
468#if QT_VERSION < QT_VERSION_CHECK(5,15,0)
469 map->mapped(id);
470#else
471 map->mappedInt(id);
472#endif
473 });
474
475 menu->addAction(act);
476 map->setMapping(act, id);
477 return act;
478}
void ShootResetWidget()
void StartHotstart(const char *filename)
TGo4Slot * GetTopSlot(bool force=false)
return top slot of structure, corresponding to this widget
bool fBlockUpdate
indicates that reset widget timer is shoot
Definition QGo4Widget.h:48
void ShowItemInfo(const QString &itemname)
virtual void requestedObjectCreated(const char *itemname, TClass *cl)
bool SaveItemToFile(const char *itemname, const char *subfolder=nullptr)
void widgetService(QGo4Widget *editor, int serviceid, const char *str, void *par)
@ service_WhereItemDrawn
Definition QGo4Widget.h:84
@ service_UndrawItem
Definition QGo4Widget.h:85
@ service_UpdateAnalysisItem
Definition QGo4Widget.h:61
@ service_ShowInfo
Definition QGo4Widget.h:58
@ service_GetLinked2
Definition QGo4Widget.h:78
@ service_EditItem
Definition QGo4Widget.h:57
@ service_HotStart
Definition QGo4Widget.h:89
@ service_CreateViewPanel
Definition QGo4Widget.h:63
@ service_Browser
Definition QGo4Widget.h:65
@ service_EditInSlot
Definition QGo4Widget.h:59
@ service_General
Definition QGo4Widget.h:86
@ service_GetLinked0
Definition QGo4Widget.h:76
@ service_AddDirectLink
Definition QGo4Widget.h:69
@ service_RemoveLink
Definition QGo4Widget.h:79
@ service_GetLinked1
Definition QGo4Widget.h:77
@ service_SaveToMemory
Definition QGo4Widget.h:66
@ service_HelpWindow
Definition QGo4Widget.h:88
@ service_GetTopSlot
Definition QGo4Widget.h:71
@ service_ConnectPad
Definition QGo4Widget.h:82
@ service_LastActivePanel
Definition QGo4Widget.h:83
@ service_AddLinkInSlot
Definition QGo4Widget.h:70
@ service_DropEvent
Definition QGo4Widget.h:54
@ service_SetLinkedName
Definition QGo4Widget.h:73
@ service_BrowserItemRemote
Definition QGo4Widget.h:64
@ service_CreateItem
Definition QGo4Widget.h:55
@ service_AddEditorSlot
Definition QGo4Widget.h:72
@ service_DrawItem
Definition QGo4Widget.h:56
@ service_GetLinkedName2
Definition QGo4Widget.h:75
@ service_GetAnalysis
Definition QGo4Widget.h:67
@ service_GetLinkedName
Definition QGo4Widget.h:74
@ service_SaveItem
Definition QGo4Widget.h:60
@ service_StatusMessage
Definition QGo4Widget.h:62
@ service_RemoveAllLinks
Definition QGo4Widget.h:80
@ service_AddEditorLink
Definition QGo4Widget.h:68
@ service_ObjectCreated
Definition QGo4Widget.h:81
@ service_DragEnter
Definition QGo4Widget.h:53
static QAction * CreateChkAction(QMenu *menu, const QString &text, bool checked, bool enabled=true)
void EditObjectInSlot(TGo4Slot *slot)
TObject * GetLinked(const char *linkname, int updatelevel=0)
void closeEvent(QCloseEvent *e) override
void ShootCloseWidget(bool closeparent=false)
void dragEnterEvent(QDragEnterEvent *e) override
const char * GetLinkedName(const char *linkname)
returns name of item, which was linked with linkname
bool IsUpdateBlocked() const
Definition QGo4Widget.h:208
virtual void ResetWidget()
TGo4ViewPanel * DrawItem(const QString &itemname, TGo4ViewPanel *panel=nullptr, TPad *pad=nullptr, bool activate=true, int updatelevel=-1)
TGo4Slot * AddSlot(const char *slotname)
add slot with specific name to widget top folder
void dragMoveEvent(QDragMoveEvent *e) override
virtual void linkedRemoved(TGo4Slot *slot, TObject *obj)
QGo4Widget(QWidget *parent=nullptr, const char *name=nullptr, Qt::WindowFlags f=Qt::Widget)
void AskToCreateObject(TClass *cl, int isremote)
Function call dialog to create object of appropriate class isremote == 0 - object should be created l...
virtual void linkedObjectRemoved(const char *linkname)
virtual bool IsAcceptDrag(const char *itemname, TClass *cl, int kind)
void dropEvent(QDropEvent *e) override
bool fWaitsForObjectCreation
Definition QGo4Widget.h:45
void RemoveLinksMasked(const char *startedwith=nullptr, bool blockreset=true)
void AddLink(const char *itemname, const char *linkname)
create link for item with name linkname
void ProcessSignal(const char *linkname, bool assigned, TObject *obj, TGo4Slot *slot)
bool fCanDestroyWidget
Definition QGo4Widget.h:46
bool UpdateItemInAnalysis(const char *itemname, TObject *obj=nullptr)
void CloseMDIParentSlot()
void StatusMessage(const QString &message)
bool fResetWidgetShooted
indicate that widget can be destroyed
Definition QGo4Widget.h:47
void SetLinkedName(TGo4Slot *slot, const char *itemname)
set name of item, which was linked by this slot
void CallServiceFunc(int id, const char *str=nullptr, void *par=nullptr)
void HelpWindow(const char *filename, const char *msg=nullptr)
TGo4ServerProxy * GetAnalysis(const char *itemname=nullptr)
bool BrowserItemRemote(const char *itemname)
static QAction * SetIdAction(QSignalMapper *map, int id, int enabled=-1, int checked=-1)
virtual void DropItem(const char *itemname, TClass *cl, int kind)
TGo4ViewPanel * WhereItemDrawn(const char *itemname)
void ServiceCall(const char *name, void *par=nullptr)
virtual void linkedObjectUpdated(const char *linkname, TObject *obj)
void ObjectCreatedByWidget(const char *itemname, TClass *cl)
static QAction * AddIdAction(QMenu *menu, QSignalMapper *map, const QString &text, int id, int enabled=-1, int checked=-1)
TGo4BrowserProxy * Browser()
TGo4ViewPanel * LastActivePanel()
void InformThatObjectCreated(const char *itemname, TClass *cl)
TGo4BrowserProxy * fBrowserProxy
set when automatic reset must be blocked
Definition QGo4Widget.h:50
void RemoveAllLinks(bool blockreset=true)
void CallPanelFunc(int id, TPad *pad=nullptr)
void UndrawItem(const char *itemname)
virtual ~QGo4Widget()
QString SaveObjectInMemory(const char *foldername, TObject *obj)
void EditItem(const QString &itemname)
virtual void linkedUpdated(TGo4Slot *slot, TObject *obj)
TGo4ViewPanel * CreateViewPanel(int ndiv=0)
void RemoveLink(const char *linkname, bool blockreset=true)
void ConnectPad(TPad *pad)
connect pad axis change signals to react on such signals
special base class for remote data servers like DABC, HTTP, hist server