QAbstractFileEngineIterator

Synopsis

Functions

Virtual functions

Detailed Description

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

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

PySide.QtCore.QAbstractFileEngineIterator is a unidirectional single-use virtual iterator that plugs into PySide.QtCore.QDirIterator , providing transparent proxy iteration for custom file engines.

You can subclass PySide.QtCore.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:

# @arg filters QDir.Filters
# @arg filterNames [str, ...]
# @return QAbstractFileEngineIterator
def beginEntryList(filters, filterNames):
    return CustomFileEngineIterator(filters, filterNames)

PySide.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; PySide.QtCore.QAbstractFileEngineIterator already provides the required filtering logics in the matchesFilters() function. You can call dirName() to get the directory name, PySide.QtCore.QAbstractFileEngineIterator.nameFilters() to get a stringlist of name filters, and PySide.QtCore.QAbstractFileEngineIterator.filters() to get the entry filters.

The pure virtual function PySide.QtCore.QAbstractFileEngineIterator.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 PySide.QtCore.QAbstractFileEngineIterator.next() to seek to the next entry.

The pure virtual function PySide.QtCore.QAbstractFileEngineIterator.currentFileName() returns the name of the current entry without advancing the iterator. The PySide.QtCore.QAbstractFileEngineIterator.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.

class CustomIterator(QAbstractFileEngineIterator):
    def __init__(self, nameFilters, filters):
        QAbstractFileEngineIterator.__init__(self, nameFilters, filters)

        self.index = 0
        # In a real iterator, these entries are fetched from the
        # file system based on the value of path().
        self.entries << "entry1" << "entry2" << "entry3"

    def hasNext(self):
        return self.index < self.entries.size() - 1

    def next(self):
       if not self.hasNext():
           return None
       index += 1
       return currentFilePath()

    def currentFileName(self):
       return self.entries.at(index)

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

class PySide.QtCore.QAbstractFileEngineIterator(filters, nameFilters)
Parameters:
  • nameFilters – list of strings
  • filtersPySide.QtCore.QDir.Filters
PySide.QtCore.QAbstractFileEngineIterator.currentFileInfo()
Return type:PySide.QtCore.QFileInfo

The virtual function returns a PySide.QtCore.QFileInfo for the current directory entry. This function is provided for convenience. It can also be slightly faster than creating a PySide.QtCore.QFileInfo object yourself, as the object returned by this function might contain cached information that PySide.QtCore.QFileInfo otherwise would have to access through the file engine.

PySide.QtCore.QAbstractFileEngineIterator.currentFileName()
Return type:unicode

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

PySide.QtCore.QAbstractFileEngineIterator.currentFilePath()
Return type:unicode

Returns the path to the current directory entry. It’s the same as prepending PySide.QtCore.QAbstractFileEngineIterator.path() to the return value of PySide.QtCore.QAbstractFileEngineIterator.currentFileName() .

PySide.QtCore.QAbstractFileEngineIterator.filters()
Return type:PySide.QtCore.QDir.Filters

Returns the entry filters for this iterator.

PySide.QtCore.QAbstractFileEngineIterator.hasNext()
Return type:PySide.QtCore.bool

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

PySide.QtCore.QAbstractFileEngineIterator.nameFilters()
Return type:list of strings

Returns the name filters for this iterator.

PySide.QtCore.QAbstractFileEngineIterator.next()
Return type:unicode

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 PySide.QtCore.QAbstractFileEngineIterator.nameFilters() and PySide.QtCore.QAbstractFileEngineIterator.filters() to optimize its performance.

Reimplement this function in a subclass to advance the iterator.

PySide.QtCore.QAbstractFileEngineIterator.path()
Return type:unicode

Returns the path for this iterator. PySide.QtCore.QDirIterator is responsible for assigning this path; it cannot change during the iterator’s lifetime.

PySide.QtCore.QAbstractFileEngineIterator.setPath(path)
Parameters:path – unicode