Commits

Rashad M committed 298dfdc

BUG: catching expceptions that can't be handled by Qt

Comments (0)

Files changed (8)

Code/BasicFilters/otbLabelImageRegionPruningFilter.txx

         m_PointCounts[label] = newPointCounts[canLabel];
         }
       }
-    /* -Wunused-variable
+
     unsigned int oldRegionCount = regionCount;
-    */
+
     regionCount = label;
 
     /* reassign labels in label image */

Code/UtilitiesAdapters/OGRAdapters/otbOGRFieldWrapper.txx

   typedef typename boost::mpl::at<internal::FieldType_Map, InterfaceType>::type Kind;
   BOOST_MPL_ASSERT_MSG(!(boost::is_same<Kind, boost::mpl::void_>::value), UNEXPECTED_KIND_TYPE, (T, InterfaceType, Kind));
   //const int VALUE = Kind::value;
-  assert(m_Definition.GetType() == VALUE && "OGR field type mismatches the type of new field value");
+  assert(m_Definition.GetType() == Kind::value && "OGR field type mismatches the type of new field value");
   typedef typename boost::mpl::at<internal::FieldSetters_Map, Kind>::type SetterType;
   // If you experience a static assertion failure in the line below, it means
   // the type of the parameter is not supported to set a field.
   typedef typename boost::mpl::at<internal::FieldType_Map, T>::type Kind;
   //const int VALUE = Kind::value;
   BOOST_STATIC_ASSERT(!(boost::is_same<Kind, boost::mpl::void_>::value));
-  assert(m_Definition.GetType() == VALUE && "OGR field type mismatches the type of requested field value");
+  assert(m_Definition.GetType() == Kind::value && "OGR field type mismatches the type of requested field value");
   typedef typename boost::mpl::at<internal::FieldGetters_Map, Kind>::type GetterType;
   // If you experience a static assertion failure in the line below, it means
   // the field cannot be extracted into the type requested.

Code/Wrappers/ApplicationLauncherQt/otbApplicationLauncherQt.cxx

 #include "otbWrapperApplicationRegistry.h"
 #include "otbWrapperQtWidgetView.h"
 #include "otbWrapperQtWidgetSimpleProgressReport.h"
+#include "otbQtApplication.h"
 #include "itksys/SystemTools.hxx"
 
 using otb::Wrapper::Application;
 using otb::Wrapper::QtWidgetView;
 //using otb::Wrapper::QtWidgetProgressReport;
 using otb::Wrapper::QtWidgetSimpleProgressReport;
+using otb::Wrapper::QtApplication;
 
 int main(int argc, char* argv[])
 {
   QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
   QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
 
-  QApplication qtApp(argc, argv);
+  QtApplication qtApp(argc, argv);
 
   if (argc < 2)
     {
   // Connect the View "Quit" signal, to the mainWindow close slot
   QObject::connect(gui, SIGNAL(QuitSignal()), mainWindow, SLOT(close()));
 
+  QObject::connect(&qtApp, SIGNAL(UnhandledException(QString)), gui, SLOT(UnhandledException(QString)));
+
+
   // build the main window, central widget is the plugin view, other
   // are docked widget (progress, logs...)
   mainWindow->setCentralWidget(gui);
-  
+
   // Show the main window
   mainWindow->show();
 

Code/Wrappers/QtWidget/CMakeLists.txt

        otbWrapperQtWidgetListViewParameter.h
        otbQtFileSelectionWidget.h
        otbQtStringSelectionWidget.h
+       otbQtApplication.h
        itkQtProgressBar.h
        otbWrapperQtWidgetInputFilenameParameter.h
        otbWrapperQtWidgetInputFilenameListParameter.h

Code/Wrappers/QtWidget/otbQtApplication.cxx

+/*=========================================================================
+
+  Program:   ORFEO Toolbox
+  Language:  C++
+  Date:      $Date$
+  Version:   $Revision$
+
+
+  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
+  See OTBCopyright.txt for details.
+
+
+     This software is distributed WITHOUT ANY WARRANTY; without even
+     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+     PURPOSE.  See the above copyright notices for more information.
+
+=========================================================================*/
+#include "otbQtApplication.h"
+#include <QObject>
+#include <iostream>
+namespace otb
+{
+namespace Wrapper
+{
+QtApplication::QtApplication(int& argc, char** argv)
+  : QApplication(argc, argv)
+{
+
+}
+
+bool
+QtApplication::notify(QObject *object, QEvent* event)
+  {
+    try
+      {
+      return QApplication::notify(object, event);
+      }
+    catch (std::exception &ex)
+      {
+      QString message = QString("<center><font color=\"#FF0000\">");
+      message.append(ex.what());
+      message.append("</font></center>");
+      emit UnhandledException(message);
+      }
+    return false;
+  }
+
+} //end of namespace Wrapper
+} //end of namespace otb

Code/Wrappers/QtWidget/otbQtApplication.h

+/*=========================================================================
+
+  Program:   ORFEO Toolbox
+  Language:  C++
+  Date:      $Date$
+  Version:   $Revision$
+
+
+  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
+  See OTBCopyright.txt for details.
+
+
+     This software is distributed WITHOUT ANY WARRANTY; without even
+     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+     PURPOSE.  See the above copyright notices for more information.
+
+=========================================================================*/
+
+#ifndef __otbQtApplication_h
+#define __otbQtApplication_h
+
+#include <QtGui>
+#include <QString>
+namespace otb
+{
+namespace Wrapper
+{
+class QtApplication : public QApplication
+{
+  Q_OBJECT
+
+public:
+  QtApplication(int& argc, char** argv);
+
+  bool notify(QObject *object, QEvent* event);
+
+signals:
+
+  void UnhandledException(QString message);
+};
+
+} //end of namespace Wrapper
+} //end of namepsace otb
+
+#endif

Code/Wrappers/QtWidget/otbWrapperQtWidgetView.cxx

 {
   // Create a VBoxLayout with the header, the input widgets, and the footer
   QVBoxLayout *mainLayout = new QVBoxLayout();
-  QTabWidget *tab = new QTabWidget();
+  m_TabWidget = new QTabWidget();
  
-  tab->addTab(CreateInputWidgets(), "Parameters");
-  QTextEdit *log = new QTextEdit();
-  connect( m_Model->GetLogOutput(), SIGNAL(NewContentLog(QString)), log, SLOT(append(QString) ) );
-  tab->addTab(log, "Logs");
+  m_TabWidget->addTab(CreateInputWidgets(), "Parameters");
+  m_LogText = new QTextEdit();
+  connect( m_Model->GetLogOutput(), SIGNAL(NewContentLog(QString)), m_LogText, SLOT(append(QString) ) );
+  m_TabWidget->addTab(m_LogText, "Logs");
   QtWidgetProgressReport* prog =  new QtWidgetProgressReport(m_Model);
   prog->SetApplication(m_Application);
-  tab->addTab(prog, "Progress");
-  tab->addTab(CreateDoc(), "Documentation");
-  mainLayout->addWidget(tab);
+  m_TabWidget->addTab(prog, "Progress");
+  m_TabWidget->addTab(CreateDoc(), "Documentation");
+  mainLayout->addWidget(m_TabWidget);
 
   m_Message = new QLabel("<center><font color=\"#FF0000\">Select parameters</font></center>");
   connect( m_Model, SIGNAL(SetApplicationReady(bool)), this, SLOT(UpdateMessageAfterApplicationReady(bool)) );
   emit QuitSignal();
 }
 
+void QtWidgetView::UnhandledException(QString message)
+{
+  m_TabWidget->setCurrentIndex(1);
+  m_LogText->append(message);
 }
+
 }
+}

Code/Wrappers/QtWidget/otbWrapperQtWidgetView.h

 
 public slots:
   void CloseSlot();
+  void UnhandledException(QString message);
 
 private slots:
   void UpdateMessageAfterExcuteClicked();
 
   QtWidgetModel* m_Model;
 
+  QTextEdit *m_LogText;
+  QTabWidget *m_TabWidget;
+
   QPushButton* m_ExecButton;
   QPushButton* m_QuitButton;
   QLabel* m_Message;