Commit 66aa4a4b authored by grunau's avatar grunau
Browse files

QTextEditLog: display log messages in a QTextEdit

QTextEditLog is a tgt::Log subclass that is initialised with a QTextEdit
instance to which it then redirects all log messages it receives.

git-svn-id: bb408c1c-ae56-11e1-83d9-df6b3e0c105e
parent 7061f724
......@@ -20,10 +20,10 @@ FILE(GLOB CampvisApplicationHeaders
FILE(GLOB CampvisApplicationForms
FILE(GLOB CampvisApplicationForms
......@@ -46,6 +46,7 @@ SET(CampvisApplicationToBeMocced
LIST(APPEND CampvisApplicationDefinitions "-DCAMPVIS_SOURCE_DIR=\"${CampvisHome}\"")
......@@ -56,8 +57,8 @@ LIST(APPEND CampvisApplicationDefinitions "-DCAMPVIS_SOURCE_DIR=\"${CampvisHome}
FIND_PACKAGE(Qt4 ${CampvisRequiredQtVersion} REQUIRED QtCore QtGui QtOpenGL)
QT4_WRAP_CPP(CampvisApplicationMoc ${CampvisApplicationToBeMocced})
LIST(APPEND CampvisApplicationSources ${CampvisApplicationMoc})
QT4_WRAP_UI(CampvisApplicationFormsHeaders ${CampvisApplicationForms})
LIST(APPEND CampvisApplicationSources ${CampvisApplicationFormsHeaders})
QT4_WRAP_UI(CampvisApplicationFormsHeaders ${CampvisApplicationForms})
LIST(APPEND CampvisApplicationSources ${CampvisApplicationFormsHeaders})
LINK_DIRECTORIES(${CampvisGlobalLinkDirectories} ${CampvisModulesLinkDirectories})
#include "qtexteditlog.h"
#include "tgt/assert.h"
namespace campvis {
QTextEditLog::QTextEditLog(QTextEdit* logDisplay, bool dateStamping, bool timeStamping,
bool showCat, bool showLevel)
: _logDisplay(logDisplay)
tgtAssert(logDisplay != 0, "Log display widget must not be 0.");
dateStamping_ = dateStamping;
timeStamping_ = timeStamping;
showCat_ = showCat;
showLevel_ = showLevel;
connect(this, SIGNAL(s_messageReady(const QString&)),
_logDisplay, SLOT(append(const QString&)));
void QTextEditLog::logFiltered(const std::string& cat, LogLevel level, const std::string& msg,
const std::string& /*extendedInfo*/)
std::string output = "";
if (dateStamping_)
output += "[" + getDateString() + "] ";
if (timeStamping_)
output += "[" + getTimeString() + "] ";
if (showCat_)
output += cat + " ";
if (showLevel_)
output += "(" + getLevelString(level) + ") ";
if (output != "")
output += '\t';
emit s_messageReady(QString::fromStdString(output + msg));
\ No newline at end of file
#include "tgt/logmanager.h"
#include <QObject>
#include <QTextEdit>
#include <QTextDocument>
using namespace tgt;
namespace campvis {
* QTextEditLog implements logging to a QTextEdit instance.
class QTextEditLog : private QObject, public Log {
* Creates a new QTextEditLog.
* QTextEditLog doesn't take ownership of the QTextEdit instance it's passed.
* \param output a QTextEdit instance to which messages will be logged
* \param dateStamping should logged messages be date-stamped
* \param timeStamping should logged messages be time-stamped
* \param showCat should the category be printed along with the messages
* \param showLevel should the LogLevel be printed along with the messages
QTextEditLog(QTextEdit* logDisplay, bool dateStamping = true, bool timeStamping = true,
bool showCat = true, bool showLevel = true);
virtual ~QTextEditLog() {}
bool isOpen() { return true; }
/** Internal signal used to pass messages to _logDisplay in a thread-safe way.
* This class' \c log method is called from several non-GUI
* threads. If it were to directly access its underlying
* QTextEdit widget, which is neither thread-safe nor reentrant,
* the application would break badly. However, if we connect
* a signal to _logDisplay's append slot to display log
* messages, Qt takes care of queueing slot accesses in the GUI
* thread for us.
void s_messageReady(const QString& message);
QTextEdit* _logDisplay;
void logFiltered(const std::string &cat, LogLevel level, const std::string &msg, const std::string &extendedInfo="");
#endif // QTEXTEDITLOG_H__
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment