From 9b2087aa3c306bc98fbd5ef6344a8ab3367ae498 Mon Sep 17 00:00:00 2001 From: asl Date: Tue, 1 Sep 2015 09:37:00 +0300 Subject: [PATCH] Add virtual function to allow the module to abort active operations on document loading/saving --- src/CAM/CAM_Application.cxx | 17 +++++++++++++++++ src/CAM/CAM_Application.h | 2 ++ src/CAM/CAM_Module.cxx | 6 ++++++ src/CAM/CAM_Module.h | 2 ++ src/STD/STD_Application.cxx | 17 +++++++++++++++++ src/STD/STD_Application.h | 2 ++ 6 files changed, 46 insertions(+) diff --git a/src/CAM/CAM_Application.cxx b/src/CAM/CAM_Application.cxx index e45d4a8cd..ed7260417 100755 --- a/src/CAM/CAM_Application.cxx +++ b/src/CAM/CAM_Application.cxx @@ -863,3 +863,20 @@ CAM_Application::ModuleShortInfoList CAM_Application::getVersionInfo() } return info; } + +/*! + \brief Abort active operations if there are any + + Iterates through all modules and asks each of them if there are pending operations that cannot be aborted. + + \return \c false if some operation cannot be aborted +*/ +bool CAM_Application::abortAllOperations() +{ + bool aborted = true; + for ( QList::const_iterator it = myModules.begin(); it != myModules.end() && aborted; ++it ) + { + aborted = (*it)->abortAllOperations(); + } + return aborted; +} diff --git a/src/CAM/CAM_Application.h b/src/CAM/CAM_Application.h index d25f4d4c2..5944e55d3 100755 --- a/src/CAM/CAM_Application.h +++ b/src/CAM/CAM_Application.h @@ -93,6 +93,8 @@ protected: static QString moduleLibrary( const QString&, const bool = true ); + virtual bool abortAllOperations(); + private: void readModuleList(); diff --git a/src/CAM/CAM_Module.cxx b/src/CAM/CAM_Module.cxx index 5d7d569de..d3a0ddaf1 100755 --- a/src/CAM/CAM_Module.cxx +++ b/src/CAM/CAM_Module.cxx @@ -1134,3 +1134,9 @@ void CAM_Module::connectToStudy( CAM_Study* camStudy ) \fn void CAM_Module::updateCommandsStatus(); \brief Update menu/toolbar actions. */ + + +bool CAM_Module::abortAllOperations() +{ + return true; +} diff --git a/src/CAM/CAM_Module.h b/src/CAM/CAM_Module.h index 74a2b6e75..952f18571 100755 --- a/src/CAM/CAM_Module.h +++ b/src/CAM/CAM_Module.h @@ -145,6 +145,8 @@ protected: // after activate/deactivate modules QMap, QKeySequence> myActionShortcutMap; //!< copy actions shortcut map + virtual bool abortAllOperations(); + private: CAM_Application* myApp; //!< parent application object QString myName; //!< module title (user name) diff --git a/src/STD/STD_Application.cxx b/src/STD/STD_Application.cxx index 557371ac0..47b3a0459 100755 --- a/src/STD/STD_Application.cxx +++ b/src/STD/STD_Application.cxx @@ -324,6 +324,9 @@ void STD_Application::onOpenDoc() /*! \retval true, if document was opened successful, else false.*/ bool STD_Application::onOpenDoc( const QString& aName ) { + if ( !abortAllOperations() ) + return false; + QApplication::setOverrideCursor( Qt::WaitCursor ); bool res = openAction( openChoice( aName ), aName ); @@ -564,6 +567,9 @@ void STD_Application::onSaveDoc() if ( !activeStudy() ) return; + if ( !abortAllOperations() ) + return; + bool isOk = false; if ( activeStudy()->isSaved() ) { @@ -599,6 +605,9 @@ bool STD_Application::onSaveAsDoc() if ( !study ) return false; + if ( !abortAllOperations() ) + return false; + bool isOk = false; while ( !isOk ) { @@ -1013,3 +1022,11 @@ int STD_Application::viewManagerId( const SUIT_ViewManager* theManager) const return myViewMgrs.indexOf(const_cast(theManager)); } +/*! + \brief Abort active operations if there are any + \return \c false if some operation cannot be aborted +*/ +bool STD_Application::abortAllOperations() +{ + return true; +} diff --git a/src/STD/STD_Application.h b/src/STD/STD_Application.h index ed3f6fed5..2b1f4653c 100755 --- a/src/STD/STD_Application.h +++ b/src/STD/STD_Application.h @@ -170,6 +170,8 @@ protected: virtual bool closeDoc( bool ask = true ); virtual bool closeActiveDoc( bool permanently = true ); + virtual bool abortAllOperations(); + private: ViewManagerList myViewMgrs; SUIT_ViewManager* myActiveViewMgr; -- 2.39.2