Commit 6ece0440 authored by Timothy M. Shead's avatar Timothy M. Shead

ENH: pqEventTranslator can ignore events from specific objects, so...

ENH: pqEventTranslator can ignore events from specific objects, so test-recording-related UI events aren't captured as part of the recording
parent 47855504
......@@ -20,8 +20,31 @@
#include <QCoreApplication>
#include <QtDebug>
#include <QSet>
#include <QVector>
pqEventTranslator::pqEventTranslator()
////////////////////////////////////////////////////////////////////////////////
// pqEventTranslator::pqImplementation
struct pqEventTranslator::pqImplementation
{
~pqImplementation()
{
for(int i = 0; i != this->Translators.size(); ++i)
delete this->Translators[i];
}
/// Stores the working set of widget translators
QVector<pqWidgetEventTranslator*> Translators;
/// Stores the set of objects that should be ignored when translating events
QSet<QObject*> IgnoredObjects;
};
////////////////////////////////////////////////////////////////////////////////
// pqEventTranslator
pqEventTranslator::pqEventTranslator() :
Implementation(new pqImplementation())
{
QCoreApplication::instance()->installEventFilter(this);
}
......@@ -30,8 +53,7 @@ pqEventTranslator::~pqEventTranslator()
{
QCoreApplication::instance()->removeEventFilter(this);
for(int i = 0; i != this->Translators.size(); ++i)
delete this->Translators[i];
delete Implementation;
}
void pqEventTranslator::addDefaultWidgetEventTranslators()
......@@ -50,7 +72,7 @@ void pqEventTranslator::addWidgetEventTranslator(pqWidgetEventTranslator* Transl
{
if(Translator)
{
this->Translators.push_back(Translator);
this->Implementation->Translators.push_back(Translator);
QObject::connect(
Translator,
......@@ -60,11 +82,16 @@ void pqEventTranslator::addWidgetEventTranslator(pqWidgetEventTranslator* Transl
}
}
void pqEventTranslator::ignoreObject(QObject* Object)
{
this->Implementation->IgnoredObjects.insert(Object);
}
bool pqEventTranslator::eventFilter(QObject* Object, QEvent* Event)
{
for(int i = 0; i != this->Translators.size(); ++i)
for(int i = 0; i != this->Implementation->Translators.size(); ++i)
{
if(this->Translators[i]->translateEvent(Object, Event))
if(this->Implementation->Translators[i]->translateEvent(Object, Event))
return false;
}
......@@ -73,6 +100,9 @@ bool pqEventTranslator::eventFilter(QObject* Object, QEvent* Event)
void pqEventTranslator::onRecordEvent(QObject* Object, const QString& Command, const QString& Arguments)
{
if(this->Implementation->IgnoredObjects.contains(Object))
return;
QString name = Object->objectName();
if(name.isEmpty())
{
......
......@@ -11,7 +11,6 @@
#define _pqEventTranslator_h
#include <QObject>
#include <QVector>
class pqWidgetEventTranslator;
......@@ -30,21 +29,24 @@ public:
/// Adds a new translator to the current working set of widget translators. pqEventTranslator assumes control of the lifetime of the supplied object.
void addWidgetEventTranslator(pqWidgetEventTranslator*);
/// Adds an object to a list of objects that should be ignored when translating events (useful to prevent recording UI events from being captured as part of the recording)
void ignoreObject(QObject* Object);
signals:
/// This signal will be emitted every time a translator generates a high-level ParaQ event. Observers should connect to this signal to serialize high-level events.
void recordEvent(const QString& Object, const QString& Command, const QString& Arguments);
private slots:
void onRecordEvent(QObject* Object, const QString& Command, const QString& Arguments);
private:
pqEventTranslator(const pqEventTranslator&);
pqEventTranslator& operator=(const pqEventTranslator&);
bool eventFilter(QObject* Object, QEvent* Event);
/// Stores the working set of widget translators
QVector<pqWidgetEventTranslator*> Translators;
private slots:
void onRecordEvent(QObject* Object, const QString& Command, const QString& Arguments);
struct pqImplementation;
pqImplementation* const Implementation;
};
#endif // !_pqEventTranslator_h
......
......@@ -7,44 +7,53 @@
* statement of authorship are reproduced on all copies.
*/
#include "pqRecordEventsDialog.h"
#include "pqEventObserverXML.h"
#include "pqEventTranslator.h"
#include "pqRecordEventsDialog.h"
#include "ui_pqRecordEventsDialog.h"
#include <QPushButton>
#include <QTimer>
#include <vtkIOStream.h>
class pqRecordEventsDialog::pqImplementation
//////////////////////////////////////////////////////////////////////////////////
// pqImplementation
struct pqRecordEventsDialog::pqImplementation
{
public:
pqImplementation(const QString& Path) :
file(Path.toAscii().data()),
observer(file)
File(Path.toAscii().data()),
Observer(File)
{
translator.addDefaultWidgetEventTranslators();
QObject::connect(
&translator,
SIGNAL(recordEvent(const QString&, const QString&, const QString&)),
&observer,
SLOT(onRecordEvent(const QString&, const QString&, const QString&)));
}
private:
ofstream file;
pqEventTranslator translator;
pqEventObserverXML observer;
Ui::pqRecordEventsDialog Ui;
ofstream File;
pqEventTranslator Translator;
pqEventObserverXML Observer;
};
///////////////////////////////////////////////////////////////////////////////////
// pqRecordEventsDialog
pqRecordEventsDialog::pqRecordEventsDialog(const QString& Path, QWidget* Parent) :
QDialog(Parent),
Implementation(new pqImplementation(Path))
{
this->Ui.setupUi(this);
this->Ui.label->setText(QString(tr("Recording User Input to %1")).arg(Path));
this->Implementation->Ui.setupUi(this);
this->Implementation->Ui.label->setText(QString(tr("Recording User Input to %1")).arg(Path));
this->Implementation->Translator.ignoreObject(this->Implementation->Ui.stopButton);
this->Implementation->Translator.addDefaultWidgetEventTranslators();
QObject::connect(
&this->Implementation->Translator,
SIGNAL(recordEvent(const QString&, const QString&, const QString&)),
&this->Implementation->Observer,
SLOT(onRecordEvent(const QString&, const QString&, const QString&)));
this->setWindowTitle(tr("Recording User Input"));
this->setObjectName("");
......
......@@ -10,7 +10,7 @@
#ifndef _pqRecordEventsDialog_h
#define _pqRecordEventsDialog_h
#include "ui_pqRecordEventsDialog.h"
#include <QDialog>
class pqRecordEventsDialog :
public QDialog
......@@ -20,20 +20,18 @@ class pqRecordEventsDialog :
public:
pqRecordEventsDialog(const QString& Path, QWidget* Parent);
private slots:
void accept();
void reject();
void onAutoDelete();
private:
pqRecordEventsDialog(const pqRecordEventsDialog&);
pqRecordEventsDialog& operator=(const pqRecordEventsDialog&);
~pqRecordEventsDialog();
class pqImplementation;
struct pqImplementation;
pqImplementation* const Implementation;
Ui::pqRecordEventsDialog Ui;
private slots:
void accept();
void reject();
void onAutoDelete();
};
#endif // !_pqRecordEventsDialog_h
......
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