#include <KERNEL_version.h>
#include <GUI_version.h>
+#include <QAction>
#include <QApplication>
+#include <QDir>
+#include <QFileInfo>
+#include <QMutex>
+#include <QMutexLocker>
#include <QRegExp>
+#include <QTextStream>
#ifdef WIN32
#include <windows.h>
}
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( ": " ) );
+ }
+}
+
static ModuleShortInfoList getVersionInfo();
+ static void logUserEvent( const QString& );
+ static void logAction( QAction*, const QString& = QString() );
+
protected:
virtual SUIT_Study* createNewStudy();
virtual void updateCommandsStatus();
myName( name ),
myDataModel( 0 ),
myMenuShown( false ),
- myToolShown( false )
+ myToolShown( false ),
+ myActionLoggingEnabled( false )
{
}
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 );
{
return true;
}
+
+/*!
+ \brief Called when an action is triggered
+*/
+void CAM_Module::moduleActionActivated()
+{
+ QAction* action = qobject_cast<QAction*>( 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;
+}
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:
virtual void onApplicationClosed( SUIT_Application* );
+ virtual void moduleActionActivated();
+
private slots:
void onInfoChanged( QString );
QMap<int, QAction*> myActionMap; //!< menu actions
bool myMenuShown; //!< menu shown flag
bool myToolShown; //!< tool shown flag
+ bool myActionLoggingEnabled; //!< action logging enabled
friend class CAM_Application;
};
<source>MODULE_ROOT_OBJECT_TOOLTIP</source>
<translation>%1 module root object</translation>
</message>
+ <message>
+ <source>ACTION_TRIGGERED</source>
+ <translation>action is triggered</translation>
+ </message>
+ <message>
+ <source>ACTION_TOGGLED</source>
+ <translation>action is toggled</translation>
+ </message>
+ <message>
+ <source>ACTION_ON</source>
+ <translation>on</translation>
+ </message>
+ <message>
+ <source>ACTION_OFF</source>
+ <translation>off</translation>
+ </message>
+ <message>
+ <source>OPERATION_APPLIED</source>
+ <translation>operation applied</translation>
+ </message>
</context>
</TS>
#include <QMimeData>
#include <QShortcut>
#include <QRegExp>
-#include <QMutex>
-#include <QMutexLocker>
#include <utilities.h>
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()
virtual bool checkExistingDoc( bool = true );
- static void logUserEvent(const QString& eventDescription);
-
#ifndef DISABLE_PYCONSOLE
PyConsole_Interp* getPyInterp();
#endif
};
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 ) );
+}
static void startPyLog(const QString&);
static void stopPyLog();
+ static void logUserEvent( const QString& );
+ static void logAction( QAction*, const QString& = QString() );
};
#endif // SALOME_PYQT_H
static void startPyLog(const QString&) /ReleaseGIL/ ;
static void stopPyLog() /ReleaseGIL/ ;
+
+ static void logUserEvent( const QString& ) /ReleaseGIL/ ;
+ static void logAction( QAction*, const QString& = QString() ) /ReleaseGIL/ ;
};