diff options
Diffstat (limited to 'src/gui/text/qtextdocumentwriter.cpp')
-rw-r--r-- | src/gui/text/qtextdocumentwriter.cpp | 102 |
1 files changed, 11 insertions, 91 deletions
diff --git a/src/gui/text/qtextdocumentwriter.cpp b/src/gui/text/qtextdocumentwriter.cpp index 0bafa5d9ff..55f8414bd5 100644 --- a/src/gui/text/qtextdocumentwriter.cpp +++ b/src/gui/text/qtextdocumentwriter.cpp @@ -1,49 +1,10 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "qtextdocumentwriter.h" #include <QtCore/qfile.h> #include <QtCore/qbytearray.h> #include <QtCore/qfileinfo.h> -#if QT_CONFIG(textcodec) -#include <QtCore/qtextcodec.h> -#endif #include <QtCore/qtextstream.h> #include <QtCore/qdebug.h> #include "qtextdocument.h" @@ -68,9 +29,6 @@ public: QByteArray format; QIODevice *device; bool deleteDevice; -#if QT_CONFIG(textcodec) - QTextCodec *codec; -#endif QTextDocumentWriter *q; }; @@ -83,7 +41,6 @@ public: \inmodule QtGui \ingroup richtext-processing - \ingroup io To write a document, construct a QTextDocumentWriter object with either a file name or a device object, and specify the document format to be @@ -109,9 +66,6 @@ public: QTextDocumentWriterPrivate::QTextDocumentWriterPrivate(QTextDocumentWriter *qq) : device(nullptr), deleteDevice(false), -#if QT_CONFIG(textcodec) - codec(QTextCodec::codecForName("utf-8")), -#endif q(qq) { } @@ -191,7 +145,7 @@ QByteArray QTextDocumentWriter::format () const unchanged. If the device is not already open, QTextDocumentWriter will attempt to - open the device in \l QIODevice::WriteOnly mode by calling open(). + open the device in \l {QIODeviceBase::}{WriteOnly} mode by calling open(). \note This will not work for certain devices, such as QProcess, QTcpSocket and QUdpSocket, where some configuration is required before @@ -220,7 +174,8 @@ QIODevice *QTextDocumentWriter::device () const /*! Sets the name of the file to be written to \a fileName. Internally, QTextDocumentWriter will create a QFile and open it in \l - QIODevice::WriteOnly mode, and use this file when writing the document. + {QIODeviceBase::}{WriteOnly} mode, and use this file when writing the + document. \sa fileName(), setDevice() */ @@ -249,9 +204,11 @@ QString QTextDocumentWriter::fileName () const */ bool QTextDocumentWriter::write(const QTextDocument *document) { - QByteArray suffix; + if (!d->device) + return false; - if (d->device && d->format.isEmpty()) { + QByteArray suffix; + if (d->format.isEmpty()) { // if there's no format, see if device is a file, and if so, find // the file suffix if (QFile *file = qobject_cast<QFile *>(d->device)) @@ -263,9 +220,6 @@ bool QTextDocumentWriter::write(const QTextDocument *document) #ifndef QT_NO_TEXTODFWRITER if (format == "odf" || format == "opendocumentformat" || format == "odt") { QTextOdfWriter writer(*document, d->device); -#if QT_CONFIG(textcodec) - writer.setCodec(d->codec); -#endif return writer.writeAll(); } #endif // QT_NO_TEXTODFWRITER @@ -288,11 +242,7 @@ bool QTextDocumentWriter::write(const QTextDocument *document) qWarning("QTextDocumentWriter::write: the device cannot be opened for writing"); return false; } - QTextStream ts(d->device); -#if QT_CONFIG(textcodec) - ts.setCodec(d->codec); - ts << document->toHtml(d->codec->name()); -#endif + d->device->write(document->toHtml().toUtf8()); d->device->close(); return true; } @@ -302,11 +252,7 @@ bool QTextDocumentWriter::write(const QTextDocument *document) qWarning("QTextDocumentWriter::write: the device cannot be opened for writing"); return false; } - QTextStream ts(d->device); -#if QT_CONFIG(textcodec) - ts.setCodec(d->codec); -#endif - ts << document->toPlainText(); + d->device->write(document->toPlainText().toUtf8()); d->device->close(); return true; } @@ -329,32 +275,6 @@ bool QTextDocumentWriter::write(const QTextDocumentFragment &fragment) } /*! - Sets the codec for this stream to \a codec. The codec is used for - encoding any data that is written. By default, QTextDocumentWriter - uses UTF-8. -*/ - -#if QT_CONFIG(textcodec) -void QTextDocumentWriter::setCodec(QTextCodec *codec) -{ - if (codec == nullptr) - codec = QTextCodec::codecForName("UTF-8"); - Q_ASSERT(codec); - d->codec = codec; -} -#endif - -/*! - Returns the codec that is currently assigned to the writer. -*/ -#if QT_CONFIG(textcodec) -QTextCodec *QTextDocumentWriter::codec() const -{ - return d->codec; -} -#endif - -/*! Returns the list of document formats supported by QTextDocumentWriter. By default, Qt can write the following formats: |