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