Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Toutes les classes  ·  Toutes les fonctions  ·  Vues d'ensemble  · 

QAbstractFileEngineIterator Class Reference

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

 #include <QAbstractFileEngineIterator>

This class was introduced in Qt 4.3.

Public Functions

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

Detailed Description

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

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:

 QAbstractFileEngineIterator *
 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;
     }

     QString next()
     {
        if (!hasNext())
            return QString();
        ++index;
        return currentFilePath();
     }

     QString currentFileName()
     {
         return entries.at(index);
     }

 private:
     QStringList entries;
     int index;
 };

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

See also QDirIterator.

Member Function Documentation

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

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

QAbstractFileEngineIterator::~QAbstractFileEngineIterator () [virtual]

Destroys the QAbstractFileEngineIterator.

See also QDirIterator.

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]

This pure virtual function returns 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. It's 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(), and path().

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

QStringList QAbstractFileEngineIterator::nameFilters () const

Returns the name filters for this iterator.

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

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

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() and filters().

Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. Microsoft ouvre aux autres compilateurs C++ AMP, la spécification pour la conception d'applications parallèles C++ utilisant le GPU 22
  2. Les développeurs ignorent-ils trop les failles découvertes dans leur code ? Prenez-vous en compte les remarques des autres ? 17
  3. RIM : « 13 % des développeurs ont gagné plus de 100 000 $ sur l'AppWord », Qt et open-source au menu du BlackBerry DevCon Europe 0
  4. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 12
  5. BlackBerry 10 : premières images du prochain OS de RIM qui devrait intégrer des widgets et des tuiles inspirées de Windows Phone 0
  6. Adieu qmake, bienvenue qbs : Qt Building Suite, un outil déclaratif et extensible pour la compilation de projets Qt 17
  7. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
Page suivante

Le Qt Developer Network au hasard

Logo

Compiler l'add-in Qt de Visual Studio

Le Qt Developer Network est un réseau de développeurs Qt anglophone, où ils peuvent partager leur expérience sur le framework. Lire l'article.

Communauté

Ressources

Liens utiles

Contact

  • Vous souhaitez rejoindre la rédaction ou proposer un tutoriel, une traduction, une question... ? Postez dans le forum Contribuez ou contactez-nous par MP ou par email (voir en bas de page).

Qt dans le magazine

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt 4.7
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web