Fix deprecated uses of QScopedPointer

Which is uses of take() and swap().
And replace it with std::unique_ptr.

Change-Id: I2580383c1d2af0ba6103a66f034235905e0988ac
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
This commit is contained in:
Mårten Nordheim 2022-03-08 17:03:47 +01:00
parent 81bbd0b45a
commit af7d0957e4
14 changed files with 50 additions and 31 deletions

View File

@ -42,6 +42,7 @@
#include <private/qimage_p.h>
#include <QSharedMemory>
#include <memory>
QT_BEGIN_NAMESPACE
@ -165,7 +166,7 @@ QImage QSharedImageLoaderPrivate::load(const QString &path, QSharedImageLoader::
if (path.isEmpty())
return nil;
QScopedPointer<QSharedMemory> shm(new QSharedMemory(q->key(path, params)));
auto shm = std::make_unique<QSharedMemory>(q->key(path, params));
bool locked = false;
if (!shm->attach(QSharedMemory::ReadOnly)) {
@ -213,7 +214,7 @@ QImage QSharedImageLoaderPrivate::load(const QString &path, QSharedImageLoader::
return nil;
}
QSharedMemory *shmp = shm.take();
QSharedMemory *shmp = shm.release();
SharedImageInfo *sii = new SharedImageInfo;
sii->path = path;
sii->shmp = shmp;

View File

@ -802,7 +802,7 @@ bool ExecutableCompilationUnit::loadFromDisk(const QUrl &url, const QDateTime &s
}
const QString sourcePath = QQmlFile::urlToLocalFileOrQrc(url);
QScopedPointer<CompilationUnitMapper> cacheFile(new CompilationUnitMapper());
auto cacheFile = std::make_unique<CompilationUnitMapper>();
const QStringList cachePaths = { sourcePath + QLatin1Char('c'), localCacheFilePath(url) };
for (const QString &cachePath : cachePaths) {
@ -827,7 +827,7 @@ bool ExecutableCompilationUnit::loadFromDisk(const QUrl &url, const QDateTime &s
dataPtrRevert.dismiss();
free(const_cast<CompiledData::Unit*>(oldDataPtr));
backingFile.reset(cacheFile.take());
backingFile = std::move(cacheFile);
return true;
}

View File

@ -60,6 +60,8 @@
#include <private/qqmlnullablevalue_p.h>
#include <private/qqmlmetatype_p.h>
#include <memory>
QT_BEGIN_NAMESPACE
class QQmlScriptData;
@ -185,7 +187,7 @@ public:
QHash<int, InlineComponentData> inlineComponentData;
QScopedPointer<CompilationUnitMapper> backingFile;
std::unique_ptr<CompilationUnitMapper> backingFile;
// --- interface for QQmlPropertyCacheCreator
using CompiledObject = CompiledData::Object;

View File

@ -45,6 +45,8 @@
#include "qqmlapplicationengine_p.h"
#include "qqmlfileselector.h"
#include <memory>
QT_BEGIN_NAMESPACE
QQmlApplicationEnginePrivate::QQmlApplicationEnginePrivate(QQmlEngine *e)
@ -95,13 +97,13 @@ void QQmlApplicationEnginePrivate::_q_loadTranslations()
if (translationsDirectory.isEmpty())
return;
QScopedPointer<QTranslator> translator(new QTranslator);
auto translator = std::make_unique<QTranslator>();
if (!uiLanguage.value().isEmpty()) {
QLocale locale(uiLanguage);
if (translator->load(locale, QLatin1String("qml"), QLatin1String("_"), translationsDirectory, QLatin1String(".qm"))) {
if (activeTranslator)
QCoreApplication::removeTranslator(activeTranslator.data());
QCoreApplication::installTranslator(translator.data());
QCoreApplication::removeTranslator(activeTranslator.get());
QCoreApplication::installTranslator(translator.get());
activeTranslator.swap(translator);
}
} else {

View File

@ -77,7 +77,7 @@ public:
QStringList extraFileSelectors;
QString translationsDirectory;
#if QT_CONFIG(translation)
QScopedPointer<QTranslator> activeTranslator;
std::unique_ptr<QTranslator> activeTranslator;
#endif
bool isInitialized = false;
};

View File

@ -346,9 +346,9 @@ void QQmlData::signalEmitted(QAbstractDeclarativeData *, QObject *object, int in
QMetaMethod m = QMetaObjectPrivate::signal(object->metaObject(), index);
QList<QByteArray> parameterTypes = m.parameterTypes();
QScopedPointer<QMetaCallEvent> ev(new QMetaCallEvent(m.methodIndex(), 0, nullptr,
object, index,
parameterTypes.count() + 1));
auto ev = std::make_unique<QMetaCallEvent>(m.methodIndex(), 0, nullptr,
object, index,
parameterTypes.count() + 1);
void **args = ev->args();
QMetaType *types = ev->types();
@ -373,7 +373,7 @@ void QQmlData::signalEmitted(QAbstractDeclarativeData *, QObject *object, int in
QQmlThreadNotifierProxyObject *mpo = new QQmlThreadNotifierProxyObject;
mpo->target = object;
mpo->moveToThread(objectThreadData->thread.loadAcquire());
QCoreApplication::postEvent(mpo, ev.take());
QCoreApplication::postEvent(mpo, ev.release());
} else {
QQmlNotifierEndpoint *ep = ddata->notify(index);

View File

@ -41,6 +41,8 @@
#include <QtQml/qqmlinfo.h>
#include <memory>
/*!
\qmltype LoggingCategory
\ingroup qml-utility-elements
@ -118,7 +120,7 @@ QQmlLoggingCategory::DefaultLogLevel QQmlLoggingCategory::defaultLogLevel() cons
QLoggingCategory *QQmlLoggingCategory::category() const
{
return m_category.data();
return m_category.get();
}
void QQmlLoggingCategory::classBegin()
@ -131,7 +133,7 @@ void QQmlLoggingCategory::componentComplete()
if (m_name.isNull()) {
qmlWarning(this) << QLatin1String("Declaring the name of a LoggingCategory is mandatory and cannot be changed later");
} else {
QScopedPointer<QLoggingCategory> category(new QLoggingCategory(m_name.constData(), QtMsgType(m_defaultLogLevel)));
auto category = std::make_unique<QLoggingCategory>(m_name.constData(), QtMsgType(m_defaultLogLevel));
m_category.swap(category);
}
}

View File

@ -58,6 +58,8 @@
#include <QtQml/qqmlparserstatus.h>
#include <QtQml/qqml.h>
#include <memory>
QT_BEGIN_NAMESPACE
class QQmlLoggingCategory : public QObject, public QQmlParserStatus
@ -95,7 +97,7 @@ public:
private:
QByteArray m_name;
QScopedPointer<QLoggingCategory> m_category;
std::unique_ptr<QLoggingCategory> m_category;
DefaultLogLevel m_defaultLogLevel = Debug;
bool m_initialized;
};

View File

@ -50,6 +50,8 @@
#include <QtCore/qloggingcategory.h>
#include <QtCore/qcryptographichash.h>
#include <memory>
Q_DECLARE_LOGGING_CATEGORY(DBG_DISK_CACHE)
QT_BEGIN_NAMESPACE
@ -902,7 +904,7 @@ QQmlError QQmlTypeData::buildTypeResolutionCaches(
m_importCache.populateCache(typeNameCache->data());
for (auto resolvedType = m_resolvedTypes.constBegin(), end = m_resolvedTypes.constEnd(); resolvedType != end; ++resolvedType) {
QScopedPointer<QV4::ResolvedTypeReference> ref(new QV4::ResolvedTypeReference);
auto ref = std::make_unique<QV4::ResolvedTypeReference>();
QQmlType qmlType = resolvedType->type;
if (resolvedType->typeData) {
if (resolvedType->needsCreation && qmlType.isCompositeSingleton()) {
@ -957,7 +959,7 @@ QQmlError QQmlTypeData::buildTypeResolutionCaches(
}
ref->setVersion(resolvedType->version);
ref->doDynamicTypeCheck();
resolvedTypeCache->insert(resolvedType.key(), ref.take());
resolvedTypeCache->insert(resolvedType.key(), ref.release());
}
QQmlError noError;
return noError;

View File

@ -49,6 +49,8 @@
#include <private/qv4qobjectwrapper_p.h>
#include <QtCore/qbasictimer.h>
#include <memory>
QT_BEGIN_NAMESPACE
void QQuickViewPrivate::init(QQmlEngine* e)
@ -488,9 +490,9 @@ void QQuickView::continueExecute()
return;
}
QScopedPointer<QObject> obj(d->initialProperties.empty()
? d->component->create()
: d->component->createWithInitialProperties(d->initialProperties));
std::unique_ptr<QObject> obj(d->initialProperties.empty()
? d->component->create()
: d->component->createWithInitialProperties(d->initialProperties));
if (d->component->isError()) {
const QList<QQmlError> errorList = d->component->errors();
@ -503,7 +505,7 @@ void QQuickView::continueExecute()
}
if (d->setRootObject(obj.get()))
obj.take();
Q_UNUSED(obj.release());
emit statusChanged(status());
}

View File

@ -53,6 +53,8 @@
#include <QOperatingSystemVersion>
#include <QOffscreenSurface>
#include <memory>
QT_BEGIN_NAMESPACE
QSGRhiSupport::QSGRhiSupport()
@ -743,8 +745,8 @@ QImage QSGRhiSupport::grabOffscreen(QQuickWindow *window)
qWarning("Failed to initialize QRhi for offscreen readback");
return QImage();
}
QScopedPointer<QRhi> rhiOwner(rhiResult.rhi);
QRhi *rhi = rhiResult.own ? rhiOwner.data() : rhiOwner.take();
std::unique_ptr<QRhi> rhiOwner(rhiResult.rhi);
QRhi *rhi = rhiResult.own ? rhiOwner.get() : rhiOwner.release();
const QSize pixelSize = window->size() * window->devicePixelRatio();
QScopedPointer<QRhiTexture> texture(rhi->newTexture(QRhiTexture::RGBA8, pixelSize, 1,

View File

@ -53,6 +53,8 @@
#include <QtQuick/private/qquickrendercontrol_p.h>
#include <QtQuick/private/qquickwindow_p.h>
#include <memory>
QT_BEGIN_NAMESPACE
Q_LOGGING_CATEGORY(lcTouch, "qt.quick.touch")
@ -1207,10 +1209,10 @@ void QQuickDeliveryAgentPrivate::deliverDelayedTouchEvent()
// Deliver and delete delayedTouch.
// Set delayedTouch to nullptr before delivery to avoid redelivery in case of
// event loop recursions (e.g if it the touch starts a dnd session).
QScopedPointer<QTouchEvent> e(delayedTouch.take());
qCDebug(lcTouchCmprs) << "delivering" << e.data();
std::unique_ptr<QTouchEvent> e(std::move(delayedTouch));
qCDebug(lcTouchCmprs) << "delivering" << e.get();
compressedTouchCount = 0;
deliverPointerEvent(e.data());
deliverPointerEvent(e.get());
}
/*! \internal
@ -1407,7 +1409,7 @@ bool QQuickDeliveryAgentPrivate::compressTouchEvent(QTouchEvent *event)
QMutableEventPoint::detach(tp);
}
++compressedTouchCount;
qCDebug(lcTouchCmprs) << "delayed" << compressedTouchCount << delayedTouch.data();
qCDebug(lcTouchCmprs) << "delayed" << compressedTouchCount << delayedTouch.get();
if (QQuickWindow *window = rootItem->window())
window->maybeUpdate();
return true;
@ -1446,7 +1448,7 @@ bool QQuickDeliveryAgentPrivate::compressTouchEvent(QTouchEvent *event)
QMutableEventPoint::detach(tp);
}
++compressedTouchCount;
qCDebug(lcTouchCmprs) << "coalesced" << compressedTouchCount << delayedTouch.data();
qCDebug(lcTouchCmprs) << "coalesced" << compressedTouchCount << delayedTouch.get();
if (QQuickWindow *window = rootItem->window())
window->maybeUpdate();
return true;

View File

@ -59,6 +59,8 @@
#include <private/qpointingdevice_p.h>
#include <private/qobject_p.h>
#include <memory>
QT_BEGIN_NAMESPACE
class QQuickDragGrabber;
@ -109,7 +111,7 @@ public:
QVector<QQuickItem *> hasFiltered; // during event delivery to a single receiver, the filtering parents for which childMouseEventFilter was already called
QVector<QQuickItem *> skipDelivery; // during delivery of one event to all receivers, Items to which we know delivery is no longer necessary
QScopedPointer<QMutableTouchEvent> delayedTouch;
std::unique_ptr<QMutableTouchEvent> delayedTouch;
QList<const QPointingDevice *> knownPointingDevices;
uint currentHoverId = 0;

View File

@ -992,7 +992,7 @@ void tst_qmldiskcache::cacheModuleScripts()
QVERIFY(unitData);
QVERIFY(unitData->flags & QV4::CompiledData::Unit::StaticData);
QVERIFY(unitData->flags & QV4::CompiledData::Unit::IsESModule);
QVERIFY(!compilationUnit->backingFile.isNull());
QVERIFY(compilationUnit->backingFile);
}
const QSet<QString> entries = entrySet(m_qmlCacheDirectory, QStringList("*.mjsc"));