Always save QTextDocuments encoded in utf-8
Get rid of the options to set another encoding. In 2020, we should always write documents as utf-8. Change-Id: If39dd3a876f85a70735169113bce9c25f2d981b3 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>bb10
parent
29de3412ad
commit
a23cb5cd06
|
|
@ -41,9 +41,6 @@
|
|||
#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 +65,6 @@ public:
|
|||
QByteArray format;
|
||||
QIODevice *device;
|
||||
bool deleteDevice;
|
||||
#if QT_CONFIG(textcodec)
|
||||
QTextCodec *codec;
|
||||
#endif
|
||||
|
||||
QTextDocumentWriter *q;
|
||||
};
|
||||
|
|
@ -109,9 +103,6 @@ public:
|
|||
QTextDocumentWriterPrivate::QTextDocumentWriterPrivate(QTextDocumentWriter *qq)
|
||||
: device(nullptr),
|
||||
deleteDevice(false),
|
||||
#if QT_CONFIG(textcodec)
|
||||
codec(QTextCodec::codecForName("utf-8")),
|
||||
#endif
|
||||
q(qq)
|
||||
{
|
||||
}
|
||||
|
|
@ -263,9 +254,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
|
||||
|
|
@ -290,8 +278,8 @@ bool QTextDocumentWriter::write(const QTextDocument *document)
|
|||
}
|
||||
QTextStream ts(d->device);
|
||||
#if QT_CONFIG(textcodec)
|
||||
ts.setCodec(d->codec);
|
||||
ts << document->toHtml(d->codec->name());
|
||||
ts.setCodec("utf-8");
|
||||
ts << document->toHtml("utf-8");
|
||||
#endif
|
||||
d->device->close();
|
||||
return true;
|
||||
|
|
@ -304,7 +292,7 @@ bool QTextDocumentWriter::write(const QTextDocument *document)
|
|||
}
|
||||
QTextStream ts(d->device);
|
||||
#if QT_CONFIG(textcodec)
|
||||
ts.setCodec(d->codec);
|
||||
ts.setCodec("utf-8");
|
||||
#endif
|
||||
ts << document->toPlainText();
|
||||
d->device->close();
|
||||
|
|
@ -328,32 +316,6 @@ bool QTextDocumentWriter::write(const QTextDocumentFragment &fragment)
|
|||
return false;
|
||||
}
|
||||
|
||||
/*!
|
||||
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.
|
||||
|
||||
|
|
|
|||
|
|
@ -70,11 +70,6 @@ public:
|
|||
bool write(const QTextDocument *document);
|
||||
bool write(const QTextDocumentFragment &fragment);
|
||||
|
||||
#if QT_CONFIG(textcodec)
|
||||
void setCodec(QTextCodec *codec);
|
||||
QTextCodec *codec() const;
|
||||
#endif
|
||||
|
||||
static QList<QByteArray> supportedDocumentFormats();
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -998,7 +998,6 @@ QTextOdfWriter::QTextOdfWriter(const QTextDocument &document, QIODevice *device)
|
|||
m_document(&document),
|
||||
m_device(device),
|
||||
m_strategy(nullptr),
|
||||
m_codec(nullptr),
|
||||
m_createArchive(true)
|
||||
{
|
||||
}
|
||||
|
|
@ -1015,10 +1014,6 @@ bool QTextOdfWriter::writeAll()
|
|||
return false;
|
||||
}
|
||||
QXmlStreamWriter writer(m_strategy->contentStream);
|
||||
#if QT_CONFIG(textcodec)
|
||||
if (m_codec)
|
||||
writer.setCodec(m_codec);
|
||||
#endif
|
||||
// prettyfy
|
||||
writer.setAutoFormatting(true);
|
||||
writer.setAutoFormattingIndent(2);
|
||||
|
|
|
|||
|
|
@ -86,7 +86,6 @@ public:
|
|||
QTextOdfWriter(const QTextDocument &document, QIODevice *device);
|
||||
bool writeAll();
|
||||
|
||||
void setCodec(QTextCodec *codec) { m_codec = codec; }
|
||||
void setCreateArchive(bool on) { m_createArchive = on; }
|
||||
bool createArchive() const { return m_createArchive; }
|
||||
|
||||
|
|
@ -116,7 +115,6 @@ private:
|
|||
QIODevice *m_device;
|
||||
|
||||
QOutputStrategy *m_strategy;
|
||||
QTextCodec *m_codec;
|
||||
bool m_createArchive;
|
||||
|
||||
QStack<QTextList *> m_listStack;
|
||||
|
|
|
|||
Loading…
Reference in New Issue