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 35 of file qdebugstream.hpp.

36 : m_stream(stream)
37 {
38 m_mutex = new QMutex();
39 log_window = text_edit;
40 m_old_buf = stream.rdbuf();
41 stream.rdbuf(this);
42 }

◆ ~QDebugStream()

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

Definition at line 43 of file qdebugstream.hpp.

44 {
45 // output anything that is left
46 if (!m_string.empty())
47 log_window->append(m_string.c_str());
48
49 m_stream.rdbuf(m_old_buf);
50 delete m_mutex;
51 }

Member Function Documentation

◆ event()

bool QDebugStream::event ( QEvent * event)
protectedvirtual

Definition at line 23 of file qdebugstream.cpp.

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

◆ overflow()

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

Definition at line 39 of file qdebugstream.cpp.

40{
41 QMutexLocker locker(m_mutex);
42 if (v == '\n') {
43 m_text.append(m_string.c_str()).append("\n");
44 m_string.erase(m_string.begin(), m_string.end());
45 } else {
46 m_string += v;
47 }
48 QCoreApplication::postEvent(this, new QEvent(QEvent::User));
49 return v;
50}
default char v[0]

◆ xsputn()

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

Definition at line 5 of file qdebugstream.cpp.

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

Member Data Documentation

◆ log_window

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

Definition at line 62 of file qdebugstream.hpp.

◆ m_mutex

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

Definition at line 63 of file qdebugstream.hpp.

◆ m_old_buf

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

Definition at line 60 of file qdebugstream.hpp.

◆ m_stream

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

Definition at line 59 of file qdebugstream.hpp.

◆ m_string

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

Definition at line 61 of file qdebugstream.hpp.

◆ m_text

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

Definition at line 64 of file qdebugstream.hpp.


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