Restructure qt displayer for thread separation

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

@ -62,12 +62,13 @@ public:
// set a special title to the window bar // set a special title to the window bar
virtual void setTitleBar (const std::string &/* titleBar */) { } 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) // 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 // true for windows
bool needSlashR; bool needSlashR;

@ -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,81 +98,7 @@ 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)
{
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<char *>(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<char *>(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;
tSigDisplay(color, str.substr(0, str.size() - 1).c_str()); tSigDisplay(color, str.substr(0, str.size() - 1).c_str());
} }
@ -198,11 +116,42 @@ void CCommandLog::returnPressed()
return; return;
std::string cmd = text.toLocal8Bit().data(); std::string cmd = text.toLocal8Bit().data();
ICommand::execute(cmd, InfoLog()); execCommand(cmd);
m_CommandInput->clear(); 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 */ } /* namespace NLQT */
/* end of file */ /* end of file */

Loading…
Cancel
Save