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 }
void write(const QString &html)
Write out a chunk of text.
Definition: htmlwriter.cpp:27
virtual QIODevice * device() const =0
Returns the QIODevice backing this HtmlWriter instance.
virtual void reset()
Stop all possibly pending processing in order to be able to call begin() again.
Definition: htmlwriter.cpp:45
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 end()
Signal the end of stuff to write.
Definition: htmlwriter.cpp:36
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Sat Apr 1 2023 04:01:56 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.