From: vsr Date: Mon, 23 May 2022 12:59:39 +0000 (+0300) Subject: bos #29467 SALOME GUI logger X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=cde8ae38395782bc30ad4366758eccdd3bb8287f;p=modules%2Fgui.git bos #29467 SALOME GUI logger --- diff --git a/src/CAM/CAM_Application.cxx b/src/CAM/CAM_Application.cxx index b4b4d9aa8..d3bfadf17 100644 --- a/src/CAM/CAM_Application.cxx +++ b/src/CAM/CAM_Application.cxx @@ -34,8 +34,14 @@ #include #include +#include #include +#include +#include +#include +#include #include +#include #ifdef WIN32 #include @@ -935,3 +941,81 @@ bool CAM_Application::abortAllOperations() } return aborted; } + +/*! + \brief Log GUI event. + \param eventDescription GUI event description. +*/ +void CAM_Application::logUserEvent( const QString& eventDescription ) +{ + static QString guiLogFile; // null string means log file was not initialized yet + static QMutex aGUILogMutex; + + if ( guiLogFile.isNull() ) + { + // log file was not initialized yet, try to do that by parsing command line arguments + guiLogFile = ""; // empty string means initialization was done but log file was not set + QStringList args = QApplication::arguments(); + for ( int i = 1; i < args.count(); i++ ) + { + QRegExp rxs ( "--gui-log-file=(.+)" ); + if ( rxs.indexIn( args[i] ) >= 0 && rxs.capturedTexts().count() > 1 ) + { + QString file = rxs.capturedTexts()[1]; + QFileInfo fi ( file ); + if ( !fi.isDir() && fi.dir().exists() ) + { + guiLogFile = fi.absoluteFilePath(); + if ( fi.exists() ) { + QFile file ( guiLogFile ); + file.remove(); // remove probably existing log file, to start with empty one + } + } + break; + } + } + } + if ( !guiLogFile.isEmpty() ) // non-empty string means log file was already initialized + { + QMutexLocker aLocker( &aGUILogMutex ); + QFile file ( guiLogFile ); + if ( file.open( QFile::Append ) ) // append to log file + { + QTextStream stream( &file ); + stream << eventDescription << endl; + file.close(); + } + } +} + +/*! + \brief Log given action. + \param action GUI action being logged. + \param moduleName optional name of module, owning an action +*/ +void CAM_Application::logAction( QAction* action, const QString& moduleName ) +{ + QString text = action->toolTip(); + if ( text.isEmpty() ) + text = action->text(); + if ( text.isEmpty() ) + text = action->iconText(); + if ( !text.isEmpty() ) + { + QStringList message; + if ( !moduleName.isEmpty() ) + message << moduleName; + if ( action->isCheckable() ) + { + message << tr( "ACTION_TOGGLED" ); + message << ( action->isChecked() ? tr( "ACTION_ON" ) : tr( "ACTION_OFF" ) ); + } + else + { + message << tr( "ACTION_TRIGGERED" ); + } + message << text; + logUserEvent( message.join( ": " ) ); + } +} + diff --git a/src/CAM/CAM_Application.h b/src/CAM/CAM_Application.h index c4ce86178..c984bbf2d 100644 --- a/src/CAM/CAM_Application.h +++ b/src/CAM/CAM_Application.h @@ -82,6 +82,9 @@ public: static ModuleShortInfoList getVersionInfo(); + static void logUserEvent( const QString& ); + static void logAction( QAction*, const QString& = QString() ); + protected: virtual SUIT_Study* createNewStudy(); virtual void updateCommandsStatus(); diff --git a/src/CAM/CAM_Module.cxx b/src/CAM/CAM_Module.cxx index 13ae3c4ab..bce98f384 100644 --- a/src/CAM/CAM_Module.cxx +++ b/src/CAM/CAM_Module.cxx @@ -92,7 +92,8 @@ CAM_Module::CAM_Module( const QString& name ) myName( name ), myDataModel( 0 ), myMenuShown( false ), - myToolShown( false ) + myToolShown( false ), + myActionLoggingEnabled( false ) { } @@ -1018,6 +1019,8 @@ QAction* CAM_Module::createAction( const int id, const QString& text, const QIco QtxAction* a = new QtxAction( text, icon, menu, key, parent, toggle, shortcutAction ); a->setStatusTip( tip ); + connect( a, SIGNAL( triggered( bool ) ), this, SLOT( moduleActionActivated() ), Qt::UniqueConnection ); + if ( reciever && member ) connect( a, SIGNAL( triggered( bool ) ), reciever, member ); @@ -1215,3 +1218,41 @@ bool CAM_Module::abortAllOperations() { return true; } + +/*! + \brief Called when an action is triggered +*/ +void CAM_Module::moduleActionActivated() +{ + QAction* action = qobject_cast( sender() ); + if ( action && !action->isSeparator() && isActionLoggingEnabled() ) + logAction( action ); +} + +/*! + \brief Log given action. + \param action GUI action being logged. + + Default implementation just forwards to CAM_Applicaion::logAction(); +*/ +void CAM_Module::logAction( QAction* action ) +{ + CAM_Application::logAction( action, moduleName() ); +} + +/*! + \brief Return \c true if action logging is enabled. +*/ +bool CAM_Module::isActionLoggingEnabled() const +{ + return myActionLoggingEnabled; +} + +/*! + \brief Enable / disable action logging. + \param enabled \c true to enable logging, or \c false to disable it. +*/ +void CAM_Module::setActionLoggingEnabled( bool enabled ) +{ + myActionLoggingEnabled = enabled; +} diff --git a/src/CAM/CAM_Module.h b/src/CAM/CAM_Module.h index 406fa4f7a..62cfd3125 100644 --- a/src/CAM/CAM_Module.h +++ b/src/CAM/CAM_Module.h @@ -122,6 +122,10 @@ public: int createMenu( QAction*, const int, const int = -1, const int = -1, const int = -1 ); int createMenu( QAction*, const QString&, const int = -1, const int = -1, const int = -1 ); + virtual void logAction( QAction* ); + bool isActionLoggingEnabled() const; + void setActionLoggingEnabled( bool ); + static QAction* separator(); public slots: @@ -135,6 +139,8 @@ public slots: virtual void onApplicationClosed( SUIT_Application* ); + virtual void moduleActionActivated(); + private slots: void onInfoChanged( QString ); @@ -164,6 +170,7 @@ private: QMap myActionMap; //!< menu actions bool myMenuShown; //!< menu shown flag bool myToolShown; //!< tool shown flag + bool myActionLoggingEnabled; //!< action logging enabled friend class CAM_Application; }; diff --git a/src/CAM/resources/CAM_msg_en.ts b/src/CAM/resources/CAM_msg_en.ts index 6779ef228..fb54357e4 100644 --- a/src/CAM/resources/CAM_msg_en.ts +++ b/src/CAM/resources/CAM_msg_en.ts @@ -15,5 +15,25 @@ MODULE_ROOT_OBJECT_TOOLTIP %1 module root object + + ACTION_TRIGGERED + action is triggered + + + ACTION_TOGGLED + action is toggled + + + ACTION_ON + on + + + ACTION_OFF + off + + + OPERATION_APPLIED + operation applied + diff --git a/src/LightApp/LightApp_Application.cxx b/src/LightApp/LightApp_Application.cxx index 2a8a4dca6..e687135f6 100644 --- a/src/LightApp/LightApp_Application.cxx +++ b/src/LightApp/LightApp_Application.cxx @@ -193,8 +193,6 @@ #include #include #include -#include -#include #include @@ -5425,45 +5423,6 @@ bool LightApp_Application::checkExistingDoc( bool closeExistingDoc ) return result; } -/*! - Log GUI action -*/ -void LightApp_Application::logUserEvent(const QString& eventDescription) -{ - static QString _gui_log_file_ = "Not initialized"; - static QMutex aGUILogMutex; - if (_gui_log_file_ == "Not initialized") { - _gui_log_file_ = ""; - QStringList args = QApplication::arguments(); - for (int i = 1; i < args.count(); i++) { - QRegExp rxs ("--gui-log-file=(.+)"); - if (rxs.indexIn( args[i] ) >= 0 && rxs.capturedTexts().count() > 1) { - QString file = rxs.capturedTexts()[1]; - QFileInfo fi ( file ); - if (!fi.isDir()) { - if (fi.dir().exists()) { - _gui_log_file_ = fi.absoluteFilePath(); - if (fi.exists()) { - QFile file (_gui_log_file_); - file.remove(); - } - } - } - break; - } - } - } - if (_gui_log_file_ != "") { - QMutexLocker aLocker (&aGUILogMutex); - QFile file (_gui_log_file_); - if (file.open(QFile::Append)) { - QTextStream stream( &file ); - stream << eventDescription << endl; - file.close(); - } - } -} - #ifndef DISABLE_PYCONSOLE PyConsole_Interp* LightApp_Application::getPyInterp() diff --git a/src/LightApp/LightApp_Application.h b/src/LightApp/LightApp_Application.h index 2ad55b938..29af725c2 100644 --- a/src/LightApp/LightApp_Application.h +++ b/src/LightApp/LightApp_Application.h @@ -189,8 +189,6 @@ public: virtual bool checkExistingDoc( bool = true ); - static void logUserEvent(const QString& eventDescription); - #ifndef DISABLE_PYCONSOLE PyConsole_Interp* getPyInterp(); #endif diff --git a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx index d7382482f..795b8593d 100644 --- a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx +++ b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx @@ -5067,3 +5067,43 @@ void SalomePyQt::stopPyLog() }; ProcessVoidEvent( new TEvent() ); } + +/*! + \brief Log GUI event. + \param eventDescription GUI event description. +*/ +void SalomePyQt::logUserEvent( const QString& eventDescription ) +{ + class TEvent: public SALOME_Event + { + QString myEventDescription; + public: + TEvent( const QString& theDescription ) : myEventDescription( theDescription ) {} + virtual void Execute() + { + LightApp_Application::logUserEvent( myEventDescription ); + } + }; + ProcessVoidEvent( new TEvent( eventDescription ) ); +} + +/*! + \brief Log given action. + \param action GUI action being logged. + \param moduleName optional name of module, owning an action +*/ +void SalomePyQt::logAction( QAction* action, const QString& moduleName ) +{ + class TEvent: public SALOME_Event + { + QAction* myAction; + QString myModuleName; + public: + TEvent( QAction* theAction, const QString& theModuleName ) : myAction( theAction ), myModuleName( theModuleName ) {} + virtual void Execute() + { + LightApp_Application::logAction( myAction, myModuleName ); + } + }; + ProcessVoidEvent( new TEvent( action, moduleName ) ); +} diff --git a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.h b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.h index e405442f6..7643b2d07 100644 --- a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.h +++ b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.h @@ -377,6 +377,8 @@ public: static void startPyLog(const QString&); static void stopPyLog(); + static void logUserEvent( const QString& ); + static void logAction( QAction*, const QString& = QString() ); }; #endif // SALOME_PYQT_H diff --git a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip index a283576ee..67c0b5e1c 100644 --- a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip +++ b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip @@ -495,4 +495,7 @@ public: static void startPyLog(const QString&) /ReleaseGIL/ ; static void stopPyLog() /ReleaseGIL/ ; + + static void logUserEvent( const QString& ) /ReleaseGIL/ ; + static void logAction( QAction*, const QString& = QString() ) /ReleaseGIL/ ; };