On this page

Core::BaseTextDocument Class

class Core::BaseTextDocument

The BaseTextDocument class is a very general base class for documents that work with text. More...

Header: #include <coreplugin/textdocument.h>
Inherits: Core::IDocument

Public Functions

Utils::TextFileFormat format() const
Core::BaseTextDocument::ReadResult read(const Utils::FilePath &filePath, Core::BaseTextDocument::DecodingFallback fallback = DecodingFallback::Allowed)
void setSupportedEncodings(const QList<Utils::TextEncoding> &encodings)
Utils::Result<> write(const Utils::FilePath &filePath, const QString &data) const
Utils::Result<> write(const Utils::FilePath &filePath, const Utils::TextFileFormat &format, const QString &data) const

Signals

void decodingFallbackChanged()

Detailed Description

This class contains helper methods for saving and reading text files with encoding and line ending settings.

See also Utils::TextFileFormat.

Member Function Documentation

[signal] void BaseTextDocument::decodingFallbackChanged()

Utils::TextFileFormat BaseTextDocument::format() const

Returns the format obtained from the last call to read().

Core::BaseTextDocument::ReadResult BaseTextDocument::read(const Utils::FilePath &filePath, Core::BaseTextDocument::DecodingFallback fallback = DecodingFallback::Allowed)

Autodetects file format and reads the text file specified by filePath. If decoding fails, reads the file again with the configured fallback encoding when fallback decoding is enabled and fallback is Allowed. When a document was previously decoded with the fallback encoding, a later read first retries the failed primary encoding.

Returns whether the operation was successful.

void BaseTextDocument::setSupportedEncodings(const QList<Utils::TextEncoding> &encodings)

Sets the list of supported encodings.

An empty list means that all encodings are supported. If the current encoding is not supported, the encoding is set to the first supported encoding.

Utils::Result<> BaseTextDocument::write(const Utils::FilePath &filePath, const QString &data) const

Writes out the contents (data) of the text file filePath. Uses the format obtained from the last read() of the file.

Returns whether the operation was successful.

Utils::Result<> BaseTextDocument::write(const Utils::FilePath &filePath, const Utils::TextFileFormat &format, const QString &data) const

Writes out the contents (data) of the text file filePath. Uses the custom format format.

Returns whether the operation was successful.

Copyright © The Qt Company Ltd. and other contributors. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.