From: David Faure Date: Sat, 5 Nov 2011 11:09:54 +0000 (+0100) Subject: Add Q_DECLARE_PRIVATE equivalent for QDir, to be able to subclass it X-Git-Tag: qt-v5.0.0-alpha1~2831 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5e26608ae2d724f5e45d9e8667378bf7faf69d8c;p=profile%2Fivi%2Fqtbase.git Add Q_DECLARE_PRIVATE equivalent for QDir, to be able to subclass it Apply the same solution to QFileInfo (no public detach(), but a non-inline d_func instead). Change-Id: I31c4c759f44a0649b97f7884b078b174c9c00f22 Reviewed-by: Thiago Macieira --- diff --git a/src/corelib/io/qdir.cpp b/src/corelib/io/qdir.cpp index e7fdc4a..32fd819 100644 --- a/src/corelib/io/qdir.cpp +++ b/src/corelib/io/qdir.cpp @@ -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 diff --git a/src/corelib/io/qdir.h b/src/corelib/io/qdir.h index de5fb1b..822173d 100644 --- a/src/corelib/io/qdir.h +++ b/src/corelib/io/qdir.h @@ -57,9 +57,6 @@ class QDirPrivate; class Q_CORE_EXPORT QDir { -protected: - QSharedDataPointer 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 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) diff --git a/src/corelib/io/qfileinfo.cpp b/src/corelib/io/qfileinfo.cpp index 7d925f3..1ea6c8d 100644 --- a/src/corelib/io/qfileinfo.cpp +++ b/src/corelib/io/qfileinfo.cpp @@ -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(); } /*! diff --git a/src/corelib/io/qfileinfo.h b/src/corelib/io/qfileinfo.h index ab3d2dc..ef45731 100644 --- a/src/corelib/io/qfileinfo.h +++ b/src/corelib/io/qfileinfo.h @@ -132,20 +132,14 @@ public: QDateTime lastModified() const; QDateTime lastRead() const; - void detach(); - bool caching() const; void setCaching(bool on); protected: QSharedDataPointer d_ptr; -private: - inline QFileInfoPrivate* d_func() - { - detach(); - return const_cast(d_ptr.constData()); - } +private: + QFileInfoPrivate* d_func(); inline const QFileInfoPrivate* d_func() const { return d_ptr.constData(); diff --git a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp index 4fa32b0..8650bc4 100644 --- a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp +++ b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp @@ -1592,9 +1592,6 @@ void tst_QFileInfo::detachingOperations() QVERIFY(info1.makeAbsolute()); QVERIFY(!info1.caching()); - - info1.detach(); - QVERIFY(!info1.caching()); } #if !defined(Q_OS_WINCE)