Commit 9e5eb8ff authored by Mario Hlawitschka's avatar Mario Hlawitschka
Browse files

[ADD] I reintroduced WApplication on OSX because it works there and added...

[ADD] I reintroduced WApplication on OSX because it works there and added catching of uncaught exceptions in the event handler to avoid crashing the software and being able to provide an appropriate bug warning.
parent bdb566c0
......@@ -22,6 +22,8 @@
//
//---------------------------------------------------------------------------
#include <exception>
#include <QtGui/QtGui>
#include "WMainWindow.h"
......@@ -29,31 +31,45 @@
#include "WApplication.h"
#include "WApplication.moc"
#include "core/common/WException.h"
WApplication::WApplication( int argc, char** argv, bool GUIenabled )
: QApplication( argc, argv, GUIenabled ),
myMainWindow( 0 )
: QApplication( argc, argv, GUIenabled )
, myMainWidget( 0 )
{
}
void WApplication::setMyMainWindow( WMainWindow* window )
void WApplication::setMyMainWidget( QWidget* widget )
{
myMainWindow = window;
myMainWidget = widget;
}
void WApplication::commitData( QSessionManager& manager ) // NOLINT
{
if( !myMainWidget )
{
manager.release(); // no main window, nothing to store, yet
return;
}
WMainWindow* mainWindow = dynamic_cast<WMainWindow*>(myMainWidget);
if( !mainWindow )
{
manager.release(); // not our main class, can't store
return;
}
QApplication::commitData( manager );
if ( manager.allowsInteraction() )
{
int ret = QMessageBox::warning(
myMainWindow,
myMainWidget,
tr( "OpenWalnut" ),
tr( "Save changes?" ),
QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel );
switch ( ret )
{
case QMessageBox::Save:
if ( myMainWindow->projectSaveAll() )
if ( mainWindow->projectSaveAll() )
{
// we want to save and saving was successful, we are ready!
manager.release();
......@@ -77,3 +93,27 @@ void WApplication::commitData( QSessionManager& manager ) // NOLINT
}
}
bool WApplication::notify( QObject* object, QEvent* event )
{
bool retval = false;
try
{
// do the default action, but catch exceptions
retval = QApplication::notify( object, event );
}
catch( WException &we )
{
std::cout << "thrown uncaught WException: " << we.what() << std::endl;
QMessageBox::critical( myMainWidget, tr("Uncaught Exception"),
tr("An uncaught exception occurred which may be due to a corrupt installation or a programming bug. Please check the openwalnut bug reporter for similar tickets and report the issue including the following text:<br>")
+ we.what() );
}
catch( std::exception &se )
{
std::cout << "thrown uncaught std::exception: " << se.what() << std::endl;
QMessageBox::critical( myMainWidget, tr("Uncaught Exception"),
tr("An uncaught exception occurred which may be due to a corrupt installation or a programming bug. Please check the openwalnut bug reporter for similar tickets and report the issue including the following text:<br>")
+ se.what() );
}
return retval;
}
......@@ -31,7 +31,7 @@ class WMainWindow;
/**
* Overloaded base class for our application that has initial handling of
* session data
* session data and catches uncaught exceptions.
*/
class WApplication : public QApplication
{
......@@ -40,17 +40,24 @@ public:
/** default constructor, see QApplication */
WApplication( int argc, char** argv, bool GUIenabled = true );
/** stores the main window used as parent for dialogs */
void setMyMainWindow( WMainWindow* window );
/** manage save dialogs when the session manager asks us to
* take care of our data.
* This is an overloaded function from QT.
*/
virtual void commitData( QSessionManager& manager ); // NOLINT
/**
* store the main widget for error reporting and session management
*/
void setMyMainWidget( QWidget* widget );
/**
* Overloaded to catch uncaught exceptions in event handlers and displays a bug-warning.
*/
virtual bool notify( QObject* receiver, QEvent* e );
protected:
WMainWindow* myMainWindow;
QWidget* myMainWidget;
};
#endif // WAPPLICATION_H
......@@ -143,8 +143,13 @@ int WQt4Gui::run()
m_loggerConnection = WLogger::getLogger()->subscribeSignal( WLogger::AddLog, boost::bind( &WQt4Gui::slotAddLog, this, _1 ) );
// make qapp instance before using the applicationDirPath() function
#ifdef Q_WS_MAC
//TODO(mario): this should run on all platforms but crashes at least on Linux right now. Therefore, I only use it on OSX
WApplication appl( m_argc, m_argv, true );
#else
QApplication appl( m_argc, m_argv, true ); // TODO( mario ): I want a WApplication here for session handling but that code crashes
#endif
// the call path of the application, this uses QApplication which needs to be instantiated.
boost::filesystem::path walnutBin = boost::filesystem::path( QApplication::applicationDirPath().toStdString() );
// setup path helper which provides several paths to others^
......@@ -210,9 +215,12 @@ int WQt4Gui::run()
// create the window
m_mainWindow = new WMainWindow();
#ifdef Q_WS_MAC
//TODO(mario): this should run on all platforms but crashes at least on Linux right now. Therefore, I only use it on OSX
appl.setMyMainWidget( m_mainWindow );
#endif
m_mainWindow->setupGUI();
m_mainWindow->show();
//appl.setMyMainWindow( m_mainWindow ); // TODO( mario ) removed due to crash
// connect out loader signal with kernel
#ifdef _WIN32
......
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