Commit 5b453ceb authored by Benjamin Long's avatar Benjamin Long

ENH: Added feature to be able to add custom comment during the record

See pqEventComment if you want to add more custom comment.
Already added :
  - simple comment
  - comment which block the play back

pqCommentEventPlayer is in charge to play back those events.
parent eb6b77c6
......@@ -99,6 +99,7 @@ QT4_WRAP_CPP(MOC_BUILT_SOURCES
pqComboBoxEventTranslator.h
pqCommentEventPlayer.h
pqDoubleSpinBoxEventTranslator.h
pqEventComment.h
pqEventDispatcher.h
pqEventObserver.h
pqEventPlayer.h
......@@ -154,6 +155,7 @@ SET(QtTesting_SOURCES
pqComboBoxEventTranslator.cxx
pqCommentEventPlayer.cxx
pqDoubleSpinBoxEventTranslator.cxx
pqEventComment.cxx
pqEventDispatcher.cxx
pqEventObserver.cxx
pqEventPlayer.cxx
......@@ -196,6 +198,7 @@ SET(QtTesting_DEVEL_HEADERS
pqComboBoxEventTranslator.h
pqCommentEventPlayer.h
pqDoubleSpinBoxEventTranslator.h
pqEventComment.h
pqEventDispatcher.h
pqEventObserver.h
pqEventPlayer.h
......
......@@ -33,28 +33,17 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "pqCommentEventPlayer.h"
// ----------------------------------------------------------------------------
pqCommentEventPlayer::pqCommentEventPlayer(QObject* parent)
pqCommentEventPlayer::pqCommentEventPlayer(pqTestUtility* testUtility,
QObject* parent)
: pqWidgetEventPlayer(parent)
{
this->CommentEnabled = false;
this->TestUtility = testUtility;
}
// ----------------------------------------------------------------------------
pqCommentEventPlayer::~pqCommentEventPlayer()
{
}
// ----------------------------------------------------------------------------
void pqCommentEventPlayer::setCommentEnabled(bool value)
{
this->CommentEnabled = value;
}
// ----------------------------------------------------------------------------
bool pqCommentEventPlayer::isCommentEnabled() const
{
return this->CommentEnabled;
this->TestUtility = 0;
}
// ----------------------------------------------------------------------------
......@@ -63,18 +52,20 @@ bool pqCommentEventPlayer::playEvent(QObject* Object,
const QString &Arguments,
bool &Error)
{
if (Command != "comment")
if (!Command.startsWith("comment"))
{
return false;
}
if (!this->CommentEnabled)
if (!Arguments.isEmpty())
{
emit this->comment(Arguments);
}
if (Command.split("-").contains("block"))
{
// We don't want to emit the comment but, we need to return true, to avoid
// an error.
return true;
this->TestUtility->dispatcher()->run(false);
}
emit this->comment(Arguments);
return true;
}
......@@ -34,6 +34,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define __pqCommentEventPlayer_h
// QtTesting includes
#include "pqTestUtility.h"
#include "pqWidgetEventPlayer.h"
/// This class is a comment class.
......@@ -45,14 +46,11 @@ class pqCommentEventPlayer : public pqWidgetEventPlayer
Q_OBJECT
public:
pqCommentEventPlayer(QObject* p =0);
pqCommentEventPlayer(pqTestUtility* testUtility, QObject* p =0);
~pqCommentEventPlayer();
bool playEvent(QObject* Object, const QString &Command, const QString &Arguments, bool &Error);
void setCommentEnabled(bool value);
bool isCommentEnabled() const;
signals:
void comment(const QString&);
......@@ -60,7 +58,7 @@ private:
pqCommentEventPlayer(const pqCommentEventPlayer&); // Not implemented
pqCommentEventPlayer& operator=(const pqCommentEventPlayer&); // Not implemented
bool CommentEnabled;
pqTestUtility* TestUtility;
};
#endif // __pqCommentEventPlayer_h
/*=========================================================================
Program: ParaView
Module: pqEventComment.cxx
Copyright (c) 2005-2008 Sandia Corporation, Kitware Inc.
All rights reserved.
ParaView is a free software; you can redistribute it and/or modify it
under the terms of the ParaView license version 1.2.
See License_v1.2.txt for the full ParaView license.
A copy of this license can be obtained by contacting
Kitware Inc.
28 Corporate Drive
Clifton Park, NY 12065
USA
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=========================================================================*/
// Qt includes
#include <QDebug>
// QtTesting includes
#include "pqEventComment.h"
// ----------------------------------------------------------------------------
pqEventComment::pqEventComment(pqTestUtility* util,
QObject* parent)
: Superclass(parent)
{
this->TestUtility = util;
}
// ----------------------------------------------------------------------------
pqEventComment::~pqEventComment()
{
this->TestUtility = 0;
}
// ----------------------------------------------------------------------------
void pqEventComment::recordComment(const QString& arguments)
{
this->recordComment(QString("comment"), arguments);
}
// ----------------------------------------------------------------------------
void pqEventComment::recordCommentBlock(const QString& arguments)
{
this->recordComment(QString("comment-block"), arguments);
}
// ----------------------------------------------------------------------------
void pqEventComment::recordComment(const QString& command,
const QString& arguments,
QObject* object)
{
if (arguments.isEmpty())
{
qCritical() << "The comment is empty ! No comment has been added !";
return;
}
emit this->recordComment(object, command, arguments);
}
/*=========================================================================
Program: ParaView
Module: pqEventComment.h
Copyright (c) 2005-2008 Sandia Corporation, Kitware Inc.
All rights reserved.
ParaView is a free software; you can redistribute it and/or modify it
under the terms of the ParaView license version 1.2.
See License_v1.2.txt for the full ParaView license.
A copy of this license can be obtained by contacting
Kitware Inc.
28 Corporate Drive
Clifton Park, NY 12065
USA
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=========================================================================*/
#ifndef __pqEventComment_h
#define __pqEventComment_h
// Qt includes
#include <QObject>
// QtTesting inlcudes
#include "pqTestUtility.h"
#include "QtTestingExport.h"
/// pqEventComment is responsible for adding any kind of events that are not added
/// by widgets.
/// For exemple, you can add an event to block the playback, to show a custom
/// comment etc ...
class QTTESTING_EXPORT pqEventComment :
public QObject
{
Q_OBJECT
typedef QObject Superclass;
public:
pqEventComment(pqTestUtility* util, QObject* parent = 0);
~pqEventComment();
/// Call this function to add an event comment, which will display a message,
/// during the playback in the log.
void recordComment(const QString& arguments);
/// Call this function to add an event comment, which will display a message,
/// and then pause the macro during the playback.
void recordCommentBlock(const QString& arguments);
signals:
/// All functions should emit this signal whenever they wish to record comment event
void recordComment(QObject* widget, const QString& type, const QString& argument);
protected:
void recordComment(const QString& command,
const QString& arguments,
QObject* = 0);
pqTestUtility* TestUtility;
};
#endif
......@@ -64,7 +64,7 @@ pqEventPlayer::~pqEventPlayer()
// ----------------------------------------------------------------------------
void pqEventPlayer::addDefaultWidgetEventPlayers(pqTestUtility* util)
{
addWidgetEventPlayer(new pqCommentEventPlayer());
addWidgetEventPlayer(new pqCommentEventPlayer(util));
addWidgetEventPlayer(new pqBasicWidgetEventPlayer());
addWidgetEventPlayer(new pqAbstractActivateEventPlayer());
addWidgetEventPlayer(new pqAbstractBooleanEventPlayer());
......@@ -151,6 +151,7 @@ void pqEventPlayer::playEvent(const QString& Object,
// If we can't find an object with the right name, we're done ...
QObject* const object = pqObjectNaming::GetObject(Object);
// Scroll bar depends on monitor's resolution
if(!object && Object.contains(QString("QScrollBar")))
{
emit this->eventPlayed(Object, Command, Arguments);
......@@ -158,7 +159,7 @@ void pqEventPlayer::playEvent(const QString& Object,
return;
}
if(!object && Command != "comment")
if(!object && !Command.startsWith("comment"))
{
qCritical() << pqObjectNaming::lastErrorMessage();
emit this->errorMessage(pqObjectNaming::lastErrorMessage());
......@@ -169,12 +170,26 @@ void pqEventPlayer::playEvent(const QString& Object,
// Loop through players until the event gets handled ...
bool accepted = false;
bool error = false;
for(int i = 0; i != this->Players.size(); ++i)
if (Command.startsWith("comment"))
{
accepted = this->Players[i]->playEvent(object, Command, Arguments, error);
if(accepted)
pqWidgetEventPlayer* widgetPlayer =
this->getWidgetEventPlayer(QString("pqCommentEventPlayer"));
pqCommentEventPlayer* commentPlayer =
qobject_cast<pqCommentEventPlayer*>(widgetPlayer);
if (commentPlayer)
{
break;
accepted = commentPlayer->playEvent(object, Command, Arguments, error);
}
}
else
{
for(int i = 0; i != this->Players.size(); ++i)
{
accepted = this->Players[i]->playEvent(object, Command, Arguments, error);
if(accepted)
{
break;
}
}
}
......@@ -183,7 +198,7 @@ void pqEventPlayer::playEvent(const QString& Object,
{
QString messageError =
QString("Unhandled event %1 object %2\n")
.arg(Command, object->objectName());
.arg(Command, object ? object->objectName() : Object);
qCritical() << messageError;
emit this->errorMessage(messageError);
Error = true;
......@@ -195,7 +210,7 @@ void pqEventPlayer::playEvent(const QString& Object,
{
QString messageError =
QString("Event error %1 object %2\n")
.arg(Command, object->objectName());
.arg(Command, object ? object->objectName() : Object);
qCritical() << messageError;
emit this->errorMessage(messageError);
Error = true;
......
......@@ -38,6 +38,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "pqBasicWidgetEventTranslator.h"
#include "pqComboBoxEventTranslator.h"
#include "pqDoubleSpinBoxEventTranslator.h"
#include "pqEventComment.h"
#include "pqLineEditEventTranslator.h"
#include "pqMenuEventTranslator.h"
#include "pqObjectNaming.h"
......@@ -57,10 +58,20 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
struct pqEventTranslator::pqImplementation
{
pqImplementation()
{
this->EventComment = 0;
}
~pqImplementation()
{
if(this->EventComment)
{
delete this->EventComment;
}
}
pqEventComment* EventComment;
/// Stores the working set of widget translators
QList<pqWidgetEventTranslator*> Translators;
/// Stores the set of objects that should be ignored when translating events
......@@ -98,8 +109,8 @@ void pqEventTranslator::start()
// ----------------------------------------------------------------------------
void pqEventTranslator::stop()
{
emit this->stopped();
QCoreApplication::instance()->removeEventFilter(this);
emit this->stopped();
}
// ----------------------------------------------------------------------------
......@@ -190,6 +201,22 @@ QList<pqWidgetEventTranslator*> pqEventTranslator::translators() const
return this->Implementation->Translators;
}
// ----------------------------------------------------------------------------
void pqEventTranslator::addDefaultEventManagers(pqTestUtility* util)
{
this->Implementation->EventComment = new pqEventComment(util);
QObject::connect(this->Implementation->EventComment,
SIGNAL(recordComment(QObject*,QString,QString)),
this,
SLOT(onRecordEvent(QObject*,QString,QString)));
}
// ----------------------------------------------------------------------------
pqEventComment* pqEventTranslator::eventComment() const
{
return this->Implementation->EventComment;
}
// ----------------------------------------------------------------------------
void pqEventTranslator::ignoreObject(QObject* Object)
{
......@@ -246,15 +273,21 @@ bool pqEventTranslator::eventFilter(QObject* Object, QEvent* Event)
}
// ----------------------------------------------------------------------------
void pqEventTranslator::onRecordEvent(QObject* Object, const QString& Command, const QString& Arguments)
void pqEventTranslator::onRecordEvent(QObject* Object,
const QString& Command,
const QString& Arguments)
{
if(this->Implementation->IgnoredObjects.contains(Object))
return;
const QString name = pqObjectNaming::GetName(*Object);
if(name.isEmpty())
return;
// qDebug() << "Event: " << name << " " << Command << " " << Arguments;
QString name;
// When sender is pqEventObject, the Object name can be NULL.
if (!qobject_cast<pqEventComment*>(this->sender()) || Object)
{
name = pqObjectNaming::GetName(*Object);
if(name.isEmpty())
return;
}
emit recordEvent(name, Command, Arguments);
}
......@@ -36,8 +36,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "QtTestingExport.h"
#include <QObject>
class pqWidgetEventTranslator;
class pqEventComment;
class pqTestUtility;
class pqWidgetEventTranslator;
/**
Manages serialization of user interaction for test-cases, demos, tutorials, etc.
......@@ -75,6 +76,12 @@ public:
/// Return a QList of all the Translators previously added.
QList<pqWidgetEventTranslator*> translators() const;
/// Add a new default eventComment in the scenario/recording to inform,
/// intract with the user during the play back.
void addDefaultEventManagers(pqTestUtility* util);
/// Return the pqEventComment, to be able to add any comment events
pqEventComment* eventComment() const;
/// Adds a Qt 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)
......
......@@ -119,7 +119,6 @@ void pqPlayBackEventsDialog::pqImplementation::init(pqPlayBackEventsDialog* dial
qobject_cast<pqCommentEventPlayer*>(widgetPlayer);
if (commentPlayer)
{
commentPlayer->setCommentEnabled(true);
QObject::connect(commentPlayer, SIGNAL(comment(QString)),
this->Ui.logBrowser, SLOT(append(QString)));
qDebug() << "Comment player : " << commentPlayer;
......@@ -366,6 +365,7 @@ void pqPlayBackEventsDialog::onStarted(const QString& filename)
this->Implementation->Ui.tableWidget->setCurrentCell(
this->Implementation->CurrentFile, 1,
QItemSelectionModel::Rows | QItemSelectionModel::SelectCurrent);
this->Implementation->Ui.logBrowser->clear();
this->Implementation->MaxLines = 0;
this->Implementation->CurrentLine = 0;
......@@ -405,6 +405,9 @@ void pqPlayBackEventsDialog::onStopped()
void pqPlayBackEventsDialog::updateUi()
{
// Update player buttons
this->Implementation->Ui.playPauseButton->setChecked(
this->Implementation->TestUtility->playingTest() &&
!this->Implementation->Dispatcher.isPaused());
this->Implementation->Ui.playPauseButton->setEnabled(
!this->Implementation->Filenames.isEmpty() &&
this->selectedFileNames().count() > 0);
......@@ -462,4 +465,6 @@ void pqPlayBackEventsDialog::updateUi()
this->Implementation->Ui.commandLabel->setText(command);
this->Implementation->Ui.argumentsLabel->setText(argument);
this->Implementation->Ui.objectLabel->setText(object);
this->update();
}
......@@ -39,6 +39,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <QPushButton>
// QtTesting includes
#include "pqEventComment.h"
#include "pqEventRecorder.h"
#include "pqRecordEventsDialog.h"
#include "pqTestUtility.h"
......@@ -90,6 +91,9 @@ pqRecordEventsDialog::pqRecordEventsDialog(pqEventRecorder* recorder,
QObject::connect(this->Implementation->TestUtility->eventTranslator(),
SIGNAL(recordEvent(QString,QString,QString)),
this, SLOT(onEventRecorded(QString,QString,QString)));
QObject::connect(this->Implementation->Ui.commentAddButton,
SIGNAL(clicked()),
this, SLOT(addComment()));
}
// ----------------------------------------------------------------------------
......@@ -116,7 +120,9 @@ void pqRecordEventsDialog::done(int value)
}
// ----------------------------------------------------------------------------
void pqRecordEventsDialog::onEventRecorded(const QString& widget, const QString& command, const QString& argument)
void pqRecordEventsDialog::onEventRecorded(const QString& widget,
const QString& command,
const QString& argument)
{
this->Implementation->Ui.eventWidgetEdit->setText(widget);
this->Implementation->Ui.eventCommandEdit->setText(command);
......@@ -124,3 +130,19 @@ void pqRecordEventsDialog::onEventRecorded(const QString& widget, const QString&
int newValue = this->Implementation->Ui.nbEvents->value() + 1;
this->Implementation->Ui.nbEvents->display(newValue);
}
// ----------------------------------------------------------------------------
void pqRecordEventsDialog::addComment()
{
if (this->Implementation->Ui.blockingCheckBox->isChecked())
{
this->Implementation->Recorder->translator()->eventComment()->recordCommentBlock(
this->Implementation->Ui.commentTextEdit->toPlainText());
}
else
{
this->Implementation->Recorder->translator()->eventComment()->recordComment(
this->Implementation->Ui.commentTextEdit->toPlainText());
}
this->Implementation->Ui.commentTextEdit->clear();
}
......@@ -57,6 +57,8 @@ private slots:
virtual void done(int);
void onEventRecorded(const QString&, const QString&, const QString&);
void addComment();
private:
pqRecordEventsDialog(const pqRecordEventsDialog&);
pqRecordEventsDialog& operator=(const pqRecordEventsDialog&);
......
This diff is collapsed.
......@@ -39,6 +39,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <QVariant>
// QtTesting includes
#include "pqEventComment.h"
#include "pqEventObserver.h"
#include "pqEventSource.h"
#include "pqEventTranslator.h"
......@@ -63,6 +64,7 @@ pqTestUtility::pqTestUtility(QObject* p)
this->FileSuffix = QString();
this->Translator.addDefaultWidgetEventTranslators(this);
this->Translator.addDefaultEventManagers(this);
this->Player.addDefaultWidgetEventPlayers(this);
#ifdef QT_TESTING_WITH_PYTHON
......@@ -242,9 +244,8 @@ bool pqTestUtility::playTests(const QStringList& filenames)
return false;
}
emit this->playbackStarted();
this->PlayingTest = true;
emit this->playbackStarted();
bool success = true;
foreach (QString filename, filenames)
......@@ -277,9 +278,10 @@ bool pqTestUtility::playTests(const QStringList& filenames)
emit this->playbackStopped(info.fileName(), success);
}
}
this->PlayingTest = false;
this->PlayingTest = false;
emit this->playbackStopped();
return success;
}
......@@ -313,7 +315,6 @@ void pqTestUtility::recordTests()
QObject::connect(&this->Recorder, SIGNAL(stopped()),
this, SLOT(onRecordStopped()), Qt::UniqueConnection);
pqRecordEventsDialog* dialog = new pqRecordEventsDialog(&this->Recorder,
this,
QApplication::activeWindow());
......
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