From: sbh Date: Tue, 29 Apr 2014 07:35:46 +0000 (+0400) Subject: Application errors handling X-Git-Tag: V_0.2~110 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=d0128ef99f0d27b41c61eb74770ed6a6cbdf56c9;p=modules%2Fshaper.git Application errors handling --- diff --git a/src/Events/CMakeLists.txt b/src/Events/CMakeLists.txt index 08c3903c2..89a27f31c 100644 --- a/src/Events/CMakeLists.txt +++ b/src/Events/CMakeLists.txt @@ -5,12 +5,14 @@ SET(PROJECT_HEADERS Events_Message.h Events_Listener.h Events_Loop.h + Events_Error.h ) SET(PROJECT_SOURCES Events_Message.cpp Events_Listener.cpp Events_Loop.cpp + Events_Error.cpp ) ADD_DEFINITIONS(-DEVENTS_EXPORTS) diff --git a/src/Events/Events_Error.cpp b/src/Events/Events_Error.cpp new file mode 100644 index 000000000..eba313e5f --- /dev/null +++ b/src/Events/Events_Error.cpp @@ -0,0 +1,41 @@ +/* + * Events_Error.cpp + * + * Created on: Apr 28, 2014 + * Author: sbh + */ + +#include +#include + +Events_Error::Events_Error(char* theDescription, const void* theSender) + : Events_Message(Events_Error::errorID(), theSender) +{ + myDescription = theDescription; +} + +Events_Error::~Events_Error() +{ +} + +Events_ID Events_Error::errorID() +{ + Events_Loop* aLoop = Events_Loop::loop(); + return aLoop->eventByName("ApplicationError"); +} + +char* Events_Error::description() const +{ + return myDescription; +} + +void Events_Error::send(char* theDescription, const void* theSender) +{ + Events_Error anError(theDescription, theSender); + Events_Loop::loop()->send(anError); +} + +static void send(std::string theDescription, const void* theSender = 0) +{ + Events_Error::send(theDescription.c_str(), theSender); +} diff --git a/src/Events/Events_Error.h b/src/Events/Events_Error.h new file mode 100644 index 000000000..7e2e62e29 --- /dev/null +++ b/src/Events/Events_Error.h @@ -0,0 +1,32 @@ +/* + * Events_Error.h + * + * Created on: Apr 28, 2014 + * Author: sbh + */ + +#ifndef EVENTS_ERROR_H_ +#define EVENTS_ERROR_H_ + +#include +#include + +#include + +class EVENTS_EXPORT Events_Error: public Events_Message +{ + char* myDescription; ///< pointer to the description of the error + +public: + virtual ~Events_Error(); + + static Events_ID errorID(); + char* description() const; + static void send(char* theDescription, const void* theSender = 0); + static void send(std::string theDescription, const void* theSender = 0); + +protected: + Events_Error(char* theDescription, const void* theSender = 0); +}; + +#endif /* EVENTS_ERROR_H_ */ diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 8acf0c38c..9eece1559 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include diff --git a/src/XGUI/CMakeLists.txt b/src/XGUI/CMakeLists.txt index 989980d3b..d8de8a441 100644 --- a/src/XGUI/CMakeLists.txt +++ b/src/XGUI/CMakeLists.txt @@ -27,6 +27,7 @@ SET(PROJECT_HEADERS XGUI_SelectionMgr.h XGUI_SalomeConnector.h XGUI_ActionsMgr.h + XGUI_ErrorDialog.h ) SET(PROJECT_AUTOMOC @@ -53,6 +54,7 @@ SET(PROJECT_SOURCES XGUI_OperationMgr.cpp XGUI_SelectionMgr.cpp XGUI_ActionsMgr.cpp + XGUI_ErrorDialog.cpp ) SET(PROJECT_RESOURCES diff --git a/src/XGUI/XGUI_ErrorDialog.cpp b/src/XGUI/XGUI_ErrorDialog.cpp new file mode 100644 index 000000000..5a8258dc0 --- /dev/null +++ b/src/XGUI/XGUI_ErrorDialog.cpp @@ -0,0 +1,66 @@ +/* + * XGUI_ErrorDialog.cpp + * + * Created on: Apr 28, 2014 + * Author: sbh + */ +#include + +#include +#include +#include +#include +#include + +XGUI_ErrorDialog::XGUI_ErrorDialog(QWidget* parent) + : QDialog(parent) +{ + QVBoxLayout* aDlgLay = new QVBoxLayout(this); + setWindowTitle(tr("Application errors")); + myErrorLog = new QTextEdit(this); + myErrorLog->setReadOnly(true); + aDlgLay->addWidget(myErrorLog); + QDialogButtonBox* aButtonBox = + new QDialogButtonBox(QDialogButtonBox::Close, Qt::Horizontal, this); + aDlgLay->addWidget(aButtonBox); + aDlgLay->setContentsMargins(2,2,2,2); + aDlgLay->setSpacing(2); + setLayout(aDlgLay); + resize(420, 240); + + connect(aButtonBox, SIGNAL(accepted()), this, SLOT(clear())); + connect(aButtonBox, SIGNAL(rejected()), this, SLOT(clear())); +} + +XGUI_ErrorDialog::~XGUI_ErrorDialog() +{ +} + +void XGUI_ErrorDialog::refresh() +{ + myErrorLog->clear(); + foreach(QString eachError, myErrors) + { + myErrorLog->append(eachError); + } +} + +void XGUI_ErrorDialog::clear() +{ + myErrorLog->clear(); + myErrors.clear(); + QDialog::reject(); +} + +void XGUI_ErrorDialog::addError(const QString& theError) +{ + myErrors.append(theError); + refresh(); +} + +void XGUI_ErrorDialog::removeError(const QString& theError) +{ + myErrors.removeAll(theError); + refresh(); +} + diff --git a/src/XGUI/XGUI_ErrorDialog.h b/src/XGUI/XGUI_ErrorDialog.h new file mode 100644 index 000000000..59de5059a --- /dev/null +++ b/src/XGUI/XGUI_ErrorDialog.h @@ -0,0 +1,34 @@ +/* + * XGUI_ErrorDialog.h + * + * Created on: Apr 28, 2014 + * Author: sbh + */ + +#ifndef XGUI_ERRORDIALOG_H_ +#define XGUI_ERRORDIALOG_H_ + +#include +#include + +class QTextEdit; + +class XGUI_ErrorDialog: public QDialog +{ + Q_OBJECT +public: + XGUI_EXPORT XGUI_ErrorDialog(QWidget* parent); + XGUI_EXPORT virtual ~XGUI_ErrorDialog(); + +public slots: + XGUI_EXPORT void refresh(); + XGUI_EXPORT void clear(); + XGUI_EXPORT void addError(const QString&); + XGUI_EXPORT void removeError(const QString&); + +private: + QTextEdit* myErrorLog; + QStringList myErrors; +}; + +#endif /* XGUI_ERRORDIALOG_H_ */ diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 6186aaedd..dd6e1200f 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -15,6 +15,7 @@ #include "XGUI_OperationMgr.h" #include "XGUI_SalomeConnector.h" #include "XGUI_ActionsMgr.h" +#include "XGUI_ErrorDialog.h" #include #include @@ -22,6 +23,7 @@ #include #include +#include #include #include #include @@ -63,9 +65,12 @@ XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector) mySelector = new XGUI_SelectionMgr(this); myOperationMgr = new XGUI_OperationMgr(this); myActionsMgr = new XGUI_ActionsMgr(this); + myErrorDlg = new XGUI_ErrorDialog(myMainWindow); + connect(myOperationMgr, SIGNAL(operationStarted()), this, SLOT(onOperationStarted())); connect(myOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)), this, SLOT(onOperationStopped(ModuleBase_Operation*))); + connect(this, SIGNAL(errorOccurred(const QString&)), myErrorDlg, SLOT(addError(const QString&))); } //****************************************************** @@ -79,6 +84,7 @@ void XGUI_Workshop::startApplication() initMenu(); //Initialize event listening Events_Loop* aLoop = Events_Loop::loop(); + aLoop->registerListener(this, Events_Error::errorID()); //!< Listening application errors. //TODO(sbh): Implement static method to extract event id [SEID] Events_ID aFeatureId = aLoop->eventByName("FeatureEvent"); aLoop->registerListener(this, aFeatureId); @@ -175,13 +181,11 @@ void XGUI_Workshop::processEvent(const Events_Message* theMessage) { static Events_ID aFeatureId = Events_Loop::loop()->eventByName("FeatureEvent"); if (theMessage->eventID() == aFeatureId) { - const Config_FeatureMessage* aFeatureMsg = - dynamic_cast(theMessage); + const Config_FeatureMessage* aFeatureMsg = dynamic_cast(theMessage); addFeature(aFeatureMsg); return; } - const Config_PointerMessage* aPartSetMsg = - dynamic_cast(theMessage); + const Config_PointerMessage* aPartSetMsg = dynamic_cast(theMessage); if (aPartSetMsg) { ModuleBase_PropPanelOperation* anOperation = (ModuleBase_PropPanelOperation*)(aPartSetMsg->pointer()); @@ -194,6 +198,13 @@ void XGUI_Workshop::processEvent(const Events_Message* theMessage) } return; } + const Events_Error* anAppError = dynamic_cast(theMessage); + if (anAppError) { + emit errorOccurred(QString::fromLatin1(anAppError->description())); + myErrorDlg->show(); + myErrorDlg->raise(); + myErrorDlg->activateWindow(); + } #ifdef _DEBUG qDebug() << "XGUI_Workshop::ProcessEvent: " diff --git a/src/XGUI/XGUI_Workshop.h b/src/XGUI/XGUI_Workshop.h index bedb8bbe1..6406381ed 100644 --- a/src/XGUI/XGUI_Workshop.h +++ b/src/XGUI/XGUI_Workshop.h @@ -19,6 +19,7 @@ class XGUI_OperationMgr; class XGUI_SalomeConnector; class XGUI_ObjectsBrowser; class XGUI_ActionsMgr; +class XGUI_ErrorDialog; class ModuleBase_Operation; class ModuleBase_PropPanelOperation; @@ -90,6 +91,9 @@ public slots: void onFeatureTriggered(); +signals: + void errorOccurred(const QString&); + protected: //Event-loop processing methods: void addFeature(const Config_FeatureMessage*); @@ -128,6 +132,7 @@ private: XGUI_OperationMgr* myOperationMgr; ///< manager to manipulate through the operations XGUI_ActionsMgr* myActionsMgr; XGUI_SalomeConnector* mySalomeConnector; + XGUI_ErrorDialog* myErrorDlg; }; #endif