Give QPixmap a move constructor
It already has a move-assignment operator, and implements swapping. This requires a specialization of the QExplicitlySharedDataPointer destructor to be forward declared, and an implementation that is identical to the default version. Otherwise we would need QPlatformPixmap to be fully defined in the public QPixmap header. Change-Id: I2651bbc29a7083a93e3b3ad671d3aeea659b7d5a Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>bb10
parent
d3c985631d
commit
2f319f3be9
|
|
@ -224,6 +224,15 @@ QPixmap::QPixmap(const QPixmap &pixmap)
|
|||
}
|
||||
}
|
||||
|
||||
/*! \fn QPixmap::QPixmap(QPixmap &&other)
|
||||
Move-constructs a QPixmap instance from \a other.
|
||||
|
||||
\sa swap() operator=(QPixmap&&)
|
||||
*/
|
||||
template<>
|
||||
QExplicitlySharedDataPointer<QPlatformPixmap>::~QExplicitlySharedDataPointer()
|
||||
{ if (d && !d->ref.deref()) delete d; }
|
||||
|
||||
/*!
|
||||
Constructs a pixmap from the given \a xpm data, which must be a
|
||||
valid XPM image.
|
||||
|
|
|
|||
|
|
@ -57,6 +57,7 @@ class QImageReader;
|
|||
class QColor;
|
||||
class QVariant;
|
||||
class QPlatformPixmap;
|
||||
template<> Q_GUI_EXPORT QExplicitlySharedDataPointer<QPlatformPixmap>::~QExplicitlySharedDataPointer();
|
||||
|
||||
class Q_GUI_EXPORT QPixmap : public QPaintDevice
|
||||
{
|
||||
|
|
@ -70,6 +71,7 @@ public:
|
|||
explicit QPixmap(const char * const xpm[]);
|
||||
#endif
|
||||
QPixmap(const QPixmap &);
|
||||
QPixmap(QPixmap &&other) noexcept : QPaintDevice(), data(std::move(other.data)) {}
|
||||
~QPixmap();
|
||||
|
||||
QPixmap &operator=(const QPixmap &);
|
||||
|
|
|
|||
|
|
@ -118,6 +118,7 @@ private slots:
|
|||
void refUnref();
|
||||
|
||||
void copy();
|
||||
void move();
|
||||
void deepCopyPreservesDpr();
|
||||
void dprPassthrough();
|
||||
void depthOfNullObjects();
|
||||
|
|
@ -1142,6 +1143,20 @@ void tst_QPixmap::copy()
|
|||
QCOMPARE(trans, transCopy);
|
||||
}
|
||||
|
||||
void tst_QPixmap::move()
|
||||
{
|
||||
QPixmap moveFrom(32, 32);
|
||||
|
||||
QPixmap moveAssigned;
|
||||
moveAssigned = std::move(moveFrom);
|
||||
QVERIFY(!moveAssigned.isNull());
|
||||
QVERIFY(moveFrom.isNull());
|
||||
|
||||
QPixmap moveConstructed(std::move(moveAssigned));
|
||||
QVERIFY(moveAssigned.isNull());
|
||||
QVERIFY(!moveConstructed.isNull());
|
||||
}
|
||||
|
||||
// QTBUG-58653: Force a deep copy of a pixmap by
|
||||
// having a QPainter and check whether DevicePixelRatio is preserved
|
||||
void tst_QPixmap::deepCopyPreservesDpr()
|
||||
|
|
|
|||
Loading…
Reference in New Issue