Qt 4.8
Public Functions | Protected Types | Protected Functions | Private Functions | Properties | Friends | List of all members
QAbstractFileEngineIterator Class Referenceabstract

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

#include <qabstractfileengine.h>

Inheritance diagram for QAbstractFileEngineIterator:
QFSFileEngineIterator QResourceFileEngineIterator

Public Functions

virtual QFileInfo currentFileInfo () const
 The virtual function returns a QFileInfo for the current directory entry. More...
 
virtual QString currentFileName () const =0
 This pure virtual function returns the name of the current directory entry, excluding the path. More...
 
QString currentFilePath () const
 Returns the path to the current directory entry. More...
 
QDir::Filters filters () const
 Returns the entry filters for this iterator. More...
 
virtual bool hasNext () const =0
 This pure virtual function returns true if there is at least one more entry in the current directory (i. More...
 
QStringList nameFilters () const
 Returns the name filters for this iterator. More...
 
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. More...
 
QString path () const
 Returns the path for this iterator. More...
 
 QAbstractFileEngineIterator (QDir::Filters filters, const QStringList &nameFilters)
 Constructs a QAbstractFileEngineIterator, using the entry filters filters, and wildcard name filters nameFilters. More...
 
virtual ~QAbstractFileEngineIterator ()
 Destroys the QAbstractFileEngineIterator. More...
 

Protected Types

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

Protected Functions

virtual QVariant entryInfo (EntryInfoType type) const
 Returns the entry info type for this iterator's current directory entry as a QVariant. More...
 

Private Functions

void setPath (const QString &path)
 Sets the iterator path to path. More...
 

Properties

QScopedPointer< QAbstractFileEngineIteratorPrivated
 

Friends

class QDirIterator
 
class QDirIteratorPrivate
 

Detailed Description

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

Since
4.3

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);
}

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.

class CustomIterator : public QAbstractFileEngineIterator
{
public:
CustomIterator(const QStringList &nameFilters, QDir::Filters filters)
: QAbstractFileEngineIterator(nameFilters, filters), index(0)
{
// 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:
int index;
};

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

See also
QDirIterator

Definition at line 214 of file qabstractfileengine.h.

Enumerations

◆ EntryInfoType

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

Warning
This function is not part of the public interface.

Definition at line 232 of file qabstractfileengine.h.

232  {
233  };

Constructors and Destructors

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

929 {
931  d->filters = filters;
932 }
QScopedPointer< QAbstractFileEngineIteratorPrivate > d
QDir::Filters filters() const
Returns the entry filters for this iterator.
QStringList nameFilters() const
Returns the name filters for this iterator.

◆ ~QAbstractFileEngineIterator()

QAbstractFileEngineIterator::~QAbstractFileEngineIterator ( )
virtual

Destroys the QAbstractFileEngineIterator.

See also
QDirIterator

Definition at line 939 of file qabstractfileengine.cpp.

940 {
941 }

Functions

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

Definition at line 1029 of file qabstractfileengine.cpp.

Referenced by QDirIteratorPrivate::advance().

1030 {
1032  if (d->fileInfo.filePath() != path)
1033  d->fileInfo.setFile(path);
1034 
1035  // return a shallow copy
1036  return d->fileInfo;
1037 }
QString path() const
Returns the path for this iterator.
The QString class provides a Unicode character string.
Definition: qstring.h:83
QScopedPointer< QAbstractFileEngineIteratorPrivate > d
void setFile(const QString &file)
Sets the file that the QFileInfo provides information about to file.
Definition: qfileinfo.cpp:468
QString currentFilePath() const
Returns the path to the current directory entry.
QString filePath() const
Returns the file name, including the path (which may be absolute or relative).
Definition: qfileinfo.cpp:707

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

Referenced by QDirIteratorPrivate::advance(), and currentFilePath().

◆ currentFilePath()

QString QAbstractFileEngineIterator::currentFilePath ( ) const

Returns the path to the current directory entry.

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

See also
currentFileName()

Definition at line 1006 of file qabstractfileengine.cpp.

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

1007 {
1009  if (!name.isNull()) {
1010  QString tmp = path();
1011  if (!tmp.isEmpty()) {
1012  if (!tmp.endsWith(QLatin1Char('/')))
1013  tmp.append(QLatin1Char('/'));
1014  name.prepend(tmp);
1015  }
1016  }
1017  return name;
1018 }
QString path() const
Returns the path for this iterator.
QString & prepend(QChar c)
Definition: qstring.h:261
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
const char * name
bool isNull() const
Returns true if this string is null; otherwise returns false.
Definition: qstring.h:505
QString & append(QChar c)
Definition: qstring.cpp:1777
virtual QString currentFileName() const =0
This pure virtual function returns the name of the current directory entry, excluding the path...
bool endsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string ends with s; otherwise returns false.
Definition: qstring.cpp:3796
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ entryInfo()

QVariant QAbstractFileEngineIterator::entryInfo ( EntryInfoType  type) const
protectedvirtual

Returns the entry info type for this iterator's current directory entry as a QVariant.

Warning
This function is not part of the public interface.

If type is undefined for this entry, a null QVariant is returned.

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

Definition at line 1051 of file qabstractfileengine.cpp.

1052 {
1053  Q_UNUSED(type)
1054  return QVariant();
1055 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
int type
Definition: qmetatype.cpp:239
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ filters()

QDir::Filters QAbstractFileEngineIterator::filters ( ) const

Returns the entry filters for this iterator.

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

Definition at line 983 of file qabstractfileengine.cpp.

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

984 {
985  return d->filters;
986 }
QScopedPointer< QAbstractFileEngineIteratorPrivate > d

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

Referenced by QDirIteratorPrivate::advance().

◆ nameFilters()

QStringList QAbstractFileEngineIterator::nameFilters ( ) const

Returns the name filters for this iterator.

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

Definition at line 973 of file qabstractfileengine.cpp.

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

974 {
975  return d->nameFilters;
976 }
QScopedPointer< QAbstractFileEngineIteratorPrivate > d

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

Referenced by QDirIteratorPrivate::advance().

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

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

950 {
951  return d->path;
952 }
QScopedPointer< QAbstractFileEngineIteratorPrivate > d

◆ setPath()

void QAbstractFileEngineIterator::setPath ( const QString path)
private

Sets the iterator path to path.

Warning
This function is not part of the public interface.

This function is called from within QDirIterator.

Definition at line 963 of file qabstractfileengine.cpp.

Referenced by QDirIteratorPrivate::pushDirectory().

964 {
965  d->path = path;
966 }
QString path() const
Returns the path for this iterator.
QScopedPointer< QAbstractFileEngineIteratorPrivate > d

Friends and Related Functions

◆ QDirIterator

friend class QDirIterator
friend

Definition at line 238 of file qabstractfileengine.h.

◆ QDirIteratorPrivate

friend class QDirIteratorPrivate
friend

Definition at line 239 of file qabstractfileengine.h.

Properties

◆ d

QScopedPointer<QAbstractFileEngineIteratorPrivate> QAbstractFileEngineIterator::d
private

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