From: vsr Date: Thu, 24 May 2007 11:48:37 +0000 (+0000) Subject: Porting to Qt 4 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=29a0a7ec53d02adb7839609107f553d2eeea419b;p=modules%2Fgui.git Porting to Qt 4 --- diff --git a/src/Event/Event.h b/src/Event/Event.h index 472e385bc..9e2abddc8 100755 --- a/src/Event/Event.h +++ b/src/Event/Event.h @@ -16,35 +16,22 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -// -// -// File: SalomeApp.h -// Created: November, 2004 -// Author: OCC team -// Copyright (C) CEA 2004 +#if !defined ( EVENT_H ) +#define EVENT_H -// The following ifdef block is the standard way of creating macros which make exporting -// from a DLL simpler. All files within this DLL are compiled with the SalomeApp_EXPORTS -// symbol defined on the command line. this symbol should not be defined on any project -// that uses this DLL. This way any other project whose source files include this file see -// SalomeApp_API functions as being imported from a DLL, wheras this DLL sees symbols -// defined with this macro as being exported. #ifdef WIN32 - -#ifdef EVENT_EXPORTS -#define EVENT_EXPORT __declspec(dllexport) -#else -#define EVENT_EXPORT __declspec(dllimport) -#endif - -#else -#define EVENT_EXPORT -#endif //WIN32 - -#define APP_VERSION "0.1" +# ifdef EVENT_EXPORTS +# define EVENT_EXPORT __declspec(dllexport) +# else +# define EVENT_EXPORT __declspec(dllimport) +# endif +#else //WIN32 +# define EVENT_EXPORT +#endif //WIN32 #if defined WIN32 #pragma warning ( disable: 4251 ) #endif +#endif // EVENT_H diff --git a/src/Event/Event.pro b/src/Event/Event.pro index 4361449c1..b28d7bdca 100644 --- a/src/Event/Event.pro +++ b/src/Event/Event.pro @@ -4,9 +4,7 @@ DESTDIR = ../../lib MOC_DIR = ../../moc OBJECTS_DIR = ../../obj/$$TARGET -KERNEL_CXXFLAGS = $$(KERNEL_ROOT_DIR)/include/salome - -INCLUDEPATH += ../../include $${KERNEL_CXXFLAGS} +INCLUDEPATH += ../../include LIBS += CONFIG -= debug release debug_and_release @@ -16,7 +14,7 @@ win32:DEFINES += WIN32 DEFINES += EVENT_EXPORTS HEADERS = Event.h -HEADERS += SALOME_Event.hxx +HEADERS += SALOME_Event.h SOURCES = SALOME_Event.cxx diff --git a/src/Event/Makefile.am b/src/Event/Makefile.am index c9948969b..c848832b1 100755 --- a/src/Event/Makefile.am +++ b/src/Event/Makefile.am @@ -32,11 +32,11 @@ lib_LTLIBRARIES = libEvent.la salomeinclude_HEADERS= \ Event.h \ - SALOME_Event.hxx + SALOME_Event.h dist_libEvent_la_SOURCES = SALOME_Event.cxx -libEvent_la_CPPFLAGS=$(QT_INCLUDES) @KERNEL_CXXFLAGS@ +libEvent_la_CPPFLAGS=$(QT_INCLUDES) libEvent_la_LDFLAGS=$(QT_MT_LIBS) diff --git a/src/Event/SALOME_Event.cxx b/src/Event/SALOME_Event.cxx index f50cdc9c4..7faf45a7d 100755 --- a/src/Event/SALOME_Event.cxx +++ b/src/Event/SALOME_Event.cxx @@ -19,60 +19,118 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -// -// // File : SALOME_Event.cxx // Author : Sergey ANIKIN -// Module : KERNEL -// $Header$ - -#include "SALOME_Event.hxx" -//#include "utilities.h" +#include "SALOME_Event.h" #include #include // asv 21.02.05 : introducing multi-platform approach of thread comparison -// on Unix using pthread_t type for storing ThreadId -// on Win32 using integer type for storing ThreadId +// - on Unix using pthread_t type for storing ThreadId +// - on Win32 using integer type for storing ThreadId // NOT using integer ThreadId on both Unix and Win32 because (from documentation): // "...Do not allow your program to rely on the internal structure or size of the pthread_t..." #ifdef WIN32 #include - static DWORD myThread; #else #include - static pthread_t myThread; #endif +/*! + \class SALOME_CustomEvent + \brief Generic event class for user-defined events + + This class contains a generic void* data member that may be used + for transferring event-specific data to the receiver. + + \warning The internal data is not destroyed by the class destructor. +*/ + +/*! + \brief Constructor. + \param type event type +*/ SALOME_CustomEvent::SALOME_CustomEvent( int type ) - : QEvent( (QEvent::Type)type ), d( 0 ) +: QEvent( (QEvent::Type)type ), d( 0 ) { } -SALOME_CustomEvent::SALOME_CustomEvent( QEvent::Type type, void *data ) - : QEvent( type ), d( data ) +/*! + \brief Constructor. + \param type event type + \param data custom data +*/ +SALOME_CustomEvent::SALOME_CustomEvent( QEvent::Type type, void* data ) +: QEvent( type ), d( data ) { } -void * SALOME_CustomEvent::data() const +/*! + \brief Get custom data. + \return pointer to the internal data +*/ +void* SALOME_CustomEvent::data() const { return d; } +/*! + \brief Set custom data. + \param data pointer to the internal data +*/ void SALOME_CustomEvent::setData( void* data ) { d = data; } +/*! + \class SALOME_Event + \brief The class which encapsulates data and functionality required for + posting component-specific events to perform arbitrary operations + in the main GUI thread. + + SALOME_Event objects can be posted by any thread belonging to the GUI process. + + It is necessary to derive a custom event class from SALOME_Event and + re-implement virtual Execute() method. This method should actually perform + the desirable operation. To pass all the required data to Execute() and + store a return value, arbitrary data fields can be added to the custom + event class. There is no need to protect such fields with a mutex, for only + one thread working with a SALOME_Event object is active at any moment. + + Usage: + - Create SALOME_Event. Components can derive their own event class from + SALOME_Event in order to pass custom data to the event handler. + - Call process() method to post the event. After process() execution + it is possible to examine fields of your custom event object. + - Perform delete operator on the event to wake up the desktop (you can also + set parameter to \c true to automatically wake up desktop after + process(). + + The method processed() is used by the desktop to signal that event processing + has been completed. + + To make all this work, it is necessary to call static method GetSessionThread() + during the application initialization, i.e. from main() function. + It is important to call this method from the primary application thread. + + Caveats: + - there are no. +*/ + +//! Total number of semaphore resources const int NumberOfResources = 2; /*! - \return thread id + \brief Initialize event mechanism. + + This function sets up the main application thread. It should be called + during the application initialization, i.e. main() function. */ void SALOME_Event::GetSessionThread(){ #ifdef WIN32 @@ -83,7 +141,8 @@ void SALOME_Event::GetSessionThread(){ } /*! - \return true if it is session thread + \brief Check if the processing is in the main application thread. + \return \c true if this method is called from the main application thread */ bool SALOME_Event::IsSessionThread(){ bool aResult = false; @@ -92,48 +151,93 @@ bool SALOME_Event::IsSessionThread(){ #else aResult = myThread == pthread_self(); #endif -// if(MYDEBUG) INFOS("IsSessionThread() - "<acquire( 1 )" ); mySemaphore->acquire( 1 ); -// if(MYDEBUG) MESSAGE( "SALOME_Event::process(): this = "<