From 51520868f1c4f13349baf7acdf3c575f176cd4ae Mon Sep 17 00:00:00 2001 From: Andreas Suter Date: Tue, 24 Oct 2023 12:55:26 +0200 Subject: [PATCH] Raw -> Smart Pointers for mupp, qt5/qt6. --- src/musredit_qt5/mupp/Pmupp.cpp | 8 +- src/musredit_qt5/mupp/Pmupp.h | 4 +- src/musredit_qt5/mupp/PmuppGui.cpp | 182 ++++++++++++-------------- src/musredit_qt5/mupp/PmuppGui.h | 60 +++++---- src/musredit_qt5/mupp/PmuppScript.cpp | 23 +--- src/musredit_qt5/mupp/PmuppScript.h | 7 +- src/musredit_qt6/mupp/Pmupp.cpp | 8 +- src/musredit_qt6/mupp/Pmupp.h | 4 +- src/musredit_qt6/mupp/PmuppGui.cpp | 2 +- 9 files changed, 140 insertions(+), 158 deletions(-) diff --git a/src/musredit_qt5/mupp/Pmupp.cpp b/src/musredit_qt5/mupp/Pmupp.cpp index cc69cc95..30ecfe7b 100644 --- a/src/musredit_qt5/mupp/Pmupp.cpp +++ b/src/musredit_qt5/mupp/Pmupp.cpp @@ -290,10 +290,10 @@ bool PParamDataHandler::ReadParamFile(const QStringList fln, QString &errorMsg) // make sure that the system environment variables are properly set QString cmd(""); - fProc = new QProcess(this); - connect( fProc, SIGNAL( readyReadStandardOutput() ), this, SLOT( readFromStdOut() ) ); - connect( fProc, SIGNAL( readyReadStandardError() ), this, SLOT( readFromStdErr() ) ); - connect( fProc, SIGNAL( finished(int, QProcess::ExitStatus) ), this, SLOT( processDone(int, QProcess::ExitStatus) ) ); + fProc = std::make_unique(this); + connect( fProc.get(), SIGNAL( readyReadStandardOutput() ), this, SLOT( readFromStdOut() ) ); + connect( fProc.get(), SIGNAL( readyReadStandardError() ), this, SLOT( readFromStdErr() ) ); + connect( fProc.get(), SIGNAL( finished(int, QProcess::ExitStatus) ), this, SLOT( processDone(int, QProcess::ExitStatus) ) ); QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); #if defined(Q_OS_DARWIN) diff --git a/src/musredit_qt5/mupp/Pmupp.h b/src/musredit_qt5/mupp/Pmupp.h index f2e40ba7..3ddaa6f2 100644 --- a/src/musredit_qt5/mupp/Pmupp.h +++ b/src/musredit_qt5/mupp/Pmupp.h @@ -30,6 +30,8 @@ #ifndef _PMUPP_H_ #define _PMUPP_H_ +#include + #include #include #include @@ -156,7 +158,7 @@ class PParamDataHandler : public QObject { void newData(); private: - QProcess *fProc; ///< this will be needed if msr2data needs to be called + std::unique_ptr fProc; ///< this will be needed if msr2data needs to be called QVector fCollection; ///< all the collections handeled bool analyzeFileList(const QStringList &fln, QString &collectionName, diff --git a/src/musredit_qt5/mupp/PmuppGui.cpp b/src/musredit_qt5/mupp/PmuppGui.cpp index 566b326e..098adff3 100644 --- a/src/musredit_qt5/mupp/PmuppGui.cpp +++ b/src/musredit_qt5/mupp/PmuppGui.cpp @@ -242,13 +242,8 @@ PmuppGui::PmuppGui(QStringList fln) fDatime = dt.toTime_t(); fMuppInstance = -1; - fMuppPlot = nullptr; - fNormalizeAction = nullptr; - fNormalize = false; - fVarDlg = nullptr; - fMacroPath = QString("./"); fMacroName = QString(""); @@ -287,135 +282,135 @@ PmuppGui::PmuppGui(QStringList fln) setupHelpActions(); // create central widget - fCentralWidget = new QWidget(this); + fCentralWidget = std::make_unique(this); // setup widgets - fBoxLayout_Main = new QBoxLayout(QBoxLayout::TopToBottom); + fBoxLayout_Main = std::make_unique(QBoxLayout::TopToBottom); fBoxLayout_Main->setGeometry(QRect(10, 40, 600, 500)); - fBoxLayout_Top = new QBoxLayout(QBoxLayout::LeftToRight); - fGridLayout_Left = new QGridLayout(); - fGridLayout_Right = new QGridLayout(); - fBoxLayout_Cmd = new QBoxLayout(QBoxLayout::LeftToRight); + fBoxLayout_Top = std::make_unique(QBoxLayout::LeftToRight); + fGridLayout_Left = std::make_unique(); + fGridLayout_Right = std::make_unique(); + fBoxLayout_Cmd = std::make_unique(QBoxLayout::LeftToRight); // label for the collection/parameter list widgets - fColLabel = new QLabel(this); + fColLabel = std::make_unique(this); fColLabel->setText("Collection -> Parameter"); fColLabel->setMaximumHeight(15); // central widget for the collection/parameter list widgets - fColParamSplitter = new QSplitter(Qt::Horizontal, this); + fColParamSplitter = std::make_unique(Qt::Horizontal, this); fColParamSplitter->setMinimumSize(550,330); - fColList = new QListWidget(this); + fColList = std::make_unique(this); fColList->setSelectionMode(QAbstractItemView::ExtendedSelection); - fParamList = new QListWidget(this); + fParamList = std::make_unique(this); // the next two lines enable drag and drop facility (drag) fParamList->setSelectionMode(QAbstractItemView::SingleSelection); fParamList->setDragEnabled(true); - fColParamSplitter->addWidget(fColList); - fColParamSplitter->addWidget(fParamList); + fColParamSplitter->addWidget(fColList.get()); + fColParamSplitter->addWidget(fParamList.get()); - fRemoveCollection = new QPushButton("Remove Collection", this); - fRefreshCollection = new QPushButton("Refresh Collection", this); + fRemoveCollection = std::make_unique("Remove Collection", this); + fRefreshCollection = std::make_unique("Refresh Collection", this); - fGridLayout_Left->addWidget(fColLabel, 1, 1, 1, 2); - fGridLayout_Left->addWidget(fColParamSplitter, 2, 1, 1, 2); - fGridLayout_Left->addWidget(fRemoveCollection, 3, 1); - fGridLayout_Left->addWidget(fRefreshCollection, 3, 2); + fGridLayout_Left->addWidget(fColLabel.get(), 1, 1, 1, 2); + fGridLayout_Left->addWidget(fColParamSplitter.get(), 2, 1, 1, 2); + fGridLayout_Left->addWidget(fRemoveCollection.get(), 3, 1); + fGridLayout_Left->addWidget(fRefreshCollection.get(), 3, 2); // X-axis - fXaxisLabel = new QLabel("x-axis"); - fViewX = new QListWidget(this); + fXaxisLabel = std::make_unique("x-axis"); + fViewX = std::make_unique(this); // the next two lines enable drag and drop facility (copy drop) fViewX->viewport()->setAcceptDrops(true); fViewX->setDropIndicatorShown(true); - fAddX = new QPushButton("add X", this); - fRemoveX = new QPushButton("remove X", this); + fAddX = std::make_unique("add X", this); + fRemoveX = std::make_unique("remove X", this); // Y-axis - fYaxisLabel = new QLabel("y-axis"); - fViewY = new QListWidget(this); + fYaxisLabel = std::make_unique("y-axis"); + fViewY = std::make_unique(this); // the next two lines enable drag and drop facility (copy drop) fViewY->viewport()->setAcceptDrops(true); fViewY->setDropIndicatorShown(true); - fAddY = new QPushButton("add Y", this); - fRemoveY = new QPushButton("remove Y", this); + fAddY = std::make_unique("add Y", this); + fRemoveY = std::make_unique("remove Y", this); // 2 column button's for the right grid - fAddDitto = new QPushButton("Add Ditto", this); - fPlot = new QPushButton("Plot", this); + fAddDitto = std::make_unique("Add Ditto", this); + fPlot = std::make_unique("Plot", this); - fGridLayout_Right->addWidget(fXaxisLabel, 1, 1); - fGridLayout_Right->addWidget(fYaxisLabel, 1, 2); - fGridLayout_Right->addWidget(fViewX, 2, 1); - fGridLayout_Right->addWidget(fViewY, 2, 2); - fGridLayout_Right->addWidget(fAddX, 3, 1); - fGridLayout_Right->addWidget(fAddY, 3, 2); - fGridLayout_Right->addWidget(fRemoveX, 4, 1); - fGridLayout_Right->addWidget(fRemoveY, 4, 2); - fGridLayout_Right->addWidget(fAddDitto, 5, 1, 1, 2); - fGridLayout_Right->addWidget(fPlot, 6, 1, 1, 2); + fGridLayout_Right->addWidget(fXaxisLabel.get(), 1, 1); + fGridLayout_Right->addWidget(fYaxisLabel.get(), 1, 2); + fGridLayout_Right->addWidget(fViewX.get(), 2, 1); + fGridLayout_Right->addWidget(fViewY.get(), 2, 2); + fGridLayout_Right->addWidget(fAddX.get(), 3, 1); + fGridLayout_Right->addWidget(fAddY.get(), 3, 2); + fGridLayout_Right->addWidget(fRemoveX.get(), 4, 1); + fGridLayout_Right->addWidget(fRemoveY.get(), 4, 2); + fGridLayout_Right->addWidget(fAddDitto.get(), 5, 1, 1, 2); + fGridLayout_Right->addWidget(fPlot.get(), 6, 1, 1, 2); - fBoxLayout_Top->addLayout(fGridLayout_Left); - fBoxLayout_Top->addLayout(fGridLayout_Right); + fBoxLayout_Top->addLayout(fGridLayout_Left.get()); + fBoxLayout_Top->addLayout(fGridLayout_Right.get()); - fCmdLineHistory = new QPlainTextEdit(this); + fCmdLineHistory = std::make_unique(this); fCmdLineHistory->setReadOnly(true); fCmdLineHistory->setMaximumBlockCount(50); // fill cmd history for (int i=0; iinsertPlainText(QString("%1\n").arg(fCmdHistory[i])); - fCmdLine = new QLineEdit(this); + fCmdLine = std::make_unique(this); fCmdLine->installEventFilter(this); fCmdLine->setText("$ "); fCmdLine->setFocus(); // sets the keyboard focus - fExitButton = new QPushButton("E&xit", this); + fExitButton = std::make_unique("E&xit", this); QVBoxLayout *cmdLayout = new QVBoxLayout; QLabel *cmdLabel = new QLabel("History:"); cmdLayout->addWidget(cmdLabel); - cmdLayout->addWidget(fCmdLineHistory); - cmdLayout->addWidget(fCmdLine); + cmdLayout->addWidget(fCmdLineHistory.get()); + cmdLayout->addWidget(fCmdLine.get()); - fBoxLayout_Cmd = new QBoxLayout(QBoxLayout::LeftToRight); + fBoxLayout_Cmd = std::make_unique(QBoxLayout::LeftToRight); fBoxLayout_Cmd->addLayout(cmdLayout); - fBoxLayout_Cmd->addWidget(fExitButton); - fBoxLayout_Cmd->setAlignment(fCmdLine, Qt::AlignBottom); - fBoxLayout_Cmd->setAlignment(fExitButton, Qt::AlignBottom); + fBoxLayout_Cmd->addWidget(fExitButton.get()); + fBoxLayout_Cmd->setAlignment(fCmdLine.get(), Qt::AlignBottom); + fBoxLayout_Cmd->setAlignment(fExitButton.get(), Qt::AlignBottom); - fCmdSplitter = new QSplitter(Qt::Vertical, this); + fCmdSplitter = std::make_unique(Qt::Vertical, this); QWidget *topWidget = new QWidget(this); // only needed since splitter needs a QWidget - topWidget->setLayout(fBoxLayout_Top); + topWidget->setLayout(fBoxLayout_Top.get()); QWidget *cmdWidget = new QWidget(this); // only needed since splitter needs a QWidget - cmdWidget->setLayout(fBoxLayout_Cmd); + cmdWidget->setLayout(fBoxLayout_Cmd.get()); fCmdSplitter->addWidget(topWidget); fCmdSplitter->addWidget(cmdWidget); - fBoxLayout_Main->addWidget(fCmdSplitter); + fBoxLayout_Main->addWidget(fCmdSplitter.get()); // establish all the necessary signal/slots - connect(fRefreshCollection, SIGNAL( pressed() ), this, SLOT( refresh() )); - connect(fRemoveCollection, SIGNAL( pressed() ), this, SLOT( remove() )); - connect(fAddX, SIGNAL( pressed() ), this, SLOT( addX() )); - connect(fAddY, SIGNAL( pressed() ), this, SLOT( addY() )); - connect(fRemoveX, SIGNAL( pressed() ), this, SLOT( removeX() )); - connect(fRemoveY, SIGNAL( pressed() ), this, SLOT( removeY() )); - connect(fAddDitto, SIGNAL( pressed() ), this, SLOT( addDitto() )); - connect(fPlot, SIGNAL( pressed()), this, SLOT( plot()) ); - connect(fCmdLine, SIGNAL ( returnPressed() ), this, SLOT( handleCmds() )); - connect(fExitButton, SIGNAL( pressed() ), this, SLOT( aboutToQuit() )); + connect(fRefreshCollection.get(), SIGNAL( pressed() ), this, SLOT( refresh() )); + connect(fRemoveCollection.get(), SIGNAL( pressed() ), this, SLOT( remove() )); + connect(fAddX.get(), SIGNAL( pressed() ), this, SLOT( addX() )); + connect(fAddY.get(), SIGNAL( pressed() ), this, SLOT( addY() )); + connect(fRemoveX.get(), SIGNAL( pressed() ), this, SLOT( removeX() )); + connect(fRemoveY.get(), SIGNAL( pressed() ), this, SLOT( removeY() )); + connect(fAddDitto.get(), SIGNAL( pressed() ), this, SLOT( addDitto() )); + connect(fPlot.get(), SIGNAL( pressed()), this, SLOT( plot()) ); + connect(fCmdLine.get(), SIGNAL ( returnPressed() ), this, SLOT( handleCmds() )); + connect(fExitButton.get(), SIGNAL( pressed() ), this, SLOT( aboutToQuit() )); - connect(fColList, SIGNAL( currentRowChanged(int) ), this, SLOT( updateParamList(int) )); - connect(fColList, SIGNAL( itemDoubleClicked(QListWidgetItem*) ), this, SLOT( editCollName(QListWidgetItem*) )); + connect(fColList.get(), SIGNAL( currentRowChanged(int) ), this, SLOT( updateParamList(int) )); + connect(fColList.get(), SIGNAL( itemDoubleClicked(QListWidgetItem*) ), this, SLOT( editCollName(QListWidgetItem*) )); - connect(fViewX, SIGNAL( currentRowChanged(int) ), this, SLOT( refreshY() )); - connect(fViewX, SIGNAL( itemChanged(QListWidgetItem*) ), this, SLOT( dropOnViewX(QListWidgetItem*) )); - connect(fViewY, SIGNAL( itemChanged(QListWidgetItem*) ), this, SLOT( dropOnViewY(QListWidgetItem*) )); + connect(fViewX.get(), SIGNAL( currentRowChanged(int) ), this, SLOT( refreshY() )); + connect(fViewX.get(), SIGNAL( itemChanged(QListWidgetItem*) ), this, SLOT( dropOnViewX(QListWidgetItem*) )); + connect(fViewY.get(), SIGNAL( itemChanged(QListWidgetItem*) ), this, SLOT( dropOnViewY(QListWidgetItem*) )); // deal with parameter data specifics if (dataAtStartup) @@ -423,8 +418,8 @@ PmuppGui::PmuppGui(QStringList fln) connect(fParamDataHandler, SIGNAL( newData() ), this, SLOT( handleNewData() )); - fCentralWidget->setLayout(fBoxLayout_Main); - setCentralWidget(fCentralWidget); + fCentralWidget->setLayout(fBoxLayout_Main.get()); + setCentralWidget(fCentralWidget.get()); // in case there is no db/dat file list given open the db/dat file open menu automatically. if (fln.size() == 0) { @@ -593,11 +588,11 @@ void PmuppGui::setupToolActions() menu->addSeparator(); - fNormalizeAction = new QAction(tr( "Normalize" ), this); + fNormalizeAction = std::make_unique(tr( "Normalize" ), this); fNormalizeAction->setStatusTip( tr("Plot Data Normalized (y-axis)") ); fNormalizeAction->setCheckable(true); - connect( fNormalizeAction, SIGNAL( changed() ), this, SLOT( normalize() ) ); - menu->addAction(fNormalizeAction); + connect( fNormalizeAction.get(), SIGNAL( changed() ), this, SLOT( normalize() ) ); + menu->addAction(fNormalizeAction.get()); } //----------------------------------------------------------------------------- @@ -1319,13 +1314,10 @@ void PmuppGui::addVar() } // call variable dialog - if (fVarDlg != nullptr) { - delete fVarDlg; - fVarDlg = nullptr; - } - fVarDlg = new PVarDialog(collection_list, fDarkTheme); - connect(fVarDlg, SIGNAL(check_request(QString,QVector)), this, SLOT(check(QString,QVector))); - connect(fVarDlg, SIGNAL(add_request(QString,QVector)), this, SLOT(add(QString,QVector))); + fVarDlg.reset(); + fVarDlg = std::make_unique(collection_list, fDarkTheme); + connect(fVarDlg.get(), SIGNAL(check_request(QString,QVector)), this, SLOT(check(QString,QVector))); + connect(fVarDlg.get(), SIGNAL(add_request(QString,QVector)), this, SLOT(add(QString,QVector))); fVarDlg->show(); } @@ -2398,7 +2390,7 @@ void PmuppGui::plot() } // start native ROOT parameter plot application if not already running - if (fMuppPlot == 0) { // not running yet + if (fMuppPlot == nullptr) { // not running yet startMuppPlot(); } else { // check if mupp_plot is still running @@ -2425,9 +2417,9 @@ void PmuppGui::startMuppPlot() // feed the mupp instance arg << QString("%1").arg(fMuppInstance); - fMuppPlot = new QProcess(this); + fMuppPlot = std::make_unique(this); if (fMuppPlot == nullptr) { - QMessageBox::critical(0, "**ERROR**", "Couldn't invoke QProcess for mupp_plot!"); + QMessageBox::critical(this, "**ERROR**", "Couldn't invoke QProcess for mupp_plot!"); return; } @@ -2443,7 +2435,7 @@ void PmuppGui::startMuppPlot() if (!fMuppPlot->waitForStarted()) { // error handling QString msg(tr("Could not execute the output command: ")+cmd); - QMessageBox::critical( 0, + QMessageBox::critical(this, tr("Fatal error"), msg, tr("Quit") ); @@ -2490,7 +2482,7 @@ void PmuppGui::handleCmds() fMacroName = tok[1]; createMacro(); } else if (cmd.startsWith("path")) { // cmd: path - QMessageBox::information(0, "INFO", "set's eventually the path for the macros to be saved."); + QMessageBox::information(this, "INFO", "set's eventually the path for the macros to be saved."); // will set the path to where to save the macro #if (QT_VERSION < QT_VERSION_CHECK(5, 14, 0)) QStringList tok = cmd.split(" ", QString::SkipEmptyParts); @@ -2514,7 +2506,7 @@ void PmuppGui::handleCmds() QString fullPath = env.value(envVar); // get environment variable value if present, otherwise "" is returned if (fullPath.isEmpty()) { fMacroPath = ""; - QMessageBox::critical(0, "ERROR", QString("Environment variable '%1' not present. Typo?!").arg(envVar.prepend("$"))); + QMessageBox::critical(this, "ERROR", QString("Environment variable '%1' not present. Typo?!").arg(envVar.prepend("$"))); return; } fMacroPath.replace(envVar.prepend("$"), fullPath); @@ -2530,7 +2522,7 @@ void PmuppGui::handleCmds() if (tok.size() > 1) addX(tok[1]); else - QMessageBox::critical(0, "ERROR", QString("Found command 'x' without variable.")); + QMessageBox::critical(this, "ERROR", QString("Found command 'x' without variable.")); } else if (cmd.startsWith("y")) { #if (QT_VERSION < QT_VERSION_CHECK(5, 14, 0)) QStringList tok = cmd.split(" ", QString::SkipEmptyParts); @@ -2540,7 +2532,7 @@ void PmuppGui::handleCmds() if (tok.size() > 1) addY(tok[1]); else - QMessageBox::critical(0, "ERROR", QString("Found command 'y' without variable.")); + QMessageBox::critical(this, "ERROR", QString("Found command 'y' without variable.")); } else if (cmd.startsWith("ditto")) { addDitto(); } else if (cmd.startsWith("rmx")) { @@ -2552,7 +2544,7 @@ void PmuppGui::handleCmds() if (tok.size() > 1) removeX(tok[1]); else - QMessageBox::critical(0, "ERROR", QString("Found command 'rmx' without variable.")); + QMessageBox::critical(this, "ERROR", QString("Found command 'rmx' without variable.")); } else if (cmd.startsWith("rmy")) { #if (QT_VERSION < QT_VERSION_CHECK(5, 14, 0)) QStringList tok = cmd.split(" ", QString::SkipEmptyParts); @@ -2562,7 +2554,7 @@ void PmuppGui::handleCmds() if (tok.size() > 1) removeY(tok[1]); else - QMessageBox::critical(0, "ERROR", QString("Found command 'rmy' without variable.")); + QMessageBox::critical(this, "ERROR", QString("Found command 'rmy' without variable.")); } else if (cmd.startsWith("norm")) { #if (QT_VERSION < QT_VERSION_CHECK(5, 14, 0)) QStringList tok = cmd.split(" ", QString::SkipEmptyParts); diff --git a/src/musredit_qt5/mupp/PmuppGui.h b/src/musredit_qt5/mupp/PmuppGui.h index e57a0301..cee0738b 100644 --- a/src/musredit_qt5/mupp/PmuppGui.h +++ b/src/musredit_qt5/mupp/PmuppGui.h @@ -30,6 +30,8 @@ #ifndef _PMUPPGUI_H_ #define _PMUPPGUI_H_ +#include + #include #include #include @@ -171,44 +173,44 @@ private: QString fMacroPath; QString fMacroName; - QWidget *fCentralWidget; + std::unique_ptr fCentralWidget; QMenu *fRecentFilesMenu; ///< recent file menu QAction *fRecentFilesAction[MAX_RECENT_FILES]; ///< array of the recent file actions - QAction *fNormalizeAction; + std::unique_ptr fNormalizeAction; - QBoxLayout *fBoxLayout_Main; // top->bottom (0) - QBoxLayout *fBoxLayout_Top; // left->right (1) - QGridLayout *fGridLayout_Left; // 2 columns, 3 rows - QGridLayout *fGridLayout_Right; // 2 columns, 6 rows - QBoxLayout *fBoxLayout_Cmd; // left->right (1) + std::unique_ptr fBoxLayout_Main; // top->bottom (0) + std::unique_ptr fBoxLayout_Top; // left->right (1) + std::unique_ptr fGridLayout_Left; // 2 columns, 3 rows + std::unique_ptr fGridLayout_Right; // 2 columns, 6 rows + std::unique_ptr fBoxLayout_Cmd; // left->right (1) - QLabel *fColLabel; - QSplitter *fColParamSplitter; - QListWidget *fColList; - QListWidget *fParamList; - QPushButton *fRemoveCollection; - QPushButton *fRefreshCollection; - QLabel *fXaxisLabel; - QLabel *fYaxisLabel; - QListWidget *fViewX; - QListWidget *fViewY; - QPushButton *fAddX; - QPushButton *fAddY; - QPushButton *fAddDitto; - QPushButton *fRemoveX; - QPushButton *fRemoveY; - QPushButton *fPlot; - QSplitter *fCmdSplitter; - QPlainTextEdit *fCmdLineHistory; - QLineEdit *fCmdLine; - QPushButton *fExitButton; + std::unique_ptr fColLabel; + std::unique_ptr fColParamSplitter; + std::unique_ptr fColList; + std::unique_ptr fParamList; + std::unique_ptr fRemoveCollection; + std::unique_ptr fRefreshCollection; + std::unique_ptr fXaxisLabel; + std::unique_ptr fYaxisLabel; + std::unique_ptr fViewX; + std::unique_ptr fViewY; + std::unique_ptr fAddX; + std::unique_ptr fAddY; + std::unique_ptr fAddDitto; + std::unique_ptr fRemoveX; + std::unique_ptr fRemoveY; + std::unique_ptr fPlot; + std::unique_ptr fCmdSplitter; + std::unique_ptr fCmdLineHistory; + std::unique_ptr fCmdLine; + std::unique_ptr fExitButton; QVector fCmdHistory; ///< command history buffer - PVarDialog *fVarDlg; ///< variable dialog + std::unique_ptr fVarDlg; ///< variable dialog - QProcess *fMuppPlot; ///< mupp plotter + std::unique_ptr fMuppPlot; ///< mupp plotter void setupFileActions(); void setupToolActions(); diff --git a/src/musredit_qt5/mupp/PmuppScript.cpp b/src/musredit_qt5/mupp/PmuppScript.cpp index 6c4981f0..76d2b5c5 100644 --- a/src/musredit_qt5/mupp/PmuppScript.cpp +++ b/src/musredit_qt5/mupp/PmuppScript.cpp @@ -49,31 +49,14 @@ PmuppScript::PmuppScript(QStringList script) : fScript(script) { - fParamDataHandler = 0; fLoadPath = QString("./"); fSavePath = QString("./"); fSelected = -2; // nothing selected fNorm = false; - fAdmin = new PmuppAdmin(); + fAdmin = std::make_unique(); } -//-------------------------------------------------------------------------- -/** - * @brief PmuppScript::~PmuppScript. Dtor - */ -PmuppScript::~PmuppScript() -{ - if (fParamDataHandler) { - delete fParamDataHandler; - fParamDataHandler = 0; - } - - if (fAdmin) { - delete fAdmin; - fAdmin = 0; - } -} //-------------------------------------------------------------------------- /** * @brief PmuppScript::executeScript. Handles the script commands. @@ -81,8 +64,8 @@ PmuppScript::~PmuppScript() */ int PmuppScript::executeScript() { - fParamDataHandler = new PParamDataHandler(); - if (fParamDataHandler == 0) { + fParamDataHandler = std::make_unique(); + if (fParamDataHandler == nullptr) { std::cerr << std::endl << "**ERROR** couldn't invoke data handler ..." << std::endl << std::endl; return -1; } diff --git a/src/musredit_qt5/mupp/PmuppScript.h b/src/musredit_qt5/mupp/PmuppScript.h index a73b2cde..e725d05c 100644 --- a/src/musredit_qt5/mupp/PmuppScript.h +++ b/src/musredit_qt5/mupp/PmuppScript.h @@ -30,6 +30,8 @@ #ifndef _PMUPPSCRIPT_H_ #define _PMUPPSCRIPT_H_ +#include + #include #include @@ -55,7 +57,6 @@ class PmuppScript : public QObject public: PmuppScript(QStringList script); - ~PmuppScript(); void setLoadPath(const QString cmd); QString getLoadPath() { return fLoadPath; } @@ -79,10 +80,10 @@ class PmuppScript : public QObject void finished(); private: - PmuppAdmin *fAdmin; ///< admin object + std::unique_ptr fAdmin; ///< admin object QStringList fScript; ///< script source - PParamDataHandler *fParamDataHandler; ///< parameter data handler + std::unique_ptr fParamDataHandler; ///< parameter data handler int fSelected; ///< -2=nothing selected, -1=all selected, >=0 is the index if the selected collection PmuppPlotEntry fPlotEntry; ///< plot entry object diff --git a/src/musredit_qt6/mupp/Pmupp.cpp b/src/musredit_qt6/mupp/Pmupp.cpp index 1e94bc61..412e5bf3 100644 --- a/src/musredit_qt6/mupp/Pmupp.cpp +++ b/src/musredit_qt6/mupp/Pmupp.cpp @@ -291,10 +291,10 @@ bool PParamDataHandler::ReadParamFile(const QStringList fln, QString &errorMsg) // make sure that the system environment variables are properly set QString cmd(""); - fProc = new QProcess(this); - connect( fProc, SIGNAL( readyReadStandardOutput() ), this, SLOT( readFromStdOut() ) ); - connect( fProc, SIGNAL( readyReadStandardError() ), this, SLOT( readFromStdErr() ) ); - connect( fProc, SIGNAL( finished(int, QProcess::ExitStatus) ), this, SLOT( processDone(int, QProcess::ExitStatus) ) ); + fProc = std::make_unique(this); + connect( fProc.get(), SIGNAL( readyReadStandardOutput() ), this, SLOT( readFromStdOut() ) ); + connect( fProc.get(), SIGNAL( readyReadStandardError() ), this, SLOT( readFromStdErr() ) ); + connect( fProc.get(), SIGNAL( finished(int, QProcess::ExitStatus) ), this, SLOT( processDone(int, QProcess::ExitStatus) ) ); QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); #if defined(Q_OS_DARWIN) diff --git a/src/musredit_qt6/mupp/Pmupp.h b/src/musredit_qt6/mupp/Pmupp.h index f2e40ba7..3ddaa6f2 100644 --- a/src/musredit_qt6/mupp/Pmupp.h +++ b/src/musredit_qt6/mupp/Pmupp.h @@ -30,6 +30,8 @@ #ifndef _PMUPP_H_ #define _PMUPP_H_ +#include + #include #include #include @@ -156,7 +158,7 @@ class PParamDataHandler : public QObject { void newData(); private: - QProcess *fProc; ///< this will be needed if msr2data needs to be called + std::unique_ptr fProc; ///< this will be needed if msr2data needs to be called QVector fCollection; ///< all the collections handeled bool analyzeFileList(const QStringList &fln, QString &collectionName, diff --git a/src/musredit_qt6/mupp/PmuppGui.cpp b/src/musredit_qt6/mupp/PmuppGui.cpp index 9e89e049..f21f9ee1 100644 --- a/src/musredit_qt6/mupp/PmuppGui.cpp +++ b/src/musredit_qt6/mupp/PmuppGui.cpp @@ -2199,7 +2199,7 @@ void PmuppGui::plot() } // start native ROOT parameter plot application if not already running - if (fMuppPlot == 0) { // not running yet + if (fMuppPlot == nullptr) { // not running yet startMuppPlot(); } else { // check if mupp_plot is still running