Commit 58ff7a8d authored by Benjamin Long's avatar Benjamin Long

Fix style/bugs and add feedbacks to QtTesting Recorder: close #174

Added the possibilty to cancel the record.

Added feedback to the user during the record:
  --> Show the last event information
  --> Show how many events have been recorded

Removed useless "flush" into the Observer, as now the recording is done
by a special class.
parent 75c24a70
......@@ -8,5 +8,6 @@
<file>Icons/minus.png</file>
<file>Icons/plus.png</file>
<file>Icons/info.png</file>
<file>Icons/playback-stop.png</file>
</qresource>
</RCC>
......@@ -44,18 +44,10 @@ pqEventObserver::pqEventObserver(QObject* p)
pqEventObserver::~pqEventObserver()
{
if(this->Stream)
{
this->Stream->flush();
}
}
void pqEventObserver::setStream(QTextStream* stream)
{
if(this->Stream)
{
this->Stream->flush();
}
this->Stream = stream;
}
......@@ -164,7 +164,7 @@ void pqEventRecorder::start()
}
// ----------------------------------------------------------------------------
void pqEventRecorder::stop()
void pqEventRecorder::stop(int value)
{
QObject::disconnect(
this->ActiveTranslator,
......@@ -173,11 +173,14 @@ void pqEventRecorder::stop()
SLOT(onRecordEvent(QString,QString,QString)));
this->ActiveObserver->setStream(NULL);
this->flush();
this->ActiveTranslator->stop();
if (!value)
{
return;
}
this->flush();
emit this->stopped();
}
......
......@@ -89,7 +89,7 @@ public slots:
void flush();
void start();
void stop();
void stop(int value);
void pause();
protected:
......
......@@ -80,13 +80,16 @@ pqRecordEventsDialog::pqRecordEventsDialog(pqEventRecorder* recorder,
Implementation(new pqImplementation(recorder, testUtility))
{
this->Implementation->Ui.setupUi(this);
this->setWindowFlags(this->windowFlags() | Qt::WindowStaysOnTopHint);
this->Implementation->TestUtility->eventTranslator()->ignoreObject(this->Implementation->Ui.stopButton);
this->Implementation->TestUtility->eventTranslator()->ignoreObject(this);
this->ignoreObject(this);
this->setWindowTitle(tr("Recording User Input"));
this->setObjectName("");
QObject::connect(this->Implementation->TestUtility->eventTranslator(),
SIGNAL(recordEvent(QString,QString,QString)),
this, SLOT(onEventRecorded(QString,QString,QString)));
}
// ----------------------------------------------------------------------------
......@@ -95,9 +98,29 @@ pqRecordEventsDialog::~pqRecordEventsDialog()
delete Implementation;
}
// ----------------------------------------------------------------------------
void pqRecordEventsDialog::ignoreObject(QObject* object)
{
this->Implementation->TestUtility->eventTranslator()->ignoreObject(object);
foreach(QObject* child, object->children())
{
this->ignoreObject(child);
}
}
// ----------------------------------------------------------------------------
void pqRecordEventsDialog::done(int value)
{
this->Implementation->TestUtility->stopRecords();
this->Implementation->TestUtility->stopRecords(value);
QDialog::done(value);
}
// ----------------------------------------------------------------------------
void pqRecordEventsDialog::onEventRecorded(const QString& widget, const QString& command, const QString& argument)
{
this->Implementation->Ui.eventWidgetEdit->setText(widget);
this->Implementation->Ui.eventCommandEdit->setText(command);
this->Implementation->Ui.eventArgumentEdit->setText(argument);
int newValue = this->Implementation->Ui.nbEvents->value() + 1;
this->Implementation->Ui.nbEvents->display(newValue);
}
......@@ -55,12 +55,15 @@ public:
private slots:
virtual void done(int);
void onEventRecorded(const QString&, const QString&, const QString&);
private:
pqRecordEventsDialog(const pqRecordEventsDialog&);
pqRecordEventsDialog& operator=(const pqRecordEventsDialog&);
~pqRecordEventsDialog();
void ignoreObject(QObject* object);
struct pqImplementation;
pqImplementation* const Implementation;
};
......
......@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>389</width>
<height>72</height>
<width>370</width>
<height>204</height>
</rect>
</property>
<property name="windowTitle">
......@@ -23,7 +23,7 @@
<item>
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
......@@ -36,22 +36,141 @@
</property>
</widget>
</item>
<item>
<widget class="QGroupBox" name="eventBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>Last Event</string>
</property>
<property name="flat">
<bool>false</bool>
</property>
<property name="checkable">
<bool>false</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="eventWidgetLabel">
<property name="text">
<string>Widget :</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="eventWidgetEdit">
<property name="enabled">
<bool>true</bool>
</property>
<property name="frame">
<bool>false</bool>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="eventArgumentLabel">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>Argument :</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="eventArgumentEdit">
<property name="enabled">
<bool>true</bool>
</property>
<property name="frame">
<bool>false</bool>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="eventCommandLabel">
<property name="text">
<string>Command :</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="eventCommandEdit">
<property name="enabled">
<bool>true</bool>
</property>
<property name="frame">
<bool>false</bool>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<layout class="QHBoxLayout">
<property name="spacing">
<number>6</number>
</property>
<property name="sizeConstraint">
<enum>QLayout::SetMinimumSize</enum>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QLCDNumber" name="nbEvents">
<property name="smallDecimalPoint">
<bool>false</bool>
</property>
<property name="digitCount">
<number>5</number>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="nbEventsLabel">
<property name="text">
<string>Events recorded</string>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>131</width>
<width>133</width>
<height>31</height>
</size>
</property>
......@@ -59,16 +178,28 @@
</item>
<item>
<widget class="QPushButton" name="stopButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Stop Recording</string>
</property>
<property name="icon">
<iconset resource="Resources/QtTesting.qrc">
<normaloff>:/Icons/playback-stop.png</normaloff>:/Icons/playback-stop.png</iconset>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<resources>
<include location="Resources/QtTesting.qrc"/>
</resources>
<connections>
<connection>
<sender>stopButton</sender>
......
......@@ -154,9 +154,9 @@ void pqTestUtility::stopTests()
}
//-----------------------------------------------------------------------------
void pqTestUtility::stopRecords()
void pqTestUtility::stopRecords(int value)
{
this->Recorder.stop();
this->Recorder.stop(value);
}
//-----------------------------------------------------------------------------
......@@ -167,10 +167,14 @@ void pqTestUtility::onRecordStopped()
{
QString newFilename = QFileDialog::getSaveFileName(0, tr("Macro File Name"),
QString("macro"), tr("XML Files (*.xml)"));
if(!newFilename.endsWith(QString(".%1").arg(this->FileSuffix)))
{
newFilename += QString(".%1").arg(this->FileSuffix);
}
if (newFilename.isEmpty())
{
return;
}
if (!newFilename.endsWith(QString(".%1").arg(this->FileSuffix)))
{
newFilename += QString(".%1").arg(this->FileSuffix);
}
// QFile::copy doesn't overwrite if the file already exist, and return false
if(QFile::exists(newFilename))
{
......@@ -178,7 +182,6 @@ void pqTestUtility::onRecordStopped()
}
QFile::copy(file->fileName(), newFilename);
}
this->File->close();
}
......@@ -275,6 +278,12 @@ void pqTestUtility::recordTests()
this,
QApplication::activeWindow());
dialog->setAttribute(Qt::WA_QuitOnClose, false);
QRect rectApp = QApplication::activeWindow()->geometry();
QRect rectDialog(QPoint(rectApp.left(),
rectApp.bottom() - dialog->sizeHint().height()),
QSize(dialog->geometry().width(), dialog->sizeHint().height()));
dialog->setGeometry(rectDialog);
dialog->show();
this->Recorder.recordEvents(&this->Translator, observer, this->File, true);
......
......@@ -122,7 +122,7 @@ public slots:
void openPlayerDialog();
void stopTests();
void stopRecords();
void stopRecords(int value);
void onRecordStopped();
......
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