Commit 98b4a860 authored by Benjamin Long's avatar Benjamin Long

Added new functionalities and fix code

parent 0113c88d
......@@ -7,5 +7,7 @@
<file>Icons/stop.png</file>
<file>Icons/clear.svg</file>
<file>Icons/info.png</file>
<file>Icons/minus.png</file>
<file>Icons/plus.png</file>
</qresource>
</RCC>
<RCC>
<qresource prefix="/">
<file>Icons/frameForward.png</file>
<file>Icons/pause.png</file>
<file>Icons/repeat.png</file>
<file>Icons/timePlay.png</file>
<file>Icons/stop.png</file>
</qresource>
</RCC>
......@@ -225,7 +225,7 @@ bool pqEventDispatcher::playEvents(pqEventSource& source, pqEventPlayer& player)
this->PlayBackFinished = false;
while (!this->PlayBackFinished)
{
qDebug() << "while Loop";
// qDebug() << "while Loop";
if(!this->PlayBackPaused)
{
this->playEvent();
......
......@@ -93,7 +93,6 @@ void pqEventPlayer::addWidgetEventPlayer(pqWidgetEventPlayer* Player)
bool pqEventPlayer::removeWidgetEventPlayer(const QString& className)
{
int index = this->getWidgetEventPlayerIndex(className);
qDebug() << "Index : " << index << this->Players.at(index)->metaObject()->className();
if (index == -1)
{
return false;
......
......@@ -146,7 +146,6 @@ bool pqEventTranslator::removeWidgetEventTranslator(const QString& className)
}
this->Implementation->Translators.remove(index);
qDebug() << "Translator : " << this->Implementation->Translators;
return true;
}
......
......@@ -30,6 +30,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=========================================================================*/
#include "pqCommentEventPlayer.h"
#include "pqEventDispatcher.h"
#include "pqEventPlayer.h"
#include "pqPlayBackEventsDialog.h"
......@@ -40,6 +41,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <QCheckBox>
#include <QFile>
#include <QFileDialog>
#include <QMessageBox>
#include <QTableWidget>
#include <QProgressBar>
#include <QPushButton>
......@@ -62,6 +64,7 @@ public:
void init(pqPlayBackEventsDialog* dialog);
void setProgressBarsValue(int value);
void setProgressBarValue(int row, int value);
QString setMaxLenght(const QString& name, int max);
Ui::pqPlayBackEventsDialog Ui;
......@@ -69,7 +72,7 @@ public:
pqEventDispatcher& Dispatcher;
pqTestUtility* TestUtility;
int CurrentLine;
int CurrentLine; // Add counter to the Dispatcher
int MaxLines;
int CurrentFile;
QStringList Filenames;
......@@ -101,18 +104,46 @@ void pqPlayBackEventsDialog::pqImplementation::init(pqPlayBackEventsDialog* dial
{
this->Ui.setupUi(dialog);
this->Ui.loadFileButton->setIcon(
QApplication::style()->standardIcon(QStyle::SP_DirOpenIcon));
this->Ui.playerErrorTextLabel->setVisible(false);
this->Ui.playerErrorIconLabel->setVisible(false);
this->Ui.infoErrorTextLabel->setVisible(false);
this->Ui.infoErrorIconLabel->setVisible(false);
this->Ui.logBrowser->setVisible(false);
pqWidgetEventPlayer* widgetPlayer =
this->Player.getWidgetEventPlayer(QString("pqCommentEventPlayer"));
pqCommentEventPlayer* commentPlayer =
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;
}
dialog->setMaximumHeight(dialog->minimumSizeHint().height());
QObject::connect(&this->Player, SIGNAL(eventAboutToBePlayed(QString, QString, QString)),
dialog, SLOT(onEventAboutToBePlayed(QString, QString, QString)));
QObject::connect(this->Ui.timeStepSpinBox, SIGNAL(valueChanged(int)),
&this->Dispatcher, SLOT(changeTimeStep(int)));
&this->Dispatcher, SLOT(setTimeStep(int)));
QObject::connect(this->Ui.loadFileButton, SIGNAL(clicked()),
dialog, SLOT(onLoadFiles()));
dialog, SLOT(loadFiles()));
QObject::connect(this->Ui.plusButton, SIGNAL(clicked()),
dialog, SLOT(insertFiles()));
QObject::connect(this->Ui.minusButton, SIGNAL(clicked()),
dialog, SLOT(removeFiles()));
QObject::connect(this->Ui.playPauseButton, SIGNAL(clicked(bool)),
dialog, SLOT(onPlayOrPause(bool)));
QObject::connect(this->Ui.stopButton, SIGNAL(clicked()),
this->TestUtility, SLOT(stop()));
this->TestUtility, SLOT(stopTests()));
QObject::connect(this->Ui.stepButton, SIGNAL(clicked()),
&this->Dispatcher, SLOT(oneStep()));
......@@ -123,9 +154,12 @@ void pqPlayBackEventsDialog::pqImplementation::init(pqPlayBackEventsDialog* dial
dialog, SLOT(updateUi()));
QObject::connect(&this->Dispatcher, SIGNAL(paused()),
dialog, SLOT(updateUi()));
QObject::connect(&this->Dispatcher, SIGNAL(started()),
QObject::connect(&this->Dispatcher, SIGNAL(restarted()),
dialog, SLOT(updateUi()));
QObject::connect(&this->Player, SIGNAL(errorMessage(QString)),
this->Ui.logBrowser, SLOT(append(QString)));
}
// ----------------------------------------------------------------------------
......@@ -138,13 +172,25 @@ void pqPlayBackEventsDialog::pqImplementation::setProgressBarsValue(int value)
}
// ----------------------------------------------------------------------------
void pqPlayBackEventsDialog::pqImplementation::setProgressBarValue(int row, int value)
void pqPlayBackEventsDialog::pqImplementation::setProgressBarValue(int row,
int value)
{
QWidget* widget = this->Ui.tableWidget->cellWidget(row, 2);
QProgressBar* progressBar = qobject_cast<QProgressBar*>(widget);
progressBar->setValue(value);
}
// ----------------------------------------------------------------------------
QString pqPlayBackEventsDialog::pqImplementation::setMaxLenght(const QString& name,
int max)
{
if(name.length() > max)
{
return name.left(max/2) + "..." + name.right(max/2);
}
return name;
}
///////////////////////////////////////////////////////////////////////////////////
// pqPlayBackEventsDialog
......@@ -157,8 +203,8 @@ pqPlayBackEventsDialog::pqPlayBackEventsDialog(pqEventPlayer& Player,
, Implementation(new pqImplementation(Player, Dispatcher, TestUtility))
{
this->Implementation->init(this);
this->onLoadFiles();
this->setAttribute(Qt::WA_DeleteOnClose);
this->loadFiles();
}
// ----------------------------------------------------------------------------
......@@ -168,15 +214,14 @@ pqPlayBackEventsDialog::~pqPlayBackEventsDialog()
}
// ----------------------------------------------------------------------------
void pqPlayBackEventsDialog::done(const int& value)
void pqPlayBackEventsDialog::done(int value)
{
this->Implementation->TestUtility->stopTests();
QDialog::done(value);
delete this;
}
// ----------------------------------------------------------------------------
QStringList pqPlayBackEventsDialog::fileNamesSelected()
QStringList pqPlayBackEventsDialog::selectedFileNames() const
{
QStringList list;
for(int i = 0; i < this->Implementation->Ui.tableWidget->rowCount(); ++i)
......@@ -204,42 +249,77 @@ void pqPlayBackEventsDialog::onEventAboutToBePlayed(const QString& Object,
}
// ----------------------------------------------------------------------------
void pqPlayBackEventsDialog::onLoadFiles()
void pqPlayBackEventsDialog::loadFiles()
{
QStringList filenames = QFileDialog::getOpenFileNames(this, "Macro File Name",
QFileDialog* dialog = new QFileDialog(this, "Macro File Name",
QString(), "XML Files (*.xml)");
if (!filenames.isEmpty())
dialog->setFileMode(QFileDialog::ExistingFiles);
if (dialog->exec())
{
this->Implementation->Filenames = filenames;
this->Implementation->Filenames = dialog->selectedFiles();
this->Implementation->Ui.tableWidget->setRowCount(0);
this->loadFiles(this->Implementation->Filenames);
}
delete dialog;
}
this->updateUi();
// ----------------------------------------------------------------------------
void pqPlayBackEventsDialog::insertFiles()
{
QFileDialog* dialog = new QFileDialog(this, "Macro File Name",
QString(), "XML Files (*.xml)");
dialog->setFileMode(QFileDialog::ExistingFiles);
if (dialog->exec())
{
this->Implementation->Filenames << dialog->selectedFiles();
this->loadFiles(dialog->selectedFiles());
}
delete dialog;
}
// ----------------------------------------------------------------------------
void pqPlayBackEventsDialog::loadFiles(const QStringList& filenames)
void pqPlayBackEventsDialog::removeFiles()
{
int rowCount = this->Implementation->Ui.tableWidget->rowCount();
for(int i = 0 ; i < rowCount ; i++)
if (QMessageBox::Ok == QMessageBox::warning(this, QString("Remove files"),
QString("Are you sure you want to \n"
"remove all checked files ?\n"),
QMessageBox::Ok,
QMessageBox::Cancel))
{
foreach(QString file, this->selectedFileNames())
{
this->Implementation->Ui.tableWidget->removeRow(0);
int index = this->Implementation->Filenames.indexOf(file);
this->Implementation->Ui.tableWidget->removeRow(index);
this->Implementation->Filenames.removeAt(index);
}
}
}
// ----------------------------------------------------------------------------
void pqPlayBackEventsDialog::loadFiles(const QStringList& filenames)
{
for(int i = 0 ; i < filenames.count() ; i++)
{
QFileInfo info(filenames[i]);
this->Implementation->Ui.tableWidget->insertRow(i);
this->addFile(filenames[i]);
}
this->Implementation->Ui.tableWidget->resizeColumnToContents(0);
}
// ----------------------------------------------------------------------------
void pqPlayBackEventsDialog::addFile(const QString& filename)
{
QFileInfo info(filename);
int newIndex = this->Implementation->Ui.tableWidget->rowCount();
this->Implementation->Ui.tableWidget->insertRow(newIndex);
this->Implementation->Ui.tableWidget->setItem(
i, 1, new QTableWidgetItem(info.fileName()));
newIndex, 1, new QTableWidgetItem(info.fileName()));
this->Implementation->Ui.tableWidget->setCellWidget(
i, 2, new QProgressBar(this->Implementation->Ui.tableWidget));
this->Implementation->setProgressBarsValue(0);
newIndex, 2, new QProgressBar(this->Implementation->Ui.tableWidget));
this->Implementation->setProgressBarValue(newIndex, 0);
QCheckBox* check = new QCheckBox(this->Implementation->Ui.tableWidget);
check->setChecked(true);
this->Implementation->Ui.tableWidget->setCellWidget(i, 0, check);
this->Implementation->Ui.tableWidget->resizeColumnToContents(0);
}
this->Implementation->Ui.tableWidget->setCellWidget(newIndex, 0, check);
this->updateUi();
}
// ----------------------------------------------------------------------------
......@@ -249,7 +329,7 @@ void pqPlayBackEventsDialog::onPlayOrPause(bool playOrPause)
{
if(!this->Implementation->TestUtility->playingTest())
{
QStringList newList = this->fileNamesSelected();
QStringList newList = this->selectedFileNames();
this->Implementation->TestUtility->playTests(newList);
}
else
......@@ -266,9 +346,11 @@ void pqPlayBackEventsDialog::onPlayOrPause(bool playOrPause)
// ----------------------------------------------------------------------------
void pqPlayBackEventsDialog::onStarted(const QString& filename)
{
this->Implementation->CurrentFile = this->Implementation->Filenames.indexOf(filename);
this->Implementation->CurrentFile =
this->Implementation->Filenames.indexOf(filename);
this->Implementation->Ui.tableWidget->setCurrentCell(
this->Implementation->CurrentFile, 1, QItemSelectionModel::Rows | QItemSelectionModel::SelectCurrent);
this->Implementation->CurrentFile, 1,
QItemSelectionModel::Rows | QItemSelectionModel::SelectCurrent);
this->Implementation->MaxLines = 0;
this->Implementation->CurrentLine = 0;
......@@ -276,12 +358,14 @@ void pqPlayBackEventsDialog::onStarted(const QString& filename)
QFile file(filename);
QFileInfo infoFile(file);
file.open(QIODevice::ReadOnly);
this->Implementation->Ui.logBrowser->append(QString("Start file : %1").arg(
infoFile.fileName()));
QTextStream stream(&file);
this->Implementation->Ui.currentFileLabel->setText(infoFile.fileName());
while(!stream.atEnd())
{
QString line = stream.readLine();
if(line.replace(" ", "").startsWith("<event"))
if(line.trimmed().startsWith("<event"))
{
++this->Implementation->MaxLines;
}
......@@ -295,36 +379,59 @@ void pqPlayBackEventsDialog::updateUi()
this->Implementation->Ui.playPauseButton->setEnabled(
!this->Implementation->Filenames.isEmpty());
this->Implementation->Ui.stepButton->setEnabled(
this->Implementation->TestUtility->playingTest() && this->Implementation->Dispatcher.isPaused());
this->Implementation->TestUtility->playingTest() &&
this->Implementation->Dispatcher.isPaused());
this->Implementation->Ui.stopButton->setEnabled(
this->Implementation->TestUtility->playingTest());
// Play or pause
this->Implementation->Ui.playPauseButton->setChecked(
this->Implementation->TestUtility->playingTest() && !this->Implementation->Dispatcher.isPaused());
this->Implementation->TestUtility->playingTest() &&
!this->Implementation->Dispatcher.isPaused());
// loadFile button
// loadFile, plus and minus buttons
this->Implementation->Ui.loadFileButton->setEnabled(
!this->Implementation->TestUtility->playingTest());
this->Implementation->Ui.plusButton->setEnabled(
!this->Implementation->TestUtility->playingTest());
this->Implementation->Ui.minusButton->setEnabled(
!this->Implementation->TestUtility->playingTest());
// Time step
this->Implementation->Ui.timeStepSpinBox->setEnabled(
!this->Implementation->Filenames.isEmpty());
// Error feedback
this->Implementation->Ui.playerErrorTextLabel->setVisible(
!this->Implementation->Dispatcher.status());
this->Implementation->Ui.playerErrorIconLabel->setVisible(
!this->Implementation->Dispatcher.status());
this->Implementation->Ui.infoErrorTextLabel->setVisible(
!this->Implementation->Dispatcher.status());
this->Implementation->Ui.infoErrorIconLabel->setVisible(
!this->Implementation->Dispatcher.status());
QString command = tr("Command : ");
QString argument = tr("Argument(s) : ");
QString object = tr("Object : ");
if(this->Implementation->TestUtility->playingTest() &&
!this->Implementation->CurrentEvent.isEmpty())
{
command += this->Implementation->CurrentEvent[1];
argument += this->Implementation->CurrentEvent[2].right(25);
object += this->Implementation->CurrentEvent[0].right(20);
command += this->Implementation->setMaxLenght(
this->Implementation->CurrentEvent[1], 40);
argument += this->Implementation->setMaxLenght(
this->Implementation->CurrentEvent[2], 40);
object += this->Implementation->setMaxLenght(
this->Implementation->CurrentEvent[0], 40);
this->Implementation->setProgressBarValue(this->Implementation->CurrentFile,
static_cast<int>((static_cast<double>(this->Implementation->CurrentLine)/static_cast<double>(this->Implementation->MaxLines-1))*100));
static_cast<int>((static_cast<double>(
this->Implementation->CurrentLine)/static_cast<double>(
this->Implementation->MaxLines-1))*100));
}
else
{
this->Implementation->Ui.currentFileLabel->setText(
QString("No Test is playing ..."));
this->Implementation->setProgressBarsValue(0);
}
this->Implementation->Ui.commandLabel->setText(command);
......
......@@ -55,17 +55,20 @@ public:
private slots:
void onEventAboutToBePlayed(const QString&,const QString&,const QString&);
void onLoadFiles();
void loadFiles();
void insertFiles();
void removeFiles();
void onPlayOrPause(bool);
void onStarted(const QString&);
public slots:
virtual void done(const int&);
virtual void done(int);
void updateUi();
private:
void loadFiles(const QStringList& filenames);
QStringList fileNamesSelected();
void addFile(const QString& filename);
QStringList selectedFileNames() const;
pqPlayBackEventsDialog(const pqPlayBackEventsDialog&); // Not Implemented
pqPlayBackEventsDialog& operator=(const pqPlayBackEventsDialog&); // Not Implemented
......
......@@ -9,16 +9,22 @@
<rect>
<x>0</x>
<y>0</y>
<width>360</width>
<height>261</height>
<width>378</width>
<height>376</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
......@@ -31,9 +37,33 @@
<property name="sizeGripEnabled">
<bool>false</bool>
</property>
<property name="modal">
<bool>false</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="tabPosition">
<enum>QTabWidget::North</enum>
</property>
......@@ -67,13 +97,16 @@
<string>Player</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="sizeConstraint">
<enum>QLayout::SetMaximumSize</enum>
</property>
<item>
<widget class="QTableWidget" name="tableWidget">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Expanding">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
......@@ -164,23 +197,120 @@
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="playerErrorIconLabel">
<property name="maximumSize">
<size>
<width>18</width>
<height>18</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap resource="Resources/QtTesting.qrc">:/Icons/clear.svg</pixmap>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<widget class="QLabel" name="playerErrorTextLabel">
<property name="palette">
<palette>
<active>
<colorrole role="WindowText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>170</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
</active>
<inactive>
<colorrole role="WindowText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>170</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
</inactive>
<disabled>
<colorrole role="WindowText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>106</red>
<green>104</green>
<blue>100</blue>
</color>
</brush>
</colorrole>
</disabled>
</palette>
</property>
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Error occured</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<width>200</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="minusButton">
<property name="text">
<string/>
</property>
<property name="icon">
<iconset>
<normaloff>:/Icons/minus.png</normaloff>:/Icons/minus.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="plusButton">
<property name="text">
<string/>
</property>
<property name="icon">
<iconset>
<normaloff>:/Icons/plus.png</normaloff>:/Icons/plus.png</iconset>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>