Qx v0.5.8
Qt Extensions Library
|
The TextStreamWriter class is a specialized wrapper for QTextStream that narrows and simplifies its usage for writing text files. More...
#include <qx/io/qx-textstreamwriter.h>
Most member functions are the same or slightly modified versions of those from QTextStream.
The file on which to operate is specified as a path and the underlying handle is managed by the stream.
Qx::TextStreamWriter::TextStreamWriter | ( | WriteMode | writeMode = Append, |
WriteOptions | writeOptions = NoWriteOptions ) |
Constructs a text stream writer that is configured with writeMode and writeOptions.
No file is initially set.
Qx::TextStreamWriter::TextStreamWriter | ( | const QString & | filePath, |
WriteMode | writeMode = Append, | ||
WriteOptions | writeOptions = NoWriteOptions ) |
Constructs a text stream writer that is linked to the file at filePath, configured with writeMode and writeOptions.
Qx::TextStreamWriter::~TextStreamWriter | ( | ) |
Destroys the text stream writer, along with closing and deleting the underlying file, if present.
void Qx::TextStreamWriter::closeFile | ( | ) |
Closes the file associated with the text stream writer, if present.
QStringConverter::Encoding Qx::TextStreamWriter::encoding | ( | ) | const |
Returns the encoding that is current assigned to the stream.
QTextStream::FieldAlignment Qx::TextStreamWriter::fieldAlignment | ( | ) | const |
Returns the current field alignment.
int Qx::TextStreamWriter::fieldWidth | ( | ) | const |
Returns the current field width.
const QFile * Qx::TextStreamWriter::file | ( | ) | const |
Returns an immutable pointer to the file managed by the stream.
bool Qx::TextStreamWriter::fileIsOpen | ( | ) | const |
Returns true
if the file managed by the stream is open; otherwise, returns false
.
QString Qx::TextStreamWriter::filePath | ( | ) | const |
Returns the path of the file associated with the stream, if present.
If no file is assigned the path will be null.
void Qx::TextStreamWriter::flush | ( | ) |
Flushes any buffered data waiting to be written to the device.
If the stream was constructed with WriteOption::Unbuffered, this function does nothing.
bool Qx::TextStreamWriter::generateByteOrderMark | ( | ) | const |
Returns true
if QTextStream is set to generate the UTF BOM (Byte Order Mark) when using a UTF encoding; otherwise returns false
.
UTF BOM generation is set to false by default.
bool Qx::TextStreamWriter::hasError | ( | ) | const |
Returns true
if the stream's current status indicates that an error has occurred; otherwise, returns false
.
Equivalent to status().isFailure()
.
int Qx::TextStreamWriter::integerBase | ( | ) | const |
Returns the current base of integers. 0
means that the base is 10
(decimal) when generating numbers.
QLocale Qx::TextStreamWriter::locale | ( | ) | const |
Returns the locale for this stream. The default locale is C
.
QTextStream::NumberFlags Qx::TextStreamWriter::numberFlags | ( | ) | const |
Returns the current number flags.
IoOpReport Qx::TextStreamWriter::openFile | ( | ) |
Opens the file associated with the text stream writer and returns an operation report.
This function must be called before any data is written after a file is assigned to the stream.
|
inline |
Writes d of type T
to the stream. Returns a reference to the stream.
This template is constrained such that effectively, the insertion operator for this class is available for all data types that QTextStream defines an insertion operator for.
QChar Qx::TextStreamWriter::padChar | ( | ) | const |
Returns the current pad character.
QTextStream::RealNumberNotation Qx::TextStreamWriter::realNumberNotation | ( | ) | const |
Returns the current real number notation.
int Qx::TextStreamWriter::realNumberPrecision | ( | ) | const |
Returns the current real number precision, or the number of fraction digits TextStreamWriter will write when generating real numbers.
void Qx::TextStreamWriter::reset | ( | ) |
Resets TextStreamWriter's formatting options, bringing it back to its original constructed state. The device, string and any buffered data is left untouched.
void Qx::TextStreamWriter::resetStatus | ( | ) |
Resets the status of the text stream reader.
void Qx::TextStreamWriter::setEncoding | ( | QStringConverter::Encoding | encoding | ) |
Sets the encoding for this stream to encoding. The encoding is used for any data that is written. By default, QStringConverter::Utf8 is used.
void Qx::TextStreamWriter::setFieldAlignment | ( | QTextStream::FieldAlignment | mode | ) |
Sets the field alignment to mode. When used together with setFieldWidth(), this function allows you to generate formatted output with text aligned to the left, to the right or center aligned.
void Qx::TextStreamWriter::setFieldWidth | ( | int | width | ) |
Sets the current field width to width. If width is 0 (the default), the field width is equal to the length of the generated text.
void Qx::TextStreamWriter::setFilePath | ( | const QString & | filePath | ) |
Links the stream to the file at filePath, which can be a null QString to unset the current file. If a file was already set to the stream, it will be closed as it is replaced.
The file must be opened through the stream before it can be used.
void Qx::TextStreamWriter::setGenerateByteOrderMark | ( | bool | generate | ) |
If generate is true
and a UTF encoding is used, QTextStream will insert the BOM (Byte Order Mark) before any data has been written to the device. If generate is false
, no BOM will be inserted. This function must be called before any data is written. Otherwise, it does nothing.
void Qx::TextStreamWriter::setIntegerBase | ( | int | base | ) |
Sets the base of integers to base. base can be either 2
(binary), 8
(octal), 10
(decimal) or 16
(hexadecimal). QTextStream assumes base is 10
unless the base has been set explicitly.
void Qx::TextStreamWriter::setLocale | ( | const QLocale & | locale | ) |
Sets the locale for this stream to locale. The specified locale is used for conversions between numbers and their string representations.
The default locale is C
and it is a special case - the thousands group separator is not used for backward compatibility reasons.
void Qx::TextStreamWriter::setNumberFlags | ( | QTextStream::NumberFlags | flags | ) |
Sets the current number flags to flags. flags is a set of flags from the QTextStream::NumberFlag enum, and describes options for formatting generated code (e.g., whether or not to always write the base or sign of a number).
void Qx::TextStreamWriter::setPadChar | ( | QChar | ch | ) |
Sets the pad character to ch. The default value is the ASCII space character (' '), or QChar(0x20). This character is used to fill in the space in fields when generating text.
void Qx::TextStreamWriter::setRealNumberNotation | ( | QTextStream::RealNumberNotation | notation | ) |
Sets the real number notation to notation. When generating numbers, TextStreamWriter uses this value to detect the formatting of real numbers.
void Qx::TextStreamWriter::setRealNumberPrecision | ( | int | precision | ) |
Sets the precision of real numbers to precision. This value describes the number of fraction digits TextStreamWriter should write when generating real numbers.
The precision cannot be a negative value. The default value is 6
.
IoOpReport Qx::TextStreamWriter::status | ( | ) | const |
Returns the status of the text stream writer.
The status is a report of the last write operation performed by TextStreamWriter. If no write operation has been performed since the stream was constructed or resetStatus() was last called the report will be null.
IoOpReport Qx::TextStreamWriter::writeLine | ( | QString | line, |
bool | ensureLineStart = true ) |
Writes line to the stream followed by a line break and returns the streams status.
If ensureLineStart is true, a line break will be written before writing line if the stream wasn't already positioned at the start of a new line.
IoOpReport Qx::TextStreamWriter::writeText | ( | QString | text | ) |
Writes text to the stream and returns the stream's status.