📄 qabstractfileengine.cpp
字号:
// In a real iterator, these entries are fetched from the // file system based on the value of path(). entries << "entry1" << "entry2" << "entry3"; } bool hasNext() const { return index < entries.size() - 1; } QString next() { if (!hasNext()) return QString(); ++index; return currentFilePath(); } QString currentFilePath() { return entries.at(index); } private: QStringList entries; int index; }; \endcode Note: QAbstractFileEngineIterator does not deal with QDir::IteratorFlags; it simply returns entries for a single directory. \sa QDirIterator*//*! \enum QAbstractFileEngineIterator::EntryInfoType \internal This enum describes the different types of information that can be requested through the QAbstractFileEngineIterator::entryInfo() function.*//*! \typedef QAbstractFileEngine::Iterator \since 4.3 \relates QAbstractFileEngine Synonym for QAbstractFileEngineIterator.*/class QAbstractFileEngineIteratorPrivate{public: QString path; QDir::Filters filters; QStringList nameFilters; QFileInfo fileInfo;};/*! Constructs a QAbstractFileEngineIterator, using the entry filters \a filters, and wildcard name filters \a nameFilters.*/QAbstractFileEngineIterator::QAbstractFileEngineIterator(QDir::Filters filters, const QStringList &nameFilters) : d(new QAbstractFileEngineIteratorPrivate){ d->nameFilters = nameFilters; d->filters = filters;}/*! Destroys the QAbstractFileEngineIterator. \sa QDirIterator*/QAbstractFileEngineIterator::~QAbstractFileEngineIterator(){ delete d;}/*! Returns the path for this iterator. QDirIterator is responsible for assigning this path; it cannot change during the iterator's lifetime. \sa nameFilters(), filters()*/QString QAbstractFileEngineIterator::path() const{ return d->path;}/*! \internal Sets the iterator path to \a path. This function is called from within QDirIterator.*/void QAbstractFileEngineIterator::setPath(const QString &path){ d->path = path;}/*! Returns the name filters for this iterator. \sa QDir::nameFilters(), filters(), path()*/QStringList QAbstractFileEngineIterator::nameFilters() const{ return d->nameFilters;}/*! Returns the entry filters for this iterator. \sa QDir::filter(), nameFilters(), path()*/QDir::Filters QAbstractFileEngineIterator::filters() const{ return d->filters;}/*! \fn QString QAbstractFileEngineIterator::currentFileName() const = 0 This pure virtual function returns the name of the current directory entry, excluding the path. \sa currentFilePath()*//*! Returns the path to the current directory entry. It's the same as prepending path() to the return value of currentFileName(). \sa currentFileName()*/QString QAbstractFileEngineIterator::currentFilePath() const{ QString name = currentFileName(); if (!name.isNull()) { QString tmp = path(); if (!tmp.isEmpty()) { if (!tmp.endsWith(QLatin1Char('/'))) tmp.append(QLatin1Char('/')); name.prepend(tmp); } } return name;}/*! The virtual function returns a QFileInfo for the current directory entry. This function is provided for convenience. It can also be slightly faster that creating a QFileInfo object yourself, as the object returned by this function might contain cached information that QFileInfo otherwise would have to access through the file engine. \sa currentFileName()*/QFileInfo QAbstractFileEngineIterator::currentFileInfo() const{ QString path = currentFilePath(); if (d->fileInfo.filePath() != path) d->fileInfo.setFile(path); // return a shallow copy return d->fileInfo;}/*! \internal Returns the entry info \a type for this iterator's current directory entry as a QVariant. If \a type is undefined for this entry, a null QVariant is returned. \sa QAbstractFileEngine::beginEntryList(), QDir::beginEntryList()*/QVariant QAbstractFileEngineIterator::entryInfo(EntryInfoType type) const{ Q_UNUSED(type) return QVariant();}/*! \fn virtual QString QAbstractFileEngineIterator::next() = 0 This pure virtual function advances the iterator to the next directory entry, and returns the file path to the current entry. This function can optionally make use of nameFilters() and filters() to optimize its performance. Reimplement this function in a subclass to advance the iterator. \sa QDirIterator::next()*//*! \fn virtual bool QAbstractFileEngineIterator::hasNext() const = 0 This pure virtual function returns true if there is at least one more entry in the current directory (i.e., the iterator path is valid and accessible, and the iterator has not reached the end of the entry list). \sa QDirIterator::hasNext()*//*! Returns an instance of a QAbstractFileEngineIterator using \a filters for entry filtering and \a filterNames for name filtering. This function is called by QDirIterator to initiate directory iteration. QDirIterator takes ownership of the returned instance, and deletes it when it's done. \sa QDirIterator*/QAbstractFileEngine::Iterator *QAbstractFileEngine::beginEntryList(QDir::Filters filters, const QStringList &filterNames){ Q_UNUSED(filters); Q_UNUSED(filterNames); return 0;}/*! \internal*/QAbstractFileEngine::Iterator *QAbstractFileEngine::endEntryList(){ return 0;}/*! Reads a number of characters from the file into \a data. At most \a maxlen characters will be read. Returns -1 if a fatal error occurs, or 0 if there are no bytes to read.*/qint64 QAbstractFileEngine::read(char *data, qint64 maxlen){ Q_UNUSED(data); Q_UNUSED(maxlen); return -1;}/*! Writes \a len bytes from \a data to the file. Returns the number of characters written on success; otherwise returns -1.*/qint64 QAbstractFileEngine::write(const char *data, qint64 len){ Q_UNUSED(data); Q_UNUSED(len); return -1;}/*! This function reads one line, terminated by a '\n' character, from the file info \a data. At most \a maxlen characters will be read. The end-of-line character is included.*/qint64 QAbstractFileEngine::readLine(char *data, qint64 maxlen){ qint64 readSoFar = 0; while (readSoFar < maxlen) { char c; qint64 readResult = read(&c, 1); if (readResult <= 0) return (readSoFar > 0) ? readSoFar : readResult; ++readSoFar; *data++ = c; if (c == '\n') return readSoFar; } return readSoFar;}/*! \enum QAbstractFileEngine::Extension \since 4.3 This enum describes the types of extensions that the file engine can support. Before using these extensions, you must verify that the extension is supported (i.e., call supportsExtension()). \value AtEndExtension Whether the current file position is at the end of the file or not. This extension allows file engines that implement local buffering to report end-of-file status without having to check the size of the file. It is also useful for sequential files, where the size of the file cannot be used to determine whether or not you have reached the end. This extension returns true if the file is at the end; otherwise it returns false. The input and output arguments to extension() are ignored. \value FastReadLineExtension Whether the file engine provides a fast implementation for readLine() or not. If readLine() remains unimplemented in the file engine, QAbstractFileEngine will provide an implementation based on calling read() repeatedly. If supportsExtension() returns false for this extension, however, QIODevice can provide a faster implementation by making use of its internal buffer. For engines that already provide a fast readLine() implementation, returning false for this extension can avoid unnnecessary double-buffering in QIODevice.*//*! \class QAbstractFileEngine::ExtensionOption \since 4.3 \brief provides an extended input argument to QAbstractFileEngine's extension support. \sa QAbstractFileEngine::extension()*//*! \class QAbstractFileEngine::ExtensionReturn \since 4.3 \brief provides an extended output argument to QAbstractFileEngine's extension support. \sa QAbstractFileEngine::extension()*//*! \since 4.3 This virtual function can be reimplemented in a QAbstractFileEngine subclass to provide support for extensions. The \a option argument is provided as input to the extension, and this function can store output results in \a output. The behavior of this function is determined by \a extension; see the Extension documentation for details. You can call supportsExtension() to check if an extension is supported by the file engine. By default, no extensions are supported, and this function returns false. \sa supportsExtension(), Extension*/bool QAbstractFileEngine::extension(Extension extension, const ExtensionOption *option, ExtensionReturn *output){ Q_UNUSED(extension); Q_UNUSED(option); Q_UNUSED(output); return false;}/*! \since 4.3 This virtual function returns true if the file engine supports \a extension; otherwise, false is returned. By default, no extensions are supported. \sa extension()*/bool QAbstractFileEngine::supportsExtension(Extension extension) const{ Q_UNUSED(extension); return false;}/*! Returns the QFile::FileError that resulted from the last failed operation. If QFile::UnspecifiedError is returned, QFile will use its own idea of the error status. \sa QFile::FileError, errorString() */QFile::FileError QAbstractFileEngine::error() const{ Q_D(const QAbstractFileEngine); return d->fileError;}/*! Returns the human-readable message appropriate to the current error reported by error(). If no suitable string is available, an empty string is returned. \sa error() */QString QAbstractFileEngine::errorString() const{ Q_D(const QAbstractFileEngine); return d->errorString;}/*! Sets the error type to \a error, and the error string to \a errorString. Call this function to set the error values returned by the higher-level classes. \sa QFile::error(), QIODevice::errorString(), QIODevice::setErrorString()*/void QAbstractFileEngine::setError(QFile::FileError error, const QString &errorString){ Q_D(QAbstractFileEngine); d->fileError = error; d->errorString = errorString;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -