From: sbh Date: Fri, 12 Sep 2014 14:49:16 +0000 (+0400) Subject: Issue #79 GUI part for posting NewGeom messages through Qt's event system X-Git-Tag: V_0.4.4~59^2~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=cc746922e5b3f93618e4341f24c0173244297d41;p=modules%2Fshaper.git Issue #79 GUI part for posting NewGeom messages through Qt's event system --- diff --git a/src/Config/Config_ValidatorMessage.h b/src/Config/Config_ValidatorMessage.h index e344cd886..16ec27922 100644 --- a/src/Config/Config_ValidatorMessage.h +++ b/src/Config/Config_ValidatorMessage.h @@ -5,8 +5,8 @@ * Author: sbh */ -#ifndef Config_ValidatorMessage_H_ -#define Config_ValidatorMessage_H_ +#ifndef CONFIG_VALIDATORMESSAGE_H_ +#define CONFIG_VALIDATORMESSAGE_H_ #include #include @@ -25,16 +25,21 @@ class Config_ValidatorMessage : public Events_Message std::list myVaidatorParameters; public: - CONFIG_EXPORT Config_ValidatorMessage(const Events_ID theId, const void* theParent = 0);CONFIG_EXPORT virtual ~Config_ValidatorMessage(); + CONFIG_EXPORT Config_ValidatorMessage(const Events_ID theId, const void* theParent = 0); + CONFIG_EXPORT virtual ~Config_ValidatorMessage(); //CONFIG_EXPORT static const char* UID() const; - CONFIG_EXPORT const std::string& validatorId() const;CONFIG_EXPORT const std::string& featureId() const;CONFIG_EXPORT const std::string& attributeId() const;CONFIG_EXPORT const std::list< - std::string>& parameters() const;CONFIG_EXPORT bool isValid() const; + CONFIG_EXPORT const std::string& validatorId() const; + CONFIG_EXPORT const std::string& featureId() const; + CONFIG_EXPORT const std::string& attributeId() const; + CONFIG_EXPORT const std::list& parameters() const; + CONFIG_EXPORT bool isValid() const; - CONFIG_EXPORT void setValidatorId(const std::string& theId);CONFIG_EXPORT void setFeatureId( - const std::string& theId);CONFIG_EXPORT void setAttributeId(const std::string& theId);CONFIG_EXPORT void setValidatorParameters( - const std::list& parameters); + CONFIG_EXPORT void setValidatorId(const std::string& theId); + CONFIG_EXPORT void setFeatureId(const std::string& theId); + CONFIG_EXPORT void setAttributeId(const std::string& theId); + CONFIG_EXPORT void setValidatorParameters(const std::list& parameters); }; #endif /* Config_ValidatorMessage_H_ */ diff --git a/src/XGUI/CMakeLists.txt b/src/XGUI/CMakeLists.txt index 9f336606e..34fe79010 100644 --- a/src/XGUI/CMakeLists.txt +++ b/src/XGUI/CMakeLists.txt @@ -33,6 +33,7 @@ SET(PROJECT_HEADERS XGUI_Selection.h XGUI_Preferences.h XGUI_IPrefMgr.h + XGUI_QtEvents.h ) SET(PROJECT_AUTOMOC @@ -65,6 +66,7 @@ SET(PROJECT_SOURCES XGUI_ModuleConnector.cpp XGUI_Selection.cpp XGUI_Preferences.cpp + XGUI_QtEvents.cpp ) SET(PROJECT_RESOURCES diff --git a/src/XGUI/XGUI_QtEvents.cpp b/src/XGUI/XGUI_QtEvents.cpp new file mode 100644 index 000000000..e3eb2b091 --- /dev/null +++ b/src/XGUI/XGUI_QtEvents.cpp @@ -0,0 +1,19 @@ +/* + * XGUI_QEvents.cpp + * + * Created on: Sep 12, 2014 + * Author: sbh + */ + +#include "XGUI_QtEvents.h" + +QEvent::Type PostponeMessageQtEvent::PostponeMessageQtEventType = QEvent::Type(QEvent::registerEventType()); + + +//TODO(mpv): #4 +//boost::shared_ptr PostponeMessageQtEvent::postponedMessage() +boost::shared_ptr PostponeMessageQtEvent::resultDoc() +{ + return myTestDoc; +} + diff --git a/src/XGUI/XGUI_QtEvents.h b/src/XGUI/XGUI_QtEvents.h new file mode 100644 index 000000000..5c415a278 --- /dev/null +++ b/src/XGUI/XGUI_QtEvents.h @@ -0,0 +1,50 @@ +/* + * XGUI_QEvents.h + * + * Created on: Sep 12, 2014 + * Author: sbh + */ + +#ifndef XGUI_QTEVENTS_H_ +#define XGUI_QTEVENTS_H_ + +#include + +#include +#include + +#include +#include + +class XGUI_EXPORT PostponeMessageQtEvent : public QEvent +{ + public: + static QEvent::Type PostponeMessageQtEventType; + + //TODO(mpv): ModelAPI_Document is taken here for example + //the commented code should be ok when you implement boost::shared_ptr on Events_Message + //the same for #1-4 + PostponeMessageQtEvent(boost::shared_ptr theDoc) + //PostponeMessageQtEvent(boost::shared_ptr theMessage) + : QEvent(PostponeMessageQtEventType), + //TODO(mpv): #1 + //myMessage(theMessage) + myTestDoc(theDoc) + { + } + static QEvent::Type type() + { + return PostponeMessageQtEventType; + } + + //TODO(mpv): #2 + //boost::shared_ptr postponedMessage(); + boost::shared_ptr resultDoc(); + + private: + //TODO(mpv): #3 + //boost::shared_ptr myMessage; + boost::shared_ptr myTestDoc; +}; + +#endif /* XGUI_QEVENTS_H_ */ diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 27b9716ac..bc7625b9a 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -22,6 +22,7 @@ #include "XGUI_ContextMenuMgr.h" #include "XGUI_ModuleConnector.h" #include "XGUI_Preferences.h" +#include #include #include @@ -57,10 +58,12 @@ #include #include #include -#include +#include +#include #ifdef _DEBUG #include +#include #endif #ifdef WIN32 @@ -232,6 +235,16 @@ XGUI_Workbench* XGUI_Workshop::addWorkbench(const QString& theName) //****************************************************** void XGUI_Workshop::processEvent(const Events_Message* theMessage) { + if (QApplication::instance()->thread() != QThread::currentThread()) { + #ifdef _DEBUG + std::cout << "XGUI_Workshop::processEvent: " << "Working in another thread." << std::endl; + #endif + SessionPtr aMgr = ModelAPI_Session::get(); + PostponeMessageQtEvent* aPostponeEvent = new PostponeMessageQtEvent(aMgr->activeDocument()); + QApplication::postEvent(this, aPostponeEvent); + return; + } + //A message to start feature creation received. if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_LOADED)) { const Config_FeatureMessage* aFeatureMsg = @@ -280,7 +293,6 @@ void XGUI_Workshop::processEvent(const Events_Message* theMessage) else if (theMessage->eventID() == Events_LongOp::eventID()) { if (Events_LongOp::isPerformed()) QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); - //QTimer::singleShot(10, this, SLOT(onStartWaiting())); else QApplication::restoreOverrideCursor(); } @@ -477,6 +489,31 @@ void XGUI_Workshop::onOperationStopped(ModuleBase_Operation* theOperation) myPropertyPanel->cleanContent(); } +bool XGUI_Workshop::event(QEvent * theEvent) +{ + PostponeMessageQtEvent* aPostponedEv = dynamic_cast(theEvent); + if (aPostponedEv) { +#ifdef _DEBUG + std::cout << "XGUI_Workshop::event " << "Got PostponeMessageQtEvent" << std::endl; + bool isMyThread = (QApplication::instance()->thread() == QThread::currentThread()); + std::cout << "XGUI_Workshop::event " << "I am in the Qt's thread: " + << isMyThread << std::endl; +#endif + boost::shared_ptr aDoc = aPostponedEv->resultDoc(); + if (aDoc) { +#ifdef _DEBUG + std::cout << "XGUI_Workshop::event " << "Passed boost ptr is ok, doc id: " << aDoc->id() + << std::endl; +#endif + } + //TODO(mpv): After modifications in the XGUI_QtEvents.* this code should be like... + //boost::shared_ptr aEventPtr = aPostponedEv->postponedMessage(); + //processEvent(aEventPtr); + return true; + } + return false; +} + /* * */ diff --git a/src/XGUI/XGUI_Workshop.h b/src/XGUI/XGUI_Workshop.h index b96986168..b4073224a 100644 --- a/src/XGUI/XGUI_Workshop.h +++ b/src/XGUI/XGUI_Workshop.h @@ -211,6 +211,7 @@ signals: void activateLastPart(); protected: + bool event(QEvent * theEvent); //Event-loop processing methods: void addFeature(const Config_FeatureMessage*); void connectWithOperation(ModuleBase_Operation* theOperation);