Q{File,Font,Color,Message}DialogOptions are no value classes
These classes are only held in QSharedPointer, so optimize for that: 1. Disable default ctor, copy ctor and assignment operator, destructor and swap for public users. 2. Add create() to return an instance in a shared pointer. 3. Allocate public and private classes in one memory block, use QSharedPointer::create() to also add the QSharedPointer control block to the same memory allocation. As a consequence, this reduces the creation of a Q*DialogOptions into a shared pointer by two memory allocations. Add a macro to enable atomic updates to QtQuick and other users outside QtBase. [ChangeLog][QtGui] [QFileDialogOptions/QFontDialogOptions/QMessageDialogOptions/QColorDialogOptions] This class no longer has value semantics, but needs to be held in QSharedPointer (as it always was). To copy an instance, use the clone() method. Change-Id: I4c81220e0a8286a310df1c224a30eca34824c4e6 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com> Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com> Reviewed-by: Shawn Rutledge <shawn.rutledge@theqtcompany.com>
This commit is contained in:
parent
aeb169a488
commit
1a42124839
@ -156,25 +156,35 @@ public:
|
||||
QString windowTitle;
|
||||
};
|
||||
|
||||
QFontDialogOptions::QFontDialogOptions() : d(new QFontDialogOptionsPrivate)
|
||||
QFontDialogOptions::QFontDialogOptions(QFontDialogOptionsPrivate *dd)
|
||||
: d(dd)
|
||||
{
|
||||
}
|
||||
|
||||
QFontDialogOptions::QFontDialogOptions(const QFontDialogOptions &rhs) : d(rhs.d)
|
||||
{
|
||||
}
|
||||
|
||||
QFontDialogOptions &QFontDialogOptions::operator=(const QFontDialogOptions &rhs)
|
||||
{
|
||||
if (this != &rhs)
|
||||
d = rhs.d;
|
||||
return *this;
|
||||
}
|
||||
|
||||
QFontDialogOptions::~QFontDialogOptions()
|
||||
{
|
||||
}
|
||||
|
||||
namespace {
|
||||
struct FontDialogCombined : QFontDialogOptionsPrivate, QFontDialogOptions
|
||||
{
|
||||
FontDialogCombined() : QFontDialogOptionsPrivate(), QFontDialogOptions(this) {}
|
||||
FontDialogCombined(const FontDialogCombined &other)
|
||||
: QFontDialogOptionsPrivate(other), QFontDialogOptions(this) {}
|
||||
};
|
||||
}
|
||||
|
||||
// static
|
||||
QSharedPointer<QFontDialogOptions> QFontDialogOptions::create()
|
||||
{
|
||||
return QSharedPointer<FontDialogCombined>::create();
|
||||
}
|
||||
|
||||
QSharedPointer<QFontDialogOptions> QFontDialogOptions::clone() const
|
||||
{
|
||||
return QSharedPointer<FontDialogCombined>::create(*static_cast<const FontDialogCombined*>(this));
|
||||
}
|
||||
|
||||
QString QFontDialogOptions::windowTitle() const
|
||||
{
|
||||
return d->windowTitle;
|
||||
@ -289,25 +299,35 @@ public:
|
||||
QString windowTitle;
|
||||
};
|
||||
|
||||
QColorDialogOptions::QColorDialogOptions() : d(new QColorDialogOptionsPrivate)
|
||||
QColorDialogOptions::QColorDialogOptions(QColorDialogOptionsPrivate *dd)
|
||||
: d(dd)
|
||||
{
|
||||
}
|
||||
|
||||
QColorDialogOptions::QColorDialogOptions(const QColorDialogOptions &rhs) : d(rhs.d)
|
||||
{
|
||||
}
|
||||
|
||||
QColorDialogOptions &QColorDialogOptions::operator=(const QColorDialogOptions &rhs)
|
||||
{
|
||||
if (this != &rhs)
|
||||
d = rhs.d;
|
||||
return *this;
|
||||
}
|
||||
|
||||
QColorDialogOptions::~QColorDialogOptions()
|
||||
{
|
||||
}
|
||||
|
||||
namespace {
|
||||
struct ColorDialogCombined : QColorDialogOptionsPrivate, QColorDialogOptions
|
||||
{
|
||||
ColorDialogCombined() : QColorDialogOptionsPrivate(), QColorDialogOptions(this) {}
|
||||
ColorDialogCombined(const ColorDialogCombined &other)
|
||||
: QColorDialogOptionsPrivate(other), QColorDialogOptions(this) {}
|
||||
};
|
||||
}
|
||||
|
||||
// static
|
||||
QSharedPointer<QColorDialogOptions> QColorDialogOptions::create()
|
||||
{
|
||||
return QSharedPointer<ColorDialogCombined>::create();
|
||||
}
|
||||
|
||||
QSharedPointer<QColorDialogOptions> QColorDialogOptions::clone() const
|
||||
{
|
||||
return QSharedPointer<ColorDialogCombined>::create(*static_cast<const ColorDialogCombined*>(this));
|
||||
}
|
||||
|
||||
QString QColorDialogOptions::windowTitle() const
|
||||
{
|
||||
return d->windowTitle;
|
||||
@ -436,25 +456,34 @@ public:
|
||||
QStringList supportedSchemes;
|
||||
};
|
||||
|
||||
QFileDialogOptions::QFileDialogOptions() : d(new QFileDialogOptionsPrivate)
|
||||
QFileDialogOptions::QFileDialogOptions(QFileDialogOptionsPrivate *dd)
|
||||
: d(dd)
|
||||
{
|
||||
}
|
||||
|
||||
QFileDialogOptions::QFileDialogOptions(const QFileDialogOptions &rhs) : d(rhs.d)
|
||||
{
|
||||
}
|
||||
|
||||
QFileDialogOptions &QFileDialogOptions::operator=(const QFileDialogOptions &rhs)
|
||||
{
|
||||
if (this != &rhs)
|
||||
d = rhs.d;
|
||||
return *this;
|
||||
}
|
||||
|
||||
QFileDialogOptions::~QFileDialogOptions()
|
||||
{
|
||||
}
|
||||
|
||||
namespace {
|
||||
struct FileDialogCombined : QFileDialogOptionsPrivate, QFileDialogOptions
|
||||
{
|
||||
FileDialogCombined() : QFileDialogOptionsPrivate(), QFileDialogOptions(this) {}
|
||||
FileDialogCombined(const FileDialogCombined &other) : QFileDialogOptionsPrivate(other), QFileDialogOptions(this) {}
|
||||
};
|
||||
}
|
||||
|
||||
// static
|
||||
QSharedPointer<QFileDialogOptions> QFileDialogOptions::create()
|
||||
{
|
||||
return QSharedPointer<FileDialogCombined>::create();
|
||||
}
|
||||
|
||||
QSharedPointer<QFileDialogOptions> QFileDialogOptions::clone() const
|
||||
{
|
||||
return QSharedPointer<FileDialogCombined>::create(*static_cast<const FileDialogCombined*>(this));
|
||||
}
|
||||
|
||||
QString QFileDialogOptions::windowTitle() const
|
||||
{
|
||||
return d->windowTitle;
|
||||
@ -728,25 +757,35 @@ public:
|
||||
QPlatformDialogHelper::StandardButtons buttons;
|
||||
};
|
||||
|
||||
QMessageDialogOptions::QMessageDialogOptions() : d(new QMessageDialogOptionsPrivate)
|
||||
QMessageDialogOptions::QMessageDialogOptions(QMessageDialogOptionsPrivate *dd)
|
||||
: d(dd)
|
||||
{
|
||||
}
|
||||
|
||||
QMessageDialogOptions::QMessageDialogOptions(const QMessageDialogOptions &rhs) : d(rhs.d)
|
||||
{
|
||||
}
|
||||
|
||||
QMessageDialogOptions &QMessageDialogOptions::operator=(const QMessageDialogOptions &rhs)
|
||||
{
|
||||
if (this != &rhs)
|
||||
d = rhs.d;
|
||||
return *this;
|
||||
}
|
||||
|
||||
QMessageDialogOptions::~QMessageDialogOptions()
|
||||
{
|
||||
}
|
||||
|
||||
namespace {
|
||||
struct MessageDialogCombined : QMessageDialogOptionsPrivate, QMessageDialogOptions
|
||||
{
|
||||
MessageDialogCombined() : QMessageDialogOptionsPrivate(), QMessageDialogOptions(this) {}
|
||||
MessageDialogCombined(const MessageDialogCombined &other)
|
||||
: QMessageDialogOptionsPrivate(other), QMessageDialogOptions(this) {}
|
||||
};
|
||||
}
|
||||
|
||||
// static
|
||||
QSharedPointer<QMessageDialogOptions> QMessageDialogOptions::create()
|
||||
{
|
||||
return QSharedPointer<MessageDialogCombined>::create();
|
||||
}
|
||||
|
||||
QSharedPointer<QMessageDialogOptions> QMessageDialogOptions::clone() const
|
||||
{
|
||||
return QSharedPointer<MessageDialogCombined>::create(*static_cast<const MessageDialogCombined*>(this));
|
||||
}
|
||||
|
||||
QString QMessageDialogOptions::windowTitle() const
|
||||
{
|
||||
return d->windowTitle;
|
||||
|
@ -72,6 +72,8 @@ class QFontDialogOptionsPrivate;
|
||||
class QFileDialogOptionsPrivate;
|
||||
class QMessageDialogOptionsPrivate;
|
||||
|
||||
#define QPLATFORMDIALOGHELPERS_HAS_CREATE
|
||||
|
||||
class Q_GUI_EXPORT QPlatformDialogHelper : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -176,6 +178,10 @@ QT_BEGIN_NAMESPACE
|
||||
class Q_GUI_EXPORT QColorDialogOptions
|
||||
{
|
||||
Q_GADGET
|
||||
Q_DISABLE_COPY(QColorDialogOptions)
|
||||
protected:
|
||||
explicit QColorDialogOptions(QColorDialogOptionsPrivate *dd);
|
||||
~QColorDialogOptions();
|
||||
public:
|
||||
enum ColorDialogOption {
|
||||
ShowAlphaChannel = 0x00000001,
|
||||
@ -186,12 +192,8 @@ public:
|
||||
Q_DECLARE_FLAGS(ColorDialogOptions, ColorDialogOption)
|
||||
Q_FLAG(ColorDialogOptions)
|
||||
|
||||
QColorDialogOptions();
|
||||
QColorDialogOptions(const QColorDialogOptions &rhs);
|
||||
QColorDialogOptions &operator=(const QColorDialogOptions &rhs);
|
||||
~QColorDialogOptions();
|
||||
|
||||
void swap(QColorDialogOptions &other) { qSwap(d, other.d); }
|
||||
static QSharedPointer<QColorDialogOptions> create();
|
||||
QSharedPointer<QColorDialogOptions> clone() const;
|
||||
|
||||
QString windowTitle() const;
|
||||
void setWindowTitle(const QString &);
|
||||
@ -211,11 +213,9 @@ public:
|
||||
static void setStandardColor(int index, QRgb color);
|
||||
|
||||
private:
|
||||
QSharedDataPointer<QColorDialogOptionsPrivate> d;
|
||||
QColorDialogOptionsPrivate *d;
|
||||
};
|
||||
|
||||
Q_DECLARE_SHARED(QColorDialogOptions)
|
||||
|
||||
class Q_GUI_EXPORT QPlatformColorDialogHelper : public QPlatformDialogHelper
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -237,6 +237,11 @@ private:
|
||||
class Q_GUI_EXPORT QFontDialogOptions
|
||||
{
|
||||
Q_GADGET
|
||||
Q_DISABLE_COPY(QFontDialogOptions)
|
||||
protected:
|
||||
explicit QFontDialogOptions(QFontDialogOptionsPrivate *dd);
|
||||
~QFontDialogOptions();
|
||||
|
||||
public:
|
||||
enum FontDialogOption {
|
||||
NoButtons = 0x00000001,
|
||||
@ -250,12 +255,8 @@ public:
|
||||
Q_DECLARE_FLAGS(FontDialogOptions, FontDialogOption)
|
||||
Q_FLAG(FontDialogOptions)
|
||||
|
||||
QFontDialogOptions();
|
||||
QFontDialogOptions(const QFontDialogOptions &rhs);
|
||||
QFontDialogOptions &operator=(const QFontDialogOptions &rhs);
|
||||
~QFontDialogOptions();
|
||||
|
||||
void swap(QFontDialogOptions &other) { qSwap(d, other.d); }
|
||||
static QSharedPointer<QFontDialogOptions> create();
|
||||
QSharedPointer<QFontDialogOptions> clone() const;
|
||||
|
||||
QString windowTitle() const;
|
||||
void setWindowTitle(const QString &);
|
||||
@ -266,11 +267,9 @@ public:
|
||||
FontDialogOptions options() const;
|
||||
|
||||
private:
|
||||
QSharedDataPointer<QFontDialogOptionsPrivate> d;
|
||||
QFontDialogOptionsPrivate *d;
|
||||
};
|
||||
|
||||
Q_DECLARE_SHARED(QFontDialogOptions)
|
||||
|
||||
class Q_GUI_EXPORT QPlatformFontDialogHelper : public QPlatformDialogHelper
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -292,6 +291,11 @@ private:
|
||||
class Q_GUI_EXPORT QFileDialogOptions
|
||||
{
|
||||
Q_GADGET
|
||||
Q_DISABLE_COPY(QFileDialogOptions)
|
||||
protected:
|
||||
QFileDialogOptions(QFileDialogOptionsPrivate *dd);
|
||||
~QFileDialogOptions();
|
||||
|
||||
public:
|
||||
enum ViewMode { Detail, List };
|
||||
Q_ENUM(ViewMode)
|
||||
@ -319,12 +323,8 @@ public:
|
||||
Q_DECLARE_FLAGS(FileDialogOptions, FileDialogOption)
|
||||
Q_FLAG(FileDialogOptions)
|
||||
|
||||
QFileDialogOptions();
|
||||
QFileDialogOptions(const QFileDialogOptions &rhs);
|
||||
QFileDialogOptions &operator=(const QFileDialogOptions &rhs);
|
||||
~QFileDialogOptions();
|
||||
|
||||
void swap(QFileDialogOptions &other) { qSwap(d, other.d); }
|
||||
static QSharedPointer<QFileDialogOptions> create();
|
||||
QSharedPointer<QFileDialogOptions> clone() const;
|
||||
|
||||
QString windowTitle() const;
|
||||
void setWindowTitle(const QString &);
|
||||
@ -383,11 +383,9 @@ public:
|
||||
static QString defaultNameFilterString();
|
||||
|
||||
private:
|
||||
QSharedDataPointer<QFileDialogOptionsPrivate> d;
|
||||
QFileDialogOptionsPrivate *d;
|
||||
};
|
||||
|
||||
Q_DECLARE_SHARED(QFileDialogOptions)
|
||||
|
||||
class Q_GUI_EXPORT QPlatformFileDialogHelper : public QPlatformDialogHelper
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -423,17 +421,18 @@ private:
|
||||
class Q_GUI_EXPORT QMessageDialogOptions
|
||||
{
|
||||
Q_GADGET
|
||||
Q_DISABLE_COPY(QMessageDialogOptions)
|
||||
protected:
|
||||
QMessageDialogOptions(QMessageDialogOptionsPrivate *dd);
|
||||
~QMessageDialogOptions();
|
||||
|
||||
public:
|
||||
// Keep in sync with QMessageBox::Icon
|
||||
enum Icon { NoIcon, Information, Warning, Critical, Question };
|
||||
Q_ENUM(Icon)
|
||||
|
||||
QMessageDialogOptions();
|
||||
QMessageDialogOptions(const QMessageDialogOptions &rhs);
|
||||
QMessageDialogOptions &operator=(const QMessageDialogOptions &rhs);
|
||||
~QMessageDialogOptions();
|
||||
|
||||
void swap(QMessageDialogOptions &other) { qSwap(d, other.d); }
|
||||
static QSharedPointer<QMessageDialogOptions> create();
|
||||
QSharedPointer<QMessageDialogOptions> clone() const;
|
||||
|
||||
QString windowTitle() const;
|
||||
void setWindowTitle(const QString &);
|
||||
@ -454,11 +453,9 @@ public:
|
||||
QPlatformDialogHelper::StandardButtons standardButtons() const;
|
||||
|
||||
private:
|
||||
QSharedDataPointer<QMessageDialogOptionsPrivate> d;
|
||||
QMessageDialogOptionsPrivate *d;
|
||||
};
|
||||
|
||||
Q_DECLARE_SHARED(QMessageDialogOptions)
|
||||
|
||||
class Q_GUI_EXPORT QPlatformMessageDialogHelper : public QPlatformDialogHelper
|
||||
{
|
||||
Q_OBJECT
|
||||
|
@ -92,7 +92,7 @@ public:
|
||||
SetColorAll = ShowColor | SelectColor
|
||||
};
|
||||
|
||||
QColorDialogPrivate() : options(new QColorDialogOptions)
|
||||
QColorDialogPrivate() : options(QColorDialogOptions::create())
|
||||
#ifdef Q_OS_WIN32
|
||||
, updateTimer(0)
|
||||
#endif
|
||||
|
@ -533,7 +533,7 @@ QFileDialogPrivate::QFileDialogPrivate()
|
||||
showHiddenAction(0),
|
||||
useDefaultCaption(true),
|
||||
qFileDialogUi(0),
|
||||
options(new QFileDialogOptions)
|
||||
options(QFileDialogOptions::create())
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -110,7 +110,7 @@ static const Qt::WindowFlags DefaultWindowFlags =
|
||||
|
||||
QFontDialogPrivate::QFontDialogPrivate()
|
||||
: writingSystem(QFontDatabase::Any),
|
||||
options(QSharedPointer<QFontDialogOptions>::create())
|
||||
options(QFontDialogOptions::create())
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -200,7 +200,7 @@ public:
|
||||
#endif
|
||||
compatMode(false), autoAddOkButton(true),
|
||||
detectedEscapeButton(0), informativeLabel(0),
|
||||
options(new QMessageDialogOptions) { }
|
||||
options(QMessageDialogOptions::create()) { }
|
||||
|
||||
void init(const QString &title = QString(), const QString &text = QString());
|
||||
void setupLayout();
|
||||
|
Loading…
Reference in New Issue
Block a user