X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDCalc%2Fgui%2FTestController.cxx;h=dfb9979228e8eb3ac668a3c95cf81b05e44d6d4c;hb=66a70e025d31e6b8d124510db0bcf9bea9493b46;hp=9f2bc8dbd4e4e2d3ebfc79f4a45c1e1280f6cad3;hpb=cfc8c7584db03dc2a31d5df9aa87d2fa411b790a;p=modules%2Fmed.git diff --git a/src/MEDCalc/gui/TestController.cxx b/src/MEDCalc/gui/TestController.cxx index 9f2bc8dbd..dfb997922 100644 --- a/src/MEDCalc/gui/TestController.cxx +++ b/src/MEDCalc/gui/TestController.cxx @@ -45,16 +45,31 @@ #include #include #include +#include + +class PlayTestEvent: public QEvent { +public: + PlayTestEvent(QEvent::Type type, const std::string & filename): QEvent(type), _filename(filename) {} + virtual ~PlayTestEvent() {} + const std::string _filename; +}; TestController::TestController(MEDModule* mod): _salomeModule(mod), _desk(SUIT_Session::session()->activeApplication()->desktop()), - _tester(0), _lock_action(0) + _tester(0), _lock_action(0), + _quitEventType(QEvent::registerEventType()), + _playEventType(QEvent::registerEventType()), + _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() @@ -120,19 +135,12 @@ void TestController::onPlayTest() _tester->playTests(fileName); } -void TestController::onPlayTestScenario() -{ - STDLOG("About to play test " << _test_scenario.toStdString()); - _tester->playTests(_test_scenario); - STDLOG("Done playing test " << _test_scenario.toStdString()); -} - -void TestController::onLockViewSize() +void TestController::onLockViewSize() const { pqTestingReaction::lockViewSize(_lock_action->isChecked()); } -void TestController::onTakeSnapshot() +void TestController::onTakeSnapshot() const { pqSaveScreenshotReaction::saveScreenshot(); } @@ -140,10 +148,10 @@ void TestController::onTakeSnapshot() void TestController::onRequestTermination() { // Check if test playing - if (_tester->playingTest()) + if (_tester->playingTest() || _aboutToPlayTest) { - STDLOG("Termination requested, but test still playing ..."); - QTimer::singleShot(200, this, SLOT(onRequestTermination())); + QEvent * e = new QEvent((QEvent::Type)_quitEventType); + QApplication::postEvent(this, e); } else { @@ -151,6 +159,38 @@ void TestController::onRequestTermination() } } +void +TestController::customEvent(QEvent * event) +{ + if (event->type() == _quitEventType) + { + if(!isMainEventLoopStarted()) + // Repost (=delay) + QApplication::postEvent(this, new QEvent((QEvent::Type)_quitEventType)); + else + onRequestTermination(); + } + else if (event->type() == _playEventType) + { + PlayTestEvent * e = dynamic_cast(event); + if (e) + { +// // Wait for main event loop to start: + if(!isMainEventLoopStarted()) + // Repost (=delay) + QApplication::postEvent(this, new PlayTestEvent((QEvent::Type)_playEventType, e->_filename)); + else + { + STDLOG("About to play test " << e->_filename); + _tester->playTests(e->_filename.c_str()); + _aboutToPlayTest = false; + STDLOG("Done playing test " << e->_filename); + } + } + } + else + { QObject::customEvent(event); } +} void TestController::processWorkspaceEvent(const MEDCALC::MedEvent* event) @@ -159,13 +199,27 @@ TestController::processWorkspaceEvent(const MEDCALC::MedEvent* event) /* [ABN] Post an event. Indeed, calling the function directly would prevent the proper refresh of the * GUI which also needs to go through the MED event loop (WorkspaceController::processWorkspaceEvent) */ - _test_scenario = QString(event->filename); - QTimer::singleShot(100, this, SLOT(onPlayTestScenario())); + _aboutToPlayTest = true; // to prevent an early quit! + PlayTestEvent * e = new PlayTestEvent((QEvent::Type)_playEventType, std::string(event->filename)); + QApplication::postEvent(this, e); } else if ( event->type == MEDCALC::EVENT_QUIT_SALOME ) { // [ABN] again: post as an event to give a chance to other events (piled up by test // scenarios for example) to execute: - QTimer::singleShot(200, this, SLOT(onRequestTermination())); + QEvent * e = new QEvent((QEvent::Type)_quitEventType); + QApplication::postEvent(this, e); } } +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); +}