Browse Source

Merge branch '249-qttesting-app-crash'

* 249-qttesting-app-crash:
  QtTesting: Cleanup QtTesting app
  QtTesting: Disable and delete pqNativeFileDialogEventTranslator
  QtTesting app: Pass pqTestUtility to ctkXMLEvent*
  QtTesting app: enable VTK rendering
Julien Finet 12 years ago
parent
commit
45d837c662

+ 19 - 15
Applications/ctkQtTesting/ctkQtTestingMainWindow.cpp

@@ -39,18 +39,17 @@ ctkQtTestingMainWindow::ctkQtTestingMainWindow()
 {
   this->Ui.setupUi(this);
 
-  QObject::connect(Ui.RecordButton, SIGNAL(clicked(bool)), this, SLOT(record()));
-  QObject::connect(Ui.PlayBackButton, SIGNAL(clicked(bool)), this, SLOT(play()));
+  QObject::connect(Ui.RecordButton, SIGNAL(toggled(bool)), this, SLOT(record(bool)));
+  QObject::connect(Ui.PlayBackButton, SIGNAL(clicked()), 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));
   Ui.renderView->setGradientBackground(true);
   Ui.renderView->setCornerAnnotationText("ctk Qt test");
-  Ui.renderView->show();
 
   // Create a cube.
   vtkSmartPointer<vtkCubeSource> cubeSource =
@@ -74,10 +73,6 @@ ctkQtTestingMainWindow::ctkQtTestingMainWindow()
 //  boxWidget->PlaceWidget();
 //  boxWidget->On();
 
-  // Render and interact
-//  Ui.renderView->renderWindow()->Render();
-//  Ui.renderView->interactor()->Start();
-
   Ui.renderView->resetCamera();
 }
 
@@ -91,14 +86,22 @@ ctkQtTestingMainWindow::~ctkQtTestingMainWindow()
 }
 
 //-----------------------------------------------------------------------------
-void ctkQtTestingMainWindow::record()
+void ctkQtTestingMainWindow::record(bool start)
 {
-  qDebug() << "Start Record";
-  QString filename = QFileDialog::getSaveFileName (this, "Test File Name",
-    QString(), "XML Files (*.xml)");
-  if (!filename.isEmpty())
+  if (start)
+    {
+    QString filename = QFileDialog::getSaveFileName (this, "Test File Name",
+                                                     QString(), "XML Files (*.xml)");
+    if (!filename.isEmpty())
+      {
+      qDebug() << "Start recording";
+      this->TestUtility->recordTests(filename);
+      }
+    }
+  else
     {
-    this->TestUtility->recordTests(filename);
+    qDebug() << "Stop recording";
+    this->TestUtility->stopRecords(1);
     }
 }
 
@@ -112,4 +115,5 @@ void ctkQtTestingMainWindow::play()
     {
     this->TestUtility->playTests(filename);
     }
+  qDebug() << "End Playback";
 }

+ 1 - 1
Applications/ctkQtTesting/ctkQtTestingMainWindow.h

@@ -14,7 +14,7 @@ public:
   ctkQtTestingMainWindow();
   ~ctkQtTestingMainWindow();
 protected slots:
-  void record();
+  void record(bool start);
   void play();
 
 private:

+ 4 - 7
Applications/ctkQtTesting/ctkQtTestingMainWindow.ui

@@ -28,9 +28,6 @@
         <property name="enabled">
          <bool>true</bool>
         </property>
-        <property name="mouseTracking">
-         <bool>false</bool>
-        </property>
         <property name="backgroundColor">
          <color>
           <red>51</red>
@@ -48,9 +45,6 @@
         <property name="gradientBackground">
          <bool>false</bool>
         </property>
-        <property name="renderEnabled">
-         <bool>false</bool>
-        </property>
         <property name="orientationWidgetVisible">
          <bool>true</bool>
         </property>
@@ -108,7 +102,10 @@
       <item>
        <widget class="QPushButton" name="RecordButton">
         <property name="text">
-         <string>Start Record</string>
+         <string>Record</string>
+        </property>
+        <property name="checkable">
+         <bool>true</bool>
         </property>
        </widget>
       </item>

+ 14 - 2
Libs/QtTesting/ctkQtTestingUtility.cpp.in

@@ -26,8 +26,14 @@ void ctkQtTestingUtility::addDefaultCTKWidgetEventTranslatorsToTranslator(pqTest
 {
   Q_UNUSED(util);
 @CTK_ADD_WIDGET_EVENT_TRANSLATORS@
-  this->eventTranslator()->removeWidgetEventTranslator(
+  pqWidgetEventTranslator* translator = this->eventTranslator()->getWidgetEventTranslator(
     QLatin1String("pqNativeFileDialogEventTranslator"));
+  if (translator)
+    {
+    this->eventTranslator()->removeWidgetEventTranslator(
+      QLatin1String("pqNativeFileDialogEventTranslator"));
+    delete translator;
+    }
 }
 
 //-----------------------------------------------------------------------------
@@ -35,8 +41,14 @@ void ctkQtTestingUtility::addDefaultCTKWidgetEventPlayersToPlayer(pqTestUtility*
 {
   Q_UNUSED(util);
 @CTK_ADD_WIDGET_EVENT_PLAYERS@
-  this->eventPlayer()->removeWidgetEventPlayer(
+  pqWidgetEventPlayer* player = this->eventPlayer()->getWidgetEventPlayer(
     QLatin1String("pqNativeFileDialogEventPlayer"));
+  if (player)
+    {
+    this->eventPlayer()->removeWidgetEventPlayer(
+      QLatin1String("pqNativeFileDialogEventPlayer"));
+    delete player;
+    }
 }
 
 //-----------------------------------------------------------------------------

+ 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);