ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ecvConsole Class Reference

Console. More...

#include <ecvConsole.h>

Inheritance diagram for ecvConsole:
Collaboration diagram for ecvConsole:

Public Slots

void refresh ()
 Refreshes console (display all messages still in queue) More...
 

Public Member Functions

 ~ecvConsole () override
 Destructor. More...
 
void setAutoRefresh (bool state)
 Sets auto-refresh state. More...
 
bool setLogFile (const QString &logPrefix)
 Sets log file with prefix (generates timestamped log file like glog) More...
 
QWidget * parentWidget ()
 Returns the parent widget (if any) More...
 
- Public Member Functions inherited from CVLog
virtual ~CVLog ()
 Destructor. More...
 

Static Public Member Functions

static void Init (QListWidget *textDisplay=nullptr, QWidget *parentWidget=nullptr, MainWindow *parentWindow=nullptr, bool redirectToStdOut=false)
 Inits console (and optionaly associates it with a text output widget) More...
 
static ecvConsoleTheInstance (bool autoInit=true)
 Returns the (unique) static instance. More...
 
static void ReleaseInstance (bool flush=true)
 Releases unique instance. More...
 
static void EnableQtMessages (bool state)
 Whether to show Qt messages (qDebug / qWarning / etc.) in Console. More...
 
static bool QtMessagesEnabled ()
 
- Static Public Member Functions inherited from CVLog
static CVLogTheInstance ()
 Returns the static and unique instance. More...
 
static void RegisterInstance (CVLog *logInstance)
 Registers a unique instance. More...
 
static void EnableMessageBackup (bool state)
 Enables the message backup system. More...
 
static int VerbosityLevel ()
 Returns the current verbosity level. More...
 
static void SetVerbosityLevel (int level)
 Sets the verbosity level. More...
 
static void LogMessage (const QString &message, int level)
 Static shortcut to CVLog::logMessage. More...
 
static bool PrintVerbose (const char *format,...)
 Prints out a verbose formatted message in console. More...
 
static bool PrintVerbose (const QString &message)
 QString version of ccLog::PrintVerbose. More...
 
static bool Print (const char *format,...)
 Prints out a formatted message in console. More...
 
static bool Print (const QString &message)
 QString version of ccLog::Print. More...
 
static bool PrintHigh (const char *format,...)
 Prints out an important formatted message in console. More...
 
static bool PrintHigh (const QString &message)
 QString version of ccLog::PrintHigh. More...
 
static bool PrintDebug (const char *format,...)
 Same as Print, but works only in Debug mode. More...
 
static bool PrintDebug (const QString &message)
 QString version of ccLog::PrintDebug. More...
 
static bool Warning (const char *format,...)
 Prints out a formatted warning message in console. More...
 
static bool Warning (const QString &message)
 QString version of ccLog::Warning. More...
 
static bool WarningDebug (const char *format,...)
 Same as Warning, but works only in Debug mode. More...
 
static bool WarningDebug (const QString &message)
 QString version of ccLog::WarningDebug. More...
 
static bool Error (const char *format,...)
 Display an error dialog with formatted message. More...
 
static bool Error (const QString &message)
 QString version of 'Error'. More...
 
static bool ErrorDebug (const char *format,...)
 Same as Error, but works only in Debug mode. More...
 
static bool ErrorDebug (const QString &message)
 QString version of ccLog::ErrorDebug. More...
 

Protected Types

using ConsoleItemType = QPair< QString, int >
 Queue element type (message + color) More...
 

Protected Member Functions

 ecvConsole ()
 Default constructor. More...
 
void logMessage (const QString &message, int level) override
 Generic message logging method. More...
 

Static Protected Member Functions

static QString generateLogFileName (const QString &prefix)
 Generate log file name with timestamp and pid. More...
 
static QString getLogDirectory ()
 Get appropriate log directory path (handles permissions on Ubuntu) More...
 

Protected Attributes

QListWidget * m_textDisplay
 Associated text display widget. More...
 
QWidget * m_parentWidget
 Parent widget. More...
 
MainWindowm_parentWindow
 Parent window (if any) More...
 
QMutex m_mutex
 Mutex for concurrent thread access to console. More...
 
QVector< ConsoleItemTypem_queue
 Queue for incoming messages. More...
 
QTimer m_timer
 Timer for auto-refresh. More...
 
QFile m_logFile
 Log file. More...
 
QTextStream * m_logStream
 Log file stream. More...
 

Static Protected Attributes

static bool s_showQtMessagesInConsole = false
 Whether to show Qt messages (qDebug / qWarning / etc.) in Console. More...
 
static bool s_redirectToStdOut = false
 

Additional Inherited Members

- Public Types inherited from CVLog
enum  MessageLevelFlags {
  LOG_VERBOSE = 0 , LOG_STANDARD = 1 , LOG_IMPORTANT = 2 , LOG_WARNING = 3 ,
  LOG_ERROR = 4 , DEBUG_FLAG = 8
}
 Message level. More...
 

Detailed Description

Console.

Definition at line 35 of file ecvConsole.h.

Member Typedef Documentation

◆ ConsoleItemType

using ecvConsole::ConsoleItemType = QPair<QString, int>
protected

Queue element type (message + color)

Definition at line 118 of file ecvConsole.h.

Constructor & Destructor Documentation

◆ ~ecvConsole()

ecvConsole::~ecvConsole ( )
override

Destructor.

Definition at line 105 of file ecvConsole.cpp.

References setLogFile().

◆ ecvConsole()

ecvConsole::ecvConsole ( )
protected

Default constructor.

Constructor is protected to avoid using this object as a non static class.

Definition at line 99 of file ecvConsole.cpp.

Referenced by Init(), and TheInstance().

Member Function Documentation

◆ EnableQtMessages()

void ecvConsole::EnableQtMessages ( bool  state)
static

Whether to show Qt messages (qDebug / qWarning / etc.) in Console.

Definition at line 170 of file ecvConsole.cpp.

References ecvPS::Console(), s_showQtMessagesInConsole, and ecvSettingManager::setValue().

◆ generateLogFileName()

QString ecvConsole::generateLogFileName ( const QString &  prefix)
staticprotected

Generate log file name with timestamp and pid.

Definition at line 345 of file ecvConsole.cpp.

Referenced by setLogFile().

◆ getLogDirectory()

QString ecvConsole::getLogDirectory ( )
staticprotected

Get appropriate log directory path (handles permissions on Ubuntu)

Definition at line 357 of file ecvConsole.cpp.

References cloudViewer::t::geometry::path.

Referenced by setLogFile().

◆ Init()

void ecvConsole::Init ( QListWidget *  textDisplay = nullptr,
QWidget *  parentWidget = nullptr,
MainWindow parentWindow = nullptr,
bool  redirectToStdOut = false 
)
static

Inits console (and optionaly associates it with a text output widget)

WARNING: in release mode, no message will be output if no 'textDisplay' widget is defined. Moreover, error messages will only appear in a (blocking) QMessageBox if a 'parentWidget' widget is defined. In debug mode, all message are sent to system console (with 'printf').

Parameters
textDisplaytext output widget (optional)
parentWidgetparent widget (optional)
parentWindowparent window (if any - optional)

Definition at line 178 of file ecvConsole.cpp.

References ecvPS::Console(), ecvConsole(), ecvSettingManager::getValue(), Settings::LOGFILE_PREFIX, myMessageOutput(), parentWidget(), CVLog::RegisterInstance(), s_console, s_redirectToStdOut, and s_showQtMessagesInConsole.

Referenced by ccCommandLineParser::Parse(), and CommandLogFile::process().

◆ logMessage()

void ecvConsole::logMessage ( const QString &  message,
int  level 
)
overrideprotectedvirtual

Generic message logging method.

To be implemented by child class.

Warning
MUST BE THREAD SAFE!
Parameters
messagemessage
levelmessage severity (see MessageLevelFlags)

Implements CVLog.

Definition at line 276 of file ecvConsole.cpp.

References DATETIME, QtCompat::endl(), CVLog::LOG_ERROR, CVLog::LOG_VERBOSE, CVLog::LOG_WARNING, m_logFile, m_logStream, m_mutex, m_parentWidget, m_queue, m_textDisplay, and s_redirectToStdOut.

◆ parentWidget()

QWidget* ecvConsole::parentWidget ( )
inline

Returns the parent widget (if any)

Definition at line 83 of file ecvConsole.h.

References m_parentWidget.

Referenced by Init().

◆ QtMessagesEnabled()

static bool ecvConsole::QtMessagesEnabled ( )
inlinestatic

Returns whether to show Qt messages (qDebug / qWarning / etc.) in Console or not

Definition at line 80 of file ecvConsole.h.

References s_showQtMessagesInConsole.

Referenced by myMessageOutput().

◆ refresh

void ecvConsole::refresh ( )
slot

Refreshes console (display all messages still in queue)

Definition at line 224 of file ecvConsole.cpp.

References ecvColor::blue(), CVLog::DEBUG_FLAG, MainWindow::forceConsoleDisplay(), CVLog::LOG_ERROR, CVLog::LOG_WARNING, m_logFile, m_logStream, m_mutex, m_parentWindow, m_queue, m_textDisplay, and ecvColor::red().

Referenced by setAutoRefresh().

◆ ReleaseInstance()

void ecvConsole::ReleaseInstance ( bool  flush = true)
static

Releases unique instance.

Definition at line 90 of file ecvConsole.cpp.

References CVLog::RegisterInstance(), and s_console.

Referenced by ccCommandLineParser::Parse(), and MainWindow::~MainWindow().

◆ setAutoRefresh()

void ecvConsole::setAutoRefresh ( bool  state)

Sets auto-refresh state.

Definition at line 214 of file ecvConsole.cpp.

References m_timer, and refresh().

Referenced by setLogFile().

◆ setLogFile()

bool ecvConsole::setLogFile ( const QString &  logPrefix)

Sets log file with prefix (generates timestamped log file like glog)

Parameters
logPrefixlog file prefix (e.g., "ACloudviewer")
Returns
true if successful, false otherwise Generates log file name: <prefix>.<timestamp>.<pid>.log

Definition at line 454 of file ecvConsole.cpp.

References cloudViewer::core::Append(), QtCompat::endl(), CVLog::Error(), generateLogFileName(), getLogDirectory(), m_logFile, m_logStream, m_mutex, CVLog::Print(), and setAutoRefresh().

Referenced by ~ecvConsole().

◆ TheInstance()

ecvConsole * ecvConsole::TheInstance ( bool  autoInit = true)
static

Returns the (unique) static instance.

Parameters
autoInitautomatically initialize the console instance (with no widget!) if not done already

Definition at line 81 of file ecvConsole.cpp.

References ecvConsole(), CVLog::RegisterInstance(), and s_console.

Member Data Documentation

◆ m_logFile

QFile ecvConsole::m_logFile
protected

Log file.

Definition at line 127 of file ecvConsole.h.

Referenced by logMessage(), refresh(), and setLogFile().

◆ m_logStream

QTextStream* ecvConsole::m_logStream
protected

Log file stream.

Definition at line 129 of file ecvConsole.h.

Referenced by logMessage(), refresh(), and setLogFile().

◆ m_mutex

QMutex ecvConsole::m_mutex
protected

Mutex for concurrent thread access to console.

Definition at line 115 of file ecvConsole.h.

Referenced by logMessage(), refresh(), and setLogFile().

◆ m_parentWidget

QWidget* ecvConsole::m_parentWidget
protected

Parent widget.

Definition at line 109 of file ecvConsole.h.

Referenced by logMessage(), and parentWidget().

◆ m_parentWindow

MainWindow* ecvConsole::m_parentWindow
protected

Parent window (if any)

Definition at line 112 of file ecvConsole.h.

Referenced by refresh().

◆ m_queue

QVector<ConsoleItemType> ecvConsole::m_queue
protected

Queue for incoming messages.

Definition at line 121 of file ecvConsole.h.

Referenced by logMessage(), and refresh().

◆ m_textDisplay

QListWidget* ecvConsole::m_textDisplay
protected

Associated text display widget.

Definition at line 106 of file ecvConsole.h.

Referenced by logMessage(), and refresh().

◆ m_timer

QTimer ecvConsole::m_timer
protected

Timer for auto-refresh.

Definition at line 124 of file ecvConsole.h.

Referenced by setAutoRefresh().

◆ s_redirectToStdOut

bool ecvConsole::s_redirectToStdOut = false
staticprotected

Definition at line 133 of file ecvConsole.h.

Referenced by Init(), and logMessage().

◆ s_showQtMessagesInConsole

bool ecvConsole::s_showQtMessagesInConsole = false
staticprotected

Whether to show Qt messages (qDebug / qWarning / etc.) in Console.

Definition at line 132 of file ecvConsole.h.

Referenced by EnableQtMessages(), Init(), and QtMessagesEnabled().


The documentation for this class was generated from the following files: