瀏覽代碼

QtTesting app: Pass pqTestUtility to ctkXMLEvent*

TestUtility is mandatory in ctkXMLEventSource and ctkXMLEventObserver.
Julien Finet 12 年之前
父節點
當前提交
620e2988ea

+ 2 - 2
Applications/ctkQtTesting/ctkQtTestingMainWindow.cpp

@@ -43,8 +43,8 @@ ctkQtTestingMainWindow::ctkQtTestingMainWindow()
   QObject::connect(Ui.PlayBackButton, SIGNAL(clicked(bool)), this, SLOT(play()));
 
   this->TestUtility = new ctkQtTestingUtility(this);
-  this->TestUtility->addEventObserver("xml", new ctkXMLEventObserver(this));
-  this->TestUtility->addEventSource("xml", new ctkXMLEventSource(this));
+  this->TestUtility->addEventObserver("xml", new ctkXMLEventObserver(this->TestUtility));
+  this->TestUtility->addEventSource("xml", new ctkXMLEventSource(this->TestUtility));
 
   Ui.renderView->setBackgroundColor(QColor(Qt::gray));
   Ui.renderView->setBackgroundColor2(QColor(Qt::darkBlue));

+ 38 - 35
Libs/QtTesting/ctkXMLEventObserver.cpp

@@ -38,6 +38,7 @@ ctkXMLEventObserver::ctkXMLEventObserver(QObject* p)
 {
   this->XMLStream = NULL;
   this->TestUtility = qobject_cast<pqTestUtility*>(p);
+  Q_ASSERT(this->TestUtility);
 }
 
 //-----------------------------------------------------------------------------
@@ -50,50 +51,52 @@ ctkXMLEventObserver::~ctkXMLEventObserver()
 //-----------------------------------------------------------------------------
 void ctkXMLEventObserver::recordApplicationSettings()
 {
-  if(this->XMLStream)
+  Q_ASSERT(this->TestUtility);
+  if (!this->XMLStream)
     {
-    this->XMLStream->writeStartElement("settings");
+    return;
+    }
+  this->XMLStream->writeStartElement("settings");
 
-    // Informations about the application
-    this->recordApplicationSetting("name","qApp", "applicationName",
-                                   QCoreApplication::applicationName());
-    this->recordApplicationSetting("version" , "qApp", "applicationVersion",
-                                   QCoreApplication::applicationVersion());
+  // Informations about the application
+  this->recordApplicationSetting("name","qApp", "applicationName",
+                                 QCoreApplication::applicationName());
+  this->recordApplicationSetting("version" , "qApp", "applicationVersion",
+                                 QCoreApplication::applicationVersion());
 
-    // save Geometry and State of the application
-    QMainWindow* window = NULL;
-    foreach(QWidget * widget, QApplication::topLevelWidgets())
+  // save Geometry and State of the application
+  QMainWindow* window = NULL;
+  foreach(QWidget * widget, QApplication::topLevelWidgets())
+    {
+    window = qobject_cast<QMainWindow*>(widget);
+    if (window)
       {
-      window = qobject_cast<QMainWindow*>(widget);
-      if (window)
-        {
-        this->recordApplicationSetting("geometry" , "MainWindow", "mainWindowGeometry",
-                                       QString(window->saveGeometry().toHex()));
-
-        this->recordApplicationSetting("state" , "MainWindow", "mainWindowState",
-                                       QString(window->saveState().toHex()));
-        break;
-        }
+      this->recordApplicationSetting("geometry" , "MainWindow", "mainWindowGeometry",
+                                     QString(window->saveGeometry().toHex()));
+
+      this->recordApplicationSetting("state" , "MainWindow", "mainWindowState",
+                                     QString(window->saveState().toHex()));
+      break;
       }
+    }
 
-    // Save extra properties from the application
-    QMap<QObject*, QStringList> states = this->TestUtility->objectStateProperty();
-    QMap<QObject*, QStringList>::iterator iter;
-    for(iter = states.begin() ; iter!=states.end() ; ++iter)
+  // Save extra properties from the application
+  QMap<QObject*, QStringList> states = this->TestUtility->objectStateProperty();
+  QMap<QObject*, QStringList>::iterator iter;
+  for(iter = states.begin() ; iter!=states.end() ; ++iter)
+    {
+    foreach(QString property, iter.value())
       {
-      foreach(QString property, iter.value())
-        {
-        this->recordApplicationSetting(
-            QString("appsetting"),
-            iter.key()->metaObject()->className(),
-            property,
-            iter.key()->property(property.toLatin1()).toString()
-            );
-        }
+      this->recordApplicationSetting(
+        QString("appsetting"),
+        iter.key()->metaObject()->className(),
+        property,
+        iter.key()->property(property.toLatin1()).toString()
+      );
       }
-
-    this->XMLStream->writeEndElement();
     }
+
+  this->XMLStream->writeEndElement();
 }
 
 //-----------------------------------------------------------------------------

+ 1 - 1
Libs/QtTesting/ctkXMLEventObserver.h

@@ -46,7 +46,7 @@ class CTK_QTTESTING_EXPORT ctkXMLEventObserver : public pqEventObserver
   Q_OBJECT
 
 public:
-  ctkXMLEventObserver(QObject* p);
+  ctkXMLEventObserver(QObject* testUtility);
   ~ctkXMLEventObserver();
 
   virtual void setStream(QTextStream* stream);

+ 4 - 3
Libs/QtTesting/ctkXMLEventSource.cpp

@@ -36,12 +36,13 @@
 // ctkXMLEventSource methods
 
 //-----------------------------------------------------------------------------
-ctkXMLEventSource::ctkXMLEventSource(QObject* p)
-  : Superclass(p)
+ctkXMLEventSource::ctkXMLEventSource(QObject* testUtility)
+  : Superclass(testUtility)
 {
   this->Automatic = false;
   this->XMLStream = NULL;
-  this->TestUtility = qobject_cast<pqTestUtility*>(p);
+  this->TestUtility = qobject_cast<pqTestUtility*>(testUtility);
+  Q_ASSERT(this->TestUtility);
 }
 
 //-----------------------------------------------------------------------------

+ 1 - 1
Libs/QtTesting/ctkXMLEventSource.h

@@ -44,7 +44,7 @@ class CTK_QTTESTING_EXPORT ctkXMLEventSource : public pqEventSource
 public:
   typedef pqEventSource Superclass;
 
-  ctkXMLEventSource(QObject* p);
+  ctkXMLEventSource(QObject* testUtility);
   ~ctkXMLEventSource();
 
   virtual void setContent(const QString& xmlfilename);