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

Console. More...

#include <ecvConsole.h>

Inheritance diagram for ecvConsole:
[legend]
Collaboration diagram for ecvConsole:
[legend]

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 ecvConsole * TheInstance (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 CVLog * TheInstance ()
 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...
 
MainWindow * m_parentWindow
 Parent window (if any) More...
 
QMutex m_mutex
 Mutex for concurrent thread access to console. More...
 
QVector< ConsoleItemType > m_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.

Member Typedef Documentation

◆ ConsoleItemType

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

Queue element type (message + color)

Constructor & Destructor Documentation

◆ ~ecvConsole()

ecvConsole::~ecvConsole ( )
override

Destructor.

References setLogFile().

◆ ecvConsole()

ecvConsole::ecvConsole ( )
protected

Default constructor.

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

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.

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

◆ generateLogFileName()

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

Generate log file name with timestamp and pid.

Referenced by setLogFile().

◆ getLogDirectory()

QString ecvConsole::getLogDirectory ( )
staticprotected

Get appropriate log directory path (handles permissions on Ubuntu)

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)

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.

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)

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

References s_showQtMessagesInConsole.

Referenced by myMessageOutput().

◆ refresh

void ecvConsole::refresh ( )
slot

◆ ReleaseInstance()

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

Releases unique instance.

References CVLog::RegisterInstance(), and s_console.

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

◆ setAutoRefresh()

void ecvConsole::setAutoRefresh ( bool  state)

Sets auto-refresh state.

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

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

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

Member Data Documentation

◆ m_logFile

QFile ecvConsole::m_logFile
protected

Log file.

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

◆ m_logStream

QTextStream* ecvConsole::m_logStream
protected

Log file stream.

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

◆ m_mutex

QMutex ecvConsole::m_mutex
protected

Mutex for concurrent thread access to console.

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

◆ m_parentWidget

QWidget* ecvConsole::m_parentWidget
protected

Parent widget.

Referenced by logMessage(), and parentWidget().

◆ m_parentWindow

MainWindow* ecvConsole::m_parentWindow
protected

Parent window (if any)

Referenced by refresh().

◆ m_queue

QVector<ConsoleItemType> ecvConsole::m_queue
protected

Queue for incoming messages.

Referenced by logMessage(), and refresh().

◆ m_textDisplay

QListWidget* ecvConsole::m_textDisplay
protected

Associated text display widget.

Referenced by logMessage(), and refresh().

◆ m_timer

QTimer ecvConsole::m_timer
protected

Timer for auto-refresh.

Referenced by setAutoRefresh().

◆ s_redirectToStdOut

bool ecvConsole::s_redirectToStdOut = false
staticprotected

Referenced by Init(), and logMessage().

◆ s_showQtMessagesInConsole

bool ecvConsole::s_showQtMessagesInConsole = false
staticprotected

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

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


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