Salome HOME
Merge from V6_main 01/04/2013
[modules/gui.git] / src / SUIT / SUIT_ExceptionHandler.cxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include "SUIT_ExceptionHandler.h"
24
25 #include "SUIT_MessageBox.h"
26
27 #ifdef ENABLE_TESTRECORDER
28   #include <TestApplication.h>
29 #endif
30
31 #include <QApplication>
32
33 /*!\class SUIT_ExceptionHandler
34  * Show exception message on error handler.
35  */
36
37 /*!
38   Checks: is internal handle on object \a o?
39 */
40 bool SUIT_ExceptionHandler::handle( QObject* o, QEvent* e )
41 {
42   return internalHandle( o, e );
43 }
44
45 /*!
46   Checks: is internal handle on object \a o?
47 */
48 bool SUIT_ExceptionHandler::internalHandle( QObject* o, QEvent* e )
49 {
50 #ifdef ENABLE_TESTRECORDER
51   TestApplication* aTApp = qobject_cast<TestApplication*>(qApp);
52   return aTApp ? aTApp->TestApplication::notify( o, e ) : false;
53 #else
54   return qApp ? qApp->QApplication::notify( o, e ) : false;
55 #endif
56 }
57
58 /*!
59   Show error message \a mgs, if application is not null.
60 */
61 void SUIT_ExceptionHandler::showMessage( const QString& title, const QString& msg )
62 {
63   if ( !qApp )
64     return;
65   
66   while ( QApplication::overrideCursor() )
67     QApplication::restoreOverrideCursor();
68
69   cleanUp();
70
71   SUIT_MessageBox::critical( 0, title, msg );
72 }
73
74 CleanUpFuncList SUIT_ExceptionHandler::myCleanUpFunctions;
75
76 void SUIT_ExceptionHandler::addCleanUpRoutine(CleanUpFunction p)
77 {
78   myCleanUpFunctions.append(p);
79 }
80
81 void SUIT_ExceptionHandler::removeCleanUpRoutine(CleanUpFunction p)
82 {
83   myCleanUpFunctions.removeAll(p);
84 }
85
86 void SUIT_ExceptionHandler::cleanUp()
87 {
88   foreach( QtCleanUpFunction f, myCleanUpFunctions )
89   {
90     f();
91   }
92 }