Qt 6.x
The Qt SDK
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 (QDir::Filters filters, const QStringList &nameFilters)
 Constructs a QAbstractFileEngineIterator, using the entry filters filters, and wildcard name filters nameFilters.
 
virtual ~QAbstractFileEngineIterator ()
 Destroys the QAbstractFileEngineIterator.
 
virtual QString next ()=0
 This pure virtual function advances the iterator to the next directory entry, and returns the file path to the current entry.
 
virtual bool 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).
 
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 Types

enum  EntryInfoType
 

Protected Member Functions

virtual QVariant entryInfo (EntryInfoType type) const
 

Friends

class QDirIterator
 
class QDirIteratorPrivate
 

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 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:

CustomFileEngine::beginEntryList(QDir::Filters filters, const QStringList &filterNames)
{
return new CustomFileEngineIterator(filters, filterNames);
}
The QAbstractFileEngineIterator class provides an iterator interface for custom file engines.
QDir::Filters filters() const
Returns the entry filters for this iterator.
\inmodule QtCore

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

{
public:
CustomIterator(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 hasNext() const override
{
return index < entries.size() - 1;
}
QString next() override
{
if (!hasNext())
return QString();
++index;
return currentFilePath();
}
QString currentFileName() override
{
return entries.at(index);
}
private:
QStringList entries;
int index;
};
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
const QChar at(qsizetype i) const
Returns the character at the given index position in the string.
Definition qstring.h:1079
short next
Definition keywords.cpp:445
GLuint index
[2]
static bool hasNext(const Symbols &symbols, int i)
Definition main.cpp:66
const QStringList filters({"Image files (*.png *.xpm *.jpg)", "Text files (*.txt)", "Any files (*)" })
[6]

Note: QAbstractFileEngineIterator does not deal with QDir::IteratorFlags; it simply returns entries for a single directory.

See also
QDirIterator

Definition at line 195 of file qabstractfileengine_p.h.

Member Enumeration Documentation

◆ EntryInfoType

This enum describes the different types of information that can be requested through the QAbstractFileEngineIterator::entryInfo() function.

Definition at line 213 of file qabstractfileengine_p.h.

Constructor & Destructor Documentation

◆ QAbstractFileEngineIterator()

QAbstractFileEngineIterator::QAbstractFileEngineIterator ( QDir::Filters  filters,
const QStringList nameFilters 
)

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

Definition at line 903 of file qabstractfileengine.cpp.

References QAbstractFileEngineIteratorPrivate::filters, filters(), QAbstractFileEngineIteratorPrivate::nameFilters, and nameFilters().

+ Here is the call graph for this function:

◆ ~QAbstractFileEngineIterator()

QAbstractFileEngineIterator::~QAbstractFileEngineIterator ( )
virtual

Destroys the QAbstractFileEngineIterator.

See also
QDirIterator

Definition at line 916 of file qabstractfileengine.cpp.

Member Function Documentation

◆ 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 QFSFileEngineIterator, and AndroidAbstractFileEngineIterator.

Definition at line 1000 of file qabstractfileengine.cpp.

References currentFilePath(), QAbstractFileEngineIteratorPrivate::fileInfo, QFileInfo::filePath(), and QFileInfo::setFile().

+ Here is the call graph for this function:

◆ currentFileName()

QString QAbstractFileEngineIterator::currentFileName ( ) const
pure virtual

This pure virtual function returns the name of the current directory entry, excluding the path.

See also
currentFilePath()

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

Referenced by currentFilePath().

+ Here is the caller graph for this function:

◆ 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 AndroidContentFileEngineIterator, and AndroidAbstractFileEngineIterator.

Definition at line 977 of file qabstractfileengine.cpp.

References QString::append(), currentFileName(), QString::endsWith(), QString::isEmpty(), path(), and QString::prepend().

Referenced by currentFileInfo(), CustomIterator::next(), QFSFileEngineIterator::next(), QResourceFileEngineIterator::next(), and QQmlPreviewFileEngineIterator::next().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ entryInfo()

QVariant QAbstractFileEngineIterator::entryInfo ( EntryInfoType  type) const
protectedvirtual

Returns the entry info type for this iterator's current directory entry as a QVariant. If type is undefined for this entry, a null QVariant is returned.

See also
QAbstractFileEngine::beginEntryList(), QDir::beginEntryList()

Definition at line 1019 of file qabstractfileengine.cpp.

References Q_UNUSED.

◆ filters()

QDir::Filters QAbstractFileEngineIterator::filters ( ) const

Returns the entry filters for this iterator.

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

Definition at line 957 of file qabstractfileengine.cpp.

References QAbstractFileEngineIteratorPrivate::filters.

Referenced by QAbstractFileEngineIterator(), and QFSFileEngineIterator::hasNext().

+ Here is the caller graph for this function:

◆ hasNext()

bool QAbstractFileEngineIterator::hasNext ( ) const
pure virtual

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).

See also
QDirIterator::hasNext()

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

◆ nameFilters()

QStringList QAbstractFileEngineIterator::nameFilters ( ) const

Returns the name filters for this iterator.

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

Definition at line 947 of file qabstractfileengine.cpp.

References QAbstractFileEngineIteratorPrivate::nameFilters.

Referenced by QAbstractFileEngineIterator(), and QFSFileEngineIterator::hasNext().

+ Here is the caller graph for this function:

◆ next()

QString QAbstractFileEngineIterator::next ( )
pure virtual

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.

See also
QDirIterator::next()

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

◆ path()

QString QAbstractFileEngineIterator::path ( ) const

Returns the path for this iterator.

QDirIterator is responsible for assigning this path; it cannot change during the iterator's lifetime.

See also
nameFilters(), filters()

Definition at line 926 of file qabstractfileengine.cpp.

References QAbstractFileEngineIteratorPrivate::path.

Referenced by currentFilePath(), QFSFileEngineIterator::hasNext(), QResourceFileEngineIterator::hasNext(), and AndroidContentFileEngineIterator::hasNext().

+ Here is the caller graph for this function:

Friends And Related Symbol Documentation

◆ QDirIterator

friend class QDirIterator
friend

Definition at line 219 of file qabstractfileengine_p.h.

◆ QDirIteratorPrivate

friend class QDirIteratorPrivate
friend

Definition at line 220 of file qabstractfileengine_p.h.


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