From 8f0f2399e2c2c0227ea48c18c4195e0abf9bd892 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 18 Feb 2017 10:43:06 +0200 Subject: [PATCH] Use QScopedPointer to prevent memory leaks. --HG-- branch : develop --- src/app/tape/tmainwindow.cpp | 10 +++++----- src/app/valentina/dialogs/vwidgetdetails.cpp | 2 +- src/app/valentina/dialogs/vwidgetgroups.cpp | 2 +- src/app/valentina/mainwindow.cpp | 10 +++++----- src/libs/vtools/dialogs/tools/dialogpiecepath.cpp | 2 +- src/libs/vtools/dialogs/tools/dialogseamallowance.cpp | 6 +++--- src/libs/vtools/tools/vtoolseamallowance.cpp | 6 +++--- 7 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/app/tape/tmainwindow.cpp b/src/app/tape/tmainwindow.cpp index d130af9f0..91c19b1a6 100644 --- a/src/app/tape/tmainwindow.cpp +++ b/src/app/tape/tmainwindow.cpp @@ -2234,11 +2234,11 @@ bool TMainWindow::MaybeSave() return true;// Don't ask if file was created without modifications. } - QMessageBox *messageBox = new QMessageBox(tr("Unsaved changes"), - tr("Measurements have been modified.\n" - "Do you want to save your changes?"), - QMessageBox::Warning, QMessageBox::Yes, QMessageBox::No, - QMessageBox::Cancel, this, Qt::Sheet); + QScopedPointer messageBox(new QMessageBox(tr("Unsaved changes"), + tr("Measurements have been modified.\n" + "Do you want to save your changes?"), + QMessageBox::Warning, QMessageBox::Yes, QMessageBox::No, + QMessageBox::Cancel, this, Qt::Sheet)); messageBox->setDefaultButton(QMessageBox::Yes); messageBox->setEscapeButton(QMessageBox::Cancel); diff --git a/src/app/valentina/dialogs/vwidgetdetails.cpp b/src/app/valentina/dialogs/vwidgetdetails.cpp index 7fe50975a..5582eed45 100644 --- a/src/app/valentina/dialogs/vwidgetdetails.cpp +++ b/src/app/valentina/dialogs/vwidgetdetails.cpp @@ -183,7 +183,7 @@ void VWidgetDetails::ToggleSectionDetails(bool select) //--------------------------------------------------------------------------------------------------------------------- void VWidgetDetails::ShowContextMenu(const QPoint &pos) { - QMenu *menu = new QMenu(this); + QScopedPointer menu(new QMenu(this)); QAction *actionSelectAll = menu->addAction(tr("Select all")); QAction *actionSelectNone = menu->addAction(tr("Select none")); diff --git a/src/app/valentina/dialogs/vwidgetgroups.cpp b/src/app/valentina/dialogs/vwidgetgroups.cpp index 9b8d77a1c..3d4c19975 100644 --- a/src/app/valentina/dialogs/vwidgetgroups.cpp +++ b/src/app/valentina/dialogs/vwidgetgroups.cpp @@ -103,7 +103,7 @@ void VWidgetGroups::CtxMenu(const QPoint &pos) item = ui->tableWidget->item(row, 0); const quint32 id = item->data(Qt::UserRole).toUInt(); - QMenu *menu = new QMenu(this); + QScopedPointer menu(new QMenu(this)); QAction *actionRename = menu->addAction(tr("Rename")); QAction *actionDelete = menu->addAction(tr("Delete")); QAction *selectedAction = menu->exec(ui->tableWidget->viewport()->mapToGlobal(pos)); diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index bc88e53dd..2e8ba9a24 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -3334,11 +3334,11 @@ bool MainWindow::MaybeSave() { if (this->isWindowModified() && guiEnabled) { - QMessageBox *messageBox = new QMessageBox(tr("Unsaved changes"), - tr("The pattern has been modified.\n" - "Do you want to save your changes?"), - QMessageBox::Warning, QMessageBox::Yes, QMessageBox::No, - QMessageBox::Cancel, this, Qt::Sheet); + QScopedPointer messageBox(new QMessageBox(tr("Unsaved changes"), + tr("The pattern has been modified.\n" + "Do you want to save your changes?"), + QMessageBox::Warning, QMessageBox::Yes, QMessageBox::No, + QMessageBox::Cancel, this, Qt::Sheet)); messageBox->setDefaultButton(QMessageBox::Yes); messageBox->setEscapeButton(QMessageBox::Cancel); diff --git a/src/libs/vtools/dialogs/tools/dialogpiecepath.cpp b/src/libs/vtools/dialogs/tools/dialogpiecepath.cpp index d564d75dd..3956793b1 100644 --- a/src/libs/vtools/dialogs/tools/dialogpiecepath.cpp +++ b/src/libs/vtools/dialogs/tools/dialogpiecepath.cpp @@ -218,7 +218,7 @@ void DialogPiecePath::ShowContextMenu(const QPoint &pos) return; } - QMenu *menu = new QMenu(this); + QScopedPointer menu(new QMenu(this)); QListWidgetItem *rowItem = ui->listWidget->item(row); SCASSERT(rowItem != nullptr); diff --git a/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp b/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp index 79238c680..9387fcae7 100644 --- a/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp +++ b/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp @@ -482,7 +482,7 @@ void DialogSeamAllowance::ShowMainPathContextMenu(const QPoint &pos) return; } - QMenu *menu = new QMenu(this); + QScopedPointer menu(new QMenu(this)); QListWidgetItem *rowItem = ui->listWidgetMainPath->item(row); SCASSERT(rowItem != nullptr); @@ -524,7 +524,7 @@ void DialogSeamAllowance::ShowCustomSAContextMenu(const QPoint &pos) return; } - QMenu *menu = new QMenu(this); + QScopedPointer menu(new QMenu(this)); QAction *actionOption = menu->addAction(QIcon::fromTheme("preferences-other"), tr("Options")); QListWidgetItem *rowItem = ui->listWidgetCustomSA->item(row); @@ -574,7 +574,7 @@ void DialogSeamAllowance::ShowInternalPathsContextMenu(const QPoint &pos) return; } - QMenu *menu = new QMenu(this); + QScopedPointer menu(new QMenu(this)); QAction *actionOption = menu->addAction(QIcon::fromTheme("preferences-other"), tr("Options")); QAction *actionDelete = menu->addAction(QIcon::fromTheme("edit-delete"), tr("Delete")); diff --git a/src/libs/vtools/tools/vtoolseamallowance.cpp b/src/libs/vtools/tools/vtoolseamallowance.cpp index ee18926cd..d324fda3f 100644 --- a/src/libs/vtools/tools/vtoolseamallowance.cpp +++ b/src/libs/vtools/tools/vtoolseamallowance.cpp @@ -1141,7 +1141,7 @@ void VToolSeamAllowance::InitInternalPaths(const VPiece &detail) //--------------------------------------------------------------------------------------------------------------------- void VToolSeamAllowance::DeleteTool(bool ask) { - DeletePiece *delDet = new DeletePiece(doc, id, VAbstractTool::data.GetPiece(id)); + QScopedPointer delDet(new DeletePiece(doc, id, VAbstractTool::data.GetPiece(id))); if (ask) { if (ConfirmDeletion() == QMessageBox::No) @@ -1149,7 +1149,7 @@ void VToolSeamAllowance::DeleteTool(bool ask) return; } /* If UnionDetails tool delete detail no need emit FullParsing.*/ - connect(delDet, &DeletePiece::NeedFullParsing, doc, &VAbstractPattern::NeedFullParsing); + connect(delDet.data(), &DeletePiece::NeedFullParsing, doc, &VAbstractPattern::NeedFullParsing); } // If UnionDetails tool delete the detail this object will be deleted only after full parse. @@ -1168,7 +1168,7 @@ void VToolSeamAllowance::DeleteTool(bool ask) hide();// User shouldn't see this object - qApp->getUndoStack()->push(delDet); + qApp->getUndoStack()->push(delDet.take()); // Throw exception, this will help prevent case when we forget to immediately quit function. VExceptionToolWasDeleted e("Tool was used after deleting.");