diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2020-09-11 15:24:17 +0200 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2020-09-17 13:26:50 +0200 |
commit | 861c4d854879b4e0358ad2f02d22753c37d57006 (patch) | |
tree | ef7584d00ca853682656de1b496af963430fb3f0 /src/gui/image | |
parent | e8b1e7e3192c258c21f01b85d52b698fe43c73e0 (diff) |
Deprecate implicit QPixmap conversion to QBitmap
It is lossy, so should be requested explicitly, using a dedicated
fromPixmap factory function.
Deprecate the constructor and assignment operator, and make the
constructor explicit.
[ChangeLog][QtGui][QBitmap] Implicitly constructing and assigning
to a QBitmap from a QPixmap has been deprecated, and the respective
constructor has been made explicit. Use the fromPixmap factory
function instead.
Change-Id: I68ce85b26c901415137b664a1db687021d48bae0
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/gui/image')
-rw-r--r-- | src/gui/image/qbitmap.cpp | 105 | ||||
-rw-r--r-- | src/gui/image/qbitmap.h | 9 |
2 files changed, 71 insertions, 43 deletions
diff --git a/src/gui/image/qbitmap.cpp b/src/gui/image/qbitmap.cpp index 58953e8d9a..0505717fb3 100644 --- a/src/gui/image/qbitmap.cpp +++ b/src/gui/image/qbitmap.cpp @@ -139,20 +139,6 @@ QBitmap::QBitmap(const QSize &size) */ /*! - Constructs a bitmap that is a copy of the given \a pixmap. - - If the pixmap has a depth greater than 1, the resulting bitmap - will be dithered automatically. - - \sa QPixmap::depth(), fromImage(), fromData() -*/ - -QBitmap::QBitmap(const QPixmap &pixmap) -{ - QBitmap::operator=(pixmap); -} - -/*! Constructs a bitmap from the file specified by the given \a fileName. If the file does not exist, or has an unknown format, the bitmap becomes a null bitmap. @@ -171,30 +157,6 @@ QBitmap::QBitmap(const QString& fileName, const char *format) } /*! - \overload - - Assigns the given \a pixmap to this bitmap and returns a reference - to this bitmap. - - If the pixmap has a depth greater than 1, the resulting bitmap - will be dithered automatically. - - \sa QPixmap::depth() - */ - -QBitmap &QBitmap::operator=(const QPixmap &pixmap) -{ - if (pixmap.isNull()) { // a null pixmap - QBitmap(0, 0).swap(*this); - } else if (pixmap.depth() == 1) { // 1-bit pixmap - QPixmap::operator=(pixmap); // shallow assignment - } else { // n-bit depth pixmap - *this = fromImage(pixmap.toImage()); // will dither image - } - return *this; -} - -/*! \fn void QBitmap::swap(QBitmap &other) \since 4.8 @@ -225,7 +187,7 @@ static QBitmap makeBitmap(QImage &&image, Qt::ImageConversionFlags flags) QScopedPointer<QPlatformPixmap> data(QGuiApplicationPrivate::platformIntegration()->createPlatformPixmap(QPlatformPixmap::BitmapType)); data->fromImageInPlace(image, flags | Qt::MonoOnly); - return QPixmap(data.take()); + return QBitmap::fromPixmap(QPixmap(data.take())); } /*! @@ -288,6 +250,68 @@ QBitmap QBitmap::fromData(const QSize &size, const uchar *bits, QImage::Format m } /*! + Returns a copy of the given \a pixmap converted to a bitmap. + + If the pixmap has a depth greater than 1, the resulting bitmap + will be dithered automatically. + + \sa QPixmap::depth() +*/ + +QBitmap QBitmap::fromPixmap(const QPixmap &pixmap) +{ + if (pixmap.isNull()) { // a null pixmap + return QBitmap(0, 0); + } else if (pixmap.depth() == 1) { // 1-bit pixmap + QBitmap bm; + if (pixmap.paintingActive()) { // make a deep copy + pixmap.copy().swap(bm); + } else { + bm.data = pixmap.data; // shallow assignment + } + return bm; + } + // n-bit depth pixmap, will dither image + return fromImage(pixmap.toImage()); +} + +#if QT_DEPRECATED_SINCE(6, 0) +/*! + \obsolete Use fromPixmap instead. + Constructs a bitmap that is a copy of the given \a pixmap. + + If the pixmap has a depth greater than 1, the resulting bitmap + will be dithered automatically. + + \sa QPixmap::depth(), fromImage(), fromData() +*/ + +QBitmap::QBitmap(const QPixmap &pixmap) +{ + *this = QBitmap::fromPixmap(pixmap); +} + +/*! + \obsolete Use fromPixmap instead. + \overload + + Assigns the given \a pixmap to this bitmap and returns a reference + to this bitmap. + + If the pixmap has a depth greater than 1, the resulting bitmap + will be dithered automatically. + + \sa QPixmap::depth() + */ + +QBitmap &QBitmap::operator=(const QPixmap &pixmap) +{ + *this = QBitmap::fromPixmap(pixmap); + return *this; +} +#endif + +/*! Returns a copy of this bitmap, transformed according to the given \a matrix. @@ -295,8 +319,7 @@ QBitmap QBitmap::fromData(const QSize &size, const uchar *bits, QImage::Format m */ QBitmap QBitmap::transformed(const QTransform &matrix) const { - QBitmap bm = QPixmap::transformed(matrix); - return bm; + return QBitmap::fromPixmap(QPixmap::transformed(matrix)); } QT_END_NAMESPACE diff --git a/src/gui/image/qbitmap.h b/src/gui/image/qbitmap.h index a114db17e0..9052e62db6 100644 --- a/src/gui/image/qbitmap.h +++ b/src/gui/image/qbitmap.h @@ -52,12 +52,16 @@ class Q_GUI_EXPORT QBitmap : public QPixmap { public: QBitmap(); - QBitmap(const QPixmap &); +#if QT_DEPRECATED_SINCE(6, 0) + QT_DEPRECATED_VERSION_X_6_0("Use fromPixmap instead.") explicit QBitmap(const QPixmap &); +#endif QBitmap(int w, int h); explicit QBitmap(const QSize &); explicit QBitmap(const QString &fileName, const char *format = nullptr); - QBitmap &operator=(const QPixmap &); +#if QT_DEPRECATED_SINCE(6, 0) + QT_DEPRECATED_VERSION_X_6_0("Use fromPixmap instead.") QBitmap &operator=(const QPixmap &); +#endif inline void swap(QBitmap &other) { QPixmap::swap(other); } // prevent QBitmap<->QPixmap swaps operator QVariant() const; @@ -67,6 +71,7 @@ public: static QBitmap fromImage(QImage &&image, Qt::ImageConversionFlags flags = Qt::AutoColor); static QBitmap fromData(const QSize &size, const uchar *bits, QImage::Format monoFormat = QImage::Format_MonoLSB); + static QBitmap fromPixmap(const QPixmap &pixmap); QBitmap transformed(const QTransform &matrix) const; |