
We bake cookies in your browser for a better experience. Using this site means that you consent.Read More
TheQAbstractFileEngineIterator class provides an iterator interface for custom file engines.More...
| Header: | #include <QAbstractFileEngineIterator> |
| Since: | Qt 4.3 |
| QAbstractFileEngineIterator(QDir::Filters filters, const QStringList & nameFilters) | |
| virtual | ~QAbstractFileEngineIterator() |
| virtual QFileInfo | currentFileInfo() const |
| virtual QString | currentFileName() const = 0 |
| QString | currentFilePath() const |
| QDir::Filters | filters() const |
| virtual bool | hasNext() const = 0 |
| QStringList | nameFilters() const |
| virtual QString | next() = 0 |
| QString | path() const |
TheQAbstractFileEngineIterator class provides an iterator interface for custom file engines.
If all you want is to iterate over entries in a directory, seeQDirIterator instead. This class is only for custom file engine authors.
QAbstractFileEngineIterator is a unidirectional single-use virtual iterator that plugs intoQDirIterator, providing transparent proxy iteration for custom file engines.
You can subclassQAbstractFileEngineIterator 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 ofQAbstractFileEngine::beginEntryList().
Example:
QAbstractFileEngineIterator*CustomFileEngine::beginEntryList(QDir::Filters filters,constQStringList&filterNames){returnnew CustomFileEngineIterator(filters, filterNames);}
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, andfilters() to get the entry filters.
The pure virtual functionhasNext() 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. Reimplementnext() to seek to the next entry.
The pure virtual functioncurrentFileName() returns the name of the current entry without advancing the iterator. ThecurrentFilePath() function is provided for convenience; it returns the full path of the current entry.
Here is an example of how to implement an iterator that returns each of three fixed entries in sequence.
class CustomIterator :publicQAbstractFileEngineIterator{public: CustomIterator(constQStringList&nameFilters,QDir::Filters filters) :QAbstractFileEngineIterator(nameFilters, filters), index(0) {// 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())returnQString();++index;return currentFilePath(); }QString currentFileName() {return entries.at(index); }private:QStringList entries;int index;};
Note:QAbstractFileEngineIterator does not deal with QDir::IteratorFlags; it simply returns entries for a single directory.
See alsoQDirIterator.
Constructs aQAbstractFileEngineIterator, using the entry filtersfilters, and wildcard name filtersnameFilters.
[virtual]QAbstractFileEngineIterator::~QAbstractFileEngineIterator()Destroys theQAbstractFileEngineIterator.
See alsoQDirIterator.
[virtual]QFileInfo QAbstractFileEngineIterator::currentFileInfo() constThe virtual function returns aQFileInfo for the current directory entry. This function is provided for convenience. It can also be slightly faster than creating aQFileInfo object yourself, as the object returned by this function might contain cached information thatQFileInfo otherwise would have to access through the file engine.
See alsocurrentFileName().
[pure virtual]QString QAbstractFileEngineIterator::currentFileName() constThis pure virtual function returns the name of the current directory entry, excluding the path.
See alsocurrentFilePath().
Returns the path to the current directory entry. It's the same as prependingpath() to the return value ofcurrentFileName().
See alsocurrentFileName().
Returns the entry filters for this iterator.
See alsoQDir::filter(),nameFilters(), andpath().
[pure virtual]bool QAbstractFileEngineIterator::hasNext() constThis 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).
See alsoQDirIterator::hasNext().
Returns the name filters for this iterator.
See alsoQDir::nameFilters(),filters(), andpath().
[pure virtual]QString QAbstractFileEngineIterator::next()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 ofnameFilters() andfilters() to optimize its performance.
Reimplement this function in a subclass to advance the iterator.
See alsoQDirIterator::next().
Returns the path for this iterator.QDirIterator is responsible for assigning this path; it cannot change during the iterator's lifetime.
See alsonameFilters() andfilters().
© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU 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.