Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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.
 
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;
};
\inmodule QtCore \reentrant
The QAbstractFileEngineIterator class provides an iterator interface for custom file engines.
std::unique_ptr< Iterator > IteratorUniquePtr
const QChar at(qsizetype i) const
Returns the character at the given index position in the string.
Definition qstring.h:1226
std::unique_ptr< QAbstractFileEngine > create(const QString &fileName) const override
[0]
GLuint index
[2]
GLsizei const GLchar *const * path
const QStringList filters({"Image files (*.png *.xpm *.jpg)", "Text files (*.txt)", "Any files (*)" })
[6]
aWidget window() -> setWindowTitle("New Window Title")
[2]
view create()
QJSEngine engine
[0]

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

See also
QDirListing

Definition at line 201 of file qabstractfileengine_p.h.

Constructor & Destructor Documentation

◆ QAbstractFileEngineIterator()

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 897 of file qabstractfileengine.cpp.

◆ ~QAbstractFileEngineIterator()

QAbstractFileEngineIterator::~QAbstractFileEngineIterator ( )
virtual

Destroys the QAbstractFileEngineIterator.

See also
QDirListing

Definition at line 910 of file qabstractfileengine.cpp.

Member Function Documentation

◆ advance()

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 CustomIterator, QFSFileEngineIterator, QResourceFileEngineIterator, AndroidContentFileEngineIterator, AndroidAbstractFileEngineIterator, and QQmlPreviewFileEngineIterator.

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

Definition at line 979 of file qabstractfileengine.cpp.

References currentFilePath(), QFileInfo::filePath(), m_fileInfo, 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 961 of file qabstractfileengine.cpp.

References currentFileName(), and path().

Referenced by currentFileInfo(), and QResourceFileEngineIterator::currentFileInfo().

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

◆ filters()

QDir::Filters QAbstractFileEngineIterator::filters ( ) const

Returns the entry filters for this iterator.

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

Definition at line 941 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 931 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 921 of file qabstractfileengine.cpp.

Referenced by QResourceFileEngineIterator::advance(), AndroidContentFileEngineIterator::advance(), and currentFilePath().

+ Here is the caller graph for this function:

Friends And Related Symbol Documentation

◆ QDirIterator

friend class QDirIterator
friend

Definition at line 223 of file qabstractfileengine_p.h.

◆ QDirIteratorPrivate

friend class QDirIteratorPrivate
friend

Definition at line 224 of file qabstractfileengine_p.h.

◆ QDirListingPrivate

friend class QDirListingPrivate
friend

Definition at line 225 of file qabstractfileengine_p.h.

Member Data Documentation

◆ m_fileInfo


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