Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
QAbstractFileEngineIterator Class Referenceabstract

The QAbstractFileEngineIterator class provides an iterator interface for custom file engines. More...

#include <qabstractfileengine_p.h>

+ Inheritance diagram for QAbstractFileEngineIterator:
+ Collaboration diagram for QAbstractFileEngineIterator:

Public Member Functions

 QAbstractFileEngineIterator (const QString &path, QDir::Filters filters, const QStringList &nameFilters)
 Constructs a QAbstractFileEngineIterator, using the entry filters filters, and wildcard name filters nameFilters.
 
 QAbstractFileEngineIterator (const QString &path, QDirListing::IteratorFlags filters, const QStringList &nameFilters)
 
virtual ~QAbstractFileEngineIterator ()
 Destroys the QAbstractFileEngineIterator.
 
virtual bool advance ()=0
 This pure virtual function advances the iterator to the next directory entry; if the operation was successful this method returns true, otherwise it returs false.
 
QString path () const
 Returns the path for this iterator.
 
QStringList nameFilters () const
 Returns the name filters for this iterator.
 
QDir::Filters filters () const
 Returns the entry filters for this iterator.
 
virtual QString currentFileName () const =0
 This pure virtual function returns the name of the current directory entry, excluding the path.
 
virtual QFileInfo currentFileInfo () const
 The virtual function returns a QFileInfo for the current directory entry.
 
virtual QString currentFilePath () const
 Returns the path to the current directory entry.
 

Protected Attributes

QFileInfo m_fileInfo
 

Friends

class QDirIterator
 
class QDirIteratorPrivate
 
class QDirListingPrivate
 

Detailed Description

The QAbstractFileEngineIterator class provides an iterator interface for custom file engines.

Since
4.3

\inmodule QtCore

If all you want is to iterate over entries in a directory, see QDirListing instead. This class is useful only for custom file engine authors.

QAbstractFileEngineIterator is a unidirectional single-use virtual iterator that plugs into QDirListing, providing transparent proxy iteration for custom file engines (for example, QResourceFileEngine).

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:

CustomFileEngine::beginEntryList(const QString &path, QDir::Filters filters,
const QStringList &filterNames)
{
return std::make_unique<CustomFileEngineIterator>(path, 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, and filters() to get the entry filters.

The pure virtual function advance(), as its name implies, advances the iterator to the next entry in the current directory; if the operation was successful this method returns true, otherwise it returns false. You have to reimplement this function in your sub-class to work with your file engine implementation.

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 iterator that returns each of three fixed entries in sequence.

{
public:
CustomIterator(const QString &path, const QStringList &nameFilters, QDir::Filters filters)
{
// In a real iterator, these entries are fetched from the
// file system based on the value of path().
entries << "entry1" << "entry2" << "entry3";
}
bool advance() override
{
if (entries.isEmpty())
return false;
if (index < entries.size() - 1) {
++index;
return true;
}
return false;
}
QString currentFileName() override
{
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 also
QDirListing

Definition at line 210 of file qabstractfileengine_p.h.

Constructor & Destructor Documentation

◆ QAbstractFileEngineIterator() [1/2]

QAbstractFileEngineIterator::QAbstractFileEngineIterator ( const QString & path,
QDir::Filters filters,
const QStringList & nameFilters )

Constructs a QAbstractFileEngineIterator, using the entry filters filters, and wildcard name filters nameFilters.

Definition at line 914 of file qabstractfileengine.cpp.

◆ QAbstractFileEngineIterator() [2/2]

QAbstractFileEngineIterator::QAbstractFileEngineIterator ( const QString & path,
QDirListing::IteratorFlags filters,
const QStringList & nameFilters )

Definition at line 922 of file qabstractfileengine.cpp.

◆ ~QAbstractFileEngineIterator()

QAbstractFileEngineIterator::~QAbstractFileEngineIterator ( )
virtual

Destroys the QAbstractFileEngineIterator.

See also
QDirListing

Definition at line 936 of file qabstractfileengine.cpp.

Member Function Documentation

◆ advance()

virtual bool QAbstractFileEngineIterator::advance ( )
pure virtual

This pure virtual function advances the iterator to the next directory entry; if the operation was successful this method returns true, otherwise it returs false.

This function can optionally make use of nameFilters() and filters() to optimize its performance.

Reimplement this function in a subclass to advance the iterator.

Implemented in AndroidAbstractFileEngineIterator, AndroidAbstractFileEngineIterator, AndroidContentFileEngineIterator, CustomIterator, CustomIterator, QAndroidApkFileEngineIterator, QFSFileEngineIterator, QQmlPreviewFileEngineIterator, QQmlPreviewFileEngineIterator, and QResourceFileEngineIterator.

◆ currentFileInfo()

QFileInfo QAbstractFileEngineIterator::currentFileInfo ( ) const
virtual

The virtual function returns a QFileInfo for the current directory entry.

This function is provided for convenience. It can also be slightly faster than 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.

See also
currentFileName()

Reimplemented in AndroidAbstractFileEngineIterator, AndroidAbstractFileEngineIterator, QFSFileEngineIterator, and QResourceFileEngineIterator.

Definition at line 1005 of file qabstractfileengine.cpp.

◆ currentFileName()

virtual QString QAbstractFileEngineIterator::currentFileName ( ) const
pure virtual

◆ currentFilePath()

QString QAbstractFileEngineIterator::currentFilePath ( ) const
virtual

Returns the path to the current directory entry.

It's the same as prepending path() to the return value of currentFileName().

See also
currentFileName()

Reimplemented in AndroidAbstractFileEngineIterator, AndroidAbstractFileEngineIterator, AndroidContentFileEngineIterator, and QAndroidApkFileEngineIterator.

Definition at line 987 of file qabstractfileengine.cpp.

◆ filters()

QDir::Filters QAbstractFileEngineIterator::filters ( ) const

Returns the entry filters for this iterator.

See also
QDir::filter(), nameFilters(), path()

Definition at line 967 of file qabstractfileengine.cpp.

◆ nameFilters()

QStringList QAbstractFileEngineIterator::nameFilters ( ) const

Returns the name filters for this iterator.

See also
QDir::nameFilters(), filters(), path()

Definition at line 957 of file qabstractfileengine.cpp.

◆ path()

QString QAbstractFileEngineIterator::path ( ) const

Returns the path for this iterator.

The path is set by beginEntryList(). The path should't be changed once iteration begins.

See also
nameFilters(), filters()

Definition at line 947 of file qabstractfileengine.cpp.

Friends And Related Symbol Documentation

◆ QDirIterator

friend class QDirIterator
friend

Definition at line 234 of file qabstractfileengine_p.h.

◆ QDirIteratorPrivate

friend class QDirIteratorPrivate
friend

Definition at line 235 of file qabstractfileengine_p.h.

◆ QDirListingPrivate

friend class QDirListingPrivate
friend

Definition at line 236 of file qabstractfileengine_p.h.

Member Data Documentation

◆ m_fileInfo

QFileInfo QAbstractFileEngineIterator::m_fileInfo
mutableprotected

Definition at line 230 of file qabstractfileengine_p.h.


The documentation for this class was generated from the following files: