From db48780d575d5bb0e9508db860f9c783a79bc96a Mon Sep 17 00:00:00 2001 From: vsr Date: Mon, 14 May 2007 14:59:32 +0000 Subject: [PATCH] Porting to Qt4 --- src/SUIT/SUIT_SelectionMgr.cxx | 93 ++++++++++++++++------------ src/SUIT/SUIT_SelectionMgr.h | 36 +++++------ src/SUIT/SUIT_Selector.cxx | 62 +++++++++++++++++-- src/SUIT/SUIT_Selector.h | 16 +++-- src/SUIT/SUIT_Session.cxx | 109 ++++++++++++++------------------- src/SUIT/SUIT_Session.h | 24 +++----- src/SUIT/SUIT_Study.cxx | 43 +++++++------ src/SUIT/SUIT_Study.h | 14 ++--- src/SUIT/SUIT_ToolButton.cxx | 98 ++++++++++------------------- src/SUIT/SUIT_ToolButton.h | 21 +++---- src/SUIT/SUIT_Tools.cxx | 8 +-- src/SUIT/SUIT_Tools.h | 6 +- 12 files changed, 268 insertions(+), 262 deletions(-) diff --git a/src/SUIT/SUIT_SelectionMgr.cxx b/src/SUIT/SUIT_SelectionMgr.cxx index 895486f21..21d02eadc 100755 --- a/src/SUIT/SUIT_SelectionMgr.cxx +++ b/src/SUIT/SUIT_SelectionMgr.cxx @@ -18,6 +18,9 @@ // #include "SUIT_SelectionMgr.h" +#include "SUIT_Selector.h" +#include "SUIT_SelectionFilter.h" + /*!\class SUIT_SelectionMgr * Provide selection manager. Manipulate by selection filters, modes, data owners. */ @@ -26,6 +29,7 @@ SUIT_SelectionMgr::SUIT_SelectionMgr( const bool Feedback, QObject* p ) : QObject( p ), myIterations( Feedback ? 1 : 0 ), +myAutoDelFilter( false ), myIsSelChangeEnabled( true ) { } @@ -33,7 +37,8 @@ myIsSelChangeEnabled( true ) /*!destructor. mySelectors auto delete.*/ SUIT_SelectionMgr::~SUIT_SelectionMgr() { - mySelectors.setAutoDelete( true ); + for ( SelectorList::iterator it = mySelectors.begin(); it != mySelectors.end(); ++it ) + delete *it; } /*!Add selector \a sel to selectors list,if it's not exists in list.*/ @@ -46,25 +51,25 @@ void SUIT_SelectionMgr::installSelector( SUIT_Selector* sel ) /*!Remove selector \a sel from list.*/ void SUIT_SelectionMgr::removeSelector( SUIT_Selector* sel ) { - mySelectors.remove( sel ); + mySelectors.removeAll( sel ); } /*!Gets selectors list to \a lst.*/ -void SUIT_SelectionMgr::selectors( QPtrList& lst ) const +void SUIT_SelectionMgr::selectors( QList& lst ) const { lst.clear(); - for ( SelectorListIterator it( mySelectors ); it.current(); ++it ) - lst.append( it.current() ); + for ( SelectorList::const_iterator it = mySelectors.begin(); it != mySelectors.end(); ++it ) + lst.append( *it ); } /*!Gets selectors list to \a lst with type \a typ.*/ -void SUIT_SelectionMgr::selectors( const QString& typ, QPtrList& lst ) const +void SUIT_SelectionMgr::selectors( const QString& typ, QList& lst ) const { lst.clear(); - for ( SelectorListIterator it( mySelectors ); it.current(); ++it ) + for ( SelectorList::const_iterator it = mySelectors.begin(); it != mySelectors.end(); ++it ) { - if ( it.current()->type() == typ ) - lst.append( it.current() ); + if ( (*it)->type() == typ ) + lst.append( *it ); } } @@ -72,10 +77,10 @@ void SUIT_SelectionMgr::selectors( const QString& typ, QPtrList& */ void SUIT_SelectionMgr::setEnabled( const bool on, const QString& typ ) { - for ( SelectorListIterator it( mySelectors ); it.current(); ++it ) + for ( SelectorList::const_iterator it = mySelectors.begin(); it != mySelectors.end(); ++it ) { - if ( typ.isEmpty() || it.current()->type() == typ ) - it.current()->setEnabled( on ); + if ( typ.isEmpty() || (*it)->type() == typ ) + (*it)->setEnabled( on ); } } @@ -85,12 +90,13 @@ void SUIT_SelectionMgr::selected( SUIT_DataOwnerPtrList& lst, const QString& typ { lst.clear(); - for ( SelectorListIterator it( mySelectors ); it.current(); ++it ) + for ( SelectorList::const_iterator it = mySelectors.begin(); it != mySelectors.end(); ++it ) { - if ( !type.isEmpty() && it.current()->type() != type ) + if ( !type.isEmpty() && (*it)->type() != type ) continue; + SUIT_DataOwnerPtrList curList; - it.current()->selected( curList ); + (*it)->selected( curList ); for ( SUIT_DataOwnerPtrList::const_iterator itr = curList.begin(); itr != curList.end(); ++itr ) lst.append( *itr ); } @@ -103,16 +109,16 @@ void SUIT_SelectionMgr::setSelected( const SUIT_DataOwnerPtrList& lst, const boo SUIT_DataOwnerPtrList owners; filterOwners( lst, owners ); - for ( SelectorListIterator it( mySelectors ); it.current(); ++it ) + for ( SelectorList::const_iterator it = mySelectors.begin(); it != mySelectors.end(); ++it ) { if ( append ) { SUIT_DataOwnerPtrList current; - it.current()->selected( current ); + (*it)->selected( current ); for ( SUIT_DataOwnerPtrList::const_iterator it = current.begin(); it != current.end(); ++it ) owners.append( *it ); } - it.current()->setSelected( owners ); + (*it)->setSelected( owners ); } } @@ -140,11 +146,10 @@ void SUIT_SelectionMgr::selectionChanged( SUIT_Selector* sel ) for ( int i = 0; i < myIterations; i++ ) { - for ( SUIT_Selector* aSel = mySelectors.first(); aSel; aSel = mySelectors.next() ) + for ( SelectorList::iterator it = mySelectors.begin(); it != mySelectors.end(); ++it ) { - // Temporary action(to avoid selection of the objects which don't pass the filters): - //if ( aSel != sel ) - aSel->setSelected( newOwners ); + if ( *it != sel ) + (*it)->setSelected( newOwners ); } } myIsSelChangeEnabled = true; @@ -170,7 +175,7 @@ bool SUIT_SelectionMgr::hasSelectionMode( const int mode ) const /*! Gets selection modes to list \a vals. */ -void SUIT_SelectionMgr::selectionModes( QValueList& vals ) const +void SUIT_SelectionMgr::selectionModes( QList& vals ) const { vals = mySelModes; } @@ -179,14 +184,14 @@ void SUIT_SelectionMgr::selectionModes( QValueList& vals ) const */ void SUIT_SelectionMgr::setSelectionModes( const int mode ) { - QValueList lst; + QList lst; lst.append( mode ); setSelectionModes( lst ); } /*! Sets selection modes list from \a lst. */ -void SUIT_SelectionMgr::setSelectionModes( const QValueList& lst ) +void SUIT_SelectionMgr::setSelectionModes( const QList& lst ) { mySelModes = lst; } @@ -195,20 +200,20 @@ void SUIT_SelectionMgr::setSelectionModes( const QValueList& lst ) */ void SUIT_SelectionMgr::appendSelectionModes( const int mode ) { - QValueList lst; + QList lst; lst.append( mode ); appendSelectionModes( lst ); } /*! Append selection modes \a lst list. */ -void SUIT_SelectionMgr::appendSelectionModes( const QValueList& lst ) +void SUIT_SelectionMgr::appendSelectionModes( const QList& lst ) { QMap map; - for ( QValueList::const_iterator it = mySelModes.begin(); it != mySelModes.end(); ++it ) + for ( QList::const_iterator it = mySelModes.begin(); it != mySelModes.end(); ++it ) map.insert( *it, 0 ); - for ( QValueList::const_iterator itr = lst.begin(); itr != lst.end(); ++itr ) + for ( QList::const_iterator itr = lst.begin(); itr != lst.end(); ++itr ) { if ( !map.contains( *itr ) ) mySelModes.append( *itr ); @@ -219,20 +224,20 @@ void SUIT_SelectionMgr::appendSelectionModes( const QValueList& lst ) */ void SUIT_SelectionMgr::removeSelectionModes( const int mode ) { - QValueList lst; + QList lst; lst.append( mode ); removeSelectionModes( lst ); } /*! Remove selection modea \a lst from list. */ -void SUIT_SelectionMgr::removeSelectionModes( const QValueList& lst ) +void SUIT_SelectionMgr::removeSelectionModes( const QList& lst ) { QMap map; - for ( QValueList::const_iterator it = mySelModes.begin(); it != mySelModes.end(); ++it ) + for ( QList::const_iterator it = mySelModes.begin(); it != mySelModes.end(); ++it ) map.insert( *it, 0 ); - for ( QValueList::const_iterator itr = lst.begin(); itr != lst.end(); ++itr ) + for ( QList::const_iterator itr = lst.begin(); itr != lst.end(); ++itr ) map.remove( *itr ); mySelModes.clear(); @@ -248,8 +253,8 @@ bool SUIT_SelectionMgr::isOk( const SUIT_DataOwner* owner ) const return false; bool ok = true; - for ( SelFilterListIterator it( myFilters ); it.current() && ok; ++it ) - ok = it.current()->isOk( owner ); + for ( SelFilterList::const_iterator it = myFilters.begin(); it != myFilters.end() && ok; ++it ) + ok = (*it)->isOk( owner ); return ok; } @@ -292,13 +297,25 @@ void SUIT_SelectionMgr::installFilter( SUIT_SelectionFilter* f, const bool updat */ void SUIT_SelectionMgr::removeFilter( SUIT_SelectionFilter* f ) { - myFilters.remove( f ); + if ( !myFilters.contains( f ) ) + return; + + myFilters.removeAll( f ); + + if ( autoDeleteFilter() ) + delete f; } /*! Clear filters list. */ void SUIT_SelectionMgr::clearFilters() { + if ( autoDeleteFilter() ) + { + for ( SelFilterList::const_iterator it = myFilters.begin(); it != myFilters.end(); ++it ) + delete *it; + } + myFilters.clear(); } @@ -306,14 +323,14 @@ void SUIT_SelectionMgr::clearFilters() */ bool SUIT_SelectionMgr::autoDeleteFilter() const { - return myFilters.autoDelete(); + return myAutoDelFilter; } /*! Sets auto delete filter to \a on. */ void SUIT_SelectionMgr::setAutoDeleteFilter( const bool on ) { - myFilters.setAutoDelete( on ); + myAutoDelFilter = on; } /*! Gets good data owners list to \a out from \a in. diff --git a/src/SUIT/SUIT_SelectionMgr.h b/src/SUIT/SUIT_SelectionMgr.h index 79576568f..7f3082737 100755 --- a/src/SUIT/SUIT_SelectionMgr.h +++ b/src/SUIT/SUIT_SelectionMgr.h @@ -19,13 +19,13 @@ #ifndef SUIT_SELECTIONMGR_H #define SUIT_SELECTIONMGR_H -#include "SUIT_Selector.h" #include "SUIT_DataOwner.h" -#include "SUIT_SelectionFilter.h" -#include -#include -#include +#include +#include + +class SUIT_Selector; +class SUIT_SelectionFilter; #ifdef WIN32 #pragma warning ( disable : 4251 ) @@ -43,24 +43,24 @@ public: virtual void selected( SUIT_DataOwnerPtrList&, const QString& = QString::null ) const; virtual void setSelected( const SUIT_DataOwnerPtrList&, const bool = false ); - void selectors( QPtrList& ) const; - void selectors( const QString&, QPtrList& ) const; + void selectors( QList& ) const; + void selectors( const QString&, QList& ) const; void setEnabled( const bool, const QString& = QString::null ); bool hasSelectionMode( const int ) const; - void selectionModes( QValueList& ) const; + void selectionModes( QList& ) const; void setSelectionModes( const int ); - virtual void setSelectionModes( const QValueList& ); + virtual void setSelectionModes( const QList& ); void appendSelectionModes( const int ); - virtual void appendSelectionModes( const QValueList& ); + virtual void appendSelectionModes( const QList& ); void removeSelectionModes( const int ); - virtual void removeSelectionModes( const QValueList& ); + virtual void removeSelectionModes( const QList& ); bool isOk( const SUIT_DataOwner* ) const; @@ -83,25 +83,21 @@ signals: protected: virtual void selectionChanged( SUIT_Selector* ); - typedef QPtrListIterator SelectorListIterator; - virtual void installSelector( SUIT_Selector* ); virtual void removeSelector( SUIT_Selector* ); private: void filterOwners( const SUIT_DataOwnerPtrList&, SUIT_DataOwnerPtrList& ) const; - typedef QPtrList SelectorList; - typedef QPtrList SelFilterList; - typedef QPtrListIterator SelFilterListIterator; - -protected: - SelectorList mySelectors; + typedef QList SelectorList; + typedef QList SelFilterList; private: SelFilterList myFilters; - QValueList mySelModes; + QList mySelModes; + SelectorList mySelectors; int myIterations; + bool myAutoDelFilter; bool myIsSelChangeEnabled; friend class SUIT_Selector; diff --git a/src/SUIT/SUIT_Selector.cxx b/src/SUIT/SUIT_Selector.cxx index ebda6a065..368d8c641 100755 --- a/src/SUIT/SUIT_Selector.cxx +++ b/src/SUIT/SUIT_Selector.cxx @@ -20,6 +20,49 @@ #include "SUIT_SelectionMgr.h" +#include + +/*!\class SUIT_Selector::Destroyer + Class provide the watching for qobject parent class of the selector. +*/ + +class SUIT_Selector::Destroyer : public QObject +{ +public: + Destroyer( SUIT_Selector*, QObject* = 0 ); + virtual ~Destroyer(); + + SUIT_Selector* selector() const; + void setSelector( SUIT_Selector* ); + +private: + SUIT_Selector* mySelector; +}; + +SUIT_Selector::Destroyer::Destroyer( SUIT_Selector* s, QObject* p ) +: QObject( p ), + mySelector( s ) +{ +} + +SUIT_Selector::Destroyer::~Destroyer() +{ + SUIT_Selector* s = mySelector; + mySelector = 0; + if ( s ) + delete s; +} + +SUIT_Selector* SUIT_Selector::Destroyer::selector() const +{ + return mySelector; +} + +void SUIT_Selector::Destroyer::setSelector( SUIT_Selector* s ) +{ + mySelector = s; +} + /*!\class SUIT_Selector * Class provide selector for data owners. */ @@ -27,15 +70,18 @@ /*! Constructor. */ -SUIT_Selector::SUIT_Selector( SUIT_SelectionMgr* selMgr, QObject* parent ) : -QObject( parent ), -mySelMgr( selMgr ), +SUIT_Selector::SUIT_Selector( SUIT_SelectionMgr* selMgr, QObject* parent ) +: mySelMgr( selMgr ), myBlock( false ), myEnabled( true ), -myAutoBlock( true ) +myAutoBlock( true ), +myDestroyer( 0 ) { if ( selMgr ) selMgr->installSelector( this ); + + if ( parent ) + myDestroyer = new Destroyer( this, parent ); } /*! @@ -45,6 +91,12 @@ SUIT_Selector::~SUIT_Selector() { if ( selectionMgr() ) selectionMgr()->removeSelector( this ); + + if ( myDestroyer && myDestroyer->selector() == this ) + { + myDestroyer->setSelector( 0 ); + delete myDestroyer; + } } /*! @@ -135,7 +187,7 @@ bool SUIT_Selector::hasSelectionMode( const int mode ) const /*! Puts to list \a lst selection modes from selection manager. */ -void SUIT_Selector::selectionModes( QValueList& lst ) const +void SUIT_Selector::selectionModes( QList& lst ) const { if ( selectionMgr() ) selectionMgr()->selectionModes( lst ); diff --git a/src/SUIT/SUIT_Selector.h b/src/SUIT/SUIT_Selector.h index 058506d24..46de6fa52 100755 --- a/src/SUIT/SUIT_Selector.h +++ b/src/SUIT/SUIT_Selector.h @@ -21,8 +21,9 @@ #include "SUIT.h" -#include -#include +#include + +class QObject; class SUIT_SelectionMgr; class SUIT_DataOwnerPtrList; @@ -34,9 +35,11 @@ class SUIT_DataOwnerPtrList; (ObjectBrowser, viewers, etc) Used by selection manager for selection synhronizing */ -class SUIT_EXPORT SUIT_Selector : public QObject + +class SUIT_EXPORT SUIT_Selector { - Q_OBJECT + class Destroyer; + public: SUIT_Selector( SUIT_SelectionMgr*, QObject* = 0 ); virtual ~SUIT_Selector(); @@ -55,7 +58,7 @@ public: void setSelected( const SUIT_DataOwnerPtrList& ); bool hasSelectionMode( const int ) const; - void selectionModes( QValueList& ) const; + void selectionModes( QList& ) const; protected: void selectionChanged(); @@ -63,10 +66,11 @@ protected: virtual void setSelection( const SUIT_DataOwnerPtrList& ) = 0; private: - bool myBlock; SUIT_SelectionMgr* mySelMgr; + bool myBlock; bool myEnabled; bool myAutoBlock; + Destroyer* myDestroyer; }; #endif diff --git a/src/SUIT/SUIT_Session.cxx b/src/SUIT/SUIT_Session.cxx index 7d2ac3839..9c816089a 100755 --- a/src/SUIT/SUIT_Session.cxx +++ b/src/SUIT/SUIT_Session.cxx @@ -18,16 +18,13 @@ // #include "SUIT_Session.h" +#include "SUIT_Study.h" #include "SUIT_Tools.h" -#include "SUIT_Desktop.h" #include "SUIT_MessageBox.h" -#include "SUIT_ViewWindow.h" -#include "SUIT_ViewManager.h" #include "SUIT_ExceptionHandler.h" +#include "SUIT_ResourceMgr.h" -#include -#include -#include +#include #ifdef WIN32 #include @@ -35,9 +32,6 @@ #include #endif -static bool SUIT_Session_IsPythonExecuted = false; -static QMutex SUIT_Session_PythonMutex; - SUIT_Session* SUIT_Session::mySession = 0; /*! Constructor.*/ @@ -45,23 +39,25 @@ SUIT_Session* SUIT_Session::mySession = 0; SUIT_Session::SUIT_Session() : QObject(), myResMgr( 0 ), -myHandler( 0 ), myActiveApp( 0 ), +myHandler( 0 ), myExitStatus( FROM_GUI ) { SUIT_ASSERT( !mySession ) mySession = this; - - myAppList.setAutoDelete( true ); } /*!destructor. Clear applications list and set mySession to zero.*/ SUIT_Session::~SUIT_Session() { + for ( AppList::iterator it = myAppList.begin(); it != myAppList.end(); ++it ) + delete *it; + myAppList.clear(); - if (myResMgr) { + if ( myResMgr ) + { delete myResMgr; myResMgr = 0; } @@ -78,7 +74,7 @@ SUIT_Session* SUIT_Session::session() Starts new application using "createApplication" function of loaded DLL. */ -SUIT_Application* SUIT_Session::startApplication( const QString& name, int args, char** argv ) +SUIT_Application* SUIT_Session::startApplication( const QString& name, int /*args*/, char** /*argv*/ ) { AppLib libHandle = 0; @@ -103,7 +99,7 @@ SUIT_Application* SUIT_Session::startApplication( const QString& name, int args, APP_CREATE_FUNC crtInst = 0; #ifdef WIN32 - crtInst = (APP_CREATE_FUNC)::GetProcAddress( libHandle, APP_CREATE_NAME ); + crtInst = (APP_CREATE_FUNC)::GetProcAddress( (HINSTANCE)libHandle, APP_CREATE_NAME ); #else crtInst = (APP_CREATE_FUNC)dlsym( libHandle, APP_CREATE_NAME ); #endif @@ -130,20 +126,15 @@ SUIT_Application* SUIT_Session::startApplication( const QString& name, int args, return 0; } - anApp->setName( appName ); - - connect( anApp, SIGNAL( applicationClosed( SUIT_Application* ) ), - this, SLOT( onApplicationClosed( SUIT_Application* ) ) ); - connect( anApp, SIGNAL( activated( SUIT_Application* ) ), - this, SLOT( onApplicationActivated( SUIT_Application* ) ) ); + anApp->setObjectName( appName ); - myAppList.append( anApp ); + insertApplication( anApp ); if ( !myHandler ) { APP_GET_HANDLER_FUNC crtHndlr = 0; #ifdef WIN32 - crtHndlr = (APP_GET_HANDLER_FUNC)::GetProcAddress( libHandle, APP_GET_HANDLER_NAME ); + crtHndlr = (APP_GET_HANDLER_FUNC)::GetProcAddress( (HINSTANCE)libHandle, APP_GET_HANDLER_NAME ); #else crtHndlr = (APP_GET_HANDLER_FUNC)dlsym( libHandle, APP_GET_HANDLER_NAME ); #endif @@ -163,15 +154,22 @@ SUIT_Application* SUIT_Session::startApplication( const QString& name, int args, /*! Gets the list of all applications */ -QPtrList SUIT_Session::applications() const +QList SUIT_Session::applications() const { - QPtrList apps; - apps.setAutoDelete( false ); + return myAppList; +} - for ( AppListIterator it( myAppList ); it.current(); ++it ) - apps.append( it.current() ); +void SUIT_Session::insertApplication( SUIT_Application* app ) +{ + if ( !app || myAppList.contains( app ) ) + return; - return apps; + myAppList.append( app ); + + connect( app, SIGNAL( applicationClosed( SUIT_Application* ) ), + this, SLOT( onApplicationClosed( SUIT_Application* ) ) ); + connect( app, SIGNAL( activated( SUIT_Application* ) ), + this, SLOT( onApplicationActivated( SUIT_Application* ) ) ); } /*! @@ -223,14 +221,16 @@ void SUIT_Session::onApplicationClosed( SUIT_Application* theApp ) { emit applicationClosed( theApp ); - myAppList.remove( theApp ); + myAppList.removeAll( theApp ); + delete theApp; + if ( theApp == myActiveApp ) myActiveApp = 0; if ( myAppList.isEmpty() ) { printf( "Calling QApplication::exit() with exit code = %d\n", myExitStatus ); - qApp->exit( myExitStatus ); + QApplication::instance()->exit( myExitStatus ); } } @@ -239,16 +239,17 @@ void SUIT_Session::onApplicationClosed( SUIT_Application* theApp ) */ void SUIT_Session::closeSession( int mode ) { - while ( !myAppList.isEmpty() ) + AppList apps = myAppList; + for ( AppList::const_iterator it = apps.begin(); it != apps.end(); ++it ) { - SUIT_Application* app = myAppList.getFirst(); + SUIT_Application* app = *it; if ( mode == ASK && !app->isPossibleToClose() ) return; else if ( mode == SAVE ) { SUIT_Study* study = app->activeStudy(); if ( study->isModified() && study->isSaved() ) - study->saveDocument(); + study->saveDocument(); } else if ( mode == DONT_SAVE ) { @@ -270,11 +271,12 @@ SUIT_ExceptionHandler* SUIT_Session::handler() const QString SUIT_Session::lastError() const { QString str; -#ifdef WNT +#ifdef WIN32 LPVOID lpMsgBuf; ::FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 0, ::GetLastError(), 0, (LPTSTR)&lpMsgBuf, 0, 0 ); - str = QString( (LPTSTR)lpMsgBuf ); + LPTSTR msg = (LPTSTR)lpMsgBuf; + str = QString( SUIT_Tools::toQString( msg ) ); LocalFree( lpMsgBuf ); #else str = QString( dlerror() ); @@ -294,10 +296,16 @@ SUIT_Session::AppLib SUIT_Session::loadLibrary( const QString& name, QString& li return 0; AppLib lib = 0; + QByteArray bid = libFile.toLatin1(); #ifdef WIN32 - lib = ::LoadLibrary( (char*)libFile.latin1() ); +#ifdef UNICODE + LPTSTR str = (LPTSTR)libFile.utf16(); +#else + LPTSTR str = (LPTSTR)(const char*)bid; +#endif + lib = ::LoadLibrary( str ); #else - lib = dlopen( (char*)libFile.latin1(), RTLD_LAZY | RTLD_GLOBAL ); + lib = dlopen( (const char*)libFile.toLatin1(), RTLD_LAZY | RTLD_GLOBAL ); #endif return lib; } @@ -330,28 +338,3 @@ void SUIT_Session::onApplicationActivated( SUIT_Application* app ) { myActiveApp = app; } - -/*! - \retval Return TRUE, if a command is currently executed in Python Console, - FALSE otherwise. -*/ -bool SUIT_Session::IsPythonExecuted() -{ - bool ret; - SUIT_Session_PythonMutex.lock(); - ret = SUIT_Session_IsPythonExecuted; - SUIT_Session_PythonMutex.unlock(); - return ret; -} - -/*! - Set value of boolean flag, being returned by method \a IsPythonExecuted(). - It is supposed to set the flag to TRUE when any python command starts - and reset it to FALSE when the command finishes. -*/ -void SUIT_Session::SetPythonExecuted(bool isPythonExecuted) -{ - SUIT_Session_PythonMutex.lock(); - SUIT_Session_IsPythonExecuted = isPythonExecuted; - SUIT_Session_PythonMutex.unlock(); -} diff --git a/src/SUIT/SUIT_Session.h b/src/SUIT/SUIT_Session.h index 840de5927..a6655aeeb 100755 --- a/src/SUIT/SUIT_Session.h +++ b/src/SUIT/SUIT_Session.h @@ -21,14 +21,11 @@ #include "SUIT.h" -#include "SUIT_Application.h" -#include "SUIT_ResourceMgr.h" +#include -#include -#include -#include -#include -#include +#include +#include +#include #ifdef WIN32 #define LIB_HANDLE HINSTANCE @@ -39,7 +36,7 @@ class SUIT_ResourceMgr; class SUIT_ExceptionHandler; -#ifdef WNT +#ifdef WIN32 #pragma warning( disable:4251 ) #endif /*! @@ -65,7 +62,7 @@ public: SUIT_Application* startApplication( const QString&, int = 0, char** = 0 ); - QPtrList applications() const; + QList applications() const; SUIT_Application* activeApplication() const; SUIT_ResourceMgr* resourceMgr() const; @@ -74,9 +71,7 @@ public: SUIT_ExceptionHandler* handler() const; - // To lock GUI user actions during python command execution (PAL12651) - static bool IsPythonExecuted(); - static void SetPythonExecuted(bool isPythonExecuted); + void insertApplication( SUIT_Application* ); signals: void applicationClosed( SUIT_Application* ); @@ -89,9 +84,8 @@ private slots: void onApplicationActivated( SUIT_Application* ); private: - typedef QPtrList AppList; - typedef QMap AppLibMap; - typedef QPtrListIterator AppListIterator; + typedef QList AppList; + typedef QMap AppLibMap; private: QString lastError() const; diff --git a/src/SUIT/SUIT_Study.cxx b/src/SUIT/SUIT_Study.cxx index a3baef3ce..c1521d0da 100755 --- a/src/SUIT/SUIT_Study.cxx +++ b/src/SUIT/SUIT_Study.cxx @@ -23,7 +23,6 @@ #include "SUIT_DataObject.h" #include "SUIT_MessageBox.h" #include "SUIT_Application.h" -#include /*!\class SUIT_Study * Support study management. Object management. Operation management. @@ -33,9 +32,9 @@ SUIT_Study::SUIT_Study( SUIT_Application* app ) : QObject(), myApp( app ), +myName( "" ), myIsSaved( false ), myIsModified( false ), -myName( "" ), myBlockChangeState( false ) { static int _id = 0; @@ -43,8 +42,6 @@ myBlockChangeState( false ) myId = ++_id; myRoot = new SUIT_DataObject(); - myOperations.setAutoDelete( false ); - myOperations.setAutoDelete( false ); } /*!Destructor.*/ @@ -91,7 +88,7 @@ QString SUIT_Study::studyName() const */ SUIT_Operation* SUIT_Study::activeOperation() const { - return myOperations.count() > 0 ? myOperations.getLast() : 0; + return myOperations.count() > 0 ? myOperations.last() : 0; } /*! @@ -113,7 +110,7 @@ bool SUIT_Study::isModified() const /*! *Close document. NOT IMPLEMENTED. */ -void SUIT_Study::closeDocument(bool permanently) +void SUIT_Study::closeDocument(bool /*permanently*/) { } @@ -121,8 +118,9 @@ void SUIT_Study::closeDocument(bool permanently) Custom document initialization to be performed \n within onNewDoc() handler can be put here */ -void SUIT_Study::createDocument() +bool SUIT_Study::createDocument( const QString& ) { + return true; } /*! @@ -163,8 +161,8 @@ bool SUIT_Study::saveDocument() void SUIT_Study::abortAllOperations() { myBlockChangeState = true; - for( SUIT_Operation* op = myOperations.first(); op; op = myOperations.next() ) - op->abort(); + for ( Operations::iterator it = myOperations.begin(); it != myOperations.end(); ++it ) + (*it)->abort(); myBlockChangeState = false; myOperations.clear(); } @@ -239,9 +237,9 @@ SUIT_Operation* SUIT_Study::blockingOperation( SUIT_Operation* theOp ) const return 0; Operations tmpOps( myOperations ); - SUIT_Operation* anOp = 0; - for ( anOp = tmpOps.last(); anOp; anOp = tmpOps.prev() ) + for ( Operations::const_iterator it = tmpOps.end(); it != tmpOps.begin(); --it ) { + SUIT_Operation* anOp = *it; if ( anOp != 0 && anOp!= theOp && !anOp->isValid( theOp ) ) return anOp; } @@ -262,7 +260,7 @@ SUIT_Operation* SUIT_Study::blockingOperation( SUIT_Operation* theOp ) const */ bool SUIT_Study::start( SUIT_Operation* theOp, const bool toCheck ) { - if ( !theOp || myOperations.find( theOp ) >= 0 ) + if ( !theOp || myOperations.contains( theOp ) ) return false; theOp->setExecStatus( SUIT_Operation::Rejected ); @@ -313,7 +311,7 @@ bool SUIT_Study::start( SUIT_Operation* theOp, const bool toCheck ) */ bool SUIT_Study::abort( SUIT_Operation* theOp ) { - if ( !theOp || myOperations.find( theOp ) == -1 ) + if ( !theOp || !myOperations.contains( theOp ) ) return false; theOp->setExecStatus( SUIT_Operation::Rejected ); @@ -337,7 +335,7 @@ bool SUIT_Study::abort( SUIT_Operation* theOp ) */ bool SUIT_Study::commit( SUIT_Operation* theOp ) { - if ( !theOp || myOperations.find( theOp ) == -1 ) + if ( !theOp || !myOperations.contains( theOp ) ) return false; theOp->setExecStatus( SUIT_Operation::Accepted ); @@ -363,7 +361,7 @@ bool SUIT_Study::commit( SUIT_Operation* theOp ) */ bool SUIT_Study::suspend( SUIT_Operation* theOp ) { - if ( !theOp || myOperations.find( theOp ) == -1 || theOp->state() == SUIT_Operation::Suspended ) + if ( !theOp || !myOperations.contains( theOp ) || theOp->state() == SUIT_Operation::Suspended ) return false; theOp->setState( SUIT_Operation::Suspended ); @@ -382,7 +380,7 @@ bool SUIT_Study::suspend( SUIT_Operation* theOp ) */ bool SUIT_Study::resume( SUIT_Operation* theOp ) { - if ( !theOp || myOperations.find( theOp ) == -1 || + if ( !theOp || !myOperations.contains( theOp ) || theOp->state() == SUIT_Operation::Running || blockingOperation( theOp ) != 0 ) return false; @@ -396,7 +394,7 @@ bool SUIT_Study::resume( SUIT_Operation* theOp ) // Move operation at the end of list in order to sort it in the order of activation. // As result active operation is a last operation of list, operation which was active // before currently active operation is located before it and so on - myOperations.remove( theOp ); + myOperations.removeAll( theOp ); myOperations.append( theOp ); emit theOp->resumed( theOp ); @@ -413,12 +411,13 @@ bool SUIT_Study::resume( SUIT_Operation* theOp ) void SUIT_Study::stop( SUIT_Operation* theOp ) { theOp->setState( SUIT_Operation::Waiting ); - myOperations.remove( theOp ); + myOperations.removeAll( theOp ); // get last operation which can be resumed - SUIT_Operation* anOp, *aResultOp = 0; - for ( anOp = myOperations.last(); anOp; anOp = myOperations.prev() ) + SUIT_Operation* aResultOp = 0; + for ( Operations::iterator it = myOperations.end(); it != myOperations.begin(); --it ) { + SUIT_Operation* anOp = *it; if ( anOp && anOp != theOp && blockingOperation( anOp ) == 0 ) { aResultOp = anOp; @@ -438,7 +437,7 @@ void SUIT_Study::stop( SUIT_Operation* theOp ) * \brief Get all started operations * \return List of all started operations */ -const QPtrList& SUIT_Study::operations() const +const QList& SUIT_Study::operations() const { return myOperations; } @@ -523,6 +522,6 @@ int SUIT_Study::storeState() /*! * \brief Restores the study state */ -void SUIT_Study::restoreState(int savePoint) +void SUIT_Study::restoreState(int /*savePoint*/) { } diff --git a/src/SUIT/SUIT_Study.h b/src/SUIT/SUIT_Study.h index 156c6bc74..6ebf2bcad 100755 --- a/src/SUIT/SUIT_Study.h +++ b/src/SUIT/SUIT_Study.h @@ -21,14 +21,12 @@ #include "SUIT.h" -#include "SUIT_Operation.h" - -#include -#include +#include +#include class SUIT_DataObject; class SUIT_Application; -class QDialog; +class SUIT_Operation; #ifdef WIN32 #pragma warning( disable:4251 ) @@ -51,9 +49,9 @@ public: virtual bool isSaved() const; virtual bool isModified() const; - virtual void createDocument(); virtual void closeDocument( bool = true ); virtual bool openDocument( const QString& ); + virtual bool createDocument( const QString& ); bool saveDocument(); virtual bool saveDocumentAs( const QString& ); @@ -65,7 +63,7 @@ public: // Operation management SUIT_Operation* activeOperation() const; virtual void abortAllOperations(); - const QPtrList& operations() const; + const QList& operations() const; virtual SUIT_Operation* blockingOperation( SUIT_Operation* ) const; @@ -98,7 +96,7 @@ protected: virtual bool commitTransaction( const QString& = QString::null ); private: - typedef QPtrList Operations; + typedef QList Operations; void stop( SUIT_Operation* ); private: diff --git a/src/SUIT/SUIT_ToolButton.cxx b/src/SUIT/SUIT_ToolButton.cxx index 35e009c6d..a7e60af9a 100755 --- a/src/SUIT/SUIT_ToolButton.cxx +++ b/src/SUIT/SUIT_ToolButton.cxx @@ -19,49 +19,31 @@ #include "SUIT_ToolButton.h" -#include -#include +#include /*!Constructor.*/ -SUIT_ToolButton::SUIT_ToolButton( QWidget *parent, - const char *name, - bool changeItemAfterClick) - : QToolButton( parent, name ), - myChangeItemAfterClick( changeItemAfterClick ) +SUIT_ToolButton::SUIT_ToolButton( QWidget *parent, const char* /*name*/, + bool changeItemAfterClick ) +: QToolButton( parent ), +myChangeItemAfterClick( changeItemAfterClick ) { initialize(); } -/*!Constructor.*/ -SUIT_ToolButton::SUIT_ToolButton( const QPixmap & pm, - const QString &textLabel, - const QString& grouptext, - QObject * receiver, - const char* slot, - QToolBar * parent, - const char* name, - bool changeItemAfterClick) - :QToolButton(pm, textLabel, grouptext, receiver, slot, parent, name), - myChangeItemAfterClick( changeItemAfterClick ) -{ - initialize(); -} - - /*!Initialize tool buttons.*/ void SUIT_ToolButton::initialize() { - mySignal = NULL; - myPopup = new QPopupMenu( this ); - setPopup(myPopup); - connect( myPopup, SIGNAL(activated(int)), SLOT(OnSelectAction(int)) ); - setPopupDelay(250); +// mySignal = NULL; + myPopup = new QMenu( this ); + setMenu( myPopup ); + connect( myPopup, SIGNAL( activated( int ) ), SLOT( OnSelectAction( int ) ) ); } /*!drawButton is redefined to draw DownArrow*/ -void SUIT_ToolButton::drawButton( QPainter * p ) +void SUIT_ToolButton::drawButton( QPainter * /*p*/ ) { - QToolButton::drawButton(p); +/* + QToolButton::drawButton( p ); //draw DownArrow int x, y, w, h; @@ -69,53 +51,40 @@ void SUIT_ToolButton::drawButton( QPainter * p ) style().drawPrimitive( QStyle::PE_ArrowDown, p, QRect(x+w/2+3, y+h/2+3, w/2, h/2), //QRect(x+(w-x)/2, y+(h-y)/2, w, h) colorGroup(), isEnabled() ); +*/ } - /*! Add action into popup*/ -void SUIT_ToolButton::AddAction(QAction* theAction) +void SUIT_ToolButton::AddAction( QAction* theAction ) { bool aIsFirst = false; - if ( myPopup->count() == 0 ) + if ( myPopup->actions().isEmpty() ) { aIsFirst = true; - setPixmap(theAction->iconSet().pixmap()); - setTextLabel(theAction->text()); - theAction->addTo( myPopup ); - QMenuItem* aItem = myPopup->findItem(myPopup->idAt(0)); - if (aItem != NULL) - { - mySignal = aItem->signal(); - } + setIcon( theAction->icon() ); + setText( theAction->text() ); } - else - theAction->addTo( myPopup ); + myPopup->addAction( theAction ); } /*! Sets myPopup item with theIndex as current*/ -void SUIT_ToolButton::SetItem(int theIndex) +void SUIT_ToolButton::SetItem( int theIndex ) { - int anId = myPopup->idAt(theIndex); - if (anId != -1) + QAction* a = myPopup->actions()[theIndex]; + if ( a ) { - // Protection against unexpected null pointers returned - if ( myPopup->iconSet(anId) ) - setPixmap(myPopup->iconSet(anId)->pixmap()); - setTextLabel(myPopup->text(anId)); - QMenuItem* aItem = myPopup->findItem(anId); - if (aItem != NULL) - { - mySignal = aItem->signal(); - } + setIcon( a->icon() ); + setText( a->text() ); } } /*!Public SLOT. * On select action (icon and text set with id = \a theItemID) */ -void SUIT_ToolButton::OnSelectAction(int theItemID) +void SUIT_ToolButton::OnSelectAction( int /*theItemID*/ ) { - if (myChangeItemAfterClick) +/* + if ( myChangeItemAfterClick ) { // Protection against unexpected null pointers returned if ( myPopup->iconSet(theItemID) ) @@ -127,18 +96,15 @@ void SUIT_ToolButton::OnSelectAction(int theItemID) mySignal = aItem->signal(); } } +*/ } - - /*!On mouse release event.*/ -void SUIT_ToolButton::mouseReleaseEvent ( QMouseEvent * theEvent) +void SUIT_ToolButton::mouseReleaseEvent( QMouseEvent* theEvent ) { - QToolButton::mouseReleaseEvent(theEvent); - if (mySignal != NULL) - { + QToolButton::mouseReleaseEvent( theEvent ); +/* + if ( mySignal ) mySignal->activate(); - } +*/ } - - diff --git a/src/SUIT/SUIT_ToolButton.h b/src/SUIT/SUIT_ToolButton.h index 10abe2629..419ef0a4a 100755 --- a/src/SUIT/SUIT_ToolButton.h +++ b/src/SUIT/SUIT_ToolButton.h @@ -19,11 +19,14 @@ #ifndef SUIT_TOOLBUTTON_H #define SUIT_TOOLBUTTON_H -#include -#include - #include "SUIT.h" +#include + +class QAction; +class QPixmap; +class QToolBar; + /*! To draw down arrow on toolbutton.*/ class SUIT_EXPORT SUIT_ToolButton : public QToolButton { @@ -35,11 +38,6 @@ public: SUIT_ToolButton( QWidget *parent = 0, const char *name = 0, bool changeItemAfterClick = true ); - SUIT_ToolButton( const QPixmap & pm, const QString &textLabel, - const QString& grouptext, - QObject * receiver, const char* slot, - QToolBar * parent, const char* name = 0, - bool changeItemAfterClick = true ); //@} void drawButton( QPainter * pQPainter); @@ -57,11 +55,10 @@ protected: private: void initialize(); - QPopupMenu* myPopup; - QSignal* mySignal; - bool myChangeItemAfterClick; + QMenu* myPopup; +// QSignal* mySignal; + bool myChangeItemAfterClick; }; #endif - diff --git a/src/SUIT/SUIT_Tools.cxx b/src/SUIT/SUIT_Tools.cxx index 953de65d4..31d997b4e 100755 --- a/src/SUIT/SUIT_Tools.cxx +++ b/src/SUIT/SUIT_Tools.cxx @@ -18,7 +18,7 @@ // #include "SUIT_Tools.h" -#include +#include #include #include @@ -37,7 +37,7 @@ void SUIT_Tools::trace( const char* lpszLog, const char* lpszFormat, ... ) tmpPath += QString( "Salome_trace" ); FILE* pStream; - pStream = fopen( lpszLog ? lpszLog : tmpPath.latin1(), "a" ); + pStream = fopen( lpszLog ? lpszLog : (const char*)tmpPath.toLatin1(), "a" ); if ( pStream ) { va_list argptr; @@ -55,7 +55,7 @@ void SUIT_Tools::trace( const char* lpszLog, const char* lpszFormat, ... ) */ QRect SUIT_Tools::makeRect( const int x1, const int y1, const int x2, const int y2 ) { - return QRect( QMIN( x1, x2 ), QMIN( y1, y2 ), QABS( x2 - x1 ), QABS( y2 - y1 ) ); + return QRect( qMin( x1, x2 ), qMin( y1, y2 ), qAbs( x2 - x1 ), qAbs( y2 - y1 ) ); } /*! @@ -64,7 +64,7 @@ QRect SUIT_Tools::makeRect( const int x1, const int y1, const int x2, const int QFont SUIT_Tools::stringToFont( const QString& fontDescription ) { QFont font; - if ( fontDescription.stripWhiteSpace().isEmpty() || !font.fromString( fontDescription ) ) + if ( fontDescription.trimmed().isEmpty() || !font.fromString( fontDescription ) ) font = QFont( "Courier", 11 ); return font; } diff --git a/src/SUIT/SUIT_Tools.h b/src/SUIT/SUIT_Tools.h index 62bc8d163..811571ddf 100755 --- a/src/SUIT/SUIT_Tools.h +++ b/src/SUIT/SUIT_Tools.h @@ -23,9 +23,9 @@ #include -#include -#include -#include +#include +#include +#include /*! \class SUIT_Tools -- 2.39.2