Restructure qt displayer for thread separation

--HG--
branch : qt5
hg/feature/qt5
kaetemi 10 years ago
parent f3a1fb0b83
commit 958e6f80bd

@ -64,8 +64,9 @@ public:
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) // 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);

@ -121,7 +121,7 @@ void CMainWindow::createDockWindows()
m_CommandLogDock = new QDockWidget(this); m_CommandLogDock = new QDockWidget(this);
m_CommandLogDock->setWindowTitle(tr("Console")); m_CommandLogDock->setWindowTitle(tr("Console"));
m_CommandLogDock->setAllowedAreas(Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea); 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); m_CommandLogDock->setWidget(m_CommandLog);
addDockWidget(Qt::BottomDockWidgetArea, m_CommandLogDock); addDockWidget(Qt::BottomDockWidgetArea, m_CommandLogDock);
m_WidgetsMenu->addAction(m_CommandLogDock->toggleViewAction()); m_WidgetsMenu->addAction(m_CommandLogDock->toggleViewAction());

@ -39,7 +39,7 @@ class QUndoStack;
class QScrollArea; class QScrollArea;
namespace NLQT { namespace NLQT {
class CCommandLog; class CCommandLogDisplayer;
} }
namespace NLTOOLS { namespace NLTOOLS {
@ -78,7 +78,7 @@ private:
private: private:
CPanoplyPreview *m_PanoplyPreview; CPanoplyPreview *m_PanoplyPreview;
NLQT::CCommandLog *m_CommandLog; NLQT::CCommandLogDisplayer *m_CommandLog;
QDockWidget *m_CommandLogDock; QDockWidget *m_CommandLogDock;
QMenu *m_WidgetsMenu; QMenu *m_WidgetsMenu;

@ -46,7 +46,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
namespace NLQT { namespace NLQT {
class CCommandLog : public QWidget, public NLMISC::IDisplayer class CCommandLog : public QWidget
{ {
Q_OBJECT Q_OBJECT
@ -54,11 +54,11 @@ public:
CCommandLog(QWidget *parent); CCommandLog(QWidget *parent);
virtual ~CCommandLog(); virtual ~CCommandLog();
protected: void doDisplay(const NLMISC::CLog::TDisplayInfo& args, const char *message);
virtual void doDisplay(const NLMISC::CLog::TDisplayInfo& args, const char *message);
signals: signals:
void tSigDisplay(const QColor &c, const QString &text); void tSigDisplay(const QColor &c, const QString &text);
void execCommand(const std::string &cmd);
private slots: private slots:
void returnPressed(); void returnPressed();
@ -74,6 +74,29 @@ private:
}; /* class CCommandLog */ }; /* 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 */ } /* namespace NLQT */
#endif /* #ifndef NLQT_COMMAND_LOG_H */ #endif /* #ifndef NLQT_COMMAND_LOG_H */

@ -39,6 +39,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <nel/misc/debug.h> #include <nel/misc/debug.h>
#include <nel/misc/command.h> #include <nel/misc/command.h>
#include <nel/misc/path.h> #include <nel/misc/path.h>
#include <nel/misc/window_displayer.h>
// Project includes // Project includes
@ -62,20 +63,11 @@ CCommandLog::CCommandLog(QWidget *parent) : QWidget(parent)
connect(m_CommandInput, SIGNAL(returnPressed()), this, SLOT(returnPressed())); connect(m_CommandInput, SIGNAL(returnPressed()), this, SLOT(returnPressed()));
connect(this, SIGNAL(tSigDisplay(const QColor &, const QString &)), this, SLOT(tSlotDisplay(const QColor &, const QString &))); 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() 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) void CCommandLog::doDisplay(const CLog::TDisplayInfo& args, const char *message)
@ -106,101 +98,58 @@ void CCommandLog::doDisplay(const CLog::TDisplayInfo& args, const char *message)
break; break;
} }
bool needSpace = false; std::string str = NLMISC::CWindowDisplayer::stringifyMessage(args, message);
//stringstream ss;
string str;
if (args.LogType != CLog::LOG_NO) tSigDisplay(color, str.substr(0, str.size() - 1).c_str());
{
str += logTypeToString(args.LogType);
needSpace = true;
} }
// Write thread identifier void CCommandLog::tSlotDisplay(const QColor &c, const QString &text)
if (args.ThreadId != 0)
{ {
if (needSpace) { str += " "; needSpace = false; } m_DisplayerOutput->setTextColor(c);
#ifdef NL_OS_WINDOWS m_DisplayerOutput->append(text);
str += NLMISC::toString("%4x", args.ThreadId);
#else
str += NLMISC::toString("%08x", args.ThreadId);
#endif
needSpace = true;
} }
if (args.FileName != NULL) void CCommandLog::returnPressed()
{ {
if (needSpace) { str += " "; needSpace = false; } QString text = m_CommandInput->text();
str += NLMISC::toString("%20s", CFile::getFilename(args.FileName).c_str()); if (text.isEmpty())
needSpace = true; return;
}
if (args.Line != -1) std::string cmd = text.toLocal8Bit().data();
{ execCommand(cmd);
if (needSpace) { str += " "; needSpace = false; }
str += NLMISC::toString("%4u", args.Line);
//ss << setw(4) << args.Line;
needSpace = true;
}
if (args.FuncName != NULL) m_CommandInput->clear();
{
if (needSpace) { str += " "; needSpace = false; }
str += NLMISC::toString("%20s", args.FuncName);
needSpace = true;
} }
if (needSpace) { str += ": "; needSpace = false; } CCommandLogDisplayer::CCommandLogDisplayer(QWidget *parent) : CCommandLog(parent)
uint nbl = 1;
char *npos, *pos = const_cast<char *>(message);
while ((npos = strchr (pos, '\n')))
{ {
*npos = '\0'; connect(this, SIGNAL(execCommand(const std::string &)), this, SLOT(execCommandLog(const std::string &)));
str += pos; DebugLog->addDisplayer(this);
/*if (needSlashR) InfoLog->addDisplayer(this);
str += "\r";*/ WarningLog->addDisplayer(this);
str += "\n"; AssertLog->addDisplayer(this);
*npos = '\n'; ErrorLog->addDisplayer(this);
pos = npos+1; m_Log.addDisplayer(this);
nbl++;
} }
str += pos;
pos = const_cast<char *>(args.CallstackAndLog.c_str()); CCommandLogDisplayer::~CCommandLogDisplayer()
while ((npos = strchr (pos, '\n')))
{ {
*npos = '\0'; DebugLog->removeDisplayer(this);
str += pos; InfoLog->removeDisplayer(this);
/*if (needSlashR) WarningLog->removeDisplayer(this);
str += "\r";*/ AssertLog->removeDisplayer(this);
str += "\n"; ErrorLog->removeDisplayer(this);
*npos = '\n'; m_Log.removeDisplayer(this);
pos = npos+1;
nbl++;
}
str += pos;
tSigDisplay(color, str.substr(0, str.size() - 1).c_str());
} }
void CCommandLog::tSlotDisplay(const QColor &c, const QString &text) void CCommandLogDisplayer::doDisplay(const NLMISC::CLog::TDisplayInfo& args, const char *message)
{ {
m_DisplayerOutput->setTextColor(c); CCommandLog::doDisplay(args, message);
m_DisplayerOutput->append(text);
} }
void CCommandLog::returnPressed() void CCommandLogDisplayer::execCommandLog(const std::string &cmd)
{ {
QString text = m_CommandInput->text(); ICommand::execute(cmd, m_Log);
if (text.isEmpty())
return;
std::string cmd = text.toLocal8Bit().data();
ICommand::execute(cmd, InfoLog());
m_CommandInput->clear();
} }
} /* namespace NLQT */ } /* namespace NLQT */

Loading…
Cancel
Save