From 62e86f42b7bfb6c009f089da51d521007a4cc4d7 Mon Sep 17 00:00:00 2001 From: Andreas Suter Date: Tue, 24 Oct 2023 09:38:37 +0200 Subject: [PATCH] Raw -> Smart Pointers in PSubTextEdit, musredit, qt5. --- src/musredit_qt5/musredit/PSubTextEdit.cpp | 56 ++++++++-------------- 1 file changed, 20 insertions(+), 36 deletions(-) diff --git a/src/musredit_qt5/musredit/PSubTextEdit.cpp b/src/musredit_qt5/musredit/PSubTextEdit.cpp index 9f58b075..ea31f3e9 100644 --- a/src/musredit_qt5/musredit/PSubTextEdit.cpp +++ b/src/musredit_qt5/musredit/PSubTextEdit.cpp @@ -27,6 +27,8 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ +#include + #include #include #include @@ -94,17 +96,15 @@ int PSubTextEdit::getFitType() void PSubTextEdit::insertTitle() { // for the time being the url's are hard coded but should be transfered to the XML startup - PGetTitleBlockDialog *dlg = new PGetTitleBlockDialog(fAdmin->getHelpUrl("title")); + std::unique_ptr dlg = std::make_unique(fAdmin->getHelpUrl("title")); - if (dlg == 0) + if (dlg == nullptr) return; if (dlg->exec() == QDialog::Accepted) { QString title = dlg->getTitle(); insertPlainText(title+"\n"); } - - delete dlg; } //---------------------------------------------------------------------------------------------------- @@ -114,16 +114,14 @@ void PSubTextEdit::insertTitle() void PSubTextEdit::insertParameterBlock() { // for the time being the url's are hard coded but should be transfered to the XML startup - PGetParameterBlockDialog *dlg = new PGetParameterBlockDialog(fAdmin->getHelpUrl("parameters")); + std::unique_ptr dlg = std::make_unique(fAdmin->getHelpUrl("parameters")); - if (dlg == 0) + if (dlg == nullptr) return; if (dlg->exec() == QDialog::Accepted) { insertPlainText(dlg->getParams()); } - - delete dlg; } //---------------------------------------------------------------------------------------------------- @@ -178,17 +176,15 @@ void PSubTextEdit::insertTheoryFunction(QString name) void PSubTextEdit::insertTheoryBlock() { // for the time being the url's are hard coded but should be transfered to the XML startup - PGetTheoryBlockDialog *dlg = new PGetTheoryBlockDialog(fAdmin, fAdmin->getHelpUrl("theory")); + std::unique_ptr dlg = std::make_unique(fAdmin, fAdmin->getHelpUrl("theory")); - if (dlg == 0) + if (dlg == nullptr) return; if (dlg->exec() == QDialog::Accepted) { insertPlainText(dlg->getTheoryBlock()); insertPlainText("\n"); } - - delete dlg; } //---------------------------------------------------------------------------------------------------- @@ -198,17 +194,15 @@ void PSubTextEdit::insertTheoryBlock() void PSubTextEdit::insertFunctionBlock() { // for the time being the url's are hard coded but should be transfered to the XML startup - PGetFunctionsBlockDialog *dlg = new PGetFunctionsBlockDialog(fAdmin->getHelpUrl("functions")); + std::unique_ptr dlg = std::make_unique(fAdmin->getHelpUrl("functions")); - if (dlg == 0) + if (dlg == nullptr) return; if (dlg->exec() == QDialog::Accepted) { insertPlainText(dlg->getFunctionsBlock()); insertPlainText("\n\n"); } - - delete dlg; } //---------------------------------------------------------------------------------------------------- @@ -218,9 +212,9 @@ void PSubTextEdit::insertFunctionBlock() void PSubTextEdit::insertAsymRunBlock() { // for the time being the url's are hard coded but should be transfered to the XML startup - PGetAsymmetryRunBlockDialog *dlg = new PGetAsymmetryRunBlockDialog(fAdmin->getHelpUrl("run")); + std::unique_ptr dlg = std::make_unique(fAdmin->getHelpUrl("run")); - if (dlg == 0) + if (dlg == nullptr) return; if (dlg->exec() == QDialog::Accepted) { @@ -314,8 +308,6 @@ void PSubTextEdit::insertAsymRunBlock() // insert Asymmetry Run Block at the current cursor position insertPlainText(str); } - - delete dlg; } //---------------------------------------------------------------------------------------------------- @@ -325,9 +317,9 @@ void PSubTextEdit::insertAsymRunBlock() void PSubTextEdit::insertSingleHistRunBlock() { // for the time being the url's are hard coded but should be transfered to the XML startup - PGetSingleHistoRunBlockDialog *dlg = new PGetSingleHistoRunBlockDialog(fAdmin->getHelpUrl("run")); + std::unique_ptr dlg = std::make_unique(fAdmin->getHelpUrl("run")); - if (dlg == 0) + if (dlg == nullptr) return; if (dlg->exec() == QDialog::Accepted) { @@ -421,8 +413,6 @@ void PSubTextEdit::insertSingleHistRunBlock() // insert Single Histogram Run Block at the current cursor position insertPlainText(str); } - - delete dlg; } //---------------------------------------------------------------------------------------------------- @@ -431,9 +421,9 @@ void PSubTextEdit::insertSingleHistRunBlock() */ void PSubTextEdit::insertNonMusrRunBlock() { - PGetNonMusrRunBlockDialog *dlg = new PGetNonMusrRunBlockDialog(fAdmin->getHelpUrl("run")); + std::unique_ptr dlg = std::make_unique(fAdmin->getHelpUrl("run")); - if (dlg == 0) + if (dlg == nullptr) return; if (dlg->exec() == QDialog::Accepted) { @@ -484,8 +474,6 @@ void PSubTextEdit::insertNonMusrRunBlock() // insert NonMusr Run Block at the current cursor position insertPlainText(str); } - - delete dlg; } //---------------------------------------------------------------------------------------------------- @@ -511,16 +499,14 @@ void PSubTextEdit::insertCommandBlock() void PSubTextEdit::insertFourierBlock() { // for the time being the url's are hard coded but should be transfered to the XML startup - PGetFourierBlockDialog *dlg = new PGetFourierBlockDialog(fAdmin->getHelpUrl("fourier")); + std::unique_ptr dlg = std::make_unique(fAdmin->getHelpUrl("fourier")); - if (dlg == 0) + if (dlg == nullptr) return; if (dlg->exec() == QDialog::Accepted) { insertPlainText(dlg->getFourierBlock()+"\n"); } - - delete dlg; } //---------------------------------------------------------------------------------------------------- @@ -530,16 +516,14 @@ void PSubTextEdit::insertFourierBlock() void PSubTextEdit::insertPlotBlock() { // for the time being the url's are hard coded but should be transfered to the XML startup - PGetPlotBlockDialog *dlg = new PGetPlotBlockDialog(fAdmin->getHelpUrl("plot")); + std::unique_ptr dlg = std::make_unique(fAdmin->getHelpUrl("plot")); - if (dlg == 0) + if (dlg == nullptr) return; if (dlg->exec() == QDialog::Accepted) { insertPlainText(dlg->getPlotBlock()+"\n"); } - - delete dlg; } //----------------------------------------------------------------------------------------------------