QtGui: Introduce delegating constructors.
Reduce code duplication by chaining constructors. Change-Id: Ida25105e33cc3ef870f416931212e2216e9c6dfb Reviewed-by: Shawn Rutledge <shawn.rutledge@theqtcompany.com> Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
This commit is contained in:
parent
e8995de22a
commit
a213011a53
@ -767,9 +767,8 @@ QImage::QImage() Q_DECL_NOEXCEPT
|
||||
drawing onto it with QPainter.
|
||||
*/
|
||||
QImage::QImage(int width, int height, Format format)
|
||||
: QPaintDevice()
|
||||
: QImage(QSize(width, height), format)
|
||||
{
|
||||
d = QImageData::create(QSize(width, height), format);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -633,12 +633,9 @@ QImageReader::QImageReader(QIODevice *device, const QByteArray &format)
|
||||
\sa setFileName()
|
||||
*/
|
||||
QImageReader::QImageReader(const QString &fileName, const QByteArray &format)
|
||||
: d(new QImageReaderPrivate(this))
|
||||
: QImageReader(new QFile(fileName), format)
|
||||
{
|
||||
QFile *file = new QFile(fileName);
|
||||
d->device = file;
|
||||
d->deleteDevice = true;
|
||||
d->format = format;
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -326,12 +326,9 @@ QImageWriter::QImageWriter(QIODevice *device, const QByteArray &format)
|
||||
by inspecting the extension of \a fileName.
|
||||
*/
|
||||
QImageWriter::QImageWriter(const QString &fileName, const QByteArray &format)
|
||||
: d(new QImageWriterPrivate(this))
|
||||
: QImageWriter(new QFile(fileName), format)
|
||||
{
|
||||
QFile *file = new QFile(fileName);
|
||||
d->device = file;
|
||||
d->deleteDevice = true;
|
||||
d->format = format;
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -125,12 +125,8 @@ QPixmap::QPixmap()
|
||||
*/
|
||||
|
||||
QPixmap::QPixmap(int w, int h)
|
||||
: QPaintDevice()
|
||||
: QPixmap(QSize(w, h))
|
||||
{
|
||||
if (!qt_pixmap_thread_test())
|
||||
doInit(0, 0, QPlatformPixmap::PixmapType);
|
||||
else
|
||||
doInit(w, h, QPlatformPixmap::PixmapType);
|
||||
}
|
||||
|
||||
/*!
|
||||
@ -144,12 +140,8 @@ QPixmap::QPixmap(int w, int h)
|
||||
*/
|
||||
|
||||
QPixmap::QPixmap(const QSize &size)
|
||||
: QPaintDevice()
|
||||
: QPixmap(size, QPlatformPixmap::PixmapType)
|
||||
{
|
||||
if (!qt_pixmap_thread_test())
|
||||
doInit(0, 0, QPlatformPixmap::PixmapType);
|
||||
else
|
||||
doInit(size.width(), size.height(), QPlatformPixmap::PixmapType);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -705,20 +705,16 @@ void QStandardItemModelPrivate::columnsRemoved(QStandardItem *parent,
|
||||
Constructs an item.
|
||||
*/
|
||||
QStandardItem::QStandardItem()
|
||||
: d_ptr(new QStandardItemPrivate)
|
||||
: QStandardItem(*new QStandardItemPrivate)
|
||||
{
|
||||
Q_D(QStandardItem);
|
||||
d->q_ptr = this;
|
||||
}
|
||||
|
||||
/*!
|
||||
Constructs an item with the given \a text.
|
||||
*/
|
||||
QStandardItem::QStandardItem(const QString &text)
|
||||
: d_ptr(new QStandardItemPrivate)
|
||||
: QStandardItem(*new QStandardItemPrivate)
|
||||
{
|
||||
Q_D(QStandardItem);
|
||||
d->q_ptr = this;
|
||||
setText(text);
|
||||
}
|
||||
|
||||
@ -726,22 +722,17 @@ QStandardItem::QStandardItem(const QString &text)
|
||||
Constructs an item with the given \a icon and \a text.
|
||||
*/
|
||||
QStandardItem::QStandardItem(const QIcon &icon, const QString &text)
|
||||
: d_ptr(new QStandardItemPrivate)
|
||||
: QStandardItem(text)
|
||||
{
|
||||
Q_D(QStandardItem);
|
||||
d->q_ptr = this;
|
||||
setIcon(icon);
|
||||
setText(text);
|
||||
}
|
||||
|
||||
/*!
|
||||
Constructs an item with \a rows rows and \a columns columns of child items.
|
||||
*/
|
||||
QStandardItem::QStandardItem(int rows, int columns)
|
||||
: d_ptr(new QStandardItemPrivate)
|
||||
: QStandardItem(*new QStandardItemPrivate)
|
||||
{
|
||||
Q_D(QStandardItem);
|
||||
d->q_ptr = this;
|
||||
setRowCount(rows);
|
||||
setColumnCount(columns);
|
||||
}
|
||||
|
@ -289,7 +289,7 @@ QMouseEvent::QMouseEvent(Type type, const QPointF &localPos, Qt::MouseButton but
|
||||
QMouseEvent::QMouseEvent(Type type, const QPointF &localPos, const QPointF &screenPos,
|
||||
Qt::MouseButton button, Qt::MouseButtons buttons,
|
||||
Qt::KeyboardModifiers modifiers)
|
||||
: QInputEvent(type, modifiers), l(localPos), w(localPos), s(screenPos), b(button), mouseState(buttons), caps(0)
|
||||
: QMouseEvent(type, localPos, localPos, screenPos, button, buttons, modifiers)
|
||||
{}
|
||||
|
||||
/*!
|
||||
@ -342,7 +342,7 @@ QMouseEvent::QMouseEvent(Type type, const QPointF &localPos, const QPointF &wind
|
||||
QMouseEvent::QMouseEvent(QEvent::Type type, const QPointF &localPos, const QPointF &windowPos, const QPointF &screenPos,
|
||||
Qt::MouseButton button, Qt::MouseButtons buttons,
|
||||
Qt::KeyboardModifiers modifiers, Qt::MouseEventSource source)
|
||||
: QInputEvent(type, modifiers), l(localPos), w(windowPos), s(screenPos), b(button), mouseState(buttons), caps(0)
|
||||
: QMouseEvent(type, localPos, windowPos, screenPos, button, buttons, modifiers)
|
||||
{
|
||||
QGuiApplicationPrivate::setMouseEventSource(this, source);
|
||||
}
|
||||
@ -829,9 +829,8 @@ QWheelEvent::QWheelEvent(const QPointF &pos, const QPointF& globalPos, int delta
|
||||
QWheelEvent::QWheelEvent(const QPointF &pos, const QPointF& globalPos,
|
||||
QPoint pixelDelta, QPoint angleDelta, int qt4Delta, Qt::Orientation qt4Orientation,
|
||||
Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
|
||||
: QInputEvent(Wheel, modifiers), p(pos), g(globalPos), pixelD(pixelDelta),
|
||||
angleD(angleDelta), qt4D(qt4Delta), qt4O(qt4Orientation), mouseState(buttons), ph(Qt::NoScrollPhase),
|
||||
src(Qt::MouseEventNotSynthesized), invertedScrolling(false)
|
||||
: QWheelEvent(pos, globalPos, pixelDelta, angleDelta, qt4Delta, qt4Orientation,
|
||||
buttons, modifiers, Qt::NoScrollPhase)
|
||||
{}
|
||||
|
||||
/*!
|
||||
@ -860,9 +859,8 @@ QWheelEvent::QWheelEvent(const QPointF &pos, const QPointF& globalPos,
|
||||
QWheelEvent::QWheelEvent(const QPointF &pos, const QPointF& globalPos,
|
||||
QPoint pixelDelta, QPoint angleDelta, int qt4Delta, Qt::Orientation qt4Orientation,
|
||||
Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Qt::ScrollPhase phase)
|
||||
: QInputEvent(Wheel, modifiers), p(pos), g(globalPos), pixelD(pixelDelta),
|
||||
angleD(angleDelta), qt4D(qt4Delta), qt4O(qt4Orientation), mouseState(buttons), ph(phase),
|
||||
src(Qt::MouseEventNotSynthesized), invertedScrolling(false)
|
||||
: QWheelEvent(pos, globalPos, pixelDelta, angleDelta, qt4Delta, qt4Orientation,
|
||||
buttons, modifiers, phase, Qt::MouseEventNotSynthesized)
|
||||
{}
|
||||
|
||||
/*!
|
||||
@ -896,9 +894,8 @@ QWheelEvent::QWheelEvent(const QPointF &pos, const QPointF& globalPos,
|
||||
QWheelEvent::QWheelEvent(const QPointF &pos, const QPointF& globalPos,
|
||||
QPoint pixelDelta, QPoint angleDelta, int qt4Delta, Qt::Orientation qt4Orientation,
|
||||
Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Qt::ScrollPhase phase, Qt::MouseEventSource source)
|
||||
: QInputEvent(Wheel, modifiers), p(pos), g(globalPos), pixelD(pixelDelta),
|
||||
angleD(angleDelta), qt4D(qt4Delta), qt4O(qt4Orientation), mouseState(buttons), ph(phase), src(source),
|
||||
invertedScrolling(false)
|
||||
: QWheelEvent(pos, globalPos, pixelDelta, angleDelta, qt4Delta, qt4Orientation,
|
||||
buttons, modifiers, phase, source, false)
|
||||
{}
|
||||
|
||||
/*!
|
||||
@ -1767,7 +1764,7 @@ QIconDragEvent::~QIconDragEvent()
|
||||
coordinates.
|
||||
*/
|
||||
QContextMenuEvent::QContextMenuEvent(Reason reason, const QPoint &pos, const QPoint &globalPos)
|
||||
: QInputEvent(ContextMenu), p(pos), gp(globalPos), reas(reason)
|
||||
: QContextMenuEvent(reason, pos, globalPos, Qt::NoModifier)
|
||||
{}
|
||||
|
||||
/*!
|
||||
@ -2450,19 +2447,8 @@ QTabletEvent::QTabletEvent(Type type, const QPointF &pos, const QPointF &globalP
|
||||
int device, int pointerType,
|
||||
qreal pressure, int xTilt, int yTilt, qreal tangentialPressure,
|
||||
qreal rotation, int z, Qt::KeyboardModifiers keyState, qint64 uniqueID)
|
||||
: QInputEvent(type, keyState),
|
||||
mPos(pos),
|
||||
mGPos(globalPos),
|
||||
mDev(device),
|
||||
mPointerType(pointerType),
|
||||
mXT(xTilt),
|
||||
mYT(yTilt),
|
||||
mZ(z),
|
||||
mPress(pressure),
|
||||
mTangential(tangentialPressure),
|
||||
mRot(rotation),
|
||||
mUnique(uniqueID),
|
||||
mExtra(new QTabletEventPrivate(Qt::NoButton, Qt::NoButton))
|
||||
: QTabletEvent(type, pos, globalPos, device, pointerType, pressure, xTilt, yTilt,
|
||||
tangentialPressure, rotation, z, keyState, uniqueID, Qt::NoButton, Qt::NoButton)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -856,10 +856,8 @@ QOpenGLFramebufferObject::QOpenGLFramebufferObject(const QSize &size, GLenum tar
|
||||
\sa size(), texture()
|
||||
*/
|
||||
QOpenGLFramebufferObject::QOpenGLFramebufferObject(int width, int height, GLenum target)
|
||||
: d_ptr(new QOpenGLFramebufferObjectPrivate)
|
||||
: QOpenGLFramebufferObject(QSize(width, height), target)
|
||||
{
|
||||
Q_D(QOpenGLFramebufferObject);
|
||||
d->init(this, QSize(width, height), NoAttachment, target, effectiveInternalFormat(0));
|
||||
}
|
||||
|
||||
/*! \overload
|
||||
@ -883,11 +881,8 @@ QOpenGLFramebufferObject::QOpenGLFramebufferObject(const QSize &size, const QOpe
|
||||
*/
|
||||
|
||||
QOpenGLFramebufferObject::QOpenGLFramebufferObject(int width, int height, const QOpenGLFramebufferObjectFormat &format)
|
||||
: d_ptr(new QOpenGLFramebufferObjectPrivate)
|
||||
: QOpenGLFramebufferObject(QSize(width, height), format)
|
||||
{
|
||||
Q_D(QOpenGLFramebufferObject);
|
||||
d->init(this, QSize(width, height), format.attachment(), format.textureTarget(),
|
||||
format.internalTextureFormat(), format.samples(), format.mipmap());
|
||||
}
|
||||
|
||||
/*! \overload
|
||||
|
@ -137,7 +137,7 @@ QOpenGLPaintDevice::QOpenGLPaintDevice(const QSize &size)
|
||||
\sa QOpenGLContext::currentContext()
|
||||
*/
|
||||
QOpenGLPaintDevice::QOpenGLPaintDevice(int width, int height)
|
||||
: d_ptr(new QOpenGLPaintDevicePrivate(QSize(width, height)))
|
||||
: QOpenGLPaintDevice(QSize(width, height))
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -2216,7 +2216,7 @@ QOpenGLTexture::QOpenGLTexture(Target target)
|
||||
OpenGL context.
|
||||
*/
|
||||
QOpenGLTexture::QOpenGLTexture(const QImage& image, MipMapGeneration genMipMaps)
|
||||
: d_ptr(new QOpenGLTexturePrivate(QOpenGLTexture::Target2D, this))
|
||||
: QOpenGLTexture(QOpenGLTexture::Target2D)
|
||||
{
|
||||
setData(image, genMipMaps);
|
||||
}
|
||||
|
@ -458,13 +458,8 @@ QBrush::QBrush(const QImage &image)
|
||||
*/
|
||||
|
||||
QBrush::QBrush(Qt::BrushStyle style)
|
||||
: QBrush(QColor(Qt::black), style)
|
||||
{
|
||||
if (qbrush_check_type(style))
|
||||
init(Qt::black, style);
|
||||
else {
|
||||
d.reset(nullBrushInstance());
|
||||
d->ref.ref();
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
@ -491,13 +486,8 @@ QBrush::QBrush(const QColor &color, Qt::BrushStyle style)
|
||||
\sa setColor(), setStyle()
|
||||
*/
|
||||
QBrush::QBrush(Qt::GlobalColor color, Qt::BrushStyle style)
|
||||
: QBrush(QColor(color), style)
|
||||
{
|
||||
if (qbrush_check_type(style))
|
||||
init(color, style);
|
||||
else {
|
||||
d.reset(nullBrushInstance());
|
||||
d->ref.ref();
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
@ -1673,13 +1663,8 @@ QLinearGradient::QLinearGradient(const QPointF &start, const QPointF &finalStop)
|
||||
\sa QGradient::setColorAt(), QGradient::setStops()
|
||||
*/
|
||||
QLinearGradient::QLinearGradient(qreal xStart, qreal yStart, qreal xFinalStop, qreal yFinalStop)
|
||||
: QLinearGradient(QPointF(xStart, yStart), QPointF(xFinalStop, yFinalStop))
|
||||
{
|
||||
m_type = LinearGradient;
|
||||
m_spread = PadSpread;
|
||||
m_data.linear.x1 = xStart;
|
||||
m_data.linear.y1 = yStart;
|
||||
m_data.linear.x2 = xFinalStop;
|
||||
m_data.linear.y2 = yFinalStop;
|
||||
}
|
||||
|
||||
|
||||
@ -1882,19 +1867,8 @@ QRadialGradient::QRadialGradient(const QPointF ¢er, qreal radius)
|
||||
*/
|
||||
|
||||
QRadialGradient::QRadialGradient(qreal cx, qreal cy, qreal radius, qreal fx, qreal fy)
|
||||
: QRadialGradient(QPointF(cx, cy), radius, QPointF(fx, fy))
|
||||
{
|
||||
m_type = RadialGradient;
|
||||
m_spread = PadSpread;
|
||||
m_data.radial.cx = cx;
|
||||
m_data.radial.cy = cy;
|
||||
m_data.radial.cradius = radius;
|
||||
|
||||
QPointF adapted_focal = qt_radial_gradient_adapt_focal_point(QPointF(cx, cy),
|
||||
radius,
|
||||
QPointF(fx, fy));
|
||||
|
||||
m_data.radial.fx = adapted_focal.x();
|
||||
m_data.radial.fy = adapted_focal.y();
|
||||
}
|
||||
|
||||
/*!
|
||||
@ -1904,14 +1878,8 @@ QRadialGradient::QRadialGradient(qreal cx, qreal cy, qreal radius, qreal fx, qre
|
||||
\sa QGradient::setColorAt(), QGradient::setStops()
|
||||
*/
|
||||
QRadialGradient::QRadialGradient(qreal cx, qreal cy, qreal radius)
|
||||
: QRadialGradient(QPointF(cx, cy), radius)
|
||||
{
|
||||
m_type = RadialGradient;
|
||||
m_spread = PadSpread;
|
||||
m_data.radial.cx = cx;
|
||||
m_data.radial.cy = cy;
|
||||
m_data.radial.cradius = radius;
|
||||
m_data.radial.fx = cx;
|
||||
m_data.radial.fy = cy;
|
||||
}
|
||||
|
||||
|
||||
@ -2211,12 +2179,8 @@ QConicalGradient::QConicalGradient(const QPointF ¢er, qreal angle)
|
||||
*/
|
||||
|
||||
QConicalGradient::QConicalGradient(qreal cx, qreal cy, qreal angle)
|
||||
: QConicalGradient(QPointF(cx, cy), angle)
|
||||
{
|
||||
m_type = ConicalGradient;
|
||||
m_spread = PadSpread;
|
||||
m_data.conical.cx = cx;
|
||||
m_data.conical.cy = cy;
|
||||
m_data.conical.angle = angle;
|
||||
}
|
||||
|
||||
|
||||
|
@ -139,12 +139,9 @@ QTextDocumentWriter::QTextDocumentWriter(QIODevice *device, const QByteArray &fo
|
||||
format by inspecting the extension of \a fileName.
|
||||
*/
|
||||
QTextDocumentWriter::QTextDocumentWriter(const QString &fileName, const QByteArray &format)
|
||||
: d(new QTextDocumentWriterPrivate(this))
|
||||
: QTextDocumentWriter(new QFile(fileName), format)
|
||||
{
|
||||
QFile *file = new QFile(fileName);
|
||||
d->device = file;
|
||||
d->deleteDevice = true;
|
||||
d->format = format;
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -216,7 +216,7 @@ public:
|
||||
*/
|
||||
|
||||
QValidator::QValidator(QObject * parent)
|
||||
: QObject(*new QValidatorPrivate, parent)
|
||||
: QValidator(*new QValidatorPrivate, parent)
|
||||
{
|
||||
}
|
||||
|
||||
@ -337,10 +337,8 @@ void QValidator::fixup(QString &) const
|
||||
*/
|
||||
|
||||
QIntValidator::QIntValidator(QObject * parent)
|
||||
: QValidator(parent)
|
||||
: QIntValidator(INT_MIN, INT_MAX, parent)
|
||||
{
|
||||
b = INT_MIN;
|
||||
t = INT_MAX;
|
||||
}
|
||||
|
||||
|
||||
@ -589,11 +587,8 @@ public:
|
||||
*/
|
||||
|
||||
QDoubleValidator::QDoubleValidator(QObject * parent)
|
||||
: QValidator(*new QDoubleValidatorPrivate , parent)
|
||||
: QDoubleValidator(-HUGE_VAL, HUGE_VAL, 1000, parent)
|
||||
{
|
||||
b = -HUGE_VAL;
|
||||
t = HUGE_VAL;
|
||||
dec = 1000;
|
||||
}
|
||||
|
||||
|
||||
@ -845,7 +840,7 @@ QDoubleValidator::Notation QDoubleValidator::notation() const
|
||||
*/
|
||||
|
||||
QRegExpValidator::QRegExpValidator(QObject *parent)
|
||||
: QValidator(parent), r(QString::fromLatin1(".*"))
|
||||
: QRegExpValidator(QRegExp(QString::fromLatin1(".*")), parent)
|
||||
{
|
||||
}
|
||||
|
||||
@ -982,7 +977,7 @@ QRegularExpressionValidator::QRegularExpressionValidator(QObject *parent)
|
||||
*/
|
||||
|
||||
QRegularExpressionValidator::QRegularExpressionValidator(const QRegularExpression &re, QObject *parent)
|
||||
: QValidator(*new QRegularExpressionValidatorPrivate, parent)
|
||||
: QRegularExpressionValidator(parent)
|
||||
{
|
||||
Q_D(QRegularExpressionValidator);
|
||||
d->setRegularExpression(re);
|
||||
|
Loading…
Reference in New Issue
Block a user