Raw -> Smart Pointers in PSubTextEdit, musredit, qt5.

This commit is contained in:
suter_a 2023-10-24 09:38:37 +02:00
parent c18ed68aa8
commit 62e86f42b7

View File

@ -27,6 +27,8 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#include <memory>
#include <QAction> #include <QAction>
#include <QMenu> #include <QMenu>
#include <QDateTime> #include <QDateTime>
@ -94,17 +96,15 @@ int PSubTextEdit::getFitType()
void PSubTextEdit::insertTitle() void PSubTextEdit::insertTitle()
{ {
// for the time being the url's are hard coded but should be transfered to the XML startup // 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<PGetTitleBlockDialog> dlg = std::make_unique<PGetTitleBlockDialog>(fAdmin->getHelpUrl("title"));
if (dlg == 0) if (dlg == nullptr)
return; return;
if (dlg->exec() == QDialog::Accepted) { if (dlg->exec() == QDialog::Accepted) {
QString title = dlg->getTitle(); QString title = dlg->getTitle();
insertPlainText(title+"\n"); insertPlainText(title+"\n");
} }
delete dlg;
} }
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
@ -114,16 +114,14 @@ void PSubTextEdit::insertTitle()
void PSubTextEdit::insertParameterBlock() void PSubTextEdit::insertParameterBlock()
{ {
// for the time being the url's are hard coded but should be transfered to the XML startup // 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<PGetParameterBlockDialog> dlg = std::make_unique<PGetParameterBlockDialog>(fAdmin->getHelpUrl("parameters"));
if (dlg == 0) if (dlg == nullptr)
return; return;
if (dlg->exec() == QDialog::Accepted) { if (dlg->exec() == QDialog::Accepted) {
insertPlainText(dlg->getParams()); insertPlainText(dlg->getParams());
} }
delete dlg;
} }
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
@ -178,17 +176,15 @@ void PSubTextEdit::insertTheoryFunction(QString name)
void PSubTextEdit::insertTheoryBlock() void PSubTextEdit::insertTheoryBlock()
{ {
// for the time being the url's are hard coded but should be transfered to the XML startup // 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<PGetTheoryBlockDialog> dlg = std::make_unique<PGetTheoryBlockDialog>(fAdmin, fAdmin->getHelpUrl("theory"));
if (dlg == 0) if (dlg == nullptr)
return; return;
if (dlg->exec() == QDialog::Accepted) { if (dlg->exec() == QDialog::Accepted) {
insertPlainText(dlg->getTheoryBlock()); insertPlainText(dlg->getTheoryBlock());
insertPlainText("\n"); insertPlainText("\n");
} }
delete dlg;
} }
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
@ -198,17 +194,15 @@ void PSubTextEdit::insertTheoryBlock()
void PSubTextEdit::insertFunctionBlock() void PSubTextEdit::insertFunctionBlock()
{ {
// for the time being the url's are hard coded but should be transfered to the XML startup // 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<PGetFunctionsBlockDialog> dlg = std::make_unique<PGetFunctionsBlockDialog>(fAdmin->getHelpUrl("functions"));
if (dlg == 0) if (dlg == nullptr)
return; return;
if (dlg->exec() == QDialog::Accepted) { if (dlg->exec() == QDialog::Accepted) {
insertPlainText(dlg->getFunctionsBlock()); insertPlainText(dlg->getFunctionsBlock());
insertPlainText("\n\n"); insertPlainText("\n\n");
} }
delete dlg;
} }
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
@ -218,9 +212,9 @@ void PSubTextEdit::insertFunctionBlock()
void PSubTextEdit::insertAsymRunBlock() void PSubTextEdit::insertAsymRunBlock()
{ {
// for the time being the url's are hard coded but should be transfered to the XML startup // 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<PGetAsymmetryRunBlockDialog> dlg = std::make_unique<PGetAsymmetryRunBlockDialog>(fAdmin->getHelpUrl("run"));
if (dlg == 0) if (dlg == nullptr)
return; return;
if (dlg->exec() == QDialog::Accepted) { if (dlg->exec() == QDialog::Accepted) {
@ -314,8 +308,6 @@ void PSubTextEdit::insertAsymRunBlock()
// insert Asymmetry Run Block at the current cursor position // insert Asymmetry Run Block at the current cursor position
insertPlainText(str); insertPlainText(str);
} }
delete dlg;
} }
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
@ -325,9 +317,9 @@ void PSubTextEdit::insertAsymRunBlock()
void PSubTextEdit::insertSingleHistRunBlock() void PSubTextEdit::insertSingleHistRunBlock()
{ {
// for the time being the url's are hard coded but should be transfered to the XML startup // 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<PGetSingleHistoRunBlockDialog> dlg = std::make_unique<PGetSingleHistoRunBlockDialog>(fAdmin->getHelpUrl("run"));
if (dlg == 0) if (dlg == nullptr)
return; return;
if (dlg->exec() == QDialog::Accepted) { if (dlg->exec() == QDialog::Accepted) {
@ -421,8 +413,6 @@ void PSubTextEdit::insertSingleHistRunBlock()
// insert Single Histogram Run Block at the current cursor position // insert Single Histogram Run Block at the current cursor position
insertPlainText(str); insertPlainText(str);
} }
delete dlg;
} }
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
@ -431,9 +421,9 @@ void PSubTextEdit::insertSingleHistRunBlock()
*/ */
void PSubTextEdit::insertNonMusrRunBlock() void PSubTextEdit::insertNonMusrRunBlock()
{ {
PGetNonMusrRunBlockDialog *dlg = new PGetNonMusrRunBlockDialog(fAdmin->getHelpUrl("run")); std::unique_ptr<PGetNonMusrRunBlockDialog> dlg = std::make_unique<PGetNonMusrRunBlockDialog>(fAdmin->getHelpUrl("run"));
if (dlg == 0) if (dlg == nullptr)
return; return;
if (dlg->exec() == QDialog::Accepted) { if (dlg->exec() == QDialog::Accepted) {
@ -484,8 +474,6 @@ void PSubTextEdit::insertNonMusrRunBlock()
// insert NonMusr Run Block at the current cursor position // insert NonMusr Run Block at the current cursor position
insertPlainText(str); insertPlainText(str);
} }
delete dlg;
} }
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
@ -511,16 +499,14 @@ void PSubTextEdit::insertCommandBlock()
void PSubTextEdit::insertFourierBlock() void PSubTextEdit::insertFourierBlock()
{ {
// for the time being the url's are hard coded but should be transfered to the XML startup // 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<PGetFourierBlockDialog> dlg = std::make_unique<PGetFourierBlockDialog>(fAdmin->getHelpUrl("fourier"));
if (dlg == 0) if (dlg == nullptr)
return; return;
if (dlg->exec() == QDialog::Accepted) { if (dlg->exec() == QDialog::Accepted) {
insertPlainText(dlg->getFourierBlock()+"\n"); insertPlainText(dlg->getFourierBlock()+"\n");
} }
delete dlg;
} }
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
@ -530,16 +516,14 @@ void PSubTextEdit::insertFourierBlock()
void PSubTextEdit::insertPlotBlock() void PSubTextEdit::insertPlotBlock()
{ {
// for the time being the url's are hard coded but should be transfered to the XML startup // 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<PGetPlotBlockDialog> dlg = std::make_unique<PGetPlotBlockDialog>(fAdmin->getHelpUrl("plot"));
if (dlg == 0) if (dlg == nullptr)
return; return;
if (dlg->exec() == QDialog::Accepted) { if (dlg->exec() == QDialog::Accepted) {
insertPlainText(dlg->getPlotBlock()+"\n"); insertPlainText(dlg->getPlotBlock()+"\n");
} }
delete dlg;
} }
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------