DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
daq::QTUtils::QDebugStream Class Reference

#include <qdebugstream.hpp>

Inheritance diagram for daq::QTUtils::QDebugStream:
[legend]
Collaboration diagram for daq::QTUtils::QDebugStream:
[legend]

Public Member Functions

 QDebugStream (std::ostream &stream, QTextEdit *text_edit)
 
 ~QDebugStream ()
 

Protected Member Functions

virtual int_type overflow (int_type v)
 
virtual std::streamsize xsputn (const char *p, std::streamsize n)
 
virtual bool event (QEvent *event)
 

Private Attributes

std::ostream & m_stream
 
std::streambuf * m_old_buf
 
std::string m_string
 
QTextEdit * log_window
 
QMutex * m_mutex
 
QString m_text
 

Detailed Description

Redirects a std::ostream (such as cout or cerr) to a text edit. In order to reset the stream simply delete the QDebugStream object.
Usage:

qout = new QDebugStream(std::cout, myTextEdit); //everything written to std::cout is appended to the text edit
...
delete qout; //resets the streamoutput
QDebugStream(std::ostream &stream, QTextEdit *text_edit)

Definition at line 27 of file qdebugstream.hpp.

Constructor & Destructor Documentation

◆ QDebugStream()

daq::QTUtils::QDebugStream::QDebugStream ( std::ostream & stream,
QTextEdit * text_edit )
inline

Definition at line 33 of file qdebugstream.hpp.

33 :
34 m_stream(stream) {
35 m_mutex = new QMutex();
36 log_window = text_edit;
37 m_old_buf = stream.rdbuf();
38 stream.rdbuf(this);
39 }

◆ ~QDebugStream()

daq::QTUtils::QDebugStream::~QDebugStream ( )
inline

Definition at line 40 of file qdebugstream.hpp.

40 {
41 // output anything that is left
42 if (!m_string.empty())
43 log_window->append(m_string.c_str());
44
45 m_stream.rdbuf(m_old_buf);
46 delete m_mutex;
47 }

Member Function Documentation

◆ event()

bool QDebugStream::event ( QEvent * event)
protectedvirtual

Definition at line 20 of file qdebugstream.cpp.

20 {
21 if (event->type() == QEvent::User) {
22 {
23 QMutexLocker locker(m_mutex);
24 if (!m_text.isEmpty())
25 log_window->append(m_text);
26 m_text.clear();
27 }
28 event->accept();
29 return true;
30 }
31 return false;
32}
virtual bool event(QEvent *event)

◆ overflow()

std::streambuf::int_type QDebugStream::overflow ( int_type v)
protectedvirtual

Definition at line 34 of file qdebugstream.cpp.

34 {
35 QMutexLocker locker(m_mutex);
36 if (v == '\n') {
37 m_text.append(m_string.c_str()).append("\n");
38 m_string.erase(m_string.begin(), m_string.end());
39 } else {
40 m_string += v;
41 }
42 QCoreApplication::postEvent(this, new QEvent(QEvent::User));
43 return v;
44}

◆ xsputn()

std::streamsize QDebugStream::xsputn ( const char * p,
std::streamsize n )
protectedvirtual

Definition at line 4 of file qdebugstream.cpp.

4 {
5 QMutexLocker locker(m_mutex);
6 m_string.append(p, p + n);
7
8 uint pos = 0;
9 while (pos != std::string::npos) {
10 pos = m_string.find('\n');
11 if (pos != std::string::npos) {
12 std::string tmp(m_string.begin(), m_string.begin() + pos);
13 m_text.append(tmp.c_str()).append("\n");
14 m_string.erase(m_string.begin(), m_string.begin() + pos + 1);
15 }
16 }
17 QCoreApplication::postEvent(this, new QEvent(QEvent::User));
18 return n;
19}

Member Data Documentation

◆ log_window

QTextEdit* daq::QTUtils::QDebugStream::log_window
private

Definition at line 57 of file qdebugstream.hpp.

◆ m_mutex

QMutex* daq::QTUtils::QDebugStream::m_mutex
private

Definition at line 58 of file qdebugstream.hpp.

◆ m_old_buf

std::streambuf* daq::QTUtils::QDebugStream::m_old_buf
private

Definition at line 55 of file qdebugstream.hpp.

◆ m_stream

std::ostream& daq::QTUtils::QDebugStream::m_stream
private

Definition at line 54 of file qdebugstream.hpp.

◆ m_string

std::string daq::QTUtils::QDebugStream::m_string
private

Definition at line 56 of file qdebugstream.hpp.

◆ m_text

QString daq::QTUtils::QDebugStream::m_text
private

Definition at line 59 of file qdebugstream.hpp.


The documentation for this class was generated from the following files: