GSI Object Oriented Online Offline (Go4)  GO4-6.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
QRootApplication.cpp
Go to the documentation of this file.
1 // $Id: QRootApplication.cpp 2767 2020-04-16 14:33:27Z 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 //Author : Denis Bertini 01.11.2000
15 
16 /**************************************************************************
17 * Copyright (C) 2000- Gesellschaft f. Schwerionenforschung, GSI *
18 * Planckstr. 1, 64291 Darmstadt, Germany *
19 * All rights reserved. *
20 * Contact: http://go4.gsi.de *
21 * *
22 * This software can be used under the license agreements as stated in *
23 * Go4License.txt file which is part of the distribution. *
24 ***************************************************************************/
25 
26 #include "QRootApplication.h"
27 
28 #include <iostream>
29 
30 #include "TSystem.h"
31 
32 #include <QtCore/QTimer>
33 
34 #ifndef WIN32
35 #ifdef __GO4X11__
36 
37 #include <X11/Xlib.h>
38 
39 static int qt_x11_errhandler( Display *dpy, XErrorEvent *err )
40 {
41 
42  // special for modality usage: XGetWindowProperty + XQueryTree()
43  if ( err->error_code == BadWindow ) {
44  //if ( err->request_code == 25 && qt_xdnd_handle_badwindow() )
45  return 0;
46  }
47  // special case for X_SetInputFocus
48  else if ( err->error_code == BadMatch
49  && err->request_code == 42 ) {
50  return 0;
51  }
52  else if ( err->error_code == BadDrawable
53  && err->request_code == 14 ) {
54  return 0;
55  }
56 
57  // here XError are forwarded
58  char errstr[256];
59  XGetErrorText( dpy, err->error_code, errstr, 256 );
60  qWarning( "X11 Error: %s %d\n Major opcode: %d",
61  errstr, err->error_code, err->request_code );
62  return 0;
63 }
64 
65 #endif
66 #endif
67 
68 bool QRootApplication::fDebug = false; //false;
69 bool QRootApplication::fWarning = false; //false;
71 
72 #if QT_VERSION < QT_VERSION_CHECK(5,0,0)
73 void qMessageOutput( QtMsgType type, const char *msg )
74 {
75  switch ( type ) {
76  case QtDebugMsg:
77  if(QRootApplication::fDebug)
78  std::cerr << "QtRoot-Debug: " << msg << std::endl;
79  break;
80  case QtWarningMsg:
81  if(QRootApplication::fWarning)
82  std::cerr << "QtRoot-Warning: " << msg << std::endl;
83  break;
84  case QtFatalMsg:
85  std::cerr << "QtRoot-Fatal: " << msg << std::endl;
86  gSystem->Abort();
87  case QtCriticalMsg:
88  std::cerr << "QtRoot-Critical: " << msg << std::endl;
89  break;
90  default:
91  std::cerr << "QtRoot-Other: " << msg << std::endl;
92  break;
93  }
94 }
95 #else
96 
97 void q5MessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg)
98 {
99  QByteArray localMsg = msg.toLocal8Bit();
100  switch (type) {
101  case QtDebugMsg:
102  if(QRootApplication::fDebug)
103  fprintf(stderr, "QtRoot-Debug: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
104  break;
105  case QtWarningMsg:
106  if(QRootApplication::fWarning)
107  fprintf(stderr, "QtRoot-Warning: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
108  break;
109  case QtCriticalMsg:
110  fprintf(stderr, "QtRoot-Critical: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
111  break;
112  case QtFatalMsg:
113  fprintf(stderr, "QtRoot-Fatal: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
114  abort();
115  default:
116  fprintf(stderr, "QtRoot-other: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
117  break;
118  }
119 }
120 #endif
121 
122 QRootApplication::QRootApplication(int& argc, char **argv, int poll) :
123  QApplication(argc,argv, true)
124 {
125 
126  // connect ROOT via Timer call back
127  if (poll == 0){
128  timer = new QTimer( this );
129  QObject::connect( timer, SIGNAL(timeout()),
130  this, SLOT(execute()) );
131  timer->setSingleShot(false);
132  timer->start(20);
133 
134  }
135  // install a msg-handler
136 #if QT_VERSION < QT_VERSION_CHECK(5,0,0)
137  qInstallMsgHandler( qMessageOutput );
138 #else
139  qInstallMessageHandler( q5MessageOutput );
140 #endif
141 
142  // install a filter on the parent
143  // use Qt-specific XError Handler (moved this call here from tqapplication JA)
144  // QApplication::installEventFilter( this );
145 
146  const char* env = gSystem->Getenv("ROOT_CANVAS");
147  int flag = 0;
148  if (env!=0) {
149  if ((strcmp(env,"yes")==0) || (strcmp(env,"YES")==0)) flag = 1; else
150  if ((strcmp(env,"no")==0) || (strcmp(env,"NO")==0)) flag = -1;
151  }
152 
153 #ifdef WIN32
154  // under Windows one should explicit enable these methods
155  fRootCanvasMenusEnabled = (flag == 1);
156 #else
157 #ifdef __GO4X11__
158  XSetErrorHandler( qt_x11_errhandler );
159 #endif
160  // under Unix one should explicit disable these methods
161  fRootCanvasMenusEnabled = (flag != -1);
162 #endif
163 }
164 
166 {
167 }
168 
170 {
171  //call the inner loop of ROOT
172 
173  //gSystem->InnerLoop();
174 
175  // SL 28.5.2015: use ProcessEvents instead of InnerLoop to avoid total block of the qt event loop
176  gSystem->ProcessEvents();
177 }
178 
180 {
181  // std::cout <<"QRootApplication::quit()" << std::endl;
182 // gSystem->Exit( 0 );
183 }
184 
186 {
188 }
static bool fDebug
QRootApplication(int &argc, char **argv, int poll=0)
static bool IsRootCanvasMenuEnabled()
static bool fWarning
void q5MessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg)
static bool fRootCanvasMenusEnabled
string msg
Definition: go4init.py:11