Commit 330ed36e authored by Utkarsh Ayachit's avatar Utkarsh Ayachit
Browse files

BUG: To faithfully record/playback tests involving QTreeWidgets, added a new

player/translator. Changed tests to use the new player/translator. This makes
these tests pass with Qt 4.5 and more reliable accross platforms.
parent d49af3ce
...@@ -62,6 +62,8 @@ QT4_WRAP_CPP(MOC_BUILT_SOURCES ...@@ -62,6 +62,8 @@ QT4_WRAP_CPP(MOC_BUILT_SOURCES
pqTestUtility.h pqTestUtility.h
pqThreadedEventSource.h pqThreadedEventSource.h
pqTabBarEventTranslator.h pqTabBarEventTranslator.h
pqTreeWidgetEventTranslator.h
pqTreeWidgetEventPlayer.h
pqWidgetEventTranslator.h pqWidgetEventTranslator.h
${PYTHON_MOCS} ${PYTHON_MOCS}
) )
...@@ -131,6 +133,10 @@ ADD_LIBRARY(QtTesting ...@@ -131,6 +133,10 @@ ADD_LIBRARY(QtTesting
pqTestUtility.h pqTestUtility.h
pqThreadedEventSource.cxx pqThreadedEventSource.cxx
pqThreadedEventSource.h pqThreadedEventSource.h
pqTreeWidgetEventTranslator.cxx
pqTreeWidgetEventTranslator.h
pqTreeWidgetEventPlayer.cxx
pqTreeWidgetEventPlayer.h
pqWidgetEventPlayer.cxx pqWidgetEventPlayer.cxx
pqWidgetEventPlayer.h pqWidgetEventPlayer.h
pqWidgetEventTranslator.h pqWidgetEventTranslator.h
......
...@@ -34,14 +34,15 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ...@@ -34,14 +34,15 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "pqAbstractActivateEventPlayer.h" #include "pqAbstractActivateEventPlayer.h"
#include "pqAbstractBooleanEventPlayer.h" #include "pqAbstractBooleanEventPlayer.h"
#include "pqAbstractMiscellaneousEventPlayer.h"
#include "pqAbstractDoubleEventPlayer.h" #include "pqAbstractDoubleEventPlayer.h"
#include "pqAbstractIntEventPlayer.h" #include "pqAbstractIntEventPlayer.h"
#include "pqAbstractItemViewEventPlayer.h" #include "pqAbstractItemViewEventPlayer.h"
#include "pqAbstractMiscellaneousEventPlayer.h"
#include "pqAbstractStringEventPlayer.h" #include "pqAbstractStringEventPlayer.h"
#include "pqTabBarEventPlayer.h"
#include "pqBasicWidgetEventPlayer.h" #include "pqBasicWidgetEventPlayer.h"
#include "pqObjectNaming.h" #include "pqObjectNaming.h"
#include "pqTabBarEventPlayer.h"
#include "pqTreeWidgetEventPlayer.h"
#include <QApplication> #include <QApplication>
#include <QWidget> #include <QWidget>
...@@ -65,6 +66,7 @@ void pqEventPlayer::addDefaultWidgetEventPlayers() ...@@ -65,6 +66,7 @@ void pqEventPlayer::addDefaultWidgetEventPlayers()
addWidgetEventPlayer(new pqAbstractItemViewEventPlayer()); addWidgetEventPlayer(new pqAbstractItemViewEventPlayer());
addWidgetEventPlayer(new pqAbstractStringEventPlayer()); addWidgetEventPlayer(new pqAbstractStringEventPlayer());
addWidgetEventPlayer(new pqTabBarEventPlayer()); addWidgetEventPlayer(new pqTabBarEventPlayer());
addWidgetEventPlayer(new pqTreeWidgetEventPlayer());
addWidgetEventPlayer(new pqAbstractMiscellaneousEventPlayer()); addWidgetEventPlayer(new pqAbstractMiscellaneousEventPlayer());
} }
......
...@@ -31,9 +31,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ...@@ -31,9 +31,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=========================================================================*/ =========================================================================*/
#include "pqEventTranslator.h" #include "pqEventTranslator.h"
#include "pqAbstractButtonEventTranslator.h" #include "pqAbstractButtonEventTranslator.h"
#include "pqAbstractItemViewEventTranslator.h" #include "pqAbstractItemViewEventTranslator.h"
#include "pqAbstractSliderEventTranslator.h" #include "pqAbstractSliderEventTranslator.h"
#include "pqBasicWidgetEventTranslator.h"
#include "pqComboBoxEventTranslator.h" #include "pqComboBoxEventTranslator.h"
#include "pqDoubleSpinBoxEventTranslator.h" #include "pqDoubleSpinBoxEventTranslator.h"
#include "pqLineEditEventTranslator.h" #include "pqLineEditEventTranslator.h"
...@@ -41,7 +43,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ...@@ -41,7 +43,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "pqObjectNaming.h" #include "pqObjectNaming.h"
#include "pqSpinBoxEventTranslator.h" #include "pqSpinBoxEventTranslator.h"
#include "pqTabBarEventTranslator.h" #include "pqTabBarEventTranslator.h"
#include "pqBasicWidgetEventTranslator.h" #include "pqTreeWidgetEventTranslator.h"
#include <QCoreApplication> #include <QCoreApplication>
#include <QtDebug> #include <QtDebug>
...@@ -104,6 +106,7 @@ void pqEventTranslator::addDefaultWidgetEventTranslators() ...@@ -104,6 +106,7 @@ void pqEventTranslator::addDefaultWidgetEventTranslators()
addWidgetEventTranslator(new pqMenuEventTranslator()); addWidgetEventTranslator(new pqMenuEventTranslator());
addWidgetEventTranslator(new pqSpinBoxEventTranslator()); addWidgetEventTranslator(new pqSpinBoxEventTranslator());
addWidgetEventTranslator(new pqTabBarEventTranslator()); addWidgetEventTranslator(new pqTabBarEventTranslator());
addWidgetEventTranslator(new pqTreeWidgetEventTranslator());
} }
void pqEventTranslator::addWidgetEventTranslator(pqWidgetEventTranslator* Translator) void pqEventTranslator::addWidgetEventTranslator(pqWidgetEventTranslator* Translator)
......
/*=========================================================================
Program: ParaView
Module: pqTreeWidgetEventPlayer.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.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 "pqTreeWidgetEventPlayer.h"
#include <QTreeView>
#include <QDebug>
//-----------------------------------------------------------------------------
pqTreeWidgetEventPlayer::pqTreeWidgetEventPlayer(QObject* parentObject)
: Superclass(parentObject)
{
}
//-----------------------------------------------------------------------------
pqTreeWidgetEventPlayer::~pqTreeWidgetEventPlayer()
{
}
//-----------------------------------------------------------------------------
bool pqTreeWidgetEventPlayer::playEvent(
QObject* object, const QString& command,
const QString& arguments, bool& error)
{
QTreeView* treeWidget = qobject_cast<QTreeView*>(object);
if (!treeWidget)
{
return false;
}
QRegExp regExp("^([\\d\\.]+),(\\d+),(\\d+)$");
if (command == "setTreeItemCheckState" && regExp.indexIn(arguments) != -1)
{
QString str_index = regExp.cap(1);
int column = regExp.cap(2).toInt();
int check_state = regExp.cap(3).toInt();
QStringList indices = str_index.split(".",QString::SkipEmptyParts);
QTreeWidgetItem* cur_item = NULL;
foreach (QString cur_index, indices)
{
int index = cur_index.toInt();
if (!cur_item)
{
cur_item = treeWidget->topLevelItem(index);
}
else
{
cur_item = cur_item->child(index);
}
if (!cur_item)
{
error=true;
qCritical() << "ERROR: Tree widget must have changed. "
<< "Indices recorded in the test are no longer valid. Cannot playback.";
return true;
}
}
cur_item->setCheckState(column, static_cast<Qt::CheckState>(check_state));
return true;
}
return false;
}
/*=========================================================================
Program: ParaView
Module: pqTreeWidgetEventPlayer.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.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 __pqTreeWidgetEventPlayer_h
#define __pqTreeWidgetEventPlayer_h
#include "pqWidgetEventPlayer.h"
/// pqTreeWidgetEventPlayer is a player for QTreeWidget. Plays back the state
/// recorded using pqTreeWidgetEventTranslator.
class QTTESTING_EXPORT pqTreeWidgetEventPlayer : public pqWidgetEventPlayer
{
Q_OBJECT
typedef pqWidgetEventPlayer Superclass;
public:
pqTreeWidgetEventPlayer(QObject* parent=0);
~pqTreeWidgetEventPlayer();
bool playEvent(QObject* object, const QString& command, const QString&
arguments, bool& error);
private:
pqTreeWidgetEventPlayer(const pqTreeWidgetEventPlayer&); // Not implemented.
void operator=(const pqTreeWidgetEventPlayer&); // Not implemented.
};
#endif
/*=========================================================================
Program: ParaView
Module: pqTreeWidgetEventTranslator.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.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 "pqTreeWidgetEventTranslator.h"
#include <QTreeWidget>
#include <QEvent>
//-----------------------------------------------------------------------------
pqTreeWidgetEventTranslator::pqTreeWidgetEventTranslator(QObject* parentObject)
: Superclass(parentObject)
{
}
//-----------------------------------------------------------------------------
pqTreeWidgetEventTranslator::~pqTreeWidgetEventTranslator()
{
}
//-----------------------------------------------------------------------------
bool pqTreeWidgetEventTranslator::translateEvent(
QObject* object, QEvent* tr_event, bool& /*error*/)
{
QTreeWidget* treeWidget = qobject_cast<QTreeWidget*>(object);
if(!treeWidget)
{
// mouse events go to the viewport widget
treeWidget = qobject_cast<QTreeWidget*>(object->parent());
}
if(!treeWidget)
{
return false;
}
if (tr_event->type() == QEvent::FocusIn)
{
QObject::disconnect(treeWidget, 0, this, 0);
QObject::connect(treeWidget, SIGNAL(itemClicked(QTreeWidgetItem*, int)),
this, SLOT(onItemChanged(QTreeWidgetItem*, int)));
}
return true;
}
//-----------------------------------------------------------------------------
void pqTreeWidgetEventTranslator::onItemChanged(
QTreeWidgetItem* item, int column)
{
QTreeWidget* treeWidget = item->treeWidget();
QTreeWidgetItem* cur_item = item;
QString str_index;
while (cur_item)
{
QTreeWidgetItem* parentItem = cur_item->parent();
if (parentItem)
{
str_index.prepend(QString("%1.").arg(parentItem->indexOfChild(cur_item)));
}
else
{
str_index.prepend(QString("%1.").arg(treeWidget->indexOfTopLevelItem(cur_item)));
}
cur_item = parentItem;
}
// remove the last ".".
str_index.chop(1);
emit this->recordEvent( treeWidget, "setTreeItemCheckState",
QString("%1,%2,%3").arg(str_index).arg(column).arg(
static_cast<int>(item->checkState(column))));
}
/*=========================================================================
Program: ParaView
Module: pqTreeWidgetEventTranslator.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.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 __pqTreeWidgetEventTranslator_h
#define __pqTreeWidgetEventTranslator_h
#include "pqWidgetEventTranslator.h"
class QTreeWidgetItem;
/// Event recorder for QTreeWidget. Records the toggling of the check states for
/// tree widget items. The recorded state can be played back using
/// pqTreeWidgetEventPlayer.
class QTTESTING_EXPORT pqTreeWidgetEventTranslator : public pqWidgetEventTranslator
{
Q_OBJECT
typedef pqWidgetEventTranslator Superclass;
public:
pqTreeWidgetEventTranslator(QObject* parent=0);
~pqTreeWidgetEventTranslator();
/// Overridden to handle events on QColorDialog.
virtual bool translateEvent(QObject* Object, QEvent* Event, bool& Error);
private slots:
void onItemChanged(QTreeWidgetItem* item, int column);
private:
pqTreeWidgetEventTranslator(const pqTreeWidgetEventTranslator&); // Not implemented.
void operator=(const pqTreeWidgetEventTranslator&); // Not implemented.
};
#endif
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