diff src/UiGuiLogger.cpp @ 751:ac165b6ae67e

Done some refactoring: - Moved includes into the cpp files where possible and using class pre-declarations if possible - Made class member variable names begin with an underscore - Made by uic created header files be used as class members instead of inherting them - Renamed some variables to reflect their purpose better - Added some NULL initializations and added some comments - Rearranged some include and declaration code parts to be consistent and better readable - Updated for QScintilla 2.4.5 - Made UiGuiSettings be accessed via a shared pointer only git-svn-id: svn://svn.code.sf.net/p/universalindent/code/trunk@1028 59b1889a-e5ac-428c-b0c7-476e01d41282
author thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
date Thu, 14 Oct 2010 19:52:47 +0000
parents aae5a8d04f70
children
line wrap: on
line diff
--- a/src/UiGuiLogger.cpp	Sat Oct 02 12:48:56 2010 +0000
+++ b/src/UiGuiLogger.cpp	Thu Oct 14 19:52:47 2010 +0000
@@ -18,28 +18,44 @@
  ***************************************************************************/
 
 #include "UiGuiLogger.h"
+#include "ui_UiGuiLoggerDialog.h"
 
-#include <ctime>
+#include "SettingsPaths.h"
+
 #include <QDateTime>
 #include <QFile>
+#include <QFileInfo>
 #include <QUrl>
 #include <QTextStream>
 #include <QDesktopServices>
 
-#include "SettingsPaths.h"
+#include <ctime>
+
+UiGuiLogger* UiGuiLogger::_instance = NULL;
+
+/*!
+    \class UiGuiLogger
+    \brief This class handles any kind of data logging, for debugging and whatever purpose.
 
-UiGuiLogger* UiGuiLogger::instance = NULL;
+    Beneath being able of displaying a dialog window containing all log messages of the
+    current session, a log file in the systems temporary directory is used. Its name
+    is "UiGUI_log.html".
+
+    Setting a verbose level allows to only write messages that have the selected minimum
+    priority to the log.
+ */
 
 /*!
     \brief Returns the only existing instance of UiGuiLogger. If the instance doesn't exist, it will be created.
  */
 UiGuiLogger* UiGuiLogger::getInstance(int verboseLevel) {
-    if ( instance == NULL )
-        instance = new UiGuiLogger(verboseLevel);
+    if ( _instance == NULL )
+        _instance = new UiGuiLogger(verboseLevel);
 
-    return instance;
+    return _instance;
 }
 
+
 /*!
     \brief Returns the only existing instance of UiGuiLogger. If the instance doesn't exist, it will be created.
  */
@@ -57,16 +73,17 @@
     Sets the default verbose level to warning level.
  */
 UiGuiLogger::UiGuiLogger(int verboseLevel) : QDialog() {
-    setupUi(this);
+	_uiGuiLoggerDialogForm = new Ui::UiGuiLoggerDialog();
+    _uiGuiLoggerDialogForm->setupUi(this);
 #ifdef _DEBUG
-    this->verboseLevel = QtDebugMsg;
+    _verboseLevel = QtDebugMsg;
 #else
-    this->verboseLevel = QtMsgType(verboseLevel);
+    _verboseLevel = QtMsgType(verboseLevel);
 #endif
 
-    logFileInitState = NOTINITIALZED;
+    _logFileInitState = NOTINITIALZED;
 
-    connect( openLogFileFolderToolButton, SIGNAL(clicked()), this, SLOT(openLogFileFolder()) );
+    connect( _uiGuiLoggerDialogForm->openLogFileFolderToolButton, SIGNAL(clicked()), this, SLOT(openLogFileFolder()) );
 
     // Make the main application not to wait for the logging window to close.
     setAttribute(Qt::WA_QuitOnClose, false);
@@ -79,11 +96,11 @@
     Only messages whos \a type have a higher priority than the set verbose level are logged.
  */
 void UiGuiLogger::messageHandler(QtMsgType type, const char *msg) {
-    if ( instance == NULL )
-        instance = UiGuiLogger::getInstance();
+    if ( _instance == NULL )
+        _instance = UiGuiLogger::getInstance();
 
     // Only log messages that have a higher or equal priority than set with the verbose level.
-    if ( type < instance->verboseLevel )
+    if ( type < _instance->_verboseLevel )
         return;
 
     // Init log message with prepended date and time.
@@ -113,10 +130,10 @@
     message += QString::fromUtf8( msg ) + "<br/>\n";
 
     // Write the message to the log windows text edit.
-    instance->logTextEdit->append( message );
+    _instance->_uiGuiLoggerDialogForm->logTextEdit->append( message );
 
     // Write/append the log message to the log file.
-    instance->writeToLogFile( message );
+    _instance->writeToLogFile( message );
 
     // In case of a fatal error abort the application.
     if ( type == QtFatalMsg )
@@ -130,21 +147,21 @@
  */
 void UiGuiLogger::setVerboseLevel(int level) {
     if ( level < 0 )
-        verboseLevel = QtDebugMsg;
+        _verboseLevel = QtDebugMsg;
     if ( level > 3 )
-        verboseLevel = QtFatalMsg;
+        _verboseLevel = QtFatalMsg;
     else
-        verboseLevel = QtMsgType(level);
+        _verboseLevel = QtMsgType(level);
 }
 
 
 /*!
-    \brief Deletes the existing instance of UiGuiLogger.
+    \brief Deletes the existing _instance of UiGuiLogger.
  */
 void UiGuiLogger::deleteInstance() {
-    if ( instance != NULL ) {
-        delete instance;
-        instance = NULL;
+    if ( _instance != NULL ) {
+        delete _instance;
+        _instance = NULL;
     }
 }
 
@@ -153,7 +170,7 @@
     \brief Opens the folder that contains the created log file with the name "UiGUI_log.html".
  */
 void UiGuiLogger::openLogFileFolder() {
-    QDesktopServices::openUrl( QFileInfo( logFile ).absolutePath() );
+    QDesktopServices::openUrl( QFileInfo( _logFile ).absolutePath() );
 }
 
 
@@ -162,8 +179,8 @@
  */
 void UiGuiLogger::writeToLogFile(const QString &message) {
     // If the file where all logging messages should go to isn't initilized yet, do that now.
-    if ( logFileInitState == NOTINITIALZED ) {
-        logFileInitState = INITIALIZING;
+    if ( _logFileInitState == NOTINITIALZED ) {
+        _logFileInitState = INITIALIZING;
 
         // On different systems it may be that "QDir::tempPath()" ends with a "/" or not. So check this.
         // Remove any trailing slashes.
@@ -195,28 +212,28 @@
         }
         logFileName += "_" + QString(randomChar) + ".html";
 
-        logFile.setFileName( tempPath + "/" + logFileName );
+        _logFile.setFileName( tempPath + "/" + logFileName );
 
         // Set the tooltip of the open log file folder button to show the unique name of the log file.
-        openLogFileFolderToolButton->setToolTip( openLogFileFolderToolButton->toolTip() + " (" + logFileName + ")" );
+        _uiGuiLoggerDialogForm->openLogFileFolderToolButton->setToolTip( _uiGuiLoggerDialogForm->openLogFileFolderToolButton->toolTip() + " (" + logFileName + ")" );
 
-        logFileInitState = INITIALZED;
+        _logFileInitState = INITIALZED;
     }
 
     // Add the message to the message queue.
-    messageQueue << message;
+    _messageQueue << message;
 
     // If the logging file is initialzed, write all messages contained in the message queue into the file.
-    if ( logFileInitState == INITIALZED ) {
+    if ( _logFileInitState == INITIALZED ) {
         // Write/append the log message to the log file.
-        if ( logFile.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append) ) {
-            QTextStream out(&logFile);
+        if ( _logFile.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append) ) {
+            QTextStream out(&_logFile);
 
-            while ( !messageQueue.isEmpty() ) {
-                out << messageQueue.takeFirst() << "\n";
+            while ( !_messageQueue.isEmpty() ) {
+                out << _messageQueue.takeFirst() << "\n";
             }
 
-            logFile.close();
+            _logFile.close();
         }
     }
 }