Qt 4.8
|
The QTextDocumentWriter class provides a format-independent interface for writing a QTextDocument to files or other devices. More...
#include <qtextdocumentwriter.h>
Public Functions | |
QTextCodec * | codec () const |
Returns the codec that is currently assigned to the writer. More... | |
QIODevice * | device () const |
Returns the device currently assigned, or 0 if no device has been assigned. More... | |
QString | fileName () const |
If the currently assigned device is a QFile, or if setFileName() has been called, this function returns the name of the file to be written to. More... | |
QByteArray | format () const |
Returns the format used for writing documents. More... | |
QTextDocumentWriter () | |
Constructs an empty QTextDocumentWriter object. More... | |
QTextDocumentWriter (QIODevice *device, const QByteArray &format) | |
Constructs a QTextDocumentWriter object to write to the given device in the document format specified by format. More... | |
QTextDocumentWriter (const QString &fileName, const QByteArray &format=QByteArray()) | |
Constructs an QTextDocumentWriter object that will write to a file with the name fileName, using the document format specified by format. More... | |
void | setCodec (QTextCodec *codec) |
Sets the codec for this stream to codec. More... | |
void | setDevice (QIODevice *device) |
Sets the writer's device to the device specified. More... | |
void | setFileName (const QString &fileName) |
Sets the name of the file to be written to fileName. More... | |
void | setFormat (const QByteArray &format) |
Sets the format used to write documents to the format specified. More... | |
bool | write (const QTextDocument *document) |
Writes the given document to the assigned device or file and returns true if successful; otherwise returns false. More... | |
bool | write (const QTextDocumentFragment &fragment) |
Writes the document fragment specified by fragment to the assigned device or file and returns true if successful; otherwise returns false. More... | |
~QTextDocumentWriter () | |
Destroys the QTextDocumentWriter object. More... | |
Static Public Functions | |
static QList< QByteArray > | supportedDocumentFormats () |
Returns the list of document formats supported by QTextDocumentWriter. More... | |
Properties | |
QTextDocumentWriterPrivate * | d |
The QTextDocumentWriter class provides a format-independent interface for writing a QTextDocument to files or other devices.
To write a document, construct a QTextDocumentWriter object with either a file name or a device object, and specify the document format to be written. You can construct a writer and set the format using setFormat() later.
Call write() to write the document to the device. If the document is successfully written, this function returns true. However, if an error occurs when writing the document, it will return false.
Call supportedDocumentFormats() for a list of formats that QTextDocumentWriter can write.
Since the capabilities of the supported output formats vary considerably, the writer simply outputs the appropriate subset of objects for each format. This typically includes the formatted text and images contained in a document.
Definition at line 58 of file qtextdocumentwriter.h.
QTextDocumentWriter::QTextDocumentWriter | ( | ) |
Constructs an empty QTextDocumentWriter object.
Before writing, you must call setFormat() to set a document format, then setDevice() or setFileName().
Definition at line 121 of file qtextdocumentwriter.cpp.
QTextDocumentWriter::QTextDocumentWriter | ( | QIODevice * | device, |
const QByteArray & | format | ||
) |
Constructs a QTextDocumentWriter object to write to the given device in the document format specified by format.
Definition at line 130 of file qtextdocumentwriter.cpp.
QTextDocumentWriter::QTextDocumentWriter | ( | const QString & | fileName, |
const QByteArray & | format = QByteArray() |
||
) |
Constructs an QTextDocumentWriter object that will write to a file with the name fileName, using the document format specified by format.
If format is not provided, QTextDocumentWriter will detect the document format by inspecting the extension of fileName.
Definition at line 143 of file qtextdocumentwriter.cpp.
QTextDocumentWriter::~QTextDocumentWriter | ( | ) |
QTextCodec * QTextDocumentWriter::codec | ( | ) | const |
Returns the codec that is currently assigned to the writer.
Definition at line 338 of file qtextdocumentwriter.cpp.
Referenced by setCodec().
QIODevice * QTextDocumentWriter::device | ( | ) | const |
Returns the device currently assigned, or 0 if no device has been assigned.
Definition at line 215 of file qtextdocumentwriter.cpp.
Referenced by QTextDocumentWriter(), and setDevice().
QString QTextDocumentWriter::fileName | ( | ) | const |
If the currently assigned device is a QFile, or if setFileName() has been called, this function returns the name of the file to be written to.
In all other cases, it returns an empty string.
Definition at line 239 of file qtextdocumentwriter.cpp.
QByteArray QTextDocumentWriter::format | ( | ) | const |
Returns the format used for writing documents.
Definition at line 183 of file qtextdocumentwriter.cpp.
Referenced by QTextDocumentWriter(), and setFormat().
void QTextDocumentWriter::setCodec | ( | QTextCodec * | codec | ) |
Sets the codec for this stream to codec.
The codec is used for encoding any data that is written. By default, QTextDocumentWriter uses UTF-8.
Definition at line 325 of file qtextdocumentwriter.cpp.
void QTextDocumentWriter::setDevice | ( | QIODevice * | device | ) |
Sets the writer's device to the device specified.
If a device has already been set, the old device is removed but otherwise left unchanged.
If the device is not already open, QTextDocumentWriter will attempt to open the device in QIODevice::WriteOnly mode by calling open().
Definition at line 202 of file qtextdocumentwriter.cpp.
Referenced by setFileName().
void QTextDocumentWriter::setFileName | ( | const QString & | fileName | ) |
Sets the name of the file to be written to fileName.
Internally, QTextDocumentWriter will create a QFile and open it in QIODevice::WriteOnly mode, and use this file when writing the document.
Definition at line 226 of file qtextdocumentwriter.cpp.
void QTextDocumentWriter::setFormat | ( | const QByteArray & | format | ) |
Sets the format used to write documents to the format specified.
format is a case insensitive text string. For example:
You can call supportedDocumentFormats() for the full list of formats QTextDocumentWriter supports.
Definition at line 173 of file qtextdocumentwriter.cpp.
|
static |
Returns the list of document formats supported by QTextDocumentWriter.
By default, Qt can write the following formats:
Format | Description |
plaintext | Plain text |
HTML | HyperText Markup Language |
ODF | OpenDocument Format |
Definition at line 358 of file qtextdocumentwriter.cpp.
bool QTextDocumentWriter::write | ( | const QTextDocument * | document | ) |
Writes the given document to the assigned device or file and returns true if successful; otherwise returns false.
Definition at line 249 of file qtextdocumentwriter.cpp.
Referenced by QTextEditMimeData::setup(), and write().
bool QTextDocumentWriter::write | ( | const QTextDocumentFragment & | fragment | ) |
Writes the document fragment specified by fragment to the assigned device or file and returns true if successful; otherwise returns false.
Definition at line 308 of file qtextdocumentwriter.cpp.
|
private |
Definition at line 86 of file qtextdocumentwriter.h.
Referenced by codec(), device(), fileName(), format(), QTextDocumentWriter(), setCodec(), setDevice(), setFileName(), setFormat(), write(), and ~QTextDocumentWriter().