Commit 55a47952 authored by Benjamin Long's avatar Benjamin Long

Add events recorded to pqTreeViewEventTranaslator/Player

Added "click", "DoubleClick", and "edit" event

this functionality should maybe moved to paAbstractItemViewTranslator
parent cb5fc5cc
......@@ -114,6 +114,12 @@ bool pqAbstractItemViewEventPlayer::playEvent(QObject* Object, const QString& Co
{
return false;
}
if (Command == "key" || Command == "editCancel" || Command == "editAccepted")
{
// We let the pqBasicWidgetEventPlayer do it ...
return false;
}
if(Command == "currentChanged") // left to support old recordings
{
......
......@@ -32,6 +32,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "pqTreeViewEventPlayer.h"
#include "pqEventDispatcher.h"
#include <QCoreApplication>
#include <QEvent>
#include <QKeyEvent>
#include <QTreeWidget>
#include <QDebug>
......@@ -78,6 +81,11 @@ bool pqTreeViewEventPlayer::playEvent(
return false;
}
if (command == "key")
{
return false;
}
QRegExp regExp0("^([\\d\\.]+),(\\d+),(\\d+)$");
if (command == "setTreeItemCheckState" && regExp0.indexIn(arguments) != -1)
{
......@@ -136,6 +144,33 @@ bool pqTreeViewEventPlayer::playEvent(
}
return true;
}
else if(command == "edit")
{
QString str_index = arguments;
QModelIndex index = ::pqTreeViewEventPlayerGetIndex(str_index, treeView, error);
if (error)
{
return true;
}
treeView->edit(index);
return true;
}
else if (command == "editCancel")
{
QString str_index = arguments;
QModelIndex index = ::pqTreeViewEventPlayerGetIndex(str_index, treeView, error);
treeView->closePersistentEditor(index);
return true;
}
else if (command == "editAccepted")
{
QStringList list = arguments.split(',');
QModelIndex index = ::pqTreeViewEventPlayerGetIndex(list.at(0), treeView, error);
QVariant value = QVariant(list.at(1));
treeView->model()->setData(index, value);
treeView->closePersistentEditor(index);
return true;
}
else if (command == "expand" || command == "collapse")
{
QString str_index = arguments;
......@@ -147,7 +182,7 @@ bool pqTreeViewEventPlayer::playEvent(
treeView->setExpanded(index, (command=="expand"));
return true;
}
else if (command == "setCurrent")
else if (command == "setCurrent" || command == "activate")
{
QString str_index = arguments;
QModelIndex index = ::pqTreeViewEventPlayerGetIndex(str_index, treeView, error);
......@@ -156,6 +191,13 @@ bool pqTreeViewEventPlayer::playEvent(
return true;
}
treeView->setCurrentIndex(index);
if (command == "activate")
{
QKeyEvent kd(QEvent::KeyPress, Qt::Key_Enter, Qt::NoModifier);
QKeyEvent ku(QEvent::KeyRelease, Qt::Key_Enter, Qt::NoModifier);
QCoreApplication::sendEvent(treeView, &kd);
QCoreApplication::sendEvent(treeView, &ku);
}
return true;
}
return false;
......
......@@ -31,8 +31,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
========================================================================*/
#include "pqTreeViewEventTranslator.h"
#include <QTreeView>
#include <QDebug>
#include <QEvent>
#include <QKeyEvent>
#include <QTreeView>
#include <QVariant>
//-----------------------------------------------------------------------------
pqTreeViewEventTranslator::pqTreeViewEventTranslator(QObject* parentObject)
......@@ -60,6 +63,28 @@ bool pqTreeViewEventTranslator::translateEvent(
return false;
}
if (tr_event->type() == QEvent::KeyRelease)
{
QKeyEvent* ke = static_cast<QKeyEvent*>(tr_event);
QModelIndex index = treeWidget->currentIndex();
QString str_index = this->getIndexAsString(index);
if (ke->key() == Qt::Key_Enter || ke->key() == Qt::Key_Return)
{
QVariant value = treeWidget->model()->data(index);
qDebug() << value << str_index;
emit this->recordEvent(treeWidget, "editAccepted",
QString("%1,%2").arg(str_index, value.toString()));
}
if (ke->key() == Qt::Key_Escape)
{
emit this->recordEvent(treeWidget, "editCancel", str_index);
}
if (ke->key() == Qt::Key_F2)
{
emit this->recordEvent(treeWidget, "edit", str_index);
}
}
if (tr_event->type() == QEvent::FocusIn)
{
if(this->TreeView)
......@@ -67,9 +92,12 @@ bool pqTreeViewEventTranslator::translateEvent(
QObject::disconnect(this->TreeView, 0, this, 0);
QObject::disconnect(this->TreeView->selectionModel(), 0, this, 0);
}
QObject::connect(treeWidget, SIGNAL(clicked(const QModelIndex&)),
this, SLOT(onItemChanged(const QModelIndex&)));
this, SLOT(onClicked(const QModelIndex&)));
QObject::connect(treeWidget, SIGNAL(activated(const QModelIndex&)),
this, SLOT(onActivated(const QModelIndex&)));
QObject::connect(treeWidget, SIGNAL(doubleClicked(const QModelIndex&)),
this, SLOT(onDoubleClicked(const QModelIndex&)));
QObject::connect(treeWidget, SIGNAL(expanded(const QModelIndex&)),
this, SLOT(onExpanded(const QModelIndex&)));
QObject::connect(treeWidget, SIGNAL(collapsed(const QModelIndex&)),
......@@ -83,9 +111,10 @@ bool pqTreeViewEventTranslator::translateEvent(
}
//-----------------------------------------------------------------------------
void pqTreeViewEventTranslator::onItemChanged(
void pqTreeViewEventTranslator::onClicked(
const QModelIndex& index)
{
static QModelIndex oldIndex;
QTreeView* treeWidget = qobject_cast<QTreeView*>(this->sender());
QString str_index = this->getIndexAsString(index);
if ( (index.model()->flags(index) & Qt::ItemIsUserCheckable) != 0)
......@@ -95,6 +124,34 @@ void pqTreeViewEventTranslator::onItemChanged(
QString("%1,%3").arg(str_index).arg(
index.model()->data(index,Qt::CheckStateRole).toInt()));
}
if ((treeWidget->editTriggers() & QAbstractItemView::SelectedClicked)
== QAbstractItemView::SelectedClicked &&
index == oldIndex)
{
emit this->recordEvent(treeWidget, "edit", str_index);
}
oldIndex = index;
}
//-----------------------------------------------------------------------------
void pqTreeViewEventTranslator::onActivated(const QModelIndex & index)
{
QTreeView* treeWidget = qobject_cast<QTreeView*>(this->sender());
QString str_index = this->getIndexAsString(index);
emit this->recordEvent(treeWidget, "activate", str_index);
}
//-----------------------------------------------------------------------------
void pqTreeViewEventTranslator::onDoubleClicked(const QModelIndex& index)
{
QTreeView* treeWidget = qobject_cast<QTreeView*>(this->sender());
QString str_index = this->getIndexAsString(index);
// record the check state change if the item is user-checkable.
if ((treeWidget->editTriggers() & QAbstractItemView::DoubleClicked)
== QAbstractItemView::DoubleClicked)
{
emit this->recordEvent(treeWidget, "edit", str_index);
}
}
//-----------------------------------------------------------------------------
......
......@@ -53,7 +53,9 @@ public:
virtual bool translateEvent(QObject* Object, QEvent* Event, bool& Error);
private slots:
void onItemChanged(const QModelIndex&);
void onClicked(const QModelIndex&);
void onActivated(const QModelIndex&);
void onDoubleClicked(const QModelIndex&);
void onExpanded(const QModelIndex&);
void onCollapsed(const QModelIndex&);
void onCurrentChanged(const QModelIndex&);
......
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