Simplify constructor code of QTemporaryFile.

Pass the name as parameter to the constructor of QTemporaryFilePrivate
and use delegation in the convenience constructors.

Change-Id: I4087600b804fe22910b4985a59a02547f54a6acd
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
This commit is contained in:
Friedemann Kleint 2016-06-01 11:54:41 +02:00
parent abe32df864
commit 740470457e
2 changed files with 13 additions and 19 deletions

View File

@ -404,7 +404,12 @@ bool QTemporaryFileEngine::close()
//************* QTemporaryFilePrivate //************* QTemporaryFilePrivate
QTemporaryFilePrivate::QTemporaryFilePrivate() : autoRemove(true) QTemporaryFilePrivate::QTemporaryFilePrivate()
{
}
QTemporaryFilePrivate::QTemporaryFilePrivate(const QString &templateNameIn)
: templateName(templateNameIn)
{ {
} }
@ -498,15 +503,11 @@ QString QTemporaryFilePrivate::defaultTemplateName()
QTemporaryFile::QTemporaryFile() QTemporaryFile::QTemporaryFile()
: QFile(*new QTemporaryFilePrivate) : QFile(*new QTemporaryFilePrivate)
{ {
Q_D(QTemporaryFile);
d->templateName = QTemporaryFilePrivate::defaultTemplateName();
} }
QTemporaryFile::QTemporaryFile(const QString &templateName) QTemporaryFile::QTemporaryFile(const QString &templateName)
: QFile(*new QTemporaryFilePrivate) : QFile(*new QTemporaryFilePrivate(templateName))
{ {
Q_D(QTemporaryFile);
d->templateName = templateName;
} }
#else #else
@ -519,10 +520,8 @@ QTemporaryFile::QTemporaryFile(const QString &templateName)
\sa setFileTemplate(), QDir::tempPath() \sa setFileTemplate(), QDir::tempPath()
*/ */
QTemporaryFile::QTemporaryFile() QTemporaryFile::QTemporaryFile()
: QFile(*new QTemporaryFilePrivate, 0) : QTemporaryFile(nullptr)
{ {
Q_D(QTemporaryFile);
d->templateName = QTemporaryFilePrivate::defaultTemplateName();
} }
/*! /*!
@ -540,10 +539,8 @@ QTemporaryFile::QTemporaryFile()
\sa open(), fileTemplate() \sa open(), fileTemplate()
*/ */
QTemporaryFile::QTemporaryFile(const QString &templateName) QTemporaryFile::QTemporaryFile(const QString &templateName)
: QFile(*new QTemporaryFilePrivate, 0) : QTemporaryFile(templateName, nullptr)
{ {
Q_D(QTemporaryFile);
d->templateName = templateName;
} }
/*! /*!
@ -557,8 +554,6 @@ QTemporaryFile::QTemporaryFile(const QString &templateName)
QTemporaryFile::QTemporaryFile(QObject *parent) QTemporaryFile::QTemporaryFile(QObject *parent)
: QFile(*new QTemporaryFilePrivate, parent) : QFile(*new QTemporaryFilePrivate, parent)
{ {
Q_D(QTemporaryFile);
d->templateName = QTemporaryFilePrivate::defaultTemplateName();
} }
/*! /*!
@ -577,10 +572,8 @@ QTemporaryFile::QTemporaryFile(QObject *parent)
\sa open(), fileTemplate() \sa open(), fileTemplate()
*/ */
QTemporaryFile::QTemporaryFile(const QString &templateName, QObject *parent) QTemporaryFile::QTemporaryFile(const QString &templateName, QObject *parent)
: QFile(*new QTemporaryFilePrivate, parent) : QFile(*new QTemporaryFilePrivate(templateName), parent)
{ {
Q_D(QTemporaryFile);
d->templateName = templateName;
} }
#endif #endif

View File

@ -67,13 +67,14 @@ class QTemporaryFilePrivate : public QFilePrivate
protected: protected:
QTemporaryFilePrivate(); QTemporaryFilePrivate();
explicit QTemporaryFilePrivate(const QString &templateNameIn);
~QTemporaryFilePrivate(); ~QTemporaryFilePrivate();
QAbstractFileEngine *engine() const; QAbstractFileEngine *engine() const;
void resetFileEngine() const; void resetFileEngine() const;
bool autoRemove; bool autoRemove = true;
QString templateName; QString templateName = defaultTemplateName();
static QString defaultTemplateName(); static QString defaultTemplateName();