CopperSpice API  1.9.1
QAbstractFileEngineIterator Class Referenceabstract

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

Public Methods

 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
 

Friends

class QDirIterator
 

Detailed Description

The QAbstractFileEngineIterator class provides an iterator interface for custom file engines. If your application only needs to iterate over entries in a directory then refer to QDirIterator. This class is used when implementing a custom file engine.

Example 1

The following three steps are required to use this class.

  • CustomFileEngineIterator must inherit from QAbstractFileEngineIterator
  • CustomFileEngine must inherit from QAbstractFileEngine
  • CustomFileEngine must override beginEntryList() and return a CustomFileEngineIterator
QAbstractFileEngineIterator * CustomFileEngine::beginEntryList(QDir::Filters filters, const QStringList &filterNames)
{
return new CustomFileEngineIterator(filters, filterNames);
}

Example 2

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 methods hasNext() returns true if the current directory has at least one more entry and false otherwise. The method currentFileName() returns the name of the current entry without advancing the iterator. The currentFilePath() method returns the full path of the current entry.

The following example shows how to implement an iterator which returns each of three fixed entries in sequence.

class CustomIterator : public QAbstractFileEngineIterator
{
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
{
return index < entries.size() - 1;
}
{
if (! hasNext()) {
return QString();
}
++index;
return currentFilePath();
}
{
return entries.at(index);
}
private:
QStringList entries;
int index;
};

QAbstractFileEngineIterator does not handle QDir::IteratorFlags it simply returns entries for a single directory.

See also
QDirIterator

Constructor & Destructor Documentation

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

Constructs a QAbstractFileEngineIterator using the entry filters and wildcard nameFilters.

QAbstractFileEngineIterator::~QAbstractFileEngineIterator ( )
virtual

Destroys the QAbstractFileEngineIterator.

See also
QDirIterator

Method Documentation

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()
QString QAbstractFileEngineIterator::currentFileName ( ) const
pure virtual

Override this method to return the name of the current directory entry, excluding the path.

See also
currentFilePath()
QString QAbstractFileEngineIterator::currentFilePath ( ) const

Returns the path to the current directory entry. This is the same as prepending path() to the return value of currentFileName().

See also
currentFileName()
QDir::Filters QAbstractFileEngineIterator::filters ( ) const

Returns the entry filters for this iterator.

See also
QDir::filter(), nameFilters(), path()
bool QAbstractFileEngineIterator::hasNext ( ) const
pure virtual

Override this method to return true if there is at least one more entry in the current directory.

See also
QDirIterator::hasNext()
QStringList QAbstractFileEngineIterator::nameFilters ( ) const

Returns the name filters for this iterator.

See also
QDir::nameFilters(), filters(), path()
QString QAbstractFileEngineIterator::next ( )
pure virtual

When overriding this method advance the iterator to the next directory entry and return the file path to this entry. This method can optionally make use of nameFilters() and filters() to optimize performance.

See also
QDirIterator::next()
QString QAbstractFileEngineIterator::path ( ) const

Returns the path for this iterator.

See also
nameFilters(), filters()