Commit 5f933bee authored by Utkarsh Ayachit's avatar Utkarsh Ayachit
Browse files

ENH: Added support for recording change in the current item for the tree view.

parent 41310000
......@@ -149,6 +149,18 @@ bool pqTreeViewEventPlayer::playEvent(
pqEventDispatcher::processEventsAndWait(10);
return true;
}
else if (command == "setCurrent")
{
QString str_index = arguments;
QModelIndex index = ::pqTreeViewEventPlayerGetIndex(str_index, treeView, error);
if (error)
{
return true;
}
treeView->setCurrentIndex(index);
pqEventDispatcher::processEventsAndWait(10);
return true;
}
return false;
}
......
......@@ -69,7 +69,10 @@ bool pqTreeViewEventTranslator::translateEvent(
this, SLOT(onExpanded(const QModelIndex&)));
QObject::connect(treeWidget, SIGNAL(collapsed(const QModelIndex&)),
this, SLOT(onCollapsed(const QModelIndex&)));
QObject::connect(treeWidget->selectionModel(),
SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)),
this, SLOT(onCurrentChanged(const QModelIndex&)));
this->TreeView = treeWidget;
}
return true;
}
......@@ -79,17 +82,7 @@ void pqTreeViewEventTranslator::onItemChanged(
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);
QString str_index = this->getIndexAsString(index);
if ( (index.model()->flags(index) & Qt::ItemIsUserCheckable) != 0)
{
// record the check state change if the item is user-checkable.
......@@ -104,18 +97,9 @@ 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);
emit this->recordEvent( treeWidget, "expand",
this->getIndexAsString(index));
}
//-----------------------------------------------------------------------------
......@@ -123,6 +107,14 @@ void pqTreeViewEventTranslator::onCollapsed(const QModelIndex& index)
{
QTreeView* treeWidget = qobject_cast<QTreeView*>(this->sender());
// record the check state change if the item is user-checkable.
emit this->recordEvent( treeWidget, "collapse",
this->getIndexAsString(index));
}
//-----------------------------------------------------------------------------
QString pqTreeViewEventTranslator::getIndexAsString(const QModelIndex& index)
{
QModelIndex curIndex = index;
QString str_index;
while (curIndex.isValid())
......@@ -133,7 +125,17 @@ void pqTreeViewEventTranslator::onCollapsed(const QModelIndex& index)
// 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);
return str_index;
}
//-----------------------------------------------------------------------------
void pqTreeViewEventTranslator::onCurrentChanged(const QModelIndex& index)
{
QTreeView* treeWidget = this->TreeView;
if (treeWidget)
{
// record the check state change if the item is user-checkable.
emit this->recordEvent(treeWidget,
"setCurrent", this->getIndexAsString(index));
}
}
......@@ -33,8 +33,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define __pqTreeViewEventTranslator_h
#include "pqWidgetEventTranslator.h"
#include <QPointer>
class QModelIndex;
class QTreeView;
/// Event recorder for QTreeView. Records the toggling of the check states for
/// tree widget items. The recorded state can be played back using
......@@ -54,7 +56,12 @@ private slots:
void onItemChanged(const QModelIndex&);
void onExpanded(const QModelIndex&);
void onCollapsed(const QModelIndex&);
void onCurrentChanged(const QModelIndex&);
private:
QString getIndexAsString(const QModelIndex&);
QPointer<QTreeView> TreeView;
private:
pqTreeViewEventTranslator(const pqTreeViewEventTranslator&); // Not implemented.
void operator=(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