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