Commit 36eb8696 authored by Utkarsh Ayachit's avatar Utkarsh Ayachit

ENH: Renaming pqTreeWidgetEventPlayer to pqTreeViewEventPlayer and

pqTreeWidgetEventTranslator to pqTreeViewEventTranslator and making them handle
QTreeView as well (not just QTreeWidget). Then fixed ExodusXML which had
recordede the tree view click to ensure that the test works correctly with Qt
4.5.
parent 714b4b1a
......@@ -62,8 +62,8 @@ QT4_WRAP_CPP(MOC_BUILT_SOURCES
pqTestUtility.h
pqThreadedEventSource.h
pqTabBarEventTranslator.h
pqTreeWidgetEventTranslator.h
pqTreeWidgetEventPlayer.h
pqTreeViewEventTranslator.h
pqTreeViewEventPlayer.h
pqWidgetEventTranslator.h
${PYTHON_MOCS}
)
......@@ -133,10 +133,10 @@ ADD_LIBRARY(QtTesting
pqTestUtility.h
pqThreadedEventSource.cxx
pqThreadedEventSource.h
pqTreeWidgetEventTranslator.cxx
pqTreeWidgetEventTranslator.h
pqTreeWidgetEventPlayer.cxx
pqTreeWidgetEventPlayer.h
pqTreeViewEventTranslator.cxx
pqTreeViewEventTranslator.h
pqTreeViewEventPlayer.cxx
pqTreeViewEventPlayer.h
pqWidgetEventPlayer.cxx
pqWidgetEventPlayer.h
pqWidgetEventTranslator.h
......
......@@ -42,7 +42,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "pqBasicWidgetEventPlayer.h"
#include "pqObjectNaming.h"
#include "pqTabBarEventPlayer.h"
#include "pqTreeWidgetEventPlayer.h"
#include "pqTreeViewEventPlayer.h"
#include <QApplication>
#include <QWidget>
......@@ -66,7 +66,7 @@ void pqEventPlayer::addDefaultWidgetEventPlayers()
addWidgetEventPlayer(new pqAbstractItemViewEventPlayer());
addWidgetEventPlayer(new pqAbstractStringEventPlayer());
addWidgetEventPlayer(new pqTabBarEventPlayer());
addWidgetEventPlayer(new pqTreeWidgetEventPlayer());
addWidgetEventPlayer(new pqTreeViewEventPlayer());
addWidgetEventPlayer(new pqAbstractMiscellaneousEventPlayer());
}
......
......@@ -43,7 +43,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "pqObjectNaming.h"
#include "pqSpinBoxEventTranslator.h"
#include "pqTabBarEventTranslator.h"
#include "pqTreeWidgetEventTranslator.h"
#include "pqTreeViewEventTranslator.h"
#include <QCoreApplication>
#include <QtDebug>
......@@ -106,7 +106,7 @@ void pqEventTranslator::addDefaultWidgetEventTranslators()
addWidgetEventTranslator(new pqMenuEventTranslator());
addWidgetEventTranslator(new pqSpinBoxEventTranslator());
addWidgetEventTranslator(new pqTabBarEventTranslator());
addWidgetEventTranslator(new pqTreeWidgetEventTranslator());
addWidgetEventTranslator(new pqTreeViewEventTranslator());
}
void pqEventTranslator::addWidgetEventTranslator(pqWidgetEventTranslator* Translator)
......
/*=========================================================================
Program: ParaView
Module: pqTreeWidgetEventPlayer.cxx
Module: pqTreeViewEventPlayer.cxx
Copyright (c) 2005,2006 Sandia Corporation, Kitware Inc.
All rights reserved.
......@@ -29,40 +29,46 @@ 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 "pqTreeViewEventPlayer.h"
#include <QTreeWidget>
#include <QDebug>
//-----------------------------------------------------------------------------
pqTreeWidgetEventPlayer::pqTreeWidgetEventPlayer(QObject* parentObject)
pqTreeViewEventPlayer::pqTreeViewEventPlayer(QObject* parentObject)
: Superclass(parentObject)
{
}
//-----------------------------------------------------------------------------
pqTreeWidgetEventPlayer::~pqTreeWidgetEventPlayer()
pqTreeViewEventPlayer::~pqTreeViewEventPlayer()
{
}
//-----------------------------------------------------------------------------
bool pqTreeWidgetEventPlayer::playEvent(
bool pqTreeViewEventPlayer::playEvent(
QObject* object, const QString& command,
const QString& arguments, bool& error)
{
QTreeWidget* treeWidget = qobject_cast<QTreeWidget*>(object);
if (!treeWidget)
QTreeView* treeView= qobject_cast<QTreeView*>(object);
if (!treeView)
{
return false;
}
QRegExp regExp("^([\\d\\.]+),(\\d+),(\\d+)$");
if (command == "setTreeItemCheckState" && regExp.indexIn(arguments) != -1)
QRegExp regExp0("^([\\d\\.]+),(\\d+),(\\d+)$");
if (command == "setTreeItemCheckState" && regExp0.indexIn(arguments) != -1)
{
QString str_index = regExp.cap(1);
int column = regExp.cap(2).toInt();
int check_state = regExp.cap(3).toInt();
// legacy command recorded from tree widgets.
QTreeWidget* treeWidget = qobject_cast<QTreeWidget*>(object);
if (!treeWidget)
{
return false;
}
QString str_index = regExp0.cap(1);
int column = regExp0.cap(2).toInt();
int check_state = regExp0.cap(3).toInt();
QStringList indices = str_index.split(".",QString::SkipEmptyParts);
QTreeWidgetItem* cur_item = NULL;
......@@ -88,6 +94,32 @@ bool pqTreeWidgetEventPlayer::playEvent(
cur_item->setCheckState(column, static_cast<Qt::CheckState>(check_state));
return true;
}
QRegExp regExp1("^([\\d\\.]+),(\\d+)$");
if (command == "setCheckState" && regExp1.indexIn(arguments) != -1)
{
QString str_index = regExp1.cap(1);
int check_state = regExp1.cap(2).toInt();
QStringList indices = str_index.split(".",QString::SkipEmptyParts);
QModelIndex index;
for (int cc=0; (cc+1) < indices.size(); cc+=2)
{
index = treeView->model()->index(indices[cc].toInt(), indices[cc+1].toInt(),
index);
if (!index.isValid())
{
error=true;
qCritical() << "ERROR: Tree view must have changed. "
<< "Indices recorded in the test are no longer valid. Cannot playback.";
return true;
}
}
treeView->model()->setData(index,
static_cast<Qt::CheckState>(check_state),
Qt::CheckStateRole);
return true;
}
return false;
}
......
/*=========================================================================
Program: ParaView
Module: pqTreeWidgetEventPlayer.h
Module: pqTreeViewEventPlayer.h
Copyright (c) 2005,2006 Sandia Corporation, Kitware Inc.
All rights reserved.
......@@ -29,27 +29,27 @@ 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
#ifndef __pqTreeViewEventPlayer_h
#define __pqTreeViewEventPlayer_h
#include "pqWidgetEventPlayer.h"
/// pqTreeWidgetEventPlayer is a player for QTreeWidget. Plays back the state
/// recorded using pqTreeWidgetEventTranslator.
class QTTESTING_EXPORT pqTreeWidgetEventPlayer : public pqWidgetEventPlayer
/// pqTreeViewEventPlayer is a player for QTreeWidget. Plays back the state
/// recorded using pqTreeViewEventTranslator.
class QTTESTING_EXPORT pqTreeViewEventPlayer : public pqWidgetEventPlayer
{
Q_OBJECT
typedef pqWidgetEventPlayer Superclass;
public:
pqTreeWidgetEventPlayer(QObject* parent=0);
~pqTreeWidgetEventPlayer();
pqTreeViewEventPlayer(QObject* parent=0);
~pqTreeViewEventPlayer();
bool playEvent(QObject* object, const QString& command, const QString&
arguments, bool& error);
private:
pqTreeWidgetEventPlayer(const pqTreeWidgetEventPlayer&); // Not implemented.
void operator=(const pqTreeWidgetEventPlayer&); // Not implemented.
pqTreeViewEventPlayer(const pqTreeViewEventPlayer&); // Not implemented.
void operator=(const pqTreeViewEventPlayer&); // Not implemented.
};
#endif
......
/*=========================================================================
Program: ParaView
Module: pqTreeWidgetEventTranslator.cxx
Module: pqTreeViewEventTranslator.cxx
Copyright (c) 2005,2006 Sandia Corporation, Kitware Inc.
All rights reserved.
......@@ -29,31 +29,31 @@ 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 "pqTreeViewEventTranslator.h"
#include <QTreeWidget>
#include <QTreeView>
#include <QEvent>
//-----------------------------------------------------------------------------
pqTreeWidgetEventTranslator::pqTreeWidgetEventTranslator(QObject* parentObject)
pqTreeViewEventTranslator::pqTreeViewEventTranslator(QObject* parentObject)
: Superclass(parentObject)
{
}
//-----------------------------------------------------------------------------
pqTreeWidgetEventTranslator::~pqTreeWidgetEventTranslator()
pqTreeViewEventTranslator::~pqTreeViewEventTranslator()
{
}
//-----------------------------------------------------------------------------
bool pqTreeWidgetEventTranslator::translateEvent(
bool pqTreeViewEventTranslator::translateEvent(
QObject* object, QEvent* tr_event, bool& /*error*/)
{
QTreeWidget* treeWidget = qobject_cast<QTreeWidget*>(object);
QTreeView* treeWidget = qobject_cast<QTreeView*>(object);
if(!treeWidget)
{
// mouse events go to the viewport widget
treeWidget = qobject_cast<QTreeWidget*>(object->parent());
treeWidget = qobject_cast<QTreeView*>(object->parent());
}
if(!treeWidget)
{
......@@ -63,38 +63,33 @@ bool pqTreeWidgetEventTranslator::translateEvent(
if (tr_event->type() == QEvent::FocusIn)
{
QObject::disconnect(treeWidget, 0, this, 0);
QObject::connect(treeWidget, SIGNAL(itemClicked(QTreeWidgetItem*, int)),
this, SLOT(onItemChanged(QTreeWidgetItem*, int)));
QObject::connect(treeWidget, SIGNAL(clicked(const QModelIndex&)),
this, SLOT(onItemChanged(const QModelIndex&)));
}
return true;
}
//-----------------------------------------------------------------------------
void pqTreeWidgetEventTranslator::onItemChanged(
QTreeWidgetItem* item, int column)
void pqTreeViewEventTranslator::onItemChanged(
const QModelIndex& index)
{
QTreeWidget* treeWidget = item->treeWidget();
QTreeView* treeWidget = qobject_cast<QTreeView*>(this->sender());
QTreeWidgetItem* cur_item = item;
QModelIndex curIndex = index;
QString str_index;
while (cur_item)
while (curIndex.isValid())
{
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;
str_index.prepend(QString("%1.%2.").arg(curIndex.row()).arg(curIndex.column()));
curIndex = curIndex.parent();
}
// 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))));
if ( (index.model()->flags(index) & Qt::ItemIsUserCheckable) != 0)
{
// record the check state change if the item is user-checkable.
emit this->recordEvent( treeWidget, "setCheckState",
QString("%1,%3").arg(str_index).arg(
index.model()->data(index,Qt::CheckStateRole).toInt()));
}
}
/*=========================================================================
Program: ParaView
Module: pqTreeWidgetEventTranslator.h
Module: pqTreeViewEventTranslator.h
Copyright (c) 2005,2006 Sandia Corporation, Kitware Inc.
All rights reserved.
......@@ -29,33 +29,33 @@ 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
#ifndef __pqTreeViewEventTranslator_h
#define __pqTreeViewEventTranslator_h
#include "pqWidgetEventTranslator.h"
class QTreeWidgetItem;
class QModelIndex;
/// Event recorder for QTreeWidget. Records the toggling of the check states for
/// Event recorder for QTreeView. 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
/// pqTreeViewEventPlayer.
class QTTESTING_EXPORT pqTreeViewEventTranslator : public pqWidgetEventTranslator
{
Q_OBJECT
typedef pqWidgetEventTranslator Superclass;
public:
pqTreeWidgetEventTranslator(QObject* parent=0);
~pqTreeWidgetEventTranslator();
pqTreeViewEventTranslator(QObject* parent=0);
~pqTreeViewEventTranslator();
/// Overridden to handle events on QColorDialog.
virtual bool translateEvent(QObject* Object, QEvent* Event, bool& Error);
private slots:
void onItemChanged(QTreeWidgetItem* item, int column);
void onItemChanged(const QModelIndex&);
private:
pqTreeWidgetEventTranslator(const pqTreeWidgetEventTranslator&); // Not implemented.
void operator=(const pqTreeWidgetEventTranslator&); // Not implemented.
pqTreeViewEventTranslator(const pqTreeViewEventTranslator&); // Not implemented.
void operator=(const pqTreeViewEventTranslator&); // 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