pqEventPlayer.cxx 5.97 KB
Newer Older
Clinton Stimpson's avatar
 
Clinton Stimpson committed
1 2 3 4 5
/*=========================================================================

   Program: ParaView
   Module:    pqEventPlayer.cxx

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.

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

Clinton Stimpson's avatar
 
Clinton Stimpson committed
33 34
#include "pqEventPlayer.h"

Clinton Stimpson's avatar
 
Clinton Stimpson committed
35 36 37 38 39
#include "pqAbstractActivateEventPlayer.h"
#include "pqAbstractBooleanEventPlayer.h"
#include "pqAbstractDoubleEventPlayer.h"
#include "pqAbstractIntEventPlayer.h"
#include "pqAbstractItemViewEventPlayer.h"
40
#include "pqAbstractMiscellaneousEventPlayer.h"
Clinton Stimpson's avatar
 
Clinton Stimpson committed
41 42
#include "pqAbstractStringEventPlayer.h"
#include "pqBasicWidgetEventPlayer.h"
43
#include "pqCommentEventPlayer.h"
Clinton Stimpson's avatar
 
Clinton Stimpson committed
44
#include "pqObjectNaming.h"
45
#include "pqTabBarEventPlayer.h"
46
#include "pqTreeViewEventPlayer.h"
47 48
#include "pqNativeFileDialogEventPlayer.h"
#include "pq3DViewEventPlayer.h"
Clinton Stimpson's avatar
 
Clinton Stimpson committed
49 50 51

#include <QApplication>
#include <QWidget>
52
#include <QDebug>
Clinton Stimpson's avatar
 
Clinton Stimpson committed
53

54
// ----------------------------------------------------------------------------
Clinton Stimpson's avatar
 
Clinton Stimpson committed
55 56 57 58
pqEventPlayer::pqEventPlayer()
{
}

59
// ----------------------------------------------------------------------------
Clinton Stimpson's avatar
 
Clinton Stimpson committed
60 61 62 63
pqEventPlayer::~pqEventPlayer()
{
}

64
// ----------------------------------------------------------------------------
65
void pqEventPlayer::addDefaultWidgetEventPlayers(pqTestUtility* util)
Clinton Stimpson's avatar
 
Clinton Stimpson committed
66
{
67
  addWidgetEventPlayer(new pqCommentEventPlayer());
Clinton Stimpson's avatar
 
Clinton Stimpson committed
68
  addWidgetEventPlayer(new pqBasicWidgetEventPlayer());
Clinton Stimpson's avatar
 
Clinton Stimpson committed
69 70 71 72 73 74
  addWidgetEventPlayer(new pqAbstractActivateEventPlayer());
  addWidgetEventPlayer(new pqAbstractBooleanEventPlayer());
  addWidgetEventPlayer(new pqAbstractDoubleEventPlayer());
  addWidgetEventPlayer(new pqAbstractIntEventPlayer());
  addWidgetEventPlayer(new pqAbstractItemViewEventPlayer());
  addWidgetEventPlayer(new pqAbstractStringEventPlayer());
Clinton Stimpson's avatar
 
Clinton Stimpson committed
75
  addWidgetEventPlayer(new pqTabBarEventPlayer());
76
  addWidgetEventPlayer(new pqTreeViewEventPlayer());
77
  addWidgetEventPlayer(new pqAbstractMiscellaneousEventPlayer());
78
  addWidgetEventPlayer(new pq3DViewEventPlayer("QGLWidget"));
79
  //addWidgetEventPlayer(new pqNativeFileDialogEventPlayer(util));
Clinton Stimpson's avatar
 
Clinton Stimpson committed
80 81
}

82
// ----------------------------------------------------------------------------
Clinton Stimpson's avatar
 
Clinton Stimpson committed
83 84 85 86
void pqEventPlayer::addWidgetEventPlayer(pqWidgetEventPlayer* Player)
{
  if(Player)
    {
Clinton Stimpson's avatar
 
Clinton Stimpson committed
87 88
    this->Players.push_front(Player);
    Player->setParent(this);
Clinton Stimpson's avatar
 
Clinton Stimpson committed
89 90 91
    }
}

92 93
// ----------------------------------------------------------------------------
bool pqEventPlayer::removeWidgetEventPlayer(const QString& className)
Clinton Stimpson's avatar
 
Clinton Stimpson committed
94
{
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
  int index = this->getWidgetEventPlayerIndex(className);
  if (index == -1)
    {
    return false;
    }

  this->Players.removeAt(index);
  return true;
}

// ----------------------------------------------------------------------------
pqWidgetEventPlayer* pqEventPlayer::getWidgetEventPlayer(const QString& className)
{
  int index = this->getWidgetEventPlayerIndex(className);
  if (index == -1)
    {
    return 0;
    }

  return this->Players.at(index);
}

// ----------------------------------------------------------------------------
int pqEventPlayer::getWidgetEventPlayerIndex(const QString& className)
{
  for(int i = 0 ; i < this->Players.count() ; ++i)
    {
    if (this->Players.at(i)->metaObject()->className() == className)
      {
      return i;
      }
    }
  return -1;
}

// ----------------------------------------------------------------------------
void pqEventPlayer::playEvent(const QString& Object,
                              const QString& Command,
                              const QString& Arguments,
                              bool& Error)
{
  emit this->eventAboutToBePlayed(Object, Command, Arguments);
137
  // If we can't find an object with the right name, we're done ...
138 139
  QString messageError;
  QObject* const object = pqObjectNaming::GetObject(Object, messageError);
140 141 142 143 144 145 146 147

  if(!object && Object.contains(QString("QScrollBar")))
    {
    emit this->eventPlayed(Object, Command, Arguments);
    Error = false;
    return;
    }

148
  if(!object && Command != "comment")
Clinton Stimpson's avatar
 
Clinton Stimpson committed
149
    {
150
    emit this->errorMessage(messageError);
151
    Error = true;
Clinton Stimpson's avatar
 
Clinton Stimpson committed
152 153 154
    return;
    }

155 156 157
  // Loop through players until the event gets handled ...
  bool accepted = false;
  bool error = false;
Clinton Stimpson's avatar
 
Clinton Stimpson committed
158 159
  for(int i = 0; i != this->Players.size(); ++i)
    {
160 161
    accepted = this->Players[i]->playEvent(object, Command, Arguments, error);
    if(accepted)
Clinton Stimpson's avatar
 
Clinton Stimpson committed
162
      {
163
      break;
Clinton Stimpson's avatar
 
Clinton Stimpson committed
164 165 166
      }
    }

167 168
  // The event wasn't handled at all ...
  if(!accepted)
Clinton Stimpson's avatar
 
Clinton Stimpson committed
169
    {
170 171 172
    messageError = QString("Unhandled event %1 object %2\n").arg(Command, object->objectName());
    qCritical() << messageError;
    emit this->errorMessage(messageError);
173 174
    Error = true;
    return;
Clinton Stimpson's avatar
 
Clinton Stimpson committed
175 176
    }

177 178
  // The event was handled, but there was a problem ...    
  if(accepted && error)
Clinton Stimpson's avatar
 
Clinton Stimpson committed
179
    {
180 181 182
    messageError = QString("Event error %1 object %2\n").arg(Command, object->objectName());
    qCritical() << messageError;
    emit this->errorMessage(messageError);
183 184
    Error = true;
    return;
Clinton Stimpson's avatar
 
Clinton Stimpson committed
185 186
    }

187
  // The event was handled successfully ...
188
  emit this->eventPlayed(Object, Command, Arguments);
189
  Error = false;
Clinton Stimpson's avatar
 
Clinton Stimpson committed
190
}
Clinton Stimpson's avatar
 
Clinton Stimpson committed
191