QScopeGuard: Make all usages of QScopeGuard consistent

Change-Id: Icfc35ecbdbdee8dadbb1b17789694093427c3ed9
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
Jarek Kobus
2023-06-07 09:39:30 +02:00
parent aefd4d759e
commit abb85b073a
27 changed files with 57 additions and 59 deletions

View File

@@ -586,7 +586,7 @@ int main(int argc, char **argv)
QCoreApplication::setOrganizationName(QLatin1String(Core::Constants::IDE_SETTINGSVARIANT_STR));
QGuiApplication::setApplicationDisplayName(Core::Constants::IDE_DISPLAY_NAME);
auto cleanup = qScopeGuard([] { Utils::Singleton::deleteAll(); });
const QScopeGuard cleanup([] { Utils::Singleton::deleteAll(); });
const QStringList pluginArguments = app.arguments();

View File

@@ -8,7 +8,6 @@
#include "qtcassert.h"
#include <QLoggingCategory>
#include <QScopeGuard>
Q_LOGGING_CATEGORY(deviceShellLog, "qtc.utils.deviceshell", QtWarningMsg)

View File

@@ -66,7 +66,7 @@ public:
return std::invoke(std::forward<Function>(function), std::forward<Args>(args)...);
QElapsedTimer timer;
timer.start();
auto cleanup = qScopeGuard([this, &timer] {
const QScopeGuard cleanup([this, &timer] {
const qint64 currentNsecs = timer.nsecsElapsed();
const bool mainThread = isMainThread();
const int hitThisAll = m_hitThisAll.fetch_add(1) + 1;

View File

@@ -341,7 +341,7 @@ bool AndroidRunnerWorker::uploadDebugServer(const QString &debugServerFileName)
}
const QString tempDebugServerPath = tempDebugServerPathTemplate.arg(count);
auto cleanUp = qScopeGuard([this, tempDebugServerPath] {
const QScopeGuard cleanup([this, tempDebugServerPath] {
if (!runAdb({"shell", "rm", "-f", tempDebugServerPath}))
qCDebug(androidRunWorkerLog) << "Debug server cleanup failed.";
});

View File

@@ -158,7 +158,7 @@ void DocumentClangToolRunner::run()
if (m_projectSettingsUpdate)
disconnect(m_projectSettingsUpdate);
m_taskTree.reset();
QScopeGuard guard([this] { finalize(); });
QScopeGuard cleanup([this] { finalize(); });
auto isEditorForCurrentDocument = [this](const IEditor *editor) {
return editor->document() == m_document;
@@ -216,7 +216,7 @@ void DocumentClangToolRunner::run()
if (tasks.isEmpty())
return;
guard.dismiss();
cleanup.dismiss();
m_taskTree.reset(new TaskTree(tasks));
connect(m_taskTree.get(), &TaskTree::done, this, &DocumentClangToolRunner::finalize);
connect(m_taskTree.get(), &TaskTree::errorOccurred, this, &DocumentClangToolRunner::finalize);

View File

@@ -15,6 +15,7 @@
#include <utils/utilsicons.h>
#include <QPushButton>
#include <QScopeGuard>
#include <QToolBar>
#include <QToolButton>
@@ -117,7 +118,7 @@ void CopilotHoverHandler::identifyMatch(TextEditorWidget *editorWidget,
int pos,
ReportPriority report)
{
auto reportNone = qScopeGuard([&] { report(Priority_None); });
QScopeGuard cleanup([&] { report(Priority_None); });
if (!editorWidget->suggestionVisible())
return;
@@ -133,7 +134,7 @@ void CopilotHoverHandler::identifyMatch(TextEditorWidget *editorWidget,
if (completions.isEmpty())
return;
reportNone.dismiss();
cleanup.dismiss();
report(Priority_Suggestion);
}

View File

@@ -3325,7 +3325,7 @@ IEditor *EditorManager::openEditorWithContents(Id editorId,
EditorManager::gotoOtherSplit();
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
const auto cleanup = qScopeGuard(&QApplication::restoreOverrideCursor);
const QScopeGuard cleanup(&QApplication::restoreOverrideCursor);
const QString title = makeTitleUnique(titlePattern);

View File

@@ -15,7 +15,6 @@
#include <QJSEngine>
#include <QPair>
#include <QPointer>
#include <QScopeGuard>
#include <chrono>

View File

@@ -591,7 +591,7 @@ void LoggingViewManagerWidget::saveLoggingsToFile() const
{
// should we just let it continue without temporarily disabling?
const bool enabled = m_manager->isEnabled();
const auto cleanup = qScopeGuard([this, enabled] { m_manager->setEnabled(enabled); });
const QScopeGuard cleanup([this, enabled] { m_manager->setEnabled(enabled); });
if (enabled)
m_manager->setEnabled(false);
const Utils::FilePath fp = Utils::FileUtils::getSaveFilePath(ICore::dialogParent(),

View File

@@ -3,8 +3,6 @@
#include "clientrequesttask.h"
#include <QScopeGuard>
using namespace LanguageServerProtocol;
namespace LanguageClient {

View File

@@ -635,7 +635,7 @@ public:
const auto selection = selectionContext();
bool showMenu = false;
auto cleanup = qScopeGuard([&]{ menu()->setEnabled(showMenu); });
const QScopeGuard cleanup([&]{ menu()->setEnabled(showMenu); });
if (!selection.isValid())
return;

View File

@@ -330,7 +330,7 @@ void DynamicPropertyRow::commitValue(const QVariant &value)
return;
m_lock = true;
auto unlock = qScopeGuard([this] { m_lock = false; });
const QScopeGuard cleanup([this] { m_lock = false; });
auto view = propertiesModel->view();
RewriterTransaction transaction = view->beginRewriterTransaction(__FUNCTION__);
@@ -371,7 +371,7 @@ void DynamicPropertyRow::commitExpression(const QString &expression)
}
m_lock = true;
auto unlock = qScopeGuard([this] { m_lock = false; });
const QScopeGuard cleanup([this] { m_lock = false; });
auto view = propertiesModel->view();
RewriterTransaction transaction = view->beginRewriterTransaction(__FUNCTION__);
@@ -426,7 +426,7 @@ void DynamicPropertyRow::resetValue()
}
} else {
m_lock = true;
auto unlock = qScopeGuard([this] { m_lock = false; });
const QScopeGuard cleanup([this] { m_lock = false; });
RewriterTransaction transaction = view->beginRewriterTransaction(__FUNCTION__);
try {

View File

@@ -306,7 +306,7 @@ QString GradientModel::readGradientOrientation() const
void GradientModel::setupModel()
{
m_locked = true;
auto guard = qScopeGuard([&] { m_locked = false; });
const QScopeGuard cleanup([&] { m_locked = false; });
beginResetModel();
endResetModel();
@@ -329,7 +329,7 @@ void GradientModel::setAnchorBackend(const QVariant &anchorBackend)
setupModel();
m_locked = true;
auto guard = qScopeGuard([&] { m_locked = false; });
const QScopeGuard cleanup([&] { m_locked = false; });
emit anchorBackendChanged();
emit hasGradientChanged();

View File

@@ -29,16 +29,17 @@
#include <utils/hostosinfo.h>
#include <utils/qtcassert.h>
#include <QCoreApplication>
#include <QDir>
#include <QFileSystemWatcher>
#include <QFileInfo>
#include <QDebug>
#include <QQuickItem>
#include <QTimer>
#include <QShortcut>
#include <QApplication>
#include <QCoreApplication>
#include <QDebug>
#include <QDir>
#include <QFileInfo>
#include <QFileSystemWatcher>
#include <QQuickItem>
#include <QScopeGuard>
#include <QScopedPointer>
#include <QShortcut>
#include <QTimer>
enum {
debug = false
@@ -241,10 +242,10 @@ void PropertyEditorView::changeExpression(const QString &propertyName)
if (noValidSelection())
return;
QScopeGuard unlock([&](){ m_locked = false; });
const QScopeGuard cleanup([&] { m_locked = false; });
m_locked = true;
executeInTransaction("PropertyEditorView::changeExpression", [this, name](){
executeInTransaction("PropertyEditorView::changeExpression", [this, name] {
PropertyName underscoreName(name);
underscoreName.replace('.', '_');

View File

@@ -13,7 +13,6 @@
#include <QFileDialog>
#include <QPainter>
#include <QPointer>
#include <QScopeGuard>
#include <QStyle>
#include <QStyleFactory>
#include <QTextTable>

View File

@@ -23,6 +23,7 @@
#include <QDebug>
#include <QMessageBox>
#include <QRegularExpression>
#include <QScopeGuard>
#include <cmath>
#include <memory>
@@ -331,7 +332,7 @@ void StatesEditorView::setWhenCondition(int internalNodeId, const QString &condi
return;
m_block = true;
auto guard = qScopeGuard([&]() { m_block = false; });
const QScopeGuard cleanup([&] { m_block = false; });
if (hasModelNodeForInternalId(internalNodeId)) {
QmlModelState state(modelNodeForInternalId(internalNodeId));
@@ -351,7 +352,7 @@ void StatesEditorView::resetWhenCondition(int internalNodeId)
return;
m_block = true;
auto guard = qScopeGuard([&]() { m_block = false; });
const QScopeGuard cleanup([&] { m_block = false; });
if (hasModelNodeForInternalId(internalNodeId)) {
QmlModelState state(modelNodeForInternalId(internalNodeId));
@@ -369,7 +370,7 @@ void StatesEditorView::setStateAsDefault(int internalNodeId)
return;
m_block = true;
auto guard = qScopeGuard([&]() { m_block = false; });
const QScopeGuard cleanup([&] { m_block = false; });
if (hasModelNodeForInternalId(internalNodeId)) {
QmlModelState state(modelNodeForInternalId(internalNodeId));
@@ -389,7 +390,7 @@ void StatesEditorView::resetDefaultState()
return;
m_block = true;
auto guard = qScopeGuard([&]() { m_block = false; });
const QScopeGuard cleanup([&] { m_block = false; });
try {
if (acitveStatesGroupNode().hasProperty("state"))
@@ -411,7 +412,7 @@ void StatesEditorView::setAnnotation(int internalNodeId)
return;
m_block = true;
auto guard = qScopeGuard([&]() { m_block = false; });
const QScopeGuard cleanup([&] { m_block = false; });
if (hasModelNodeForInternalId(internalNodeId)) {
QmlModelState state(modelNodeForInternalId(internalNodeId));
@@ -438,7 +439,7 @@ void StatesEditorView::removeAnnotation(int internalNodeId)
return;
m_block = true;
auto guard = qScopeGuard([&]() { m_block = false; });
const QScopeGuard cleanup([&] { m_block = false; });
if (hasModelNodeForInternalId(internalNodeId)) {
QmlModelState state(modelNodeForInternalId(internalNodeId));
@@ -580,7 +581,7 @@ void StatesEditorView::variantPropertiesChanged(const QList<VariantProperty> &pr
return;
m_block = true;
auto guard = qScopeGuard([&]() { m_block = false; });
const QScopeGuard cleanup([&] { m_block = false; });
for (const VariantProperty &property : propertyList) {
if (property.name() == "name"

View File

@@ -29,8 +29,10 @@
#include "stateseditorwidget.h"
#include <QDebug>
#include <QRegularExpression>
#include <QMessageBox>
#include <QRegularExpression>
#include <QScopeGuard>
#include <cmath>
#include <memory>
@@ -572,7 +574,7 @@ void StatesEditorView::setWhenCondition(int internalNodeId, const QString &condi
return;
m_block = true;
auto guard = qScopeGuard([&]() { m_block = false; });
const QScopeGuard cleanup([&] { m_block = false; });
if (hasModelNodeForInternalId(internalNodeId)) {
QmlModelState state(modelNodeForInternalId(internalNodeId));
@@ -592,7 +594,7 @@ void StatesEditorView::resetWhenCondition(int internalNodeId)
return;
m_block = true;
auto guard = qScopeGuard([&]() { m_block = false; });
const QScopeGuard cleanup([&] { m_block = false; });
if (hasModelNodeForInternalId(internalNodeId)) {
QmlModelState state(modelNodeForInternalId(internalNodeId));
@@ -612,7 +614,7 @@ void StatesEditorView::setStateAsDefault(int internalNodeId)
return;
m_block = true;
auto guard = qScopeGuard([&]() { m_block = false; });
const QScopeGuard cleanup([&] { m_block = false; });
if (hasModelNodeForInternalId(internalNodeId)) {
QmlModelState state(modelNodeForInternalId(internalNodeId));
@@ -632,7 +634,7 @@ void StatesEditorView::resetDefaultState()
return;
m_block = true;
auto guard = qScopeGuard([&]() { m_block = false; });
const QScopeGuard cleanup([&] { m_block = false; });
try {
if (activeStatesGroupNode().hasProperty("state"))
@@ -654,7 +656,7 @@ void StatesEditorView::setAnnotation(int internalNodeId)
return;
m_block = true;
auto guard = qScopeGuard([&]() { m_block = false; });
const QScopeGuard cleanup([&] { m_block = false; });
if (hasModelNodeForInternalId(internalNodeId)) {
QmlModelState state(modelNodeForInternalId(internalNodeId));
@@ -683,7 +685,7 @@ void StatesEditorView::removeAnnotation(int internalNodeId)
return;
m_block = true;
auto guard = qScopeGuard([&]() { m_block = false; });
const QScopeGuard cleanup([&] { m_block = false; });
if (hasModelNodeForInternalId(internalNodeId)) {
QmlModelState state(modelNodeForInternalId(internalNodeId));
@@ -869,7 +871,7 @@ void StatesEditorView::variantPropertiesChanged(const QList<VariantProperty> &pr
return;
m_block = true;
auto guard = qScopeGuard([&]() { m_block = false; });
const QScopeGuard cleanup([&] { m_block = false; });
for (const VariantProperty &property : propertyList) {
if (property.name() == "name"
@@ -948,7 +950,7 @@ void StatesEditorView::moveStates(int from, int to)
return;
m_block = true;
auto guard = qScopeGuard([&]() { m_block = false; });
const QScopeGuard cleanup([&] { m_block = false; });
if (!activeStatesGroupNode().hasNodeListProperty("states"))
return;

View File

@@ -1022,7 +1022,7 @@ Document::MutablePtr TextToModelMerger::createParsedDocument(const QUrl &url, co
bool TextToModelMerger::load(const QString &data, DifferenceHandler &differenceHandler)
{
QmlJS::ScopeChain::setSkipmakeComponentChain(true);
QScopeGuard unSkip([]() { QmlJS::ScopeChain::setSkipmakeComponentChain(false); });
const QScopeGuard cleanup([] { QmlJS::ScopeChain::setSkipmakeComponentChain(false); });
qCInfo(rewriterBenchmark) << Q_FUNC_INFO;

View File

@@ -40,7 +40,6 @@
#include <QMutex>
#include <QReadWriteLock>
#include <QRegularExpression>
#include <QScopeGuard>
#include <QTemporaryDir>
#include <QThread>
#include <QTimer>

View File

@@ -121,7 +121,7 @@ void BaseHoverHandler::process(TextEditorWidget *widget, int pos, ReportPriority
void BaseHoverHandler::identifyMatch(TextEditorWidget *editorWidget, int pos, ReportPriority report)
{
const auto cleanup = qScopeGuard([this, report] { report(priority()); });
const QScopeGuard cleanup([this, report] { report(priority()); });
QString tooltip = editorWidget->extraSelectionTooltip(pos);
if (!tooltip.isEmpty())

View File

@@ -158,7 +158,7 @@ void CodeAssistantPrivate::requestProposal(AssistReason reason,
bool isUpdate)
{
// make sure to cleanup old proposals if we cannot find a new assistant
auto cleanup = qScopeGuard([this] { destroyContext(); });
QScopeGuard cleanup([this] { destroyContext(); });
if (isWaitingForProposal())
cancelCurrentRequest();

View File

@@ -335,7 +335,7 @@ static QColor colorFromFuncAndArgs(const QString &func, const QStringList &args)
void ColorPreviewHoverHandler::identifyMatch(TextEditorWidget *editorWidget,
int pos, ReportPriority report)
{
const auto cleanup = qScopeGuard([this, report] { report(priority()); });
const QScopeGuard cleanup([this, report] { report(priority()); });
if (editorWidget->extraSelectionTooltip(pos).isEmpty()) {
const QTextBlock tb = editorWidget->document()->findBlock(pos);

View File

@@ -1435,7 +1435,7 @@ void TextEditorWidgetPrivate::print(QPrinter *printer)
return;
doc = doc->clone(doc);
const auto cleanup = qScopeGuard([doc] { delete doc; });
const QScopeGuard cleanup([doc] { delete doc; });
QTextOption opt = doc->defaultTextOption();
opt.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
@@ -2555,7 +2555,7 @@ void TextEditorWidget::keyPressEvent(QKeyEvent *e)
{
ICore::restartTrimmer();
auto clearBlockSelectionGuard = qScopeGuard([&]() { d->clearBlockSelection(); });
QScopeGuard cleanup([&] { d->clearBlockSelection(); });
if (!isModifier(e) && mouseHidingEnabled())
viewport()->setCursor(Qt::BlankCursor);
@@ -2834,7 +2834,7 @@ void TextEditorWidget::keyPressEvent(QKeyEvent *e)
}
if (blockSelectionOperation != QTextCursor::NoMove) {
clearBlockSelectionGuard.dismiss();
cleanup.dismiss();
d->handleMoveBlockSelection(blockSelectionOperation);
} else if (!d->cursorMoveKeyEvent(e)) {
QTextCursor cursor = textCursor();
@@ -5284,7 +5284,7 @@ void TextEditorWidgetPrivate::paintTextMarks(QPainter &painter, const ExtraAreaP
int yoffset = blockBoundingRect.top();
painter.save();
const auto cleanup = qScopeGuard([&painter, size, yoffset, xoffset, overrideIcon] {
const QScopeGuard cleanup([&painter, size, yoffset, xoffset, overrideIcon] {
if (!overrideIcon.isNull()) {
const QRect r(xoffset, yoffset, size, size);
overrideIcon.paint(&painter, r, Qt::AlignCenter);

View File

@@ -32,7 +32,7 @@ int main(int argc, char *argv[])
return 1;
}
auto cleanup = qScopeGuard([] { Utils::Singleton::deleteAll(); });
const QScopeGuard cleanup([] { Utils::Singleton::deleteAll(); });
Utils::Internal::LauncherSocketHandler launcher(app.arguments().constLast());
QTimer::singleShot(0, &launcher, &Utils::Internal::LauncherSocketHandler::start);

View File

@@ -28,7 +28,7 @@ int main(int argc, char **argv)
#endif
QCoreApplication app(argc, argv);
auto cleanup = qScopeGuard([] { Singleton::deleteAll(); });
const QScopeGuard cleanup([] { Singleton::deleteAll(); });
TemporaryDirectory::setMasterTemporaryDirectory(QDir::tempPath() + "/"
+ Core::Constants::IDE_CASED_ID + "-XXXXXX");

View File

@@ -33,7 +33,7 @@ void ProcessTestApp::invokeSubProcess()
{
ProcessTestApp processTestApp;
int returnValue = 1;
auto cleanup = qScopeGuard([&returnValue] {
const QScopeGuard cleanup([&returnValue] {
QMetaObject::invokeMethod(qApp, [returnValue] {
qApp->exit(returnValue);
}, Qt::QueuedConnection);

View File

@@ -13,7 +13,6 @@
#include <QGuiApplication>
#include <QLoggingCategory>
#include <QScopeGuard>
#ifdef WITH_BENCHMARKS
#include <benchmark/benchmark.h>