#include <LogView.h>
Public Slots | |
void | flushBuffer () |
Signals | |
void | bufferReady () |
Public Member Functions | |
void | append (const QString &text) |
virtual ClassId | classId () const |
void | clear () |
LogView (QWidget *parent=0) | |
void | operator= (LogView &o) |
void | remove () |
Protected Member Functions | |
virtual void | flushStream () |
virtual void | sendToStream (const QString &val) |
QGpGuiTools::LogView::LogView | ( | QWidget * | parent = 0 | ) |
A LogView is a QWidget but also an AbstractStream that can be automatically deleted by the log manager at application level. To prevent abusive deletion while still linked to its QWidget parent, an auto-reference is added in this constructor. As a matter ofconsequence, you cannot delete this object (or let its parent destroying it) directly with delete. Instead, call remove().
References QGpCoreTools::SharedObject::addReference(), bufferReady(), flushBuffer(), and TRACE.
: QTextBrowser(parent), AbstractStream() { TRACE; setAcceptRichText (false); setFontFamily( "Bitstream Vera Sans Mono" ); setLineWrapMode(QTextEdit::NoWrap); // Avoid more than 2 refresh of the widget per second _clock.setInterval(500); connect(&_clock, SIGNAL(timeout()), this, SLOT(flushBuffer()) ); connect(this, SIGNAL(bufferReady()), this, SLOT(wakeUp()), Qt::QueuedConnection); addReference(); // Avoid deletion by stream management }
void QGpGuiTools::LogView::append | ( | const QString & | text | ) | [inline] |
void QGpGuiTools::LogView::bufferReady | ( | ) | [signal] |
Referenced by flushStream(), LogView(), and sendToStream().
virtual ClassId QGpGuiTools::LogView::classId | ( | ) | const [inline, virtual] |
Implements QGpCoreTools::AbstractStream.
{return LogViewId;}
void QGpGuiTools::LogView::clear | ( | ) |
References QGpCoreTools::AbstractStream::lock(), TRACE, and QGpCoreTools::AbstractStream::unlock().
{ TRACE; lock (); _buffer.clear(); QTextBrowser::clear(); unlock(); }
void QGpGuiTools::LogView::flushBuffer | ( | ) | [slot] |
References append(), QGpCoreTools::AbstractStream::lock(), TRACE, TRACE_BUG, and QGpCoreTools::AbstractStream::unlock().
Referenced by LogView(), operator=(), and QGpGuiTools::LogWidget::text().
{ TRACE; lock (); if(_buffer.isEmpty()) { TRACE_BUG; _clock.stop(); } else if(_buffer.length()>1000000) { TRACE_BUG; _buffer+= "\n\n Buffer overflow!\nFreezing stream..."; QTextBrowser::append( "\n\n [...] \n\n" ); _buffer=_buffer.right(500000); } else { if(_buffer.endsWith("\n")) { TRACE_BUG; _buffer.chop(1); QTextBrowser::append(_buffer); _buffer.clear(); } else { TRACE_BUG; int lastLF=_buffer.lastIndexOf("\n"); if(lastLF > -1) { QTextBrowser::append(_buffer.left(lastLF) ); _buffer=_buffer.right(_buffer.length() - lastLF - 1); } } } unlock(); }
void QGpGuiTools::LogView::flushStream | ( | ) | [protected, virtual] |
Implements QGpCoreTools::AbstractStream.
References bufferReady().
{ if(!_clock.isActive()) emit bufferReady(); }
void QGpGuiTools::LogView::operator= | ( | LogView & | o | ) |
References flushBuffer(), QGpCoreTools::AbstractStream::lock(), TRACE, and QGpCoreTools::AbstractStream::unlock().
{ TRACE; lock (); o.lock (); _buffer=o._buffer; setText(o.toPlainText()); o.unlock(); unlock(); flushBuffer(); }
void QGpGuiTools::LogView::remove | ( | ) |
Detach from its QWidget parent, if any and delete this oblect
References QGpCoreTools::SharedObject::removeReference(), and TRACE.
{ TRACE; hide(); setParent(0); removeReference(this); }
void QGpGuiTools::LogView::sendToStream | ( | const QString & | val | ) | [protected, virtual] |
Implements QGpCoreTools::AbstractStream.
References bufferReady().
{ _buffer+=val; if(!_clock.isActive()) emit bufferReady(); }