QDirIterator: don't inherit from QDir
authorMarc Mutz <marc.mutz@kdab.com>
Mon, 5 Mar 2012 17:27:10 +0000 (18:27 +0100)
committerQt by Nokia <qt-info@nokia.com>
Fri, 23 Mar 2012 10:22:40 +0000 (11:22 +0100)
Remove the inheritance hack used in
QDirIterator to gain access to QDir's
d-pointer by simply making QDirIterator
a friend of QDir.

This allows to turn QDir into a final class.

Change-Id: I97efef8714bb194d62b9fe5192ce240a90f2bf97
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
src/corelib/io/qdir.h
src/corelib/io/qdiriterator.cpp

index 5551ecd..a5105fe 100644 (file)
@@ -52,6 +52,7 @@ QT_BEGIN_HEADER
 QT_BEGIN_NAMESPACE
 
 
+class QDirIterator;
 class QDirPrivate;
 
 class Q_CORE_EXPORT QDir
@@ -210,6 +211,7 @@ protected:
     QSharedDataPointer<QDirPrivate> d_ptr;
 
 private:
+    friend class QDirIterator;
     // Q_DECLARE_PRIVATE equivalent for shared data pointers
     QDirPrivate* d_func();
     inline const QDirPrivate* d_func() const
index b8536a8..56912e8 100644 (file)
@@ -410,9 +410,7 @@ bool QDirIteratorPrivate::matchesFilters(const QString &fileName, const QFileInf
 */
 QDirIterator::QDirIterator(const QDir &dir, IteratorFlags flags)
 {
-    // little trick to get hold of the QDirPrivate while there is no API on QDir to give it to us
-    class MyQDir : public QDir { public: const QDirPrivate *priv() const { return d_ptr.constData(); } };
-    const QDirPrivate *other = static_cast<const MyQDir*>(&dir)->priv();
+    const QDirPrivate *other = dir.d_ptr.constData();
     d.reset(new QDirIteratorPrivate(other->dirEntry, other->nameFilters, other->filters, flags, !other->fileEngine.isNull()));
 }