notify() for MApplication.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2015-09-19 23:08:03 +03:00
parent b5c6bf8260
commit 274cbb3aad
2 changed files with 70 additions and 0 deletions

View file

@ -29,6 +29,13 @@
#include "mapplication.h"
#include "version.h"
#include "tmainwindow.h"
#include "../ifc/exception/vexceptionobjecterror.h"
#include "../ifc/exception/vexceptionbadid.h"
#include "../ifc/exception/vexceptionconversionerror.h"
#include "../ifc/exception/vexceptionemptyparameter.h"
#include "../ifc/exception/vexceptionwrongid.h"
#include "../vmisc/logging.h"
#include "../qmuparser/qmuparsererror.h"
#include <QDir>
#include <QFileOpenEvent>
@ -40,6 +47,8 @@
#include <QMessageBox>
#include <iostream>
Q_LOGGING_CATEGORY(mApp, "m.application")
#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0)
# include "../../libs/vmisc/backport/qcommandlineparser.h"
#else
@ -188,6 +197,65 @@ MApplication::~MApplication()
}
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief notify Reimplemented from QApplication::notify().
* @param receiver receiver.
* @param event event.
* @return value that is returned from the receiver's event handler.
*/
// reimplemented from QApplication so we can throw exceptions in slots
bool MApplication::notify(QObject *receiver, QEvent *event)
{
try
{
return QApplication::notify(receiver, event);
}
catch (const VExceptionObjectError &e)
{
e.CriticalMessageBox(tr("Error parsing file. Program will be terminated."), mainWindow);
abort();
}
catch (const VExceptionBadId &e)
{
e.CriticalMessageBox(tr("Error bad id. Program will be terminated."), mainWindow);
abort();
}
catch (const VExceptionConversionError &e)
{
e.CriticalMessageBox(tr("Error can't convert value. Program will be terminated."), mainWindow);
abort();
}
catch (const VExceptionEmptyParameter &e)
{
e.CriticalMessageBox(tr("Error empty parameter. Program will be terminated."), mainWindow);
abort();
}
catch (const VExceptionWrongId &e)
{
e.CriticalMessageBox(tr("Error wrong id. Program will be terminated."), mainWindow);
abort();
}
catch (const VException &e)
{
e.CriticalMessageBox(tr("Something's wrong!!"), mainWindow);
return true;
}
// These last two cases special. I found that we can't show here modal dialog with error message.
// Somehow program doesn't waite untile an error dialog will be closed. But if ignore this program will hang.
catch (const qmu::QmuParserError &e)
{
qCDebug(mApp, "Parser error: %s", e.GetMsg().toUtf8().constData());
abort();
}
catch (std::exception& e)
{
qCDebug(mApp, "Critical error! Exception thrown: %s", e.what());
abort();
}
return false;
}
//---------------------------------------------------------------------------------------------------------------------
bool MApplication::IsTheOnly() const
{

View file

@ -52,6 +52,8 @@ public:
MApplication(int &argc, char **argv);
virtual ~MApplication() Q_DECL_OVERRIDE;
virtual bool notify(QObject * receiver, QEvent * event) Q_DECL_OVERRIDE;
bool IsTheOnly() const;
TMainWindow *MainWindow();
QList<TMainWindow*> MainWindows();