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 <thiago.macieira@intel.com>
This commit is contained in:
David Faure 2011-11-05 12:09:54 +01:00 committed by Qt by Nokia
parent 4d398c90fb
commit 5e26608ae2
5 changed files with 33 additions and 18 deletions

View File

@ -507,6 +507,13 @@ inline void QDirPrivate::initFileEngine()
\sa QFileInfo, QFile, QFileDialog, QApplication::applicationDirPath(), {Find Files Example}
*/
/*!
\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

View 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)

View 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();
}
/*!

View 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();

View 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)