📄 qabstractfileengine.cpp
字号:
bool QAbstractFileEngine::flush(){ return false;}/*! Returns the size of the file.*/qint64 QAbstractFileEngine::size() const{ return 0;}/*! Returns the current file position. This is the position of the data read/write head of the file.*/qint64 QAbstractFileEngine::pos() const{ return 0;}/*! \fn bool QAbstractFileEngine::seek(qint64 offset) Sets the file position to the given \a offset. Returns true if the position was successfully set; otherwise returns false. The offset is from the beginning of the file, unless the file is sequential. \sa isSequential()*/bool QAbstractFileEngine::seek(qint64 pos){ Q_UNUSED(pos); return false;}/*! Returns true if the file is a sequential access device; returns false if the file is a direct access device. Operations involving size() and seek(int) are not valid on sequential devices.*/bool QAbstractFileEngine::isSequential() const{ return false;}/*! Requests that the file is deleted from the file system. If the operation succeeds return true; otherwise return false. This virtual function must be reimplemented by all subclasses. \sa setFileName() rmdir() */bool QAbstractFileEngine::remove(){ return false;}/*! Copies the contents of this file to a file with the name \a newName. Returns true on success; otherwise, false is returned.*/bool QAbstractFileEngine::copy(const QString &newName){ Q_UNUSED(newName); return false;}/*! Requests that the file be renamed to \a newName in the file system. If the operation succeeds return true; otherwise return false. This virtual function must be reimplemented by all subclasses. \sa setFileName() */bool QAbstractFileEngine::rename(const QString &newName){ Q_UNUSED(newName); return false;}/*! Creates a link from the file currently specified by fileName() to \a newName. What a link is depends on the underlying filesystem (be it a shortcut on Windows or a symbolic link on Unix). Returns true if successful; otherwise returns false.*/bool QAbstractFileEngine::link(const QString &newName){ Q_UNUSED(newName); return false;}/*! Requests that the directory \a dirName be created. If \a createParentDirectories is true, then any sub-directories in \a dirName that don't exist must be created. If \a createParentDirectories is false then any sub-directories in \a dirName must already exist for the function to succeed. If the operation succeeds return true; otherwise return false. This virtual function must be reimplemented by all subclasses. \sa setFileName() rmdir() isRelativePath() */bool QAbstractFileEngine::mkdir(const QString &dirName, bool createParentDirectories) const{ Q_UNUSED(dirName); Q_UNUSED(createParentDirectories); return false;}/*! Requests that the directory \a dirName is deleted from the file system. When \a recurseParentDirectories is true, then any empty parent-directories in \a dirName must also be deleted. If \a recurseParentDirectories is false, only the \a dirName leaf-node should be deleted. In most file systems a directory cannot be deleted using this function if it is non-empty. If the operation succeeds return true; otherwise return false. This virtual function must be reimplemented by all subclasses. \sa setFileName() remove() mkdir() isRelativePath() */bool QAbstractFileEngine::rmdir(const QString &dirName, bool recurseParentDirectories) const{ Q_UNUSED(dirName); Q_UNUSED(recurseParentDirectories); return false;}/*! Requests that the file be set to size \a size. If \a size is larger than the current file then it is filled with 0's, if smaller it is simply truncated. If the operations succceeds return true; otherwise return false; This virtual function must be reimplemented by all subclasses. \sa size()*/bool QAbstractFileEngine::setSize(qint64 size){ Q_UNUSED(size); return false;}/*! Should return true if the underlying file system is case-sensitive; otherwise return false. This virtual function must be reimplemented by all subclasses. */bool QAbstractFileEngine::caseSensitive() const{ return false;}/*! Return true if the file referred to by this file engine has a relative path; otherwise return false. This virtual function must be reimplemented by all subclasses. \sa setFileName() */bool QAbstractFileEngine::isRelativePath() const{ return false;}/*! Requests that a list of all the files matching the \a filters list based on the \a filterNames in the file engine's directory are returned. Should return an empty list if the file engine refers to a file rather than a directory, or if the directory is unreadable or does not exist or if nothing matches the specifications. This virtual function must be reimplemented by all subclasses. \sa setFileName() */QStringList QAbstractFileEngine::entryList(QDir::Filters filters, const QStringList &filterNames) const{ QStringList ret; QDirIterator it(fileName(), filterNames, filters); while (it.hasNext()) { it.next(); ret << it.fileName(); } return ret;}/*! This function should return the set of OR'd flags that are true for the file engine's file, and that are in the \a type's OR'd members. In your reimplementation you can use the \a type argument as an optimization hint and only return the OR'd set of members that are true and that match those in \a type; in other words you can ignore any members not mentioned in \a type, thus avoiding some potentially expensive lookups or system calls. This virtual function must be reimplemented by all subclasses. \sa setFileName()*/QAbstractFileEngine::FileFlags QAbstractFileEngine::fileFlags(FileFlags type) const{ Q_UNUSED(type); return 0;}/*! Requests that the file's permissions be set to \a perms. The argument perms will be set to the OR-ed together combination of QAbstractFileEngine::FileInfo, with only the QAbstractFileEngine::PermsMask being honored. If the operations succceeds return true; otherwise return false; This virtual function must be reimplemented by all subclasses. \sa size()*/bool QAbstractFileEngine::setPermissions(uint perms){ Q_UNUSED(perms); return false;}/*! Return the file engine's current file name in the format specified by \a file. If you don't handle some \c FileName possibilities, return the file name set in setFileName() when an unhandled format is requested. This virtual function must be reimplemented by all subclasses. \sa setFileName(), FileName */QString QAbstractFileEngine::fileName(FileName file) const{ Q_UNUSED(file); return QString();}/*! If \a owner is \c OwnerUser return the ID of the user who owns the file. If \a owner is \c OwnerGroup return the ID of the group that own the file. If you can't determine the owner return -2. This virtual function must be reimplemented by all subclasses. \sa owner() setFileName(), FileOwner */uint QAbstractFileEngine::ownerId(FileOwner owner) const{ Q_UNUSED(owner); return 0;}/*! If \a owner is \c OwnerUser return the name of the user who owns the file. If \a owner is \c OwnerGroup return the name of the group that own the file. If you can't determine the owner return QString(). This virtual function must be reimplemented by all subclasses. \sa ownerId() setFileName(), FileOwner */QString QAbstractFileEngine::owner(FileOwner owner) const{ Q_UNUSED(owner); return QString();}/*! If \a time is \c CreationTime, return when the file was created. If \a time is \c ModificationTime, return when the file was most recently modified. If \a time is \c AccessTime, return when the file was most recently accessed (e.g. read or written). If the time cannot be determined return QDateTime() (an invalid date time). This virtual function must be reimplemented by all subclasses. \sa setFileName(), QDateTime, QDateTime::isValid(), FileTime */QDateTime QAbstractFileEngine::fileTime(FileTime time) const{ Q_UNUSED(time); return QDateTime();}/*! Sets the file engine's file name to \a file. This file name is the file that the rest of the virtual functions will operate on. This virtual function must be reimplemented by all subclasses. \sa rename() */void QAbstractFileEngine::setFileName(const QString &file){ Q_UNUSED(file);}/*! Returns the native file handle for this file engine. This handle must be used with care; its value and type are platform specific, and using it will most likely lead to non-portable code.*/int QAbstractFileEngine::handle() const{ return -1;}/*! \since 4.3 Returns true if the current position is at the end of the file; otherwise, returns false. This function bases its behavior on calling extension() with AtEndExtension. If the engine does not support this extension, false is returned. \sa extension(), supportsExtension(), QFile::atEnd()*/bool QAbstractFileEngine::atEnd() const{ return const_cast<QAbstractFileEngine *>(this)->extension(AtEndExtension);}/*! \since 4.3 \class QAbstractFileEngineIterator \brief The QAbstractFileEngineIterator class provides an iterator interface for custom file engines. If all you want is to iterate over entries in a directory, see QDirIterator instead. This class is only for custom file engine authors. QAbstractFileEngineIterator is a unidirectional single-use virtual iterator that plugs into QDirIterator, providing transparent proxy iteration for custom file engines. You can subclass QAbstractFileEngineIterator to provide an iterator when writing your own file engine. To plug the iterator into your file system, you simply return an instance of this subclass from a reimplementation of QAbstractFileEngine::beginEntryList(). Example: \code QAbstractFileEngineIterator * CustomFileEngine::beginEntryList(QDir::Filters filters, const QStringList &filterNames) { return new CustomFileEngineIterator(filters, filterNames); } \endcode QAbstractFileEngineIterator is associated with a path, name filters, and entry filters. The path is the directory that the iterator lists entries in. The name filters and entry filters are provided for file engines that can optimize directory listing at the iterator level (e.g., network file systems that need to minimize network traffic), but they can also be ignored by the iterator subclass; QAbstractFileEngineIterator already provides the required filtering logics in the matchesFilters() function. You can call dirName() to get the directory name, nameFilters() to get a stringlist of name filters, and filters() to get the entry filters. The pure virual function hasNext() returns true if the current directory has at least one more entry (i.e., the directory name is valid and accessible, and we have not reached the end of the entry list), and false otherwise. Reimplement next() to seek to the next entry. The pure virtual function currentFileName() returns the name of the current entry without advancing the iterator. The currentFilePath() function is provided for convenience; it returns the full path of the current entry. Here is an example of how to implement an interator that returns each of three fixed entries in sequence. \code class CustomIterator : public QAbstractFileEngineIterator { public: CustomIterator(const QStringList &nameFilters, QDir::Filters filters) : QAbstractFileEngineIterator(nameFilters, filters), index(0) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -