Add Q_DECLARE_PRIVATE equivalent for QDir, to be able to subclass it
authorDavid Faure <faure@kde.org>
Sat, 5 Nov 2011 11:09:54 +0000 (12:09 +0100)
committerQt by Nokia <qt-info@nokia.com>
Tue, 8 Nov 2011 11:09:06 +0000 (12:09 +0100)
Apply the same solution to QFileInfo (no public detach(), but a
non-inline d_func instead).

Change-Id: I31c4c759f44a0649b97f7884b078b174c9c00f22
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
src/corelib/io/qdir.cpp
src/corelib/io/qdir.h
src/corelib/io/qfileinfo.cpp
src/corelib/io/qfileinfo.h
tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp

index e7fdc4a..32fd819 100644 (file)
@@ -508,6 +508,13 @@ inline void QDirPrivate::initFileEngine()
 */
 
 /*!
+    \internal
+*/
+QDir::QDir(QDirPrivate &p) : d_ptr(&p)
+{
+}
+
+/*!
     Constructs a QDir pointing to the given directory \a path. If path
     is empty the program's working directory, ("."), is used.
 
@@ -2097,6 +2104,13 @@ void QDir::refresh() const
     d->clearFileLists();
 }
 
+/*! \internal
+*/
+QDirPrivate* QDir::d_func()
+{
+    return d_ptr.data();
+}
+
 /*!
     \internal
 
index de5fb1b..822173d 100644 (file)
@@ -57,9 +57,6 @@ class QDirPrivate;
 
 class Q_CORE_EXPORT QDir
 {
-protected:
-    QSharedDataPointer<QDirPrivate> d_ptr;
-
 public:
     enum Filter { Dirs        = 0x001,
                   Files       = 0x002,
@@ -99,7 +96,7 @@ public:
                     Reversed    = 0x08,
                     IgnoreCase  = 0x10,
                     DirsLast    = 0x20,
-                    LocaleAware = 0x40, 
+                    LocaleAware = 0x40,
                     Type        = 0x80,
                     NoSort = -1
     };
@@ -208,6 +205,20 @@ public:
 
     static QString cleanPath(const QString &path);
     void refresh() const;
+
+protected:
+    explicit QDir(QDirPrivate &d);
+
+    QSharedDataPointer<QDirPrivate> d_ptr;
+
+private:
+    // Q_DECLARE_PRIVATE equivalent for shared data pointers
+    QDirPrivate* d_func();
+    inline const QDirPrivate* d_func() const
+    {
+        return d_ptr.constData();
+    }
+
 };
 
 Q_DECLARE_OPERATORS_FOR_FLAGS(QDir::Filters)
index 7d925f3..1ea6c8d 100644 (file)
@@ -1275,11 +1275,10 @@ QDateTime QFileInfo::lastRead() const
 }
 
 /*! \internal
-    Detaches all internal data.
 */
-void QFileInfo::detach()
+QFileInfoPrivate* QFileInfo::d_func()
 {
-    d_ptr.detach();
+    return d_ptr.data();
 }
 
 /*!
index ab3d2dc..ef45731 100644 (file)
@@ -132,20 +132,14 @@ public:
     QDateTime lastModified() const;
     QDateTime lastRead() const;
 
-    void detach();
-
     bool caching() const;
     void setCaching(bool on);
 
 protected:
     QSharedDataPointer<QFileInfoPrivate> d_ptr;
-private:
-    inline QFileInfoPrivate* d_func()
-    {
-        detach();
-        return const_cast<QFileInfoPrivate *>(d_ptr.constData());
-    }
 
+private:
+    QFileInfoPrivate* d_func();
     inline const QFileInfoPrivate* d_func() const
     {
         return d_ptr.constData();
index 4fa32b0..8650bc4 100644 (file)
@@ -1592,9 +1592,6 @@ void tst_QFileInfo::detachingOperations()
 
     QVERIFY(info1.makeAbsolute());
     QVERIFY(!info1.caching());
-
-    info1.detach();
-    QVERIFY(!info1.caching());
 }
 
 #if !defined(Q_OS_WINCE)