pqEventDispatcher.h 4.74 KB
Newer Older
Clinton Stimpson's avatar
 
Clinton Stimpson committed
1 2 3
/*=========================================================================

   Program: ParaView
4
   Module:    pqEventDispatcher.h
Clinton Stimpson's avatar
 
Clinton Stimpson committed
5

6
   Copyright (c) 2005-2008 Sandia Corporation, Kitware Inc.
Clinton Stimpson's avatar
 
Clinton Stimpson committed
7 8 9
   All rights reserved.

   ParaView is a free software; you can redistribute it and/or modify it
10
   under the terms of the ParaView license version 1.2. 
Clinton Stimpson's avatar
 
Clinton Stimpson committed
11

12
   See License_v1.2.txt for the full ParaView license.
Clinton Stimpson's avatar
 
Clinton Stimpson committed
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
   A copy of this license can be obtained by contacting
   Kitware Inc.
   28 Corporate Drive
   Clifton Park, NY 12065
   USA

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

=========================================================================*/

33 34
#ifndef _pqEventDispatcher_h
#define _pqEventDispatcher_h
Clinton Stimpson's avatar
 
Clinton Stimpson committed
35 36

#include "QtTestingExport.h"
37

Clinton Stimpson's avatar
 
Clinton Stimpson committed
38
#include <QObject>
39
#include <QTimer>
40
#include <QTime>
41
#include <QEventLoop>
Clinton Stimpson's avatar
 
Clinton Stimpson committed
42 43

class pqEventPlayer;
44
class pqEventSource;
Clinton Stimpson's avatar
 
Clinton Stimpson committed
45

46 47 48 49
/// pqEventDispatcher is responsible for taking each "event" from the test and
/// 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.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
/// 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.
66
class QTTESTING_EXPORT pqEventDispatcher : public QObject
Clinton Stimpson's avatar
 
Clinton Stimpson committed
67 68
{
  Q_OBJECT
69
  typedef QObject Superclass; 
Clinton Stimpson's avatar
 
Clinton Stimpson committed
70
public:
71
  pqEventDispatcher(QObject* parent=0);
72 73
  ~pqEventDispatcher();

74 75 76 77 78
  /// Retrieves events from the given event source, dispatching them to
  /// the given event player for test case playback. This call blocks until all
  /// the events from the source have been played back (or failure). Returns
  /// true if playback was successful.
  bool playEvents(pqEventSource& source, pqEventPlayer& player);
79

80 81 82 83 84
  /// 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();

Clinton Stimpson's avatar
 
Clinton Stimpson committed
85
  /** Wait function provided for players that need to wait for the GUI
86 87 88
      to perform a certain action.
      Note: the minimum wait time is 100ms. This is set to avoid timiing issues
      on slow processors that hang tests.*/
Clinton Stimpson's avatar
 
Clinton Stimpson committed
89 90
  static void processEventsAndWait(int ms);

91 92 93 94
    /** proccessEvents method for widgets and paraview to use instead of
    calling Qt version, since that will break test playback*/
  static void processEvents(QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents);

95 96 97
  /// register a timer that needs to be ensured to have timed-out after every
  /// event dispatch.
  static void registerTimer(QTimer* timer);
98

99
signals:
100 101 102 103 104 105
  /// signal when playback starts
  void started();

  /// signal when playback stops
  void stopped();

106 107 108
protected slots:
  /// Plays a single event. this->PlayBackFinished and this->PlayBackStatus are
  /// updated by this method.
109
  void playEvent(int indent=0);
110
  void playEventOnBlocking();
Clinton Stimpson's avatar
 
Clinton Stimpson committed
111

112 113
  /// Called when the mainThread is about to block.
  void aboutToBlock();
114

115 116
  /// Called when the mainThread wakes up.
  void awake();
117 118 119 120

protected:
  bool PlayBackFinished;
  bool PlayBackStatus;
121
  static bool DeferMenuTimeouts;
122 123 124

  pqEventSource* ActiveSource;
  pqEventPlayer* ActivePlayer;
125
  QTimer BlockTimer;
126
};
Clinton Stimpson's avatar
 
Clinton Stimpson committed
127

128
#endif // !_pqEventDispatcher_h