Qt 4.8
Public Functions | Public Variables | List of all members
QDirIteratorPrivate Class Reference

Public Functions

void advance ()
 
void checkAndPushDirectory (const QFileInfo &)
 
bool entryMatches (const QString &fileName, const QFileInfo &fileInfo)
 
bool matchesFilters (const QString &fileName, const QFileInfo &fi) const
 This convenience function implements the iterator's filtering logics and applies then to the current directory entry. More...
 
void pushDirectory (const QFileInfo &fileInfo)
 
 QDirIteratorPrivate (const QFileSystemEntry &entry, const QStringList &nameFilters, QDir::Filters filters, QDirIterator::IteratorFlags flags, bool resolveEngine=true)
 

Public Variables

QFileInfo currentFileInfo
 
QFileSystemEntry dirEntry
 
QScopedPointer< QAbstractFileEngineengine
 
QDirIteratorPrivateIteratorStack< QAbstractFileEngineIteratorfileEngineIterators
 
const QDir::Filters filters
 
const QDirIterator::IteratorFlags iteratorFlags
 
const QStringList nameFilters
 
QVector< QRegExpnameRegExps
 
QDirIteratorPrivateIteratorStack< QFileSystemIteratornativeIterators
 
QFileInfo nextFileInfo
 
QSet< QStringvisitedLinks
 

Detailed Description

Definition at line 126 of file qdiriterator.cpp.

Constructors and Destructors

◆ QDirIteratorPrivate()

QDirIteratorPrivate::QDirIteratorPrivate ( const QFileSystemEntry entry,
const QStringList nameFilters,
QDir::Filters  filters,
QDirIterator::IteratorFlags  flags,
bool  resolveEngine = true 
)
Warning
This function is not part of the public interface.

Definition at line 165 of file qdiriterator.cpp.

Referenced by QDirIterator::QDirIterator().

167  : dirEntry(entry)
168  , nameFilters(nameFilters.contains(QLatin1String("*")) ? QStringList() : nameFilters)
169  , filters(QDir::NoFilter == filters ? QDir::AllEntries : filters)
170  , iteratorFlags(flags)
171 {
172 #ifndef QT_NO_REGEXP
173  nameRegExps.reserve(nameFilters.size());
174  for (int i = 0; i < nameFilters.size(); ++i)
176  QRegExp(nameFilters.at(i),
179 #endif
180  QFileSystemMetaData metaData;
181  if (resolveEngine)
183  QFileInfo fileInfo(new QFileInfoPrivate(dirEntry, metaData));
184 
185  // Populate fields for hasNext() and next()
186  pushDirectory(fileInfo);
187  advance();
188 }
The QDir class provides access to directory structures and their contents.
Definition: qdir.h:58
The QRegExp class provides pattern matching using regular expressions.
Definition: qregexp.h:61
void pushDirectory(const QFileInfo &fileInfo)
QVector< QRegExp > nameRegExps
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
QBool contains(const QString &str, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the list contains the string str; otherwise returns false.
Definition: qstringlist.h:172
void reset(T *other=0)
Deletes the existing object it is pointing to if any, and sets its pointer to other.
QScopedPointer< QAbstractFileEngine > engine
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
const QDirIterator::IteratorFlags iteratorFlags
const QStringList nameFilters
static QAbstractFileEngine * resolveEntryAndCreateLegacyEngine(QFileSystemEntry &entry, QFileSystemMetaData &data)
Resolves the entry (see QDir::searchPaths) and returns an engine for it, but never a QFSFileEngine...
void reserve(int size)
Attempts to allocate memory for at least size elements.
Definition: qvector.h:339
The QFileInfo class provides system-independent file information.
Definition: qfileinfo.h:60
const QDir::Filters filters
QFileSystemEntry dirEntry

Functions

◆ advance()

void QDirIteratorPrivate::advance ( )
Warning
This function is not part of the public interface.

Definition at line 241 of file qdiriterator.cpp.

Referenced by QDirIterator::next(), and QDirIteratorPrivate().

242 {
243  if (engine) {
244  while (!fileEngineIterators.isEmpty()) {
245  // Find the next valid iterator that matches the filters.
247  while (it = fileEngineIterators.top(), it->hasNext()) {
248  it->next();
249  if (entryMatches(it->currentFileName(), it->currentFileInfo()))
250  return;
251  }
252 
254  delete it;
255  }
256  } else {
257 #ifndef QT_NO_FILESYSTEMITERATOR
258  QFileSystemEntry nextEntry;
259  QFileSystemMetaData nextMetaData;
260 
261  while (!nativeIterators.isEmpty()) {
262  // Find the next valid iterator that matches the filters.
264  while (it = nativeIterators.top(), it->advance(nextEntry, nextMetaData)) {
265  QFileInfo info(new QFileInfoPrivate(nextEntry, nextMetaData));
266 
267  if (entryMatches(nextEntry.fileName(), info))
268  return;
269  }
270 
272  delete it;
273  }
274 #endif
275  }
276 
279 }
static mach_timebase_info_data_t info
#define it(className, varName)
T pop()
Removes the top item from the stack and returns it.
Definition: qstack.h:67
QDirIteratorPrivateIteratorStack< QAbstractFileEngineIterator > fileEngineIterators
bool entryMatches(const QString &fileName, const QFileInfo &fileInfo)
QString fileName() const
virtual bool hasNext() const =0
This pure virtual function returns true if there is at least one more entry in the current directory ...
bool advance(QFileSystemEntry &fileEntry, QFileSystemMetaData &metaData)
QScopedPointer< QAbstractFileEngine > engine
The QAbstractFileEngineIterator class provides an iterator interface for custom file engines...
virtual QString next()=0
This pure virtual function advances the iterator to the next directory entry, and returns the file pa...
QDirIteratorPrivateIteratorStack< QFileSystemIterator > nativeIterators
virtual QString currentFileName() const =0
This pure virtual function returns the name of the current directory entry, excluding the path...
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
Definition: qvector.h:139
The QFileInfo class provides system-independent file information.
Definition: qfileinfo.h:60
virtual QFileInfo currentFileInfo() const
The virtual function returns a QFileInfo for the current directory entry.
T & top()
Returns a reference to the stack&#39;s top item.
Definition: qstack.h:72

◆ checkAndPushDirectory()

void QDirIteratorPrivate::checkAndPushDirectory ( const QFileInfo fileInfo)
Warning
This function is not part of the public interface.

Definition at line 284 of file qdiriterator.cpp.

Referenced by entryMatches().

285 {
286  // If we're doing flat iteration, we're done.
288  return;
289 
290  // Never follow non-directory entries
291  if (!fileInfo.isDir())
292  return;
293 
294  // Follow symlinks only when asked
296  return;
297 
298  // Never follow . and ..
299  QString fileName = fileInfo.fileName();
300  if (QLatin1String(".") == fileName || QLatin1String("..") == fileName)
301  return;
302 
303  // No hidden directories unless requested
304  if (!(filters & QDir::AllDirs) && !(filters & QDir::Hidden) && fileInfo.isHidden())
305  return;
306 
307  // Stop link loops
308  if (!visitedLinks.isEmpty() &&
310  return;
311 
312  pushDirectory(fileInfo);
313 }
bool isHidden() const
Returns true if this is a `hidden&#39; file; otherwise returns false.
Definition: qfileinfo.cpp:951
bool isEmpty() const
Definition: qset.h:77
QString fileName() const
Returns the name of the file, excluding the path.
Definition: qfileinfo.cpp:726
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
void pushDirectory(const QFileInfo &fileInfo)
bool isDir() const
Returns true if this object points to a directory or to a symbolic link to a directory; otherwise ret...
Definition: qfileinfo.cpp:990
bool contains(const T &value) const
Definition: qset.h:91
QString canonicalFilePath() const
Returns the canonical path including the file name, i.e.
Definition: qfileinfo.cpp:551
const QDirIterator::IteratorFlags iteratorFlags
bool isSymLink() const
Returns true if this object points to a symbolic link (or to a shortcut on Windows); otherwise return...
Definition: qfileinfo.cpp:1044
static QString fileName(const QString &fileUrl)
QSet< QString > visitedLinks
const QDir::Filters filters

◆ entryMatches()

bool QDirIteratorPrivate::entryMatches ( const QString fileName,
const QFileInfo fileInfo 
)
inline

Definition at line 223 of file qdiriterator.cpp.

Referenced by advance().

224 {
225  checkAndPushDirectory(fileInfo);
226 
227  if (matchesFilters(fileName, fileInfo)) {
229  nextFileInfo = fileInfo;
230 
231  //We found a matching entry.
232  return true;
233  }
234 
235  return false;
236 }
bool matchesFilters(const QString &fileName, const QFileInfo &fi) const
This convenience function implements the iterator&#39;s filtering logics and applies then to the current ...
void checkAndPushDirectory(const QFileInfo &)

◆ matchesFilters()

bool QDirIteratorPrivate::matchesFilters ( const QString fileName,
const QFileInfo fi 
) const

This convenience function implements the iterator's filtering logics and applies then to the current directory entry.

Warning
This function is not part of the public interface.

It returns true if the current entry matches the filters (i.e., the current entry will be returned as part of the directory iteration); otherwise, false is returned.

Definition at line 329 of file qdiriterator.cpp.

Referenced by entryMatches().

330 {
331  Q_ASSERT(!fileName.isEmpty());
332 
333  // filter . and ..?
334  const int fileNameSize = fileName.size();
335  const bool dotOrDotDot = fileName[0] == QLatin1Char('.')
336  && ((fileNameSize == 1)
337  ||(fileNameSize == 2 && fileName[1] == QLatin1Char('.')));
338  if ((filters & QDir::NoDot) && dotOrDotDot && fileNameSize == 1)
339  return false;
340  if ((filters & QDir::NoDotDot) && dotOrDotDot && fileNameSize == 2)
341  return false;
342  if ((filters & QDir::NoDotAndDotDot) && dotOrDotDot) // ### Qt5 remove (NoDotAndDotDot == NoDot|NoDotDot)
343  return false;
344 
345  // name filter
346 #ifndef QT_NO_REGEXP
347  // Pass all entries through name filters, except dirs if the AllDirs
348  if (!nameFilters.isEmpty() && !((filters & QDir::AllDirs) && fi.isDir())) {
349  bool matched = false;
352  iter != end; ++iter) {
353 
354  if (iter->exactMatch(fileName)) {
355  matched = true;
356  break;
357  }
358  }
359  if (!matched)
360  return false;
361  }
362 #endif
363  // skip symlinks
364  const bool skipSymlinks = (filters & QDir::NoSymLinks);
365  const bool includeSystem = (filters & QDir::System);
366  if(skipSymlinks && fi.isSymLink()) {
367  // The only reason to save this file is if it is a broken link and we are requesting system files.
368  if(!includeSystem || fi.exists())
369  return false;
370  }
371 
372  // filter hidden
373  const bool includeHidden = (filters & QDir::Hidden);
374  if (!includeHidden && !dotOrDotDot && fi.isHidden())
375  return false;
376 
377  // filter system files
378  if (!includeSystem && (!(fi.isFile() || fi.isDir() || fi.isSymLink())
379  || (!fi.exists() && fi.isSymLink())))
380  return false;
381 
382  // skip directories
383  const bool skipDirs = !(filters & (QDir::Dirs | QDir::AllDirs));
384  if (skipDirs && fi.isDir())
385  return false;
386 
387  // skip files
388  const bool skipFiles = !(filters & QDir::Files);
389  if (skipFiles && fi.isFile())
390  // Basically we need a reason not to exclude this file otherwise we just eliminate it.
391  return false;
392 
393  // filter permissions
394  const bool filterPermissions = ((filters & QDir::PermissionMask)
396  const bool doWritable = !filterPermissions || (filters & QDir::Writable);
397  const bool doExecutable = !filterPermissions || (filters & QDir::Executable);
398  const bool doReadable = !filterPermissions || (filters & QDir::Readable);
399  if (filterPermissions
400  && ((doReadable && !fi.isReadable())
401  || (doWritable && !fi.isWritable())
402  || (doExecutable && !fi.isExecutable()))) {
403  return false;
404  }
405 
406  return true;
407 }
bool isHidden() const
Returns true if this is a `hidden&#39; file; otherwise returns false.
Definition: qfileinfo.cpp:951
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the vector...
Definition: qvector.h:252
bool exists() const
Returns true if the file exists; otherwise returns false.
Definition: qfileinfo.cpp:675
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the vector.
Definition: qvector.h:249
bool isDir() const
Returns true if this object points to a directory or to a symbolic link to a directory; otherwise ret...
Definition: qfileinfo.cpp:990
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QVector< QRegExp > nameRegExps
bool isExecutable() const
Returns true if the file is executable; otherwise returns false.
Definition: qfileinfo.cpp:932
bool isFile() const
Returns true if this object points to a file or to a symbolic link to a file.
Definition: qfileinfo.cpp:971
const QStringList nameFilters
bool isReadable() const
Returns true if the user can read the file; otherwise returns false.
Definition: qfileinfo.cpp:896
bool isSymLink() const
Returns true if this object points to a symbolic link (or to a shortcut on Windows); otherwise return...
Definition: qfileinfo.cpp:1044
static const KeyPair *const end
bool isWritable() const
Returns true if the user can write to the file; otherwise returns false.
Definition: qfileinfo.cpp:914
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
const QDir::Filters filters

◆ pushDirectory()

void QDirIteratorPrivate::pushDirectory ( const QFileInfo fileInfo)
Warning
This function is not part of the public interface.

Definition at line 193 of file qdiriterator.cpp.

Referenced by checkAndPushDirectory(), and QDirIteratorPrivate().

194 {
195  QString path = fileInfo.filePath();
196 
197 #ifdef Q_OS_WIN
198  if (fileInfo.isSymLink())
199  path = fileInfo.canonicalFilePath();
200 #endif
201 
203  visitedLinks << fileInfo.canonicalFilePath();
204 
205  if (engine) {
206  engine->setFileName(path);
208  if (it) {
209  it->setPath(path);
211  } else {
212  // No iterator; no entry list.
213  }
214  } else {
215 #ifndef QT_NO_FILESYSTEMITERATOR
218  nativeIterators << it;
219 #endif
220  }
221 }
QFileSystemEntry fileEntry
Definition: qfileinfo_p.h:142
#define it(className, varName)
QSharedDataPointer< QFileInfoPrivate > d_ptr
Definition: qfileinfo.h:177
The QString class provides a Unicode character string.
Definition: qstring.h:83
virtual void setFileName(const QString &file)
Sets the file engine&#39;s file name to file.
QDirIteratorPrivateIteratorStack< QAbstractFileEngineIterator > fileEngineIterators
QString canonicalFilePath() const
Returns the canonical path including the file name, i.e.
Definition: qfileinfo.cpp:551
void setPath(const QString &path)
Sets the iterator path to path.
virtual Iterator * beginEntryList(QDir::Filters filters, const QStringList &filterNames)
Returns an instance of a QAbstractFileEngineIterator using filters for entry filtering and filterName...
QScopedPointer< QAbstractFileEngine > engine
The QAbstractFileEngineIterator class provides an iterator interface for custom file engines...
const QDirIterator::IteratorFlags iteratorFlags
QDirIteratorPrivateIteratorStack< QFileSystemIterator > nativeIterators
const QStringList nameFilters
bool isSymLink() const
Returns true if this object points to a symbolic link (or to a shortcut on Windows); otherwise return...
Definition: qfileinfo.cpp:1044
QString filePath() const
Returns the file name, including the path (which may be absolute or relative).
Definition: qfileinfo.cpp:707
QSet< QString > visitedLinks
const QDir::Filters filters

Properties

◆ currentFileInfo

QFileInfo QDirIteratorPrivate::currentFileInfo

◆ dirEntry

QFileSystemEntry QDirIteratorPrivate::dirEntry

Definition at line 141 of file qdiriterator.cpp.

Referenced by QDirIterator::path(), and QDirIteratorPrivate().

◆ engine

QScopedPointer<QAbstractFileEngine> QDirIteratorPrivate::engine

◆ fileEngineIterators

QDirIteratorPrivateIteratorStack<QAbstractFileEngineIterator> QDirIteratorPrivate::fileEngineIterators

Definition at line 150 of file qdiriterator.cpp.

Referenced by advance(), QDirIterator::hasNext(), and pushDirectory().

◆ filters

const QDir::Filters QDirIteratorPrivate::filters

Definition at line 143 of file qdiriterator.cpp.

Referenced by checkAndPushDirectory(), matchesFilters(), and pushDirectory().

◆ iteratorFlags

const QDirIterator::IteratorFlags QDirIteratorPrivate::iteratorFlags

Definition at line 144 of file qdiriterator.cpp.

Referenced by checkAndPushDirectory(), and pushDirectory().

◆ nameFilters

const QStringList QDirIteratorPrivate::nameFilters

Definition at line 142 of file qdiriterator.cpp.

Referenced by matchesFilters(), and pushDirectory().

◆ nameRegExps

QVector<QRegExp> QDirIteratorPrivate::nameRegExps

Definition at line 147 of file qdiriterator.cpp.

Referenced by matchesFilters(), and QDirIteratorPrivate().

◆ nativeIterators

QDirIteratorPrivateIteratorStack<QFileSystemIterator> QDirIteratorPrivate::nativeIterators

Definition at line 152 of file qdiriterator.cpp.

Referenced by advance(), QDirIterator::hasNext(), and pushDirectory().

◆ nextFileInfo

QFileInfo QDirIteratorPrivate::nextFileInfo

Definition at line 156 of file qdiriterator.cpp.

Referenced by advance(), and entryMatches().

◆ visitedLinks

QSet<QString> QDirIteratorPrivate::visitedLinks

Definition at line 159 of file qdiriterator.cpp.

Referenced by checkAndPushDirectory(), and pushDirectory().


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