Salome HOME
Merge remote-tracking branch 'origin/vsr/qtesting'
authorabn <adrien.bruneton@cea.fr>
Wed, 27 Jul 2016 10:12:25 +0000 (12:12 +0200)
committerabn <adrien.bruneton@cea.fr>
Wed, 27 Jul 2016 10:12:25 +0000 (12:12 +0200)
src/MEDCalc/gui/TestController.cxx
src/MEDCalc/gui/TestController.hxx

index 78bb46dd2c3f1d7134c33daa12ec1a1dccdcbe32..dfb9979228e8eb3ac668a3c95cf81b05e44d6d4c 100644 (file)
@@ -60,12 +60,16 @@ TestController::TestController(MEDModule* mod):
   _tester(0), _lock_action(0),
   _quitEventType(QEvent::registerEventType()),
   _playEventType(QEvent::registerEventType()),
-  _aboutToPlayTest(false)
+  _aboutToPlayTest(false),
+  _myEventLoopStarted(false)
 {
   STDLOG("Creating a TestController");
   _tester = new pqTestUtility(_desk);
   _tester->addEventObserver("xml", new pqXMLEventObserver(_desk));
   _tester->addEventSource("xml", new pqXMLEventSource(_desk));
+
+  QApplication::instance()->installEventFilter(this);
+  //QTimer::singleShot(0, this, SLOT(onMainEventLoopStarting()));
 }
 
 TestController::~TestController()
@@ -160,7 +164,7 @@ TestController::customEvent(QEvent * event)
 {
   if (event->type() == _quitEventType)
     {
-      if(!_salomeModule->getApp()->isMainEventLoopStarted())
+      if(!isMainEventLoopStarted())
           // Repost (=delay)
           QApplication::postEvent(this, new QEvent((QEvent::Type)_quitEventType));
       else
@@ -172,7 +176,7 @@ TestController::customEvent(QEvent * event)
       if (e)
         {
 //          // Wait for main event loop to start:
-          if(!_salomeModule->getApp()->isMainEventLoopStarted())
+          if(!isMainEventLoopStarted())
               // Repost (=delay)
               QApplication::postEvent(this, new PlayTestEvent((QEvent::Type)_playEventType, e->_filename));
           else
@@ -207,3 +211,15 @@ TestController::processWorkspaceEvent(const MEDCALC::MedEvent* event)
   }
 }
 
+void TestController::onMainEventLoopStarting()
+{
+  _myEventLoopStarted = true;
+  QApplication::instance()->removeEventFilter(this);
+}
+
+bool TestController::eventFilter(QObject *obj, QEvent *event)
+{
+  if ( obj == QApplication::instance() && event->type() == 9999 )
+    onMainEventLoopStarting();
+  return QObject::eventFilter(obj, event);
+}
index 9f5acfd6f9f0a67d8620527a947fe75f08c37219..d78557e1fb17d6812fdcfc28a3aaf9640a854545 100644 (file)
@@ -40,8 +40,10 @@ public:
 
   void createActions();
 
+  bool isMainEventLoopStarted() const { return _myEventLoopStarted; }
 
-
+  bool eventFilter(QObject *obj, QEvent *event);
+  
 protected:
   virtual void customEvent(QEvent * event);
 
@@ -62,11 +64,16 @@ protected:
   pqTestUtility * _tester;
   QAction * _lock_action;
 
+private slots:
+  void onMainEventLoopStarting();
+
 private:
   const int _playEventType;
   const int _quitEventType;
 
   bool _aboutToPlayTest;
+
+  bool _myEventLoopStarted;
 };
 
 #endif /* SRC_MEDCALC_GUI_TESTCONTROLLER_HXX_ */