Messagelib

htmlwriter.cpp
1 /*
2  SPDX-FileCopyrightText: 2017 Volker Krause <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "htmlwriter.h"
8 
9 #include <QTextStream>
10 
11 using namespace MessageViewer;
12 
13 HtmlWriter::HtmlWriter() = default;
14 HtmlWriter::~HtmlWriter() = default;
15 
17 {
18  if (!m_stream) {
19  m_stream = std::make_unique<QTextStream>();
20  }
21  m_stream->setDevice(device());
22 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
23  m_stream->setCodec("UTF-8");
24 #endif
25 }
26 
27 void HtmlWriter::write(const QString &html)
28 {
29  Q_ASSERT(m_stream);
30  if (!m_stream) {
31  return;
32  }
33  *stream() << html;
34 }
35 
37 {
38  if (!m_stream) {
39  return;
40  }
41  m_stream->flush();
42  m_stream->setDevice(nullptr);
43 }
44 
46 {
47  if (!m_stream) {
48  return;
49  }
50  m_stream->setDevice(nullptr);
51 }
52 
54 {
55  return m_stream.get();
56 }
57 
58 void HtmlWriter::setCodec(const QByteArray &codec)
59 {
60  mCodec = codec;
61 }
62 
63 QByteArray HtmlWriter::codec() const
64 {
65  return mCodec;
66 }
virtual QIODevice * device() const =0
Returns the QIODevice backing this HtmlWriter instance.
virtual void end()
Signal the end of stuff to write.
Definition: htmlwriter.cpp:36
virtual void begin()
Signal the begin of stuff to write.
Definition: htmlwriter.cpp:16
QTextStream * stream() const
Returns a QTextStream on device().
Definition: htmlwriter.cpp:53
virtual void reset()
Stop all possibly pending processing in order to be able to call begin() again.
Definition: htmlwriter.cpp:45
void write(const QString &html)
Write out a chunk of text.
Definition: htmlwriter.cpp:27
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sun Dec 5 2021 23:04:53 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.