34 #include <QSharedPointer> 37 #include <QTextStream> 38 #include <QDataStream> 81 explicit ZFile(QObject* parent = 0);
118 void setFileName(const QString&
fileName);
141 Q_INVOKABLE
void close();
147 Q_INVOKABLE
bool open(
int openMode);
153 Q_INVOKABLE
bool copy(const QString& newName);
159 Q_INVOKABLE
bool rename(const QString& newName);
165 Q_INVOKABLE
bool remove();
171 Q_INVOKABLE
bool exists();
180 Q_INVOKABLE
bool exists(const QString& fileName);
203 Q_INVOKABLE QObject*
zReadData(
int maxSize);
223 Q_INVOKABLE QList<
int>
jReadData(
int maxSize);
252 Q_INVOKABLE
bool jWriteData(const QList<
int> data);
306 QList<
int>
jGetData(
int maxSize,
bool lineModeOn = false);
314 inline
void initFile(const QString& fileName);
368 m_f = ZqFilePtr::create();
370 m_f->setFileName(fileName);
377 "Use ZFile::fileName property to set the file name.");
387 if(!
m_f->isReadable())
389 "Error, file is not readable.");
396 if(!
m_f->isWritable())
398 "Error, file is not writable.");
407 if(
m_f->error() != QFileDevice::NoError)
409 QString msg(
"File error attempting to read data: %1");
410 msg = msg.arg(
m_f->errorString());
This class supports streaming of text and binary data.
void getQDevice(QIODevice **device)
Q_INVOKABLE bool zWriteData(const ZByteArray &data)
Write the contents of a ZByteArray to the device.
void validateReadable() const
Ensures the embedded QFile object is readable by throwing an exception if not.
Q_INVOKABLE QObject * zTextStream()
Returns a Zbl::ZTextStream object that can be used to stream text to or from the device.
Q_INVOKABLE QObject * zReadDataLine(int maxSize)
Reads up to the next new line or up to maxSize bytes or up to end of data, whichever comes first...
Q_INVOKABLE bool open(int openMode)
Opens the device and sets its open mode to openMode. Returns true if successful; otherwise returns fa...
Q_INVOKABLE bool jWriteData(const QList< int > data)
Write the contents of a Javascript array of numbers to the device as bytes.
Q_INVOKABLE QObject * zReadDataAll()
Reads up to the end of data into a ZByteArray.
#define ZBL_DECLARE_LOGGED_OBJECT
Q_INVOKABLE QString getCanonicalFilePath(const QString &filePath)
Returns the canonical file path for the given file path.
Q_INVOKABLE void close()
Closes the device and sets its OpenMode to NotOpen. The error string is also reset.
Q_INVOKABLE QList< int > jReadData(int maxSize)
Reads up to maxSize bytes or up to end of data, whichever comes first, into a Javascript array...
QString fileName
The name of the file.
static void registerType()
Registers ZFile as a QML type.
Q_INVOKABLE bool remove()
Removes the file. Returns true if successful; otherwise returns false.
QString getFileName() const
static QVariant m_tags
A QVariantMap used to pass QFile enumeration values to Javascript programs.
Q_INVOKABLE bool exists()
Determine if the file currently exists. Returns true if file exists; otherwise returns false...
QObject device
A ZioDevice object that represents the File's QioDevice interface.
Q_INVOKABLE void release()
Releases references from this object to wrapped Qt C++ objects.
QSharedPointer< QFile > ZqFilePtr
A javascript wrapper for QFile.
Q_INVOKABLE bool copy(const QString &newName)
Copies this file to newName.
A javascript wrapper for QIODevice.
void setFileName(const QString &fileName)
void initFile(const QString &fileName)
Closes the current file if opened, then creates a new embedded QFile object with the specified file n...
void validateWritable() const
Ensures the embedded QFile object is writable by throwing an exception if not.
Q_INVOKABLE QObject * zReadData(int maxSize)
Reads up to maxSize bytes or up to end of data, whichever comes first, into a ZByteArray.
void createTags()
Create the m_tag object that presents a Javascript interface to QFile enumeration values...
Q_INVOKABLE QString getAbsoluteFilePath(const QString &filePath)
Returns the absolute file path for the given file path.
Q_INVOKABLE QList< int > jReadDataLine(int maxSize)
Reads up to the next new line or up to maxSize bytes or up to end of data, whichever comes first...
ZBL_DECLARE_LOGGED_OBJECT void initZioDevice()
Construct and connect a ZioDevice object that presents a Javascript interface to this file's QIODevic...
Zuble's Qt Exception Object.
ZqFilePtr m_f
Smart pointer to the embedded QFile object.
ZioDevice * m_zd
Pointer to QioDevice interface object.
QVariant tags
A Javascript object containing QFile enumeration values.
Q_INVOKABLE QList< int > jReadDataAll()
Reads up to the end of data into a Javascript array.
void validateReadDataSuccess(const QByteArray &ba) const
Throws an exception if both the supplied QByteArray object is empty and an error condition exists on ...
void validateFile() const
Ensures the embedded QFile object has been initialized by throwing an exception if not...
Q_INVOKABLE bool rename(const QString &newName)
Renames this file to newName.
QList< int > jGetData(int maxSize, bool lineModeOn=false)
A common method for line and no-line mode data fetch operations into a Javascript array...
Q_INVOKABLE QObject * zDataStream()
Returns a Zbl::ZDataStream object that can be used to stream binary data to or from the device...