Commit d20436ef authored by Benjamin Long's avatar Benjamin Long

Add generic function to record/restore property for QObject

parent 2e720a59
......@@ -82,7 +82,7 @@ public:
~XMLEventSource() { delete this->XMLStream; }
protected:
virtual void setContent(const QString& xmlfilename)
virtual bool setContent(const QString& xmlfilename)
{
delete this->XMLStream;
this->XMLStream = NULL;
......@@ -91,7 +91,7 @@ protected:
if (!xml.open(QIODevice::ReadOnly))
{
qDebug() << "Failed to load " << xmlfilename;
return;
return false;
}
QByteArray data = xml.readAll();
this->XMLStream = new QXmlStreamReader(data);
......@@ -114,6 +114,7 @@ protected:
{
qDebug() << "Invalid xml" << endl;
}
return true;
}
int getNextEvent(QString& widget, QString& command, QString&
......
......@@ -58,7 +58,7 @@ public:
/** Set the filename for contents.
Returns true for valid file, false for invalid file */
virtual void setContent(const QString& filename) = 0;
virtual bool setContent(const QString& filename) = 0;
/** tell the source to stop feeding in events */
virtual void stop() {}
......
......@@ -174,7 +174,14 @@ bool pqTestUtility::playTests(const QStringList& filenames)
iter = this->EventSources.find(suffix);
if(info.isReadable() && iter != this->EventSources.end())
{
iter.value()->setContent(filename);
if(!iter.value()->setContent(filename))
{
return false;
}
// QEventLoop loop;
// QTimer::singleShot(100, &loop, SLOT(quit()));
// loop.exec();
QApplication::processEvents();
if (!this->Dispatcher.playEvents(*iter.value(), this->Player))
{
// dispatcher returned failure, don't continue with rest of the tests
......@@ -233,6 +240,17 @@ void pqTestUtility::recordTests(const QString& filename)
dialog->show();
}
// ----------------------------------------------------------------------------
void pqTestUtility::addObjectStateProperty(QObject* object, const QString& property)
{
this->ObjectStateProperty[object] = property;
}
// ----------------------------------------------------------------------------
QMap<QObject*, QString> pqTestUtility::objectStateProperty() const
{
return this->ObjectStateProperty;
}
//-----------------------------------------------------------------------------
void pqTestUtility::addDataDirectory(const QString& label, const QDir& path)
{
......
......@@ -93,6 +93,10 @@ public:
/// start the recording of tests to a file
Q_INVOKABLE void recordTests(const QString& filename);
/// Add custom object properties, which will be saved during the recording
/// and restored before the playback
void addObjectStateProperty(QObject* object, const QString& property);
QMap<QObject*, QString> objectStateProperty() const;
/// add a directory for recording/playback of file dialogs
void addDataDirectory(const QString& label, const QDir& path);
......@@ -125,7 +129,8 @@ protected:
QMap<QString, pqEventSource*> EventSources;
QMap<QString, pqEventObserver*> EventObservers;
QMap<QString, QDir> DataDirectories;
QMap<QString, QDir> DataDirectories;
QMap<QObject*, QString> ObjectStateProperty;
};
......
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