summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorMårten Nordheim <marten.nordheim@qt.io>2022-03-04 12:28:49 +0100
committerMårten Nordheim <marten.nordheim@qt.io>2022-03-08 15:44:17 +0100
commit034d8898f8166423db085da529787e56204c8e15 (patch)
treef58e930c7880d1cd79cd39745ed366d27dcd9e55 /src/gui
parent87725ee75981ec9ab25456c41acc74681c85ae2e (diff)
Fix deprecated uses of QScopedPointer
By changing it to unique_ptr. Pick-to: 6.2 6.3 Change-Id: I91abb69445b537d4c95983ae735341882352b29d Reviewed-by: Marc Mutz <marc.mutz@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/image/qbitmap.cpp6
-rw-r--r--src/gui/image/qimage.cpp6
-rw-r--r--src/gui/image/qpixmap.cpp14
-rw-r--r--src/gui/itemmodels/qfilesystemmodel.cpp4
-rw-r--r--src/gui/painting/qpaintengine.cpp9
-rw-r--r--src/gui/painting/qpainter.cpp12
-rw-r--r--src/gui/painting/qpainter.h3
-rw-r--r--src/gui/painting/qpainter_p.h2
-rw-r--r--src/gui/painting/qregion.cpp5
-rw-r--r--src/gui/rhi/qrhi.cpp8
-rw-r--r--src/gui/text/freetype/qfontengine_ft.cpp29
-rw-r--r--src/gui/text/freetype/qfontengine_ft_p.h1
-rw-r--r--src/gui/text/qzip.cpp14
13 files changed, 66 insertions, 47 deletions
diff --git a/src/gui/image/qbitmap.cpp b/src/gui/image/qbitmap.cpp
index 16bd91f942..c528ff1337 100644
--- a/src/gui/image/qbitmap.cpp
+++ b/src/gui/image/qbitmap.cpp
@@ -46,6 +46,8 @@
#include <qpainter.h>
#include <private/qguiapplication_p.h>
+#include <memory>
+
QT_BEGIN_NAMESPACE
/*!
@@ -189,10 +191,10 @@ static QBitmap makeBitmap(QImage &&image, Qt::ImageConversionFlags flags)
image.setColor(1, c0);
}
- QScopedPointer<QPlatformPixmap> data(QGuiApplicationPrivate::platformIntegration()->createPlatformPixmap(QPlatformPixmap::BitmapType));
+ std::unique_ptr<QPlatformPixmap> data(QGuiApplicationPrivate::platformIntegration()->createPlatformPixmap(QPlatformPixmap::BitmapType));
data->fromImageInPlace(image, flags | Qt::MonoOnly);
- return QBitmap::fromPixmap(QPixmap(data.take()));
+ return QBitmap::fromPixmap(QPixmap(data.release()));
}
/*!
diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp
index 2468b52d84..d681c28d8d 100644
--- a/src/gui/image/qimage.cpp
+++ b/src/gui/image/qimage.cpp
@@ -77,6 +77,8 @@
#include <qtgui_tracepoints_p.h>
+#include <memory>
+
QT_BEGIN_NAMESPACE
// MSVC 19.28 does show spurious warning "C4723: potential divide by 0" for code that divides
@@ -140,7 +142,7 @@ QImageData * QImageData::create(const QSize &size, QImage::Format format)
if (!params.isValid())
return nullptr;
- QScopedPointer<QImageData> d(new QImageData);
+ auto d = std::make_unique<QImageData>();
switch (format) {
case QImage::Format_Mono:
@@ -168,7 +170,7 @@ QImageData * QImageData::create(const QSize &size, QImage::Format format)
return nullptr;
d->ref.ref();
- return d.take();
+ return d.release();
}
QImageData::~QImageData()
diff --git a/src/gui/image/qpixmap.cpp b/src/gui/image/qpixmap.cpp
index 4bfdbd9253..89fd62305b 100644
--- a/src/gui/image/qpixmap.cpp
+++ b/src/gui/image/qpixmap.cpp
@@ -68,6 +68,8 @@
#include <qtgui_tracepoints_p.h>
+#include <memory>
+
QT_BEGIN_NAMESPACE
// MSVC 19.28 does show spurious warning "C4723: potential divide by 0" for code that divides
@@ -1479,9 +1481,9 @@ QPixmap QPixmap::fromImage(const QImage &image, Qt::ImageConversionFlags flags)
return QPixmap();
}
- QScopedPointer<QPlatformPixmap> data(QGuiApplicationPrivate::platformIntegration()->createPlatformPixmap(QPlatformPixmap::PixmapType));
+ std::unique_ptr<QPlatformPixmap> data(QGuiApplicationPrivate::platformIntegration()->createPlatformPixmap(QPlatformPixmap::PixmapType));
data->fromImage(image, flags);
- return QPixmap(data.take());
+ return QPixmap(data.release());
}
/*!
@@ -1506,9 +1508,9 @@ QPixmap QPixmap::fromImageInPlace(QImage &image, Qt::ImageConversionFlags flags)
return QPixmap();
}
- QScopedPointer<QPlatformPixmap> data(QGuiApplicationPrivate::platformIntegration()->createPlatformPixmap(QPlatformPixmap::PixmapType));
+ std::unique_ptr<QPlatformPixmap> data(QGuiApplicationPrivate::platformIntegration()->createPlatformPixmap(QPlatformPixmap::PixmapType));
data->fromImageInPlace(image, flags);
- return QPixmap(data.take());
+ return QPixmap(data.release());
}
/*!
@@ -1530,9 +1532,9 @@ QPixmap QPixmap::fromImageReader(QImageReader *imageReader, Qt::ImageConversionF
return QPixmap();
}
- QScopedPointer<QPlatformPixmap> data(QGuiApplicationPrivate::platformIntegration()->createPlatformPixmap(QPlatformPixmap::PixmapType));
+ std::unique_ptr<QPlatformPixmap> data(QGuiApplicationPrivate::platformIntegration()->createPlatformPixmap(QPlatformPixmap::PixmapType));
data->fromImageReader(imageReader, flags);
- return QPixmap(data.take());
+ return QPixmap(data.release());
}
/*!
diff --git a/src/gui/itemmodels/qfilesystemmodel.cpp b/src/gui/itemmodels/qfilesystemmodel.cpp
index d29a1c0114..66467b82fd 100644
--- a/src/gui/itemmodels/qfilesystemmodel.cpp
+++ b/src/gui/itemmodels/qfilesystemmodel.cpp
@@ -907,14 +907,14 @@ bool QFileSystemModel::setData(const QModelIndex &idx, const QVariant &value, in
int visibleLocation = parentNode->visibleLocation(parentNode->children.value(indexNode->fileName)->fileName);
parentNode->visibleChildren.removeAt(visibleLocation);
- QScopedPointer<QFileSystemModelPrivate::QFileSystemNode> nodeToRename(parentNode->children.take(oldName));
+ std::unique_ptr<QFileSystemModelPrivate::QFileSystemNode> nodeToRename(parentNode->children.take(oldName));
nodeToRename->fileName = newName;
nodeToRename->parent = parentNode;
#if QT_CONFIG(filesystemwatcher)
nodeToRename->populate(d->fileInfoGatherer.getInfo(QFileInfo(parentPath, newName)));
#endif
nodeToRename->isVisible = true;
- parentNode->children[newName] = nodeToRename.take();
+ parentNode->children[newName] = nodeToRename.release();
parentNode->visibleChildren.insert(visibleLocation, newName);
d->delayedSort();
diff --git a/src/gui/painting/qpaintengine.cpp b/src/gui/painting/qpaintengine.cpp
index 9b0ec446ff..db84b20d06 100644
--- a/src/gui/painting/qpaintengine.cpp
+++ b/src/gui/painting/qpaintengine.cpp
@@ -52,6 +52,7 @@
#include <private/qpaintengineex_p.h>
#include <private/qtextengine_p.h>
+#include <memory>
QT_BEGIN_NAMESPACE
@@ -1009,9 +1010,9 @@ QPixmap QPaintEngine::createPixmap(QSize size)
return QPixmap();
}
- QScopedPointer<QPlatformPixmap> data(QGuiApplicationPrivate::platformIntegration()->createPlatformPixmap(QPlatformPixmap::PixmapType));
+ std::unique_ptr<QPlatformPixmap> data(QGuiApplicationPrivate::platformIntegration()->createPlatformPixmap(QPlatformPixmap::PixmapType));
data->resize(size.width(), size.height());
- return QPixmap(data.take());
+ return QPixmap(data.release());
}
/*!
@@ -1026,12 +1027,12 @@ QPixmap QPaintEngine::createPixmapFromImage(QImage image, Qt::ImageConversionFla
return QPixmap();
}
- QScopedPointer<QPlatformPixmap> data(QGuiApplicationPrivate::platformIntegration()->createPlatformPixmap(QPlatformPixmap::PixmapType));
+ std::unique_ptr<QPlatformPixmap> data(QGuiApplicationPrivate::platformIntegration()->createPlatformPixmap(QPlatformPixmap::PixmapType));
if (image.isDetached())
data->fromImageInPlace(image, flags);
else
data->fromImage(image, flags);
- return QPixmap(data.take());
+ return QPixmap(data.release());
}
QPaintEnginePrivate::~QPaintEnginePrivate()
diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp
index f1b02f3e9b..704b841b15 100644
--- a/src/gui/painting/qpainter.cpp
+++ b/src/gui/painting/qpainter.cpp
@@ -38,6 +38,7 @@
****************************************************************************/
// QtCore
+#include <memory>
#include <qdebug.h>
#include <qmath.h>
#include <qmutex.h>
@@ -77,6 +78,9 @@
QT_BEGIN_NAMESPACE
+// We changed the type from QScopedPointer to unique_ptr, make sure it's binary compatible:
+static_assert(sizeof(QScopedPointer<QPainterPrivate>) == sizeof(std::unique_ptr<QPainterPrivate>));
+
#define QGradient_StretchToDevice 0x10000000
#define QPaintEngine_OpaqueBackground 0x40000000
@@ -276,9 +280,9 @@ bool QPainterPrivate::attachPainterPrivate(QPainter *q, QPaintDevice *pdev)
// the current d_ptr to the shared painter's d_ptr.
sp->save();
++sp->d_ptr->refcount;
- sp->d_ptr->d_ptrs.push_back(q->d_ptr.data());
- q->d_ptr.take();
- q->d_ptr.reset(sp->d_ptr.data());
+ sp->d_ptr->d_ptrs.push_back(q->d_ptr.get());
+ Q_UNUSED(q->d_ptr.release());
+ q->d_ptr.reset(sp->d_ptr.get());
Q_ASSERT(q->d_ptr->state);
@@ -333,7 +337,7 @@ void QPainterPrivate::detachPainterPrivate(QPainter *q)
}
q->restore();
- q->d_ptr.take();
+ Q_UNUSED(q->d_ptr.release());
q->d_ptr.reset(original);
if (emulationEngine) {
diff --git a/src/gui/painting/qpainter.h b/src/gui/painting/qpainter.h
index a3f556bfdf..51393bca7e 100644
--- a/src/gui/painting/qpainter.h
+++ b/src/gui/painting/qpainter.h
@@ -48,6 +48,7 @@
#include <QtGui/qpixmap.h>
#include <QtGui/qimage.h>
#include <QtGui/qtextoption.h>
+#include <memory>
#ifndef QT_INCLUDE_COMPAT
#include <QtGui/qpolygon.h>
@@ -448,7 +449,7 @@ public:
private:
Q_DISABLE_COPY(QPainter)
- QScopedPointer<QPainterPrivate> d_ptr;
+ std::unique_ptr<QPainterPrivate> d_ptr;
friend class QWidget;
friend class QFontEngine;
diff --git a/src/gui/painting/qpainter_p.h b/src/gui/painting/qpainter_p.h
index 7f5fe1a6c5..6cf1846862 100644
--- a/src/gui/painting/qpainter_p.h
+++ b/src/gui/painting/qpainter_p.h
@@ -252,7 +252,7 @@ public:
static QPainterPrivate *get(QPainter *painter)
{
- return painter->d_ptr.data();
+ return painter->d_ptr.get();
}
QTransform viewTransform() const;
diff --git a/src/gui/painting/qregion.cpp b/src/gui/painting/qregion.cpp
index 6ca87cb416..7a15174725 100644
--- a/src/gui/painting/qregion.cpp
+++ b/src/gui/painting/qregion.cpp
@@ -48,6 +48,7 @@
#include "qbitmap.h"
#include "qtransform.h"
+#include <memory>
#include <private/qdebug_p.h>
#ifdef Q_OS_WIN
@@ -3915,7 +3916,7 @@ QRegion &QRegion::operator=(const QRegion &r)
QRegion QRegion::copy() const
{
QRegion r;
- QScopedPointer<QRegionData> x(new QRegionData);
+ auto x = std::make_unique<QRegionData>();
x->ref.initializeOwned();
if (d->qt_rgn)
x->qt_rgn = new QRegionPrivate(*d->qt_rgn);
@@ -3923,7 +3924,7 @@ QRegion QRegion::copy() const
x->qt_rgn = new QRegionPrivate;
if (!r.d->ref.deref())
cleanUp(r.d);
- r.d = x.take();
+ r.d = x.release();
return r;
}
diff --git a/src/gui/rhi/qrhi.cpp b/src/gui/rhi/qrhi.cpp
index d62b2eea61..70b99abbb6 100644
--- a/src/gui/rhi/qrhi.cpp
+++ b/src/gui/rhi/qrhi.cpp
@@ -55,6 +55,8 @@
#include "qrhimetal_p_p.h"
#endif
+#include <memory>
+
QT_BEGIN_NAMESPACE
Q_LOGGING_CATEGORY(QRHI_LOG_INFO, "qt.rhi.general")
@@ -5305,7 +5307,7 @@ QRhi::~QRhi()
*/
QRhi *QRhi::create(Implementation impl, QRhiInitParams *params, Flags flags, QRhiNativeHandles *importDevice)
{
- QScopedPointer<QRhi> r(new QRhi);
+ std::unique_ptr<QRhi> r(new QRhi);
switch (impl) {
case Null:
@@ -5351,7 +5353,7 @@ QRhi *QRhi::create(Implementation impl, QRhiInitParams *params, Flags flags, QRh
}
if (r->d) {
- r->d->q = r.data();
+ r->d->q = r.get();
// Play nice with QSG_INFO since that is still the most commonly used
// way to get graphics info printed from Qt Quick apps, and the Quick
@@ -5364,7 +5366,7 @@ QRhi *QRhi::create(Implementation impl, QRhiInitParams *params, Flags flags, QRh
if (r->d->create(flags)) {
r->d->implType = impl;
r->d->implThread = QThread::currentThread();
- return r.take();
+ return r.release();
}
}
diff --git a/src/gui/text/freetype/qfontengine_ft.cpp b/src/gui/text/freetype/qfontengine_ft.cpp
index b24e620d15..c494c77e95 100644
--- a/src/gui/text/freetype/qfontengine_ft.cpp
+++ b/src/gui/text/freetype/qfontengine_ft.cpp
@@ -59,6 +59,8 @@
#include <qmath.h>
#include <qendian.h>
+#include <memory>
+
#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_OUTLINE_H
@@ -224,7 +226,8 @@ QFreetypeFace *QFreetypeFace::getFace(const QFontEngine::FaceId &face_id,
if (freetype) {
freetype->ref.ref();
} else {
- QScopedPointer<QFreetypeFace> newFreetype(new QFreetypeFace);
+ const auto deleter = [](QFreetypeFace *f) { delete f; };
+ std::unique_ptr<QFreetypeFace, decltype(deleter)> newFreetype(new QFreetypeFace, deleter);
FT_Face face;
if (!face_id.filename.isEmpty()) {
QString fileName = QFile::decodeName(face_id.filename);
@@ -293,13 +296,13 @@ QFreetypeFace *QFreetypeFace::getFace(const QFontEngine::FaceId &face_id,
FT_Set_Charmap(newFreetype->face, newFreetype->unicode_map);
QT_TRY {
- freetypeData->faces.insert(face_id, newFreetype.data());
+ freetypeData->faces.insert(face_id, newFreetype.get());
} QT_CATCH(...) {
- newFreetype.take()->release(face_id);
+ newFreetype.release()->release(face_id);
// we could return null in principle instead of throwing
QT_RETHROW;
}
- freetype = newFreetype.take();
+ freetype = newFreetype.release();
}
return freetype;
}
@@ -594,7 +597,7 @@ static QFontEngine::SubpixelAntialiasingType subpixelAntialiasingTypeHint()
QFontEngineFT *QFontEngineFT::create(const QFontDef &fontDef, FaceId faceId, const QByteArray &fontData)
{
- QScopedPointer<QFontEngineFT> engine(new QFontEngineFT(fontDef));
+ auto engine = std::make_unique<QFontEngineFT>(fontDef);
QFontEngineFT::GlyphFormat format = QFontEngineFT::Format_Mono;
const bool antialias = !(fontDef.styleStrategy & QFont::NoAntialias);
@@ -616,7 +619,7 @@ QFontEngineFT *QFontEngineFT::create(const QFontDef &fontDef, FaceId faceId, con
}
engine->setQtDefaultHintStyle(static_cast<QFont::HintingPreference>(fontDef.hintingPreference));
- return engine.take();
+ return engine.release();
}
namespace {
@@ -1075,7 +1078,7 @@ QFontEngineFT::Glyph *QFontEngineFT::loadGlyph(QGlyphSet *set, uint glyph,
}
int glyph_buffer_size = 0;
- QScopedArrayPointer<uchar> glyph_buffer;
+ std::unique_ptr<uchar[]> glyph_buffer;
FT_Render_Mode renderMode = (default_hint_style == HintLight) ? FT_RENDER_MODE_LIGHT : FT_RENDER_MODE_NORMAL;
switch (format) {
case Format_Mono:
@@ -1120,7 +1123,7 @@ QFontEngineFT::Glyph *QFontEngineFT::loadGlyph(QGlyphSet *set, uint glyph,
if (slot->bitmap.pixel_mode == FT_PIXEL_MODE_MONO) {
uchar *src = slot->bitmap.buffer;
- uchar *dst = glyph_buffer.data();
+ uchar *dst = glyph_buffer.get();
int h = slot->bitmap.rows;
// Some fonts return bitmaps even when we requested something else:
if (format == Format_Mono) {
@@ -1149,7 +1152,7 @@ QFontEngineFT::Glyph *QFontEngineFT::loadGlyph(QGlyphSet *set, uint glyph,
} else if (slot->bitmap.pixel_mode == 7 /*FT_PIXEL_MODE_BGRA*/) {
Q_ASSERT(format == Format_ARGB);
uchar *src = slot->bitmap.buffer;
- uchar *dst = glyph_buffer.data();
+ uchar *dst = glyph_buffer.get();
int h = slot->bitmap.rows;
while (h--) {
#if Q_BYTE_ORDER == Q_BIG_ENDIAN
@@ -1169,7 +1172,7 @@ QFontEngineFT::Glyph *QFontEngineFT::loadGlyph(QGlyphSet *set, uint glyph,
} else if (slot->bitmap.pixel_mode == FT_PIXEL_MODE_GRAY) {
Q_ASSERT(format == Format_A8);
uchar *src = slot->bitmap.buffer;
- uchar *dst = glyph_buffer.data();
+ uchar *dst = glyph_buffer.get();
int h = slot->bitmap.rows;
int bytes = info.width;
while (h--) {
@@ -1179,10 +1182,10 @@ QFontEngineFT::Glyph *QFontEngineFT::loadGlyph(QGlyphSet *set, uint glyph,
}
} else if (slot->bitmap.pixel_mode == FT_PIXEL_MODE_LCD) {
Q_ASSERT(format == Format_A32);
- convertRGBToARGB(slot->bitmap.buffer, (uint *)glyph_buffer.data(), info.width, info.height, slot->bitmap.pitch, subpixelType != Subpixel_RGB);
+ convertRGBToARGB(slot->bitmap.buffer, (uint *)glyph_buffer.get(), info.width, info.height, slot->bitmap.pitch, subpixelType != Subpixel_RGB);
} else if (slot->bitmap.pixel_mode == FT_PIXEL_MODE_LCD_V) {
Q_ASSERT(format == Format_A32);
- convertRGBToARGB_V(slot->bitmap.buffer, (uint *)glyph_buffer.data(), info.width, info.height, slot->bitmap.pitch, subpixelType != Subpixel_VRGB);
+ convertRGBToARGB_V(slot->bitmap.buffer, (uint *)glyph_buffer.get(), info.width, info.height, slot->bitmap.pitch, subpixelType != Subpixel_VRGB);
} else {
qWarning("QFontEngine: Glyph rendered in unknown pixel_mode=%d", slot->bitmap.pixel_mode);
return nullptr;
@@ -1201,7 +1204,7 @@ QFontEngineFT::Glyph *QFontEngineFT::loadGlyph(QGlyphSet *set, uint glyph,
g->advance = info.xOff;
g->format = format;
delete [] g->data;
- g->data = glyph_buffer.take();
+ g->data = glyph_buffer.release();
if (set)
set->setGlyph(glyph, subPixelPosition, g);
diff --git a/src/gui/text/freetype/qfontengine_ft_p.h b/src/gui/text/freetype/qfontengine_ft_p.h
index 03059c7d13..f3ae6d8cad 100644
--- a/src/gui/text/freetype/qfontengine_ft_p.h
+++ b/src/gui/text/freetype/qfontengine_ft_p.h
@@ -117,7 +117,6 @@ public:
private:
friend class QFontEngineFT;
friend class QtFreetypeData;
- friend struct QScopedPointerDeleter<QFreetypeFace>;
QFreetypeFace() = default;
~QFreetypeFace() {}
void cleanup();
diff --git a/src/gui/text/qzip.cpp b/src/gui/text/qzip.cpp
index 1fe7a6d042..0b1fe00779 100644
--- a/src/gui/text/qzip.cpp
+++ b/src/gui/text/qzip.cpp
@@ -48,6 +48,8 @@
#include <qdebug.h>
#include <qdir.h>
+#include <memory>
+
#include <zlib.h>
// Zip standard version for archives handled by this API
@@ -822,7 +824,7 @@ void QZipWriterPrivate::addEntry(EntryType type, const QString &fileName, const
*/
QZipReader::QZipReader(const QString &archive, QIODevice::OpenMode mode)
{
- QScopedPointer<QFile> f(new QFile(archive));
+ auto f = std::make_unique<QFile>(archive);
const bool result = f->open(mode);
QZipReader::Status status;
const QFileDevice::FileError error = f->error();
@@ -839,8 +841,8 @@ QZipReader::QZipReader(const QString &archive, QIODevice::OpenMode mode)
status = FileError;
}
- d = new QZipReaderPrivate(f.data(), /*ownDevice=*/true);
- f.take();
+ d = new QZipReaderPrivate(f.get(), /*ownDevice=*/true);
+ Q_UNUSED(f.release());
d->status = status;
}
@@ -1139,7 +1141,7 @@ void QZipReader::close()
*/
QZipWriter::QZipWriter(const QString &fileName, QIODevice::OpenMode mode)
{
- QScopedPointer<QFile> f(new QFile(fileName));
+ auto f = std::make_unique<QFile>(fileName);
QZipWriter::Status status;
if (f->open(mode) && f->error() == QFile::NoError)
status = QZipWriter::NoError;
@@ -1154,8 +1156,8 @@ QZipWriter::QZipWriter(const QString &fileName, QIODevice::OpenMode mode)
status = QZipWriter::FileError;
}
- d = new QZipWriterPrivate(f.data(), /*ownDevice=*/true);
- f.take();
+ d = new QZipWriterPrivate(f.get(), /*ownDevice=*/true);
+ Q_UNUSED(f.release());
d->status = status;
}