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