Commit 8e48b954 authored by Utkarsh Ayachit's avatar Utkarsh Ayachit
Browse files

ENH: Added support to record tree view expansion/collapsing.

parent a70e9621
...@@ -46,6 +46,26 @@ pqTreeViewEventPlayer::~pqTreeViewEventPlayer() ...@@ -46,6 +46,26 @@ pqTreeViewEventPlayer::~pqTreeViewEventPlayer()
{ {
} }
QModelIndex pqTreeViewEventPlayerGetIndex(const QString& str_index,
QTreeView* treeView, bool &error)
{
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.";
break;
}
}
return index;
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
bool pqTreeViewEventPlayer::playEvent( bool pqTreeViewEventPlayer::playEvent(
QObject* object, const QString& command, QObject* object, const QString& command,
...@@ -102,19 +122,10 @@ bool pqTreeViewEventPlayer::playEvent( ...@@ -102,19 +122,10 @@ bool pqTreeViewEventPlayer::playEvent(
QString str_index = regExp1.cap(1); QString str_index = regExp1.cap(1);
int check_state = regExp1.cap(2).toInt(); int check_state = regExp1.cap(2).toInt();
QStringList indices = str_index.split(".",QString::SkipEmptyParts); QModelIndex index = ::pqTreeViewEventPlayerGetIndex(str_index, treeView, error);
QModelIndex index; if (error)
for (int cc=0; (cc+1) < indices.size(); cc+=2)
{ {
index = treeView->model()->index(indices[cc].toInt(), indices[cc+1].toInt(), return true;
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, treeView->model()->setData(index,
static_cast<Qt::CheckState>(check_state), static_cast<Qt::CheckState>(check_state),
...@@ -122,6 +133,18 @@ bool pqTreeViewEventPlayer::playEvent( ...@@ -122,6 +133,18 @@ bool pqTreeViewEventPlayer::playEvent(
pqEventDispatcher::processEventsAndWait(10); pqEventDispatcher::processEventsAndWait(10);
return true; return true;
} }
else if (command == "expand" || command == "collapse")
{
QString str_index = arguments;
QModelIndex index = ::pqTreeViewEventPlayerGetIndex(str_index, treeView, error);
if (error)
{
return true;
}
treeView->setExpanded(index, (command=="expand"));
pqEventDispatcher::processEventsAndWait(10);
return true;
}
return false; return false;
} }
......
...@@ -65,6 +65,11 @@ bool pqTreeViewEventTranslator::translateEvent( ...@@ -65,6 +65,11 @@ bool pqTreeViewEventTranslator::translateEvent(
QObject::disconnect(treeWidget, 0, this, 0); QObject::disconnect(treeWidget, 0, this, 0);
QObject::connect(treeWidget, SIGNAL(clicked(const QModelIndex&)), QObject::connect(treeWidget, SIGNAL(clicked(const QModelIndex&)),
this, SLOT(onItemChanged(const QModelIndex&))); this, SLOT(onItemChanged(const QModelIndex&)));
QObject::connect(treeWidget, SIGNAL(expanded(const QModelIndex&)),
this, SLOT(onExpanded(const QModelIndex&)));
QObject::connect(treeWidget, SIGNAL(collapsed(const QModelIndex&)),
this, SLOT(onCollapsed(const QModelIndex&)));
} }
return true; return true;
} }
...@@ -93,3 +98,42 @@ void pqTreeViewEventTranslator::onItemChanged( ...@@ -93,3 +98,42 @@ void pqTreeViewEventTranslator::onItemChanged(
index.model()->data(index,Qt::CheckStateRole).toInt())); index.model()->data(index,Qt::CheckStateRole).toInt()));
} }
} }
//-----------------------------------------------------------------------------
void pqTreeViewEventTranslator::onExpanded(const QModelIndex& index)
{
QTreeView* treeWidget = qobject_cast<QTreeView*>(this->sender());
QModelIndex curIndex = index;
QString str_index;
while (curIndex.isValid())
{
str_index.prepend(QString("%1.%2.").arg(curIndex.row()).arg(curIndex.column()));
curIndex = curIndex.parent();
}
// remove the last ".".
str_index.chop(1);
// record the check state change if the item is user-checkable.
emit this->recordEvent( treeWidget, "expand", str_index);
}
//-----------------------------------------------------------------------------
void pqTreeViewEventTranslator::onCollapsed(const QModelIndex& index)
{
QTreeView* treeWidget = qobject_cast<QTreeView*>(this->sender());
QModelIndex curIndex = index;
QString str_index;
while (curIndex.isValid())
{
str_index.prepend(QString("%1.%2.").arg(curIndex.row()).arg(curIndex.column()));
curIndex = curIndex.parent();
}
// remove the last ".".
str_index.chop(1);
// record the check state change if the item is user-checkable.
emit this->recordEvent( treeWidget, "collapse", str_index);
}
...@@ -52,6 +52,8 @@ public: ...@@ -52,6 +52,8 @@ public:
private slots: private slots:
void onItemChanged(const QModelIndex&); void onItemChanged(const QModelIndex&);
void onExpanded(const QModelIndex&);
void onCollapsed(const QModelIndex&);
private: private:
pqTreeViewEventTranslator(const pqTreeViewEventTranslator&); // Not implemented. pqTreeViewEventTranslator(const pqTreeViewEventTranslator&); // Not implemented.
......
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