Commit 236b4165 authored by Clinton Stimpson's avatar Clinton Stimpson

ENH: Add ability to record/playback for QTabBar.

parent bad4e52c
......@@ -4,7 +4,6 @@ INCLUDE_DIRECTORIES(
${QtTesting_BINARY_DIR}
${QtTesting_SOURCE_DIR}
${QT_QTTEST_INCLUDE_DIR}
${VTK_INCLUDE_DIR}
)
# Reduce the number of dirs that get included on moc command line
......@@ -27,6 +26,7 @@ QT4_WRAP_CPP(MOC_BUILT_SOURCES
pqRecordEventsDialog.h
pqSpinBoxEventTranslator.h
pqStdoutEventObserver.h
pqTabBarEventTranslator.h
pqWidgetEventTranslator.h
pqXMLEventObserver.h
)
......@@ -84,6 +84,10 @@ ADD_LIBRARY(QtTesting
pqSpinBoxEventTranslator.h
pqStdoutEventObserver.cxx
pqStdoutEventObserver.h
pqTabBarEventPlayer.cxx
pqTabBarEventPlayer.h
pqTabBarEventTranslator.cxx
pqTabBarEventTranslator.h
pqWidgetEventPlayer.h
pqWidgetEventTranslator.h
pqXMLEventObserver.cxx
......
......@@ -36,8 +36,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <QAbstractEventDispatcher>
#include <QtDebug>
#include <QtTest>
#include <QTimer>
#include <QApplication>
////////////////////////////////////////////////////////////////////////////
// pqEventDispatcher::pqImplementation
......
......@@ -30,14 +30,16 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=========================================================================*/
#include "pqEventPlayer.h"
#include "pqAbstractActivateEventPlayer.h"
#include "pqAbstractBooleanEventPlayer.h"
#include "pqAbstractDoubleEventPlayer.h"
#include "pqAbstractIntEventPlayer.h"
#include "pqAbstractItemViewEventPlayer.h"
#include "pqAbstractStringEventPlayer.h"
#include "pqTabBarEventPlayer.h"
#include "pqBasicWidgetEventPlayer.h"
#include "pqEventPlayer.h"
#include "pqObjectNaming.h"
#include <QApplication>
......@@ -63,6 +65,7 @@ void pqEventPlayer::addDefaultWidgetEventPlayers()
addWidgetEventPlayer(new pqAbstractIntEventPlayer());
addWidgetEventPlayer(new pqAbstractItemViewEventPlayer());
addWidgetEventPlayer(new pqAbstractStringEventPlayer());
addWidgetEventPlayer(new pqTabBarEventPlayer());
addWidgetEventPlayer(new pqBasicWidgetEventPlayer());
}
......
......@@ -30,16 +30,17 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=========================================================================*/
#include "pqEventTranslator.h"
#include "pqAbstractButtonEventTranslator.h"
#include "pqAbstractItemViewEventTranslator.h"
#include "pqAbstractSliderEventTranslator.h"
#include "pqComboBoxEventTranslator.h"
#include "pqDoubleSpinBoxEventTranslator.h"
#include "pqEventTranslator.h"
#include "pqLineEditEventTranslator.h"
#include "pqMenuEventTranslator.h"
#include "pqObjectNaming.h"
#include "pqSpinBoxEventTranslator.h"
#include "pqTabBarEventTranslator.h"
#include "pqBasicWidgetEventTranslator.h"
#include <QCoreApplication>
......@@ -90,6 +91,7 @@ void pqEventTranslator::addDefaultWidgetEventTranslators()
addWidgetEventTranslator(new pqLineEditEventTranslator());
addWidgetEventTranslator(new pqMenuEventTranslator());
addWidgetEventTranslator(new pqSpinBoxEventTranslator());
addWidgetEventTranslator(new pqTabBarEventTranslator());
addWidgetEventTranslator(new pqBasicWidgetEventTranslator());
}
......
......@@ -38,8 +38,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <QPushButton>
#include <QTimer>
#include <vtkIOStream.h>
#include <QFile>
#include <QTextStream>
//////////////////////////////////////////////////////////////////////////////////
// pqImplementation
......@@ -49,21 +49,26 @@ struct pqRecordEventsDialog::pqImplementation
public:
pqImplementation(pqEventTranslator* translator, const QString& path) :
Translator(translator),
File(path.toAscii().data()),
Observer(File)
File(path)
{
this->File.open(QIODevice::WriteOnly);
this->Stream.setDevice(&this->File);
this->Observer = new pqXMLEventObserver(this->Stream);
}
~pqImplementation()
{
delete this->Translator;
delete this->Observer;
this->Stream.flush();
}
Ui::pqRecordEventsDialog Ui;
pqEventTranslator* const Translator;
ofstream File;
pqXMLEventObserver Observer;
QFile File;
QTextStream Stream;
pqXMLEventObserver* Observer;
};
///////////////////////////////////////////////////////////////////////////////////
......@@ -81,7 +86,7 @@ pqRecordEventsDialog::pqRecordEventsDialog(pqEventTranslator* Translator, const
QObject::connect(
this->Implementation->Translator,
SIGNAL(recordEvent(const QString&, const QString&, const QString&)),
&this->Implementation->Observer,
this->Implementation->Observer,
SLOT(onRecordEvent(const QString&, const QString&, const QString&)));
this->setWindowTitle(tr("Recording User Input"));
......
/*=========================================================================
Program: ParaView
Module: pqTabBarEventPlayer.cxx
Copyright (c) 2005,2006 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.1.
See License_v1.1.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 "pqTabBarEventPlayer.h"
#include <QComboBox>
#include <QLineEdit>
#include <QtDebug>
pqTabBarEventPlayer::pqTabBarEventPlayer()
{
}
bool pqTabBarEventPlayer::playEvent(QObject* Object, const QString& Command, const QString& Arguments, bool& Error)
{
if(Command != "set_tab")
return false;
const QString value = Arguments;
if(QTabBar* const object = qobject_cast<QTabBar*>(Object))
{
bool ok = false;
int which = value.toInt(&ok);
if(!ok)
{
qCritical() << "calling set_tab with invalid argument on " << Object;
Error = true;
}
else if(object->count() < which)
{
qCritical() << "calling set_tab with out of bounds index on " << Object;
Error = true;
}
else
{
object->setCurrentIndex(which);
}
return true;
}
qCritical() << "calling set_tab on unhandled type " << Object;
Error = true;
return true;
}
/*=========================================================================
Program: ParaView
Module: pqTabBarEventPlayer.h
Copyright (c) 2005,2006 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.1.
See License_v1.1.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 _pqTabBarEventPlayer_h
#define _pqTabBarEventPlayer_h
#include "pqWidgetEventPlayer.h"
/**
Concrete implementation of pqWidgetEventPlayer that translates high-level ParaView events into low-level Qt events.
\sa pqEventPlayer
*/
class pqTabBarEventPlayer :
public pqWidgetEventPlayer
{
public:
pqTabBarEventPlayer();
bool playEvent(QObject* Object, const QString& Command, const QString& Arguments, bool& Error);
private:
pqTabBarEventPlayer(const pqTabBarEventPlayer&);
pqTabBarEventPlayer& operator=(const pqTabBarEventPlayer&);
};
#endif // !_pqTabBarEventPlayer_h
/*=========================================================================
Program: ParaView
Module: pqTabBarEventTranslator.cxx
Copyright (c) 2005,2006 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.1.
See License_v1.1.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 "pqTabBarEventTranslator.h"
#include <QTabBar>
#include <QEvent>
pqTabBarEventTranslator::pqTabBarEventTranslator() :
CurrentObject(0)
{
}
bool pqTabBarEventTranslator::translateEvent(QObject* Object, QEvent* Event, bool& /*Error*/)
{
QTabBar* const object = qobject_cast<QTabBar*>(Object);
if(!object)
return false;
switch(Event->type())
{
case QEvent::Enter:
if(this->CurrentObject != Object)
{
if(this->CurrentObject)
{
disconnect(this->CurrentObject, 0, this, 0);
}
this->CurrentObject = object;
connect(object, SIGNAL(currentChanged(int)), this, SLOT(indexChanged(int)));
}
break;
default:
break;
}
return true;
}
void pqTabBarEventTranslator::indexChanged(int which)
{
emit recordEvent(this->CurrentObject, "set_tab",
QString("%1").arg(which));
}
/*=========================================================================
Program: ParaView
Module: pqTabBarEventTranslator.h
Copyright (c) 2005,2006 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.1.
See License_v1.1.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 _pqTabBarEventTranslator_h
#define _pqTabBarEventTranslator_h
#include "pqWidgetEventTranslator.h"
#include <QPointer>
class QTabBar;
/**
Translates low-level Qt events into high-level ParaView events that can be recorded as test cases.
\sa pqEventTranslator
*/
class pqTabBarEventTranslator :
public pqWidgetEventTranslator
{
Q_OBJECT
public:
pqTabBarEventTranslator();
virtual bool translateEvent(QObject* Object, QEvent* Event, bool& Error);
protected slots:
void indexChanged(int);
private:
pqTabBarEventTranslator(const pqTabBarEventTranslator&);
pqTabBarEventTranslator& operator=(const pqTabBarEventTranslator&);
QPointer<QTabBar> CurrentObject;
};
#endif // !_pqTabBarEventTranslator_h
......@@ -32,6 +32,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "pqXMLEventObserver.h"
#include <QTextStream>
/// Escapes strings so they can be embedded in an XML document
static const QString textToXML(const QString& string)
{
......@@ -48,7 +50,7 @@ static const QString textToXML(const QString& string)
////////////////////////////////////////////////////////////////////////////////////
// pqXMLEventObserver
pqXMLEventObserver::pqXMLEventObserver(ostream& stream) :
pqXMLEventObserver::pqXMLEventObserver(QTextStream& stream) :
Stream(stream)
{
this->Stream << "<?xml version=\"1.0\" ?>\n";
......
......@@ -34,7 +34,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define _pqXMLEventObserver_h
#include <QObject>
#include <vtkIOStream.h>
class QTextStream;
/**
Observes high-level ParaView events, and serializes them to a stream as XML
......@@ -54,7 +54,7 @@ class pqXMLEventObserver :
Q_OBJECT
public:
pqXMLEventObserver(ostream& Stream);
pqXMLEventObserver(QTextStream& Stream);
~pqXMLEventObserver();
public slots:
......@@ -65,7 +65,7 @@ public slots:
private:
/// Stores a stream that will be used to store the XML output
ostream& Stream;
QTextStream& Stream;
};
#endif // !_pqXMLEventObserver_h
......
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