Commit 65e1c1c2 authored by Utkarsh Ayachit's avatar Utkarsh Ayachit

Added support to register timers to time-out during playback.

Timers cause major issues with the test playback since they may not timeout as
tests are being played back, but the tend to when user is using the application.
To avoid such issues, we now add mechanism to register such timer with the
pqEventDispatcher.
parent 8cb3031d
......@@ -42,10 +42,34 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <QThread>
#include <QDialog>
#include <QMainWindow>
#include <QList>
#include <QPointer>
#include <QTimer>
#include <iostream>
using namespace std;
namespace
{
static QList<QPointer<QTimer> > RegisteredTimers;
void processTimers()
{
foreach (QTimer* timer, RegisteredTimers)
{
if (timer && timer->isActive())
{
QTimerEvent event(timer->timerId());
qApp->notify(timer, &event);
processTimers();
break;
}
}
}
static int EventPlaybackDelay = QT_TESTING_EVENT_PLAYBACK_DELAY;
};
bool pqEventDispatcher::DeferMenuTimeouts = false;
//-----------------------------------------------------------------------------
pqEventDispatcher::pqEventDispatcher(QObject* parentObject) :
......@@ -71,6 +95,28 @@ pqEventDispatcher::~pqEventDispatcher()
{
}
//-----------------------------------------------------------------------------
void pqEventDispatcher::setEventPlaybackDelay(int milliseconds)
{
EventPlaybackDelay = (milliseconds <= 0)? 0 : milliseconds;
}
//-----------------------------------------------------------------------------
int pqEventDispatcher::eventPlaybackDelay()
{
return EventPlaybackDelay;
}
//-----------------------------------------------------------------------------
void pqEventDispatcher::registerTimer(QTimer* timer)
{
if (timer)
{
RegisteredTimers.push_back(timer);
}
}
//-----------------------------------------------------------------------------
void pqEventDispatcher::aboutToBlock()
{
......@@ -222,19 +268,16 @@ void pqEventDispatcher::playEvent(int indent)
bool error = false;
this->ActivePlayer->playEvent(object, command, arguments, error);
this->BlockTimer.stop();
//QCoreApplication::sendPostedEvents();
//QCoreApplication::flush();
if (print_debug)
{
cout << " -- pre-processEventsAndWait: " << local_counter <<endl;
}
// let what's going to happen after the playback, happen.
this->processEventsAndWait(QT_TESTING_EVENT_PLAYBACK_DELAY);
if (print_debug)
{
cout << " -- post-processEventsAndWait: " << local_counter <<endl;
}
// process any posted events. We call processEvents() so that any slots
// connected using QueuedConnection also get handled.
this->processEventsAndWait(EventPlaybackDelay);
// We explicitly timeout timers that have been registered with us.
processTimers();
this->BlockTimer.stop();
if (print_debug)
{
cout << QTime::currentTime().toString("hh:mm:ss").toStdString().c_str()
......
......@@ -47,6 +47,22 @@ class pqEventSource;
/// then "playing" it using the player. The dispatcher is the critical component
/// of this playback since it decides when it's time to dispatch the next
/// "event" from the test.
/// After an event is posted, there are two options:
/// \li the default option is to simply wait for a small amount of time before
/// processing the next event. The hope is that within that time any pending
/// requests such as timers, slots connected using Qt::QueuedConnection etc.
/// will be handled and all will work well. This however it fraught with
/// problems resulting is large number of random test failures especially in
/// large and complex applications such as ParaView. In such cases the better
/// option is the second option.
/// \li we only process already posted events (using a call to
/// QApplication::processEvents() and then rely on timers being registered using
/// registerTimer(). All these timers are explicitly timed-out, if active, before
/// processing the next event.
///
/// To enable the second mode simply set the eventPlaybackDelay to 0.
/// In either mode, all timers registered using registerTimer() will be
/// timed-out before dispatching next event.
class QTTESTING_EXPORT pqEventDispatcher : public QObject
{
Q_OBJECT
......@@ -61,6 +77,11 @@ public:
/// true if playback was successful.
bool playEvents(pqEventSource& source, pqEventPlayer& player);
/// Set the delay between dispatching successive events. Default is set using
/// CMake variable QT_TESTING_EVENT_PLAYBACK_DELAY.
static void setEventPlaybackDelay(int milliseconds);
static int eventPlaybackDelay();
/** Wait function provided for players that need to wait for the GUI
to perform a certain action.
Note: the minimum wait time is 100ms. This is set to avoid timiing issues
......@@ -71,8 +92,11 @@ public:
calling Qt version, since that will break test playback*/
static void processEvents(QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents);
signals:
/// register a timer that needs to be ensured to have timed-out after every
/// event dispatch.
static void registerTimer(QTimer* timer);
signals:
/// signal when playback starts
void started();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment