diff --git a/code/nel/include/nel/misc/window_displayer.h b/code/nel/include/nel/misc/window_displayer.h index de05b25d5..a1dfdc8cf 100644 --- a/code/nel/include/nel/misc/window_displayer.h +++ b/code/nel/include/nel/misc/window_displayer.h @@ -62,12 +62,13 @@ public: // set a special title to the window bar virtual void setTitleBar (const std::string &/* titleBar */) { } - virtual void getWindowPos (uint32 &x, uint32 &y, uint32 &w, uint32 &h) { x=y=w=h=0; } + virtual void getWindowPos(uint32 &x, uint32 &y, uint32 &w, uint32 &h) { x = y = w = h = 0; } -protected: + static std::string stringifyMessage(const NLMISC::CLog::TDisplayInfo &args, const char *message, bool needSlashR = false); +protected: // display a string (MT) - virtual void doDisplay (const NLMISC::CLog::TDisplayInfo &args, const char *message); + virtual void doDisplay(const NLMISC::CLog::TDisplayInfo &args, const char *message); // true for windows bool needSlashR; diff --git a/code/nel/tools/3d/panoply_preview/main_window.cpp b/code/nel/tools/3d/panoply_preview/main_window.cpp index 5b5128c2b..621f33d6f 100644 --- a/code/nel/tools/3d/panoply_preview/main_window.cpp +++ b/code/nel/tools/3d/panoply_preview/main_window.cpp @@ -121,7 +121,7 @@ void CMainWindow::createDockWindows() m_CommandLogDock = new QDockWidget(this); m_CommandLogDock->setWindowTitle(tr("Console")); m_CommandLogDock->setAllowedAreas(Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea); - m_CommandLog = new NLQT::CCommandLog(m_CommandLogDock); + m_CommandLog = new NLQT::CCommandLogDisplayer(m_CommandLogDock); m_CommandLogDock->setWidget(m_CommandLog); addDockWidget(Qt::BottomDockWidgetArea, m_CommandLogDock); m_WidgetsMenu->addAction(m_CommandLogDock->toggleViewAction()); diff --git a/code/nel/tools/3d/panoply_preview/main_window.h b/code/nel/tools/3d/panoply_preview/main_window.h index cf2a1c75f..3e3d2f025 100644 --- a/code/nel/tools/3d/panoply_preview/main_window.h +++ b/code/nel/tools/3d/panoply_preview/main_window.h @@ -39,7 +39,7 @@ class QUndoStack; class QScrollArea; namespace NLQT { - class CCommandLog; + class CCommandLogDisplayer; } namespace NLTOOLS { @@ -78,7 +78,7 @@ private: private: CPanoplyPreview *m_PanoplyPreview; - NLQT::CCommandLog *m_CommandLog; + NLQT::CCommandLogDisplayer *m_CommandLog; QDockWidget *m_CommandLogDock; QMenu *m_WidgetsMenu; diff --git a/code/nelqt/include/nelqt/displayer/command_log.h b/code/nelqt/include/nelqt/displayer/command_log.h index d60a8de19..d51a93463 100644 --- a/code/nelqt/include/nelqt/displayer/command_log.h +++ b/code/nelqt/include/nelqt/displayer/command_log.h @@ -46,7 +46,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace NLQT { -class CCommandLog : public QWidget, public NLMISC::IDisplayer +class CCommandLog : public QWidget { Q_OBJECT @@ -54,11 +54,11 @@ public: CCommandLog(QWidget *parent); virtual ~CCommandLog(); -protected: - virtual void doDisplay(const NLMISC::CLog::TDisplayInfo& args, const char *message); + void doDisplay(const NLMISC::CLog::TDisplayInfo& args, const char *message); signals: void tSigDisplay(const QColor &c, const QString &text); + void execCommand(const std::string &cmd); private slots: void returnPressed(); @@ -74,6 +74,29 @@ private: }; /* class CCommandLog */ +class CCommandLogDisplayer : public CCommandLog, public NLMISC::IDisplayer +{ + Q_OBJECT + +public: + CCommandLogDisplayer(QWidget *parent); + virtual ~CCommandLogDisplayer(); + +protected: + virtual void doDisplay(const NLMISC::CLog::TDisplayInfo& args, const char *message); + +private slots: + void execCommandLog(const std::string &cmd); + +private: + NLMISC::CLog m_Log; + +private: + CCommandLogDisplayer(const CCommandLogDisplayer &); + CCommandLogDisplayer &operator=(const CCommandLogDisplayer &); + +}; /* class CCommandLogDisplayer */ + } /* namespace NLQT */ #endif /* #ifndef NLQT_COMMAND_LOG_H */ diff --git a/code/nelqt/src/displayer/command_log.cpp b/code/nelqt/src/displayer/command_log.cpp index 8d6437dab..d51565306 100644 --- a/code/nelqt/src/displayer/command_log.cpp +++ b/code/nelqt/src/displayer/command_log.cpp @@ -39,6 +39,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include // Project includes @@ -62,20 +63,11 @@ CCommandLog::CCommandLog(QWidget *parent) : QWidget(parent) connect(m_CommandInput, SIGNAL(returnPressed()), this, SLOT(returnPressed())); connect(this, SIGNAL(tSigDisplay(const QColor &, const QString &)), this, SLOT(tSlotDisplay(const QColor &, const QString &))); - DebugLog->addDisplayer(this); - InfoLog->addDisplayer(this); - WarningLog->addDisplayer(this); - AssertLog->addDisplayer(this); - ErrorLog->addDisplayer(this); } CCommandLog::~CCommandLog() { - DebugLog->removeDisplayer(this); - InfoLog->removeDisplayer(this); - WarningLog->removeDisplayer(this); - AssertLog->removeDisplayer(this); - ErrorLog->removeDisplayer(this); + } void CCommandLog::doDisplay(const CLog::TDisplayInfo& args, const char *message) @@ -106,81 +98,7 @@ void CCommandLog::doDisplay(const CLog::TDisplayInfo& args, const char *message) break; } - bool needSpace = false; - //stringstream ss; - string str; - - if (args.LogType != CLog::LOG_NO) - { - str += logTypeToString(args.LogType); - needSpace = true; - } - - // Write thread identifier - if (args.ThreadId != 0) - { - if (needSpace) { str += " "; needSpace = false; } -#ifdef NL_OS_WINDOWS - str += NLMISC::toString("%4x", args.ThreadId); -#else - str += NLMISC::toString("%08x", args.ThreadId); -#endif - needSpace = true; - } - - if (args.FileName != NULL) - { - if (needSpace) { str += " "; needSpace = false; } - str += NLMISC::toString("%20s", CFile::getFilename(args.FileName).c_str()); - needSpace = true; - } - - if (args.Line != -1) - { - if (needSpace) { str += " "; needSpace = false; } - str += NLMISC::toString("%4u", args.Line); - //ss << setw(4) << args.Line; - needSpace = true; - } - - if (args.FuncName != NULL) - { - if (needSpace) { str += " "; needSpace = false; } - str += NLMISC::toString("%20s", args.FuncName); - needSpace = true; - } - - if (needSpace) { str += ": "; needSpace = false; } - - uint nbl = 1; - - char *npos, *pos = const_cast(message); - while ((npos = strchr (pos, '\n'))) - { - *npos = '\0'; - str += pos; - /*if (needSlashR) - str += "\r";*/ - str += "\n"; - *npos = '\n'; - pos = npos+1; - nbl++; - } - str += pos; - - pos = const_cast(args.CallstackAndLog.c_str()); - while ((npos = strchr (pos, '\n'))) - { - *npos = '\0'; - str += pos; - /*if (needSlashR) - str += "\r";*/ - str += "\n"; - *npos = '\n'; - pos = npos+1; - nbl++; - } - str += pos; + std::string str = NLMISC::CWindowDisplayer::stringifyMessage(args, message); tSigDisplay(color, str.substr(0, str.size() - 1).c_str()); } @@ -198,11 +116,42 @@ void CCommandLog::returnPressed() return; std::string cmd = text.toLocal8Bit().data(); - ICommand::execute(cmd, InfoLog()); + execCommand(cmd); m_CommandInput->clear(); } +CCommandLogDisplayer::CCommandLogDisplayer(QWidget *parent) : CCommandLog(parent) +{ + connect(this, SIGNAL(execCommand(const std::string &)), this, SLOT(execCommandLog(const std::string &))); + DebugLog->addDisplayer(this); + InfoLog->addDisplayer(this); + WarningLog->addDisplayer(this); + AssertLog->addDisplayer(this); + ErrorLog->addDisplayer(this); + m_Log.addDisplayer(this); +} + +CCommandLogDisplayer::~CCommandLogDisplayer() +{ + DebugLog->removeDisplayer(this); + InfoLog->removeDisplayer(this); + WarningLog->removeDisplayer(this); + AssertLog->removeDisplayer(this); + ErrorLog->removeDisplayer(this); + m_Log.removeDisplayer(this); +} + +void CCommandLogDisplayer::doDisplay(const NLMISC::CLog::TDisplayInfo& args, const char *message) +{ + CCommandLog::doDisplay(args, message); +} + +void CCommandLogDisplayer::execCommandLog(const std::string &cmd) +{ + ICommand::execute(cmd, m_Log); +} + } /* namespace NLQT */ /* end of file */