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()
{
}
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(
QObject* object, const QString& command,
......@@ -102,26 +122,29 @@ bool pqTreeViewEventPlayer::playEvent(
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)
QModelIndex index = ::pqTreeViewEventPlayerGetIndex(str_index, treeView, error);
if (error)
{
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);
pqEventDispatcher::processEventsAndWait(10);
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;
}
......
......@@ -65,6 +65,11 @@ bool pqTreeViewEventTranslator::translateEvent(
QObject::disconnect(treeWidget, 0, this, 0);
QObject::connect(treeWidget, SIGNAL(clicked(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;
}
......@@ -93,3 +98,42 @@ void pqTreeViewEventTranslator::onItemChanged(
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:
private slots:
void onItemChanged(const QModelIndex&);
void onExpanded(const QModelIndex&);
void onCollapsed(const QModelIndex&);
private:
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