Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
FileDocumentWriter Class Reference

Production implementation of DocumentWriter that writes to files. More...

#include <filedocumentwriter.h>

Inheritance diagram for FileDocumentWriter:
Collaboration diagram for FileDocumentWriter:

Public Member Functions

 FileDocumentWriter (OutputContext context)
 The constructor takes a context.
 ~FileDocumentWriter () override
 The destructor ensures a call to endDocument before the object is destroyed.
 FileDocumentWriter (const FileDocumentWriter &)=delete
FileDocumentWriteroperator= (const FileDocumentWriter &)=delete
 FileDocumentWriter (FileDocumentWriter &&) noexcept=default
FileDocumentWriteroperator= (FileDocumentWriter &&) noexcept=default
void beginDocument (const QString &fileName)
 Opens a new document with the given fileName for writing.
void endDocument ()
 Closes the current document, flushing any buffered content.
void write (QStringView content) override
 Writes content to the output without a trailing newline.
void writeLine (QStringView content) override
 Writes content to the output followed by a newline.
bool isOpen () const override
 Returns true if a document is currently open for writing.
QString currentFileName () const override
 Returns the file name of the currently open document, or an empty string if no document is open.
const OutputContextcontext () const
 Returns the output context used by this writer.
Public Member Functions inherited from DocumentWriter
virtual ~DocumentWriter ()=default

Detailed Description

Production implementation of DocumentWriter that writes to files.

FileDocumentWriter manages the lifecycle of output files, replacing the Generator's beginSubPage()/endSubPage() pattern with an explicit interface.

writer.beginDocument("output.html");
writer.write("<html>");
writer.writeLine("<body>Content</body>");
writer.write("</html>");
writer.endDocument();
FileDocumentWriter(OutputContext context)
The constructor takes a context.
const OutputContext & context() const
Returns the output context used by this writer.

If the file cannot be opened, beginDocument() reports an error and subsequent write calls become no-ops.

See also
DocumentWriter, StringDocumentWriter, OutputContext

Definition at line 17 of file filedocumentwriter.h.

Constructor & Destructor Documentation

◆ FileDocumentWriter() [1/3]

FileDocumentWriter::FileDocumentWriter ( OutputContext context)
explicit

The constructor takes a context.

See also
OutputContext

Definition at line 52 of file filedocumentwriter.cpp.

◆ ~FileDocumentWriter()

FileDocumentWriter::~FileDocumentWriter ( )
override

The destructor ensures a call to endDocument before the object is destroyed.

See also
endDocument()

Definition at line 62 of file filedocumentwriter.cpp.

◆ FileDocumentWriter() [2/3]

FileDocumentWriter::FileDocumentWriter ( const FileDocumentWriter & )
delete

◆ FileDocumentWriter() [3/3]

FileDocumentWriter::FileDocumentWriter ( FileDocumentWriter && )
defaultnoexcept

Member Function Documentation

◆ beginDocument()

void FileDocumentWriter::beginDocument ( const QString & fileName)

Opens a new document with the given fileName for writing.

If a document is already open, it will be closed first.

Definition at line 72 of file filedocumentwriter.cpp.

References Location::Location().

Here is the call graph for this function:

◆ context()

const OutputContext & FileDocumentWriter::context ( ) const
inlinenodiscard

Returns the output context used by this writer.

Definition at line 37 of file filedocumentwriter.h.

◆ currentFileName()

QString FileDocumentWriter::currentFileName ( ) const
nodiscardoverridevirtual

Returns the file name of the currently open document, or an empty string if no document is open.

Implements DocumentWriter.

Definition at line 137 of file filedocumentwriter.cpp.

◆ endDocument()

void FileDocumentWriter::endDocument ( )

Closes the current document, flushing any buffered content.

Safe to call even if no document is open.

Definition at line 107 of file filedocumentwriter.cpp.

◆ isOpen()

bool FileDocumentWriter::isOpen ( ) const
nodiscardoverridevirtual

Returns true if a document is currently open for writing.

Implements DocumentWriter.

Definition at line 132 of file filedocumentwriter.cpp.

◆ operator=() [1/2]

FileDocumentWriter & FileDocumentWriter::operator= ( const FileDocumentWriter & )
delete

◆ operator=() [2/2]

FileDocumentWriter & FileDocumentWriter::operator= ( FileDocumentWriter && )
defaultnoexcept

◆ write()

void FileDocumentWriter::write ( QStringView content)
overridevirtual

Writes content to the output without a trailing newline.

Implements DocumentWriter.

Definition at line 120 of file filedocumentwriter.cpp.

◆ writeLine()

void FileDocumentWriter::writeLine ( QStringView content)
overridevirtual

Writes content to the output followed by a newline.

Implements DocumentWriter.

Definition at line 126 of file filedocumentwriter.cpp.


The documentation for this class was generated from the following files: