Commit 13136187 authored by Clinton Stimpson's avatar Clinton Stimpson

Add support for 3d views and native file dialogs.

3D view recording/playback is generic and works off a given class name.

pqTestUtility has methods for an application to add data directories.  If a file is opened or saved from under a data
directory, a label for that directory is recorded.  Playback reverses the label to an absolute file.
parent d6b0baa8
......@@ -78,6 +78,7 @@ GET_DIRECTORY_PROPERTY(include_dirs_tmp INCLUDE_DIRECTORIES)
SET_DIRECTORY_PROPERTIES(PROPERTIES INCLUDE_DIRECTORIES "${MOC_INCLUDE_DIRS}")
QT4_WRAP_CPP(MOC_BUILT_SOURCES
pq3DViewEventTranslator.h
pqAbstractButtonEventTranslator.h
pqAbstractItemViewEventTranslator.h
pqAbstractSliderEventTranslator.h
......@@ -91,6 +92,8 @@ QT4_WRAP_CPP(MOC_BUILT_SOURCES
pqEventTranslator.h
pqLineEditEventTranslator.h
pqMenuEventTranslator.h
pqNativeFileDialogEventTranslator.h
pqNativeFileDialogEventPlayer.h
pqRecordEventsDialog.h
pqSpinBoxEventTranslator.h
pqStdoutEventObserver.h
......@@ -111,6 +114,10 @@ QT4_WRAP_UI(UI_BUILT_SOURCES
ADD_LIBRARY(QtTesting
QtTestingExport.h
pq3DViewEventPlayer.cxx
pq3DViewEventPlayer.h
pq3DViewEventTranslator.cxx
pq3DViewEventTranslator.h
pqAbstractActivateEventPlayer.cxx
pqAbstractActivateEventPlayer.h
pqAbstractBooleanEventPlayer.cxx
......@@ -150,6 +157,10 @@ ADD_LIBRARY(QtTesting
pqEventSource.h
pqLineEditEventTranslator.cxx
pqLineEditEventTranslator.h
pqNativeFileDialogEventPlayer.cxx
pqNativeFileDialogEventPlayer.h
pqNativeFileDialogEventTranslator.cxx
pqNativeFileDialogEventTranslator.h
pqMenuEventTranslator.cxx
pqMenuEventTranslator.h
pqObjectNaming.cxx
......
/*=========================================================================
Program: ParaView
Module: pq3DViewEventPlayer.cxx
Copyright (c) 2005-2008 Sandia Corporation, Kitware Inc.
All rights reserved.
ParaView is a free software; you can redistribute it and/or modify it
under the terms of the ParaView license version 1.2.
See License_v1.2.txt for the full ParaView license.
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.
=========================================================================*/
#include "pq3DViewEventPlayer.h"
#include <QApplication>
#include <QKeyEvent>
#include <QMouseEvent>
#include <QtDebug>
#include <QRegExp>
#include <QWidget>
pq3DViewEventPlayer::pq3DViewEventPlayer(const QByteArray& classname, QObject * p)
: pqWidgetEventPlayer(p), mClassType(classname)
{
}
bool pq3DViewEventPlayer::playEvent(QObject* Object,
const QString& Command,
const QString& Arguments,
bool& Error)
{
QWidget* widget = qobject_cast<QWidget*>(Object);
if(widget && Object->inherits(mClassType.data()))
{
if (Command == "mousePress" || Command=="mouseRelease" || Command=="mouseMove")
{
QRegExp mouseRegExp("\\(([^,]*),([^,]*),([^,]),([^,]),([^,]*)\\)");
if (mouseRegExp.indexIn(Arguments)!= -1)
{
QVariant v = mouseRegExp.cap(1);
int x = static_cast<int>(v.toDouble() * widget->size().width());
v = mouseRegExp.cap(2);
int y = static_cast<int>(v.toDouble() * widget->size().height());
v = mouseRegExp.cap(3);
Qt::MouseButton button = static_cast<Qt::MouseButton>(v.toInt());
v = mouseRegExp.cap(4);
Qt::MouseButtons buttons = static_cast<Qt::MouseButton>(v.toInt());
v = mouseRegExp.cap(5);
Qt::KeyboardModifiers keym = static_cast<Qt::KeyboardModifier>(v.toInt());
QEvent::Type type = (Command == "mousePress")? QEvent::MouseButtonPress :
((Command=="mouseMove")? QEvent::MouseMove : QEvent::MouseButtonRelease);
QMouseEvent e(type, QPoint(x,y), button, buttons, keym);
QCoreApplication::sendEvent(Object, &e);
}
return true;
}
}
return false;
}
/*=========================================================================
Program: ParaView
Module: pq3DViewEventPlayer.h
Copyright (c) 2005-2008 Sandia Corporation, Kitware Inc.
All rights reserved.
ParaView is a free software; you can redistribute it and/or modify it
under the terms of the ParaView license version 1.2.
See License_v1.2.txt for the full ParaView license.
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.
=========================================================================*/
#ifndef _pq3DViewEventPlayer_h
#define _pq3DViewEventPlayer_h
#include "pqWidgetEventPlayer.h"
/**
Concrete implementation of pqWidgetEventPlayer that handles playback of "activate" events for 3d views.
It is not registered by default, and user can register with their own 3d view type.
\sa pqEventPlayer
*/
class QTTESTING_EXPORT pq3DViewEventPlayer :
public pqWidgetEventPlayer
{
public:
pq3DViewEventPlayer(const QByteArray& classname, QObject* p = 0);
bool playEvent(QObject* Object, const QString& Command, const QString& Arguments, bool& Error);
protected:
QByteArray mClassType;
private:
pq3DViewEventPlayer(const pq3DViewEventPlayer&);
pq3DViewEventPlayer& operator=(const pq3DViewEventPlayer&);
};
#endif // !_pq3DViewEventPlayer_h
/*=========================================================================
Program: ParaView
Module: pq3DViewEventTranslator.cxx
Copyright (c) 2005-2008 Sandia Corporation, Kitware Inc.
All rights reserved.
ParaView is a free software; you can redistribute it and/or modify it
under the terms of the ParaView license version 1.2.
See License_v1.2.txt for the full ParaView license.
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.
=========================================================================*/
#include "pq3DViewEventTranslator.h"
#include <QEvent>
#include <QMouseEvent>
#include <QKeyEvent>
#include <QWidget>
pq3DViewEventTranslator::pq3DViewEventTranslator(const QByteArray& classname, QObject* p)
: pqWidgetEventTranslator(p), mClassType(classname),
lastMoveEvent(QEvent::MouseButtonPress, QPoint(), Qt::MouseButton(),
Qt::MouseButtons(), Qt::KeyboardModifiers())
{
}
pq3DViewEventTranslator::~pq3DViewEventTranslator()
{
}
bool pq3DViewEventTranslator::translateEvent(QObject* Object, QEvent* Event,
bool& /*Error*/)
{
QWidget* widget = qobject_cast<QWidget*>(Object);
if(!widget || !Object->inherits(mClassType.data()))
{
return false;
}
bool handled = false;
switch(Event->type())
{
case QEvent::ContextMenu:
handled=true;
break;
case QEvent::MouseButtonPress:
{
QMouseEvent* mouseEvent = dynamic_cast<QMouseEvent*>(Event);
if (mouseEvent)
{
QSize size = widget->size();
double normalized_x = mouseEvent->x()/static_cast<double>(size.width());
double normalized_y = mouseEvent->y()/static_cast<double>(size.height());
int button = mouseEvent->button();
int buttons = mouseEvent->buttons();
int modifiers = mouseEvent->modifiers();
emit recordEvent(Object, "mousePress", QString("(%1,%2,%3,%4,%5)")
.arg(normalized_x)
.arg(normalized_y)
.arg(button)
.arg(buttons)
.arg(modifiers));
}
// reset lastMoveEvent
QMouseEvent e(QEvent::MouseButtonPress, QPoint(), Qt::MouseButton(),
Qt::MouseButtons(), Qt::KeyboardModifiers());
lastMoveEvent = e;
}
handled = true;
break;
case QEvent::MouseMove:
{
QMouseEvent* mouseEvent = dynamic_cast<QMouseEvent*>(Event);
if (mouseEvent)
{
QMouseEvent e(QEvent::MouseMove, QPoint(mouseEvent->x(), mouseEvent->y()),
mouseEvent->button(), mouseEvent->buttons(),
mouseEvent->modifiers());
lastMoveEvent = e;
}
}
handled = true;
break;
case QEvent::MouseButtonRelease:
{
QMouseEvent* mouseEvent = dynamic_cast<QMouseEvent*>(Event);
if (mouseEvent)
{
QSize size = widget->size();
// record last move event if it is valid
if(lastMoveEvent.type() == QEvent::MouseMove)
{
double normalized_x = lastMoveEvent.x()/static_cast<double>(size.width());
double normalized_y = lastMoveEvent.y()/static_cast<double>(size.height());
int button = lastMoveEvent.button();
int buttons = lastMoveEvent.buttons();
int modifiers = lastMoveEvent.modifiers();
emit recordEvent(Object, "mouseMove", QString("(%1,%2,%3,%4,%5)")
.arg(normalized_x)
.arg(normalized_y)
.arg(button)
.arg(buttons)
.arg(modifiers));
}
double normalized_x = mouseEvent->x()/static_cast<double>(size.width());
double normalized_y = mouseEvent->y()/static_cast<double>(size.height());
int button = mouseEvent->button();
int buttons = mouseEvent->buttons();
int modifiers = mouseEvent->modifiers();
emit recordEvent(Object, "mouseRelease", QString("(%1,%2,%3,%4,%5)")
.arg(normalized_x)
.arg(normalized_y)
.arg(button)
.arg(buttons)
.arg(modifiers));
}
}
handled = true;
break;
case QEvent::KeyPress:
case QEvent::KeyRelease:
{
QKeyEvent* ke = static_cast<QKeyEvent*>(Event);
QString data =QString("%1:%2:%3:%4:%5:%6")
.arg(ke->type())
.arg(ke->key())
.arg(static_cast<int>(ke->modifiers()))
.arg(ke->text())
.arg(ke->isAutoRepeat())
.arg(ke->count());
emit recordEvent(Object, "keyEvent", data);
}
break;
default:
break;
}
return handled;
}
/*=========================================================================
Program: ParaView
Module: pq3DViewEventTranslator.h
Copyright (c) 2005-2008 Sandia Corporation, Kitware Inc.
All rights reserved.
ParaView is a free software; you can redistribute it and/or modify it
under the terms of the ParaView license version 1.2.
See License_v1.2.txt for the full ParaView license.
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.
=========================================================================*/
#ifndef _pq3DViewEventTranslator_h
#define _pq3DViewEventTranslator_h
#include "pqWidgetEventTranslator.h"
#include <QMouseEvent>
/**
Translates low-level Qt events into high-level ParaView events that can be recorded as test cases.
\sa pqEventTranslator
*/
class QTTESTING_EXPORT pq3DViewEventTranslator :
public pqWidgetEventTranslator
{
Q_OBJECT
public:
pq3DViewEventTranslator(const QByteArray& classname, QObject* p=0);
~pq3DViewEventTranslator();
virtual bool translateEvent(QObject* Object, QEvent* Event, bool& Error);
protected:
QByteArray mClassType;
QMouseEvent lastMoveEvent;
private:
pq3DViewEventTranslator(const pq3DViewEventTranslator&);
pq3DViewEventTranslator& operator=(const pq3DViewEventTranslator&);
};
#endif // !_pq3DViewEventTranslator_h
......@@ -40,7 +40,7 @@ Concrete implementation of pqWidgetEventPlayer that translates high-level ParaVi
\sa pqEventPlayer
*/
class pqAbstractBooleanEventPlayer :
class QTTESTING_EXPORT pqAbstractBooleanEventPlayer :
public pqWidgetEventPlayer
{
public:
......
......@@ -43,7 +43,7 @@ Translates low-level Qt events into high-level ParaView events that can be recor
\sa pqEventTranslator
*/
class pqAbstractButtonEventTranslator :
class QTTESTING_EXPORT pqAbstractButtonEventTranslator :
public pqWidgetEventTranslator
{
Q_OBJECT
......
......@@ -41,7 +41,7 @@ Concrete implementation of pqWidgetEventPlayer that translates high-level ParaVi
\sa pqEventPlayer
*/
class pqAbstractDoubleEventPlayer :
class QTTESTING_EXPORT pqAbstractDoubleEventPlayer :
public pqWidgetEventPlayer
{
public:
......
......@@ -104,6 +104,8 @@ bool pqEventDispatcher::playEvents(pqEventSource& source, pqEventPlayer& player)
return false;
}
emit this->started();
this->ActiveSource = &source;
this->ActivePlayer = &player;
......@@ -140,6 +142,8 @@ bool pqEventDispatcher::playEvents(pqEventSource& source, pqEventPlayer& player)
QObject::disconnect(QAbstractEventDispatcher::instance(), SIGNAL(awake()),
this, SLOT(awake()));
emit this->stopped();
return this->PlayBackStatus;
}
......
......@@ -69,6 +69,14 @@ public:
calling Qt version, since that will break test playback*/
static void processEvents(QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents);
signals:
/// signal when playback starts
void started();
/// signal when playback stops
void stopped();
protected slots:
/// Plays a single event. this->PlayBackFinished and this->PlayBackStatus are
/// updated by this method.
......
......@@ -43,6 +43,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "pqObjectNaming.h"
#include "pqTabBarEventPlayer.h"
#include "pqTreeViewEventPlayer.h"
#include "pqNativeFileDialogEventPlayer.h"
#include "pq3DViewEventPlayer.h"
#include <QApplication>
#include <QWidget>
......@@ -56,7 +58,7 @@ pqEventPlayer::~pqEventPlayer()
{
}
void pqEventPlayer::addDefaultWidgetEventPlayers()
void pqEventPlayer::addDefaultWidgetEventPlayers(pqTestUtility* util)
{
addWidgetEventPlayer(new pqBasicWidgetEventPlayer());
addWidgetEventPlayer(new pqAbstractActivateEventPlayer());
......@@ -68,6 +70,8 @@ void pqEventPlayer::addDefaultWidgetEventPlayers()
addWidgetEventPlayer(new pqTabBarEventPlayer());
addWidgetEventPlayer(new pqTreeViewEventPlayer());
addWidgetEventPlayer(new pqAbstractMiscellaneousEventPlayer());
addWidgetEventPlayer(new pq3DViewEventPlayer("QGLWidget"));
addWidgetEventPlayer(new pqNativeFileDialogEventPlayer(util));
}
void pqEventPlayer::addWidgetEventPlayer(pqWidgetEventPlayer* Player)
......
......@@ -40,6 +40,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <QList>
class pqWidgetEventPlayer;
class pqTestUtility;
/**
Manages playback of test-cases, demos, tutorials, etc.
......@@ -80,7 +81,7 @@ public:
/** Adds the default set of widget players to the current working set.
Players are executed in-order, so you can call addWidgetEventPlayer()
before this function to override default players. */
void addDefaultWidgetEventPlayers();
void addDefaultWidgetEventPlayers(pqTestUtility* util);
/** Adds a new player to the current working set of widget players.
pqEventPlayer assumes control of the lifetime of the supplied object. */
void addWidgetEventPlayer(pqWidgetEventPlayer*);
......
......@@ -44,6 +44,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "pqSpinBoxEventTranslator.h"
#include "pqTabBarEventTranslator.h"
#include "pqTreeViewEventTranslator.h"
#include "pqNativeFileDialogEventTranslator.h"
#include "pq3DViewEventTranslator.h"
#include <QCoreApplication>
#include <QtDebug>
......@@ -87,14 +89,16 @@ pqEventTranslator::~pqEventTranslator()
void pqEventTranslator::start()
{
QCoreApplication::instance()->installEventFilter(this);
emit this->started();
}
void pqEventTranslator::stop()
{
emit this->stopped();
QCoreApplication::instance()->removeEventFilter(this);
}
void pqEventTranslator::addDefaultWidgetEventTranslators()
void pqEventTranslator::addDefaultWidgetEventTranslators(pqTestUtility* util)
{
addWidgetEventTranslator(new pqBasicWidgetEventTranslator());
addWidgetEventTranslator(new pqAbstractButtonEventTranslator());
......@@ -107,6 +111,8 @@ void pqEventTranslator::addDefaultWidgetEventTranslators()
addWidgetEventTranslator(new pqSpinBoxEventTranslator());
addWidgetEventTranslator(new pqTabBarEventTranslator());
addWidgetEventTranslator(new pqTreeViewEventTranslator());
addWidgetEventTranslator(new pq3DViewEventTranslator("QGLWidget"));
addWidgetEventTranslator(new pqNativeFileDialogEventTranslator(util));
}
void pqEventTranslator::addWidgetEventTranslator(pqWidgetEventTranslator* Translator)
......
......@@ -37,6 +37,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <QObject>
class pqWidgetEventTranslator;
class pqTestUtility;
/**
Manages serialization of user interaction for test-cases, demos, tutorials, etc.
......@@ -62,7 +63,7 @@ public:
Adds the default set of widget translators to the working set. Translators are executed in order, so you may call
addWidgetEventTranslator() with your own custom translators before calling this method, to "override" the default translators.
*/
void addDefaultWidgetEventTranslators();
void addDefaultWidgetEventTranslators(pqTestUtility* util);
/// Adds a new translator to the current working set of widget translators. pqEventTranslator assumes control of the lifetime of the supplied object.
void addWidgetEventTranslator(pqWidgetEventTranslator*);
......@@ -79,6 +80,12 @@ signals:
/// This signal will be emitted every time a translator generates a high-level ParaView event. Observers should connect to this signal to serialize high-level events.
void recordEvent(const QString& Object, const QString& Command, const QString& Arguments);
/// this signals when recording starts
void started();
/// this signals when recording stops
void stopped();
private slots:
void onRecordEvent(QObject* Object, const QString& Command, const QString& Arguments);
......
/*=========================================================================
Program: ParaView
Module: pqNativeFileDialogEventPlayer.cxx
Copyright (c) 2005-2008 Sandia Corporation, Kitware Inc.
All rights reserved.
ParaView is a free software; you can redistribute it and/or modify it
under the terms of the ParaView license version 1.2.
See License_v1.2.txt for the full ParaView license.
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.
=========================================================================*/
#include "pqNativeFileDialogEventPlayer.h"
#include <QEvent>
#include <QFileDialog>
#include <QApplication>
#include "pqEventDispatcher.h"
#include "pqTestUtility.h"
typedef QString (*_qt_filedialog_existing_directory_hook)(QWidget *parent, const QString &caption, const QString &dir, QFileDialog::Options options);
extern _qt_filedialog_existing_directory_hook qt_filedialog_existing_directory_hook;
typedef QString (*_qt_filedialog_open_filename_hook)(QWidget * parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFileDialog::Options options);
extern _qt_filedialog_open_filename_hook qt_filedialog_open_filename_hook;
typedef QStringList (*_qt_filedialog_open_filenames_hook)(QWidget * parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFileDialog::Options options);
extern _qt_filedialog_open_filenames_hook qt_filedialog_open_filenames_hook;
typedef QString (*_qt_filedialog_save_filename_hook)(QWidget * parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFileDialog::Options options);
extern _qt_filedialog_save_filename_hook qt_filedialog_save_filename_hook;
namespace
{
pqNativeFileDialogEventPlayer* self;
_qt_filedialog_existing_directory_hook old_existing_directory_hook;
_qt_filedialog_open_filename_hook old_open_filename_hook;
_qt_filedialog_open_filenames_hook old_open_filenames_hook;
_qt_filedialog_save_filename_hook old_save_filename_hook;
QEventLoop loop;
QString filename;
QStringList filenames;
QString dir_hook(QWidget* parent, const QString& caption, const QString& dir,
QFileDialog::Options options)
{
// wait for next event played to give us a filename
loop.exec();
return filename;
}
QString filename_hook(QWidget* parent, const QString& caption, const QString& dir,
const QString& filter, QString *selectedFilter,
QFileDialog::Options options)
{
// wait for next event played to give us a filename
loop.exec();
return filename;
}
QStringList filenames_hook(QWidget* parent, const QString& caption, const QString& dir,
const QString& filter, QString *selectedFilter,
QFileDialog::Options options)
{
// wait for next event played to give us a filename
loop.exec();
return filenames;
}
}
pqNativeFileDialogEventPlayer::pqNativeFileDialogEventPlayer(pqTestUtility* util, QObject* p)
: pqWidgetEventPlayer(p), mUtil(util)
{
QObject::connect(mUtil->dispatcher(), SIGNAL(started()), this, SLOT(start()));
QObject::connect(mUtil->dispatcher(), SIGNAL(stopped()), this, SLOT(stop()));
}
pqNativeFileDialogEventPlayer::~pqNativeFileDialogEventPlayer()
{
}
void pqNativeFileDialogEventPlayer::start()
{
self = this;
// existing dir hook
old_existing_directory_hook = qt_filedialog_existing_directory_hook;
qt_filedialog_existing_directory_hook = dir_hook;
// open file hook
old_open_filename_hook = qt_filedialog_open_filename_hook;
qt_filedialog_open_filename_hook = filename_hook;
// open files hook
old_open_filenames_hook = qt_filedialog_open_filenames_hook;
qt_filedialog_open_filenames_hook = filenames_hook;
// save file hook
old_save_filename_hook = qt_filedialog_save_filename_hook;
qt_filedialog_save_filename_hook = filename_hook;
}
void pqNativeFileDialogEventPlayer::stop()
{
self = NULL;
qt_filedialog_existing_directory_hook = old_existing_directory_hook;
qt_filedialog_open_filename_hook = old_open_filename_hook;
qt_filedialog_open_filenames_hook = old_open_filenames_hook;
qt_filedialog_save_filename_hook = old_save_filename_hook;
}
bool pqNativeFileDialogEventPlayer::playEvent(QObject* Object, const QString& Command, const QString& Arguments, bool& Error)
{
if(!qobject_cast<QApplication*>(Object))
{
return false;
}
QStringList normalized_files = Arguments.split(";");
QStringList files;
foreach(QString file, normalize