raw -> smart pointer for musredit where it makes sence.

This commit is contained in:
suter_a 2023-10-21 22:33:19 +02:00
parent be29e55834
commit 89146f3cee
12 changed files with 70 additions and 92 deletions

View File

@ -36,7 +36,7 @@
#include <QPixmap>
#include <QXmlStreamReader>
#include <musredit.h>
#include "musredit.h"
class PAdmin;

View File

@ -219,8 +219,7 @@ PDefaultPaths::PDefaultPaths() : QObject()
*/
PChangeDefaultPathsDialog::PChangeDefaultPathsDialog()
{
fDefaultPath = 0;
fDefaultPath = new PDefaultPaths();
fDefaultPath = std::make_unique<PDefaultPaths>();
if (!fDefaultPath->isValid())
return;

View File

@ -30,6 +30,8 @@
#ifndef _PCHANGEDEFAULTPATHSDIALOG_H_
#define _PCHANGEDEFAULTPATHSDIALOG_H_
#include <memory>
#include <QDialog>
#include <QMessageBox>
#include <QXmlStreamReader>
@ -61,7 +63,7 @@ class PDefaultPathsXMLParser
QXmlStreamReader fXml; ///< xml stream reader object
bool fValid; ///< flag showing if XML read has been successful
EAdminKeyWords fKeyWord; ///< key word tag to know how to handle the content
PDefaultPaths *fDefaultPaths; ///< keeps the default search paths for the data files
PDefaultPaths *fDefaultPaths; ///< keeps the default search paths for the data files
};
//---------------------------------------------------------------------------
@ -98,7 +100,7 @@ class PChangeDefaultPathsDialog : public QDialog, private Ui::PChangeDefaultPath
void saveDefaultPathList();
private:
PDefaultPaths *fDefaultPath;
std::unique_ptr<PDefaultPaths> fDefaultPath;
};
#endif // _PCHANGEDEFAULTPATHSDIALOG_H_

View File

@ -45,20 +45,20 @@ PDumpOutputHandler::PDumpOutputHandler(QVector<QString> &cmd)
return;
// Layout
fVbox = new QVBoxLayout( this );
fOutput = new QTextEdit();
fVbox->addWidget(fOutput);
fVbox = std::make_unique<QVBoxLayout>( this );
fOutput = std::make_unique<QTextEdit>();
fVbox->addWidget(fOutput.get());
fOutput->setMinimumSize(600, 755);
fOutput->setReadOnly(true);
connect( fOutput, SIGNAL( destroyed() ), this, SLOT( quitButtonPressed() ) );
fQuitButton = new QPushButton( tr("Quit") );
fVbox->addWidget(fQuitButton);
connect( fQuitButton, SIGNAL( clicked() ), this, SLOT( quitButtonPressed() ) );
connect( fOutput.get(), SIGNAL( destroyed() ), this, SLOT( quitButtonPressed() ) );
fQuitButton = std::make_unique<QPushButton>( tr("Quit") );
fVbox->addWidget(fQuitButton.get());
connect( fQuitButton.get(), SIGNAL( clicked() ), this, SLOT( quitButtonPressed() ) );
resize( 600, 800 );
fQuitButton->setFocus();
// QProcess related code
fProc = new QProcess( this );
fProc = std::make_unique<QProcess>( this );
// make sure that the system environment variables are properly set
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
@ -75,8 +75,8 @@ PDumpOutputHandler::PDumpOutputHandler(QVector<QString> &cmd)
for (int i=1; i<cmd.size(); i++)
arguments << cmd[i];
connect( fProc, SIGNAL( readyReadStandardOutput() ), this, SLOT( readFromStdOut() ) );
connect( fProc, SIGNAL( readyReadStandardError() ), this, SLOT( readFromStdErr() ) );
connect( fProc.get(), SIGNAL( readyReadStandardOutput() ), this, SLOT( readFromStdOut() ) );
connect( fProc.get(), SIGNAL( readyReadStandardError() ), this, SLOT( readFromStdErr() ) );
fProc->start(program, arguments);
@ -110,10 +110,6 @@ PDumpOutputHandler::~PDumpOutputHandler()
qDebug() << msg << Qt::endl;
system(cmd.toLatin1());
}
if (fProc) {
delete fProc;
fProc = 0;
}
}
//----------------------------------------------------------------------------------------------------

View File

@ -40,6 +40,7 @@
#include <QVector>
#include <cstdlib>
#include <memory>
//---------------------------------------------------------------------------------------
/**
@ -62,11 +63,11 @@ class PDumpOutputHandler : public QDialog
private:
qint64 fProcPID; ///< keeps the process PID
QProcess *fProc; ///< pointer to the dump_header process
std::unique_ptr<QProcess> fProc; ///< pointer to the dump_header process
QVBoxLayout *fVbox; ///< pointer to the dialog layout manager
QTextEdit *fOutput; ///< the captured dump_header output is written (read only) into this text edit object.
QPushButton *fQuitButton; ///< quit button
std::unique_ptr<QVBoxLayout> fVbox; ///< pointer to the dialog layout manager
std::unique_ptr<QTextEdit> fOutput; ///< the captured dump_header output is written (read only) into this text edit object.
std::unique_ptr<QPushButton> fQuitButton; ///< quit button
};
#endif // _PDUMPOUTPUTHANDLER_H_

View File

@ -46,22 +46,22 @@ PFitOutputHandler::PFitOutputHandler(QString workingDirectory, QVector<QString>
return;
// Layout
fVbox = new QVBoxLayout( this );
fVbox = std::make_unique<QVBoxLayout>( this );
//Qt.3x fVbox->resize(800, 500);
fOutput = new QPlainTextEdit();
fOutput = std::make_unique<QPlainTextEdit>();
fOutput->setMaximumBlockCount(1000);
fVbox->addWidget(fOutput);
fVbox->addWidget(fOutput.get());
fOutput->setMinimumSize(800, 455);
fOutput->setReadOnly(true);
connect( fOutput, SIGNAL( destroyed() ), this, SLOT( quitButtonPressed() ) );
fQuitButton = new QPushButton( tr("Fitting...") );
fVbox->addWidget(fQuitButton);
connect( fQuitButton, SIGNAL( clicked() ), this, SLOT( quitButtonPressed() ) );
connect( fOutput.get(), SIGNAL( destroyed() ), this, SLOT( quitButtonPressed() ) );
fQuitButton = std::make_unique<QPushButton>( tr("Fitting...") );
fVbox->addWidget(fQuitButton.get());
connect( fQuitButton.get(), SIGNAL( clicked() ), this, SLOT( quitButtonPressed() ) );
resize( 800, 500 );
fQuitButton->setFocus();
// QProcess related code
fProc = new QProcess( this );
fProc = std::make_unique<QProcess>( this );
// make sure that the system environment variables are properly set
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
@ -79,9 +79,9 @@ PFitOutputHandler::PFitOutputHandler(QString workingDirectory, QVector<QString>
for (int i=1; i<cmd.size(); i++)
arguments << cmd[i];
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) ) );
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) ) );
fProc->start(program, arguments);
if ( !fProc->waitForStarted() ) {
@ -113,10 +113,6 @@ PFitOutputHandler::~PFitOutputHandler()
qDebug() << msg << Qt::endl;
system(cmd.toLatin1());
}
if (fProc) {
delete fProc;
fProc = nullptr;
}
}
//----------------------------------------------------------------------------------------------------

View File

@ -40,6 +40,7 @@
#include <QVector>
#include <cstdlib>
#include <memory>
//---------------------------------------------------------------------------------------
/**
@ -63,11 +64,11 @@ class PFitOutputHandler : public QDialog
private:
qint64 fProcPID; ///< keeps the process PID
QProcess *fProc; ///< pointer to the musrfit process
std::unique_ptr<QProcess> fProc; ///< pointer to the musrfit process
QVBoxLayout *fVbox; ///< pointer to the dialog layout manager
QPlainTextEdit *fOutput; ///< the captured musrfit output is written (read only) into this text edit object.
QPushButton *fQuitButton; ///< quit button, either to interrupt the fit or to close the dialog at the end of the fit.
std::unique_ptr<QVBoxLayout> fVbox; ///< pointer to the dialog layout manager
std::unique_ptr<QPlainTextEdit> fOutput; ///< the captured musrfit output is written (read only) into this text edit object.
std::unique_ptr<QPushButton> fQuitButton; ///< quit button, either to interrupt the fit or to close the dialog at the end of the fit.
};
#endif // _PFITOUTPUTHANDLER_H_

View File

@ -27,6 +27,8 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <memory>
#include "PChangeDefaultPathsDialog.h"
#include "PPrefsDialog.h"
@ -129,13 +131,11 @@ void PPrefsDialog::dumpRoot()
*/
void PPrefsDialog::handleDefaultPaths()
{
PChangeDefaultPathsDialog *dlg = new PChangeDefaultPathsDialog();
std::unique_ptr<PChangeDefaultPathsDialog> dlg = std::make_unique<PChangeDefaultPathsDialog>();
if (dlg->exec() == QDialog::Accepted) {
}
delete dlg;
}
//----------------------------------------------------------------------------------------------------

View File

@ -27,6 +27,8 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <memory>
#include <QAction>
#include <QMenu>
#include <QDateTime>
@ -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<PGetTitleBlockDialog> dlg = std::make_unique<PGetTitleBlockDialog>(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<PGetParameterBlockDialog> dlg = std::make_unique<PGetParameterBlockDialog>(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<PGetTheoryBlockDialog> dlg = std::make_unique<PGetTheoryBlockDialog>(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<PGetFunctionsBlockDialog> dlg = std::make_unique<PGetFunctionsBlockDialog>(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<PGetAsymmetryRunBlockDialog> dlg = std::make_unique<PGetAsymmetryRunBlockDialog>(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<PGetSingleHistoRunBlockDialog> dlg = std::make_unique<PGetSingleHistoRunBlockDialog>(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<PGetNonMusrRunBlockDialog> dlg = std::make_unique<PGetNonMusrRunBlockDialog>(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<PGetFourierBlockDialog> dlg = std::make_unique<PGetFourierBlockDialog>(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<PGetPlotBlockDialog> dlg = std::make_unique<PGetPlotBlockDialog>(fAdmin->getHelpUrl("plot"));
if (dlg == 0)
if (dlg == nullptr)
return;
if (dlg->exec() == QDialog::Accepted) {
insertPlainText(dlg->getPlotBlock()+"\n");
}
delete dlg;
}
//----------------------------------------------------------------------------------------------------

View File

@ -91,7 +91,7 @@ PTextEdit::PTextEdit( QWidget *parent )
bool gotTheme = getTheme();
// reads and manages the conents of the xml-startup (musredit_startup.xml) file
fAdmin = new PAdmin();
fAdmin = std::make_unique<PAdmin>();
// set default setting of the fDarkMenuIconIcons only if a theme has been recognized, otherwise take the
// one from the xml startup file.
@ -166,10 +166,6 @@ PTextEdit::PTextEdit( QWidget *parent )
*/
void PTextEdit::aboutToQuit()
{
if (fAdmin) {
delete fAdmin;
fAdmin = nullptr;
}
if (fMusrT0Action) {
delete fMusrT0Action;
fMusrT0Action = nullptr;
@ -983,7 +979,7 @@ void PTextEdit::load( const QString &f, const int index )
return;
// create a new text edit object
PSubTextEdit *edit = new PSubTextEdit( fAdmin );
PSubTextEdit *edit = new PSubTextEdit( fAdmin.get() );
edit->setFont(QFont(fAdmin->getFontName(), fAdmin->getFontSize()));
// place the text edit object at the appropriate tab position
@ -1167,7 +1163,7 @@ void PTextEdit::insertStatisticBlock()
*/
void PTextEdit::fileNew()
{
PSubTextEdit *edit = new PSubTextEdit( fAdmin );
PSubTextEdit *edit = new PSubTextEdit( fAdmin.get() );
edit->setFont(QFont(fAdmin->getFontName(), fAdmin->getFontSize()));
doConnections( edit );
fTabWidget->addTab( edit, tr( "noname" ) );
@ -2703,7 +2699,7 @@ void PTextEdit::musrFT()
*/
void PTextEdit::musrPrefs()
{
PPrefsDialog *dlg = new PPrefsDialog(fAdmin);
PPrefsDialog *dlg = new PPrefsDialog(fAdmin.get());
if (dlg == nullptr) {
QMessageBox::critical(this, "ERROR musrPrefs", "Couldn't invoke Preferences Dialog.");

View File

@ -43,7 +43,9 @@
#include <QtDebug>
#include <memory>
#include "PAdmin.h"
#include "musredit.h"
class PSubTextEdit;
@ -167,7 +169,7 @@ private slots:
private:
bool fDarkMenuIcon; ///< flag indicating if a dark or plain icon shall be used in the menu pull-downs
bool fDarkToolBarIcon; ///< flag indicating if a dark or plain icon shall be used in the toolbar
PAdmin *fAdmin; ///< pointer to the xml-startup file informations. Needed for different purposes like default working- and executable directories etc.
std::unique_ptr<PAdmin> fAdmin; ///< pointer to the xml-startup file informations. Needed for different purposes like default working- and executable directories etc.
QFileSystemWatcher *fFileSystemWatcher; ///< checks if msr-files are changing on the disk while being open in musredit.
bool fFileSystemWatcherActive; ///< flag to enable/disable the file system watcher
QTimer fFileSystemWatcherTimeout; ///< timer used to re-enable file system watcher. Needed to delay the re-enabling

View File

@ -28,6 +28,7 @@
***************************************************************************/
#include <iostream>
#include <memory>
#include <QApplication>
@ -66,12 +67,12 @@ int main( int argc, char ** argv )
QApplication a( argc, argv );
PTextEdit *mw = new PTextEdit();
std::unique_ptr<PTextEdit> mw = std::make_unique<PTextEdit>();
mw->setWindowTitle( "MusrFit Editor" );
mw->resize( mw->getEditW(), mw->getEditH() );
mw->show();
a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );
a.connect( &a, SIGNAL( aboutToQuit() ), mw, SLOT( aboutToQuit() ) );
a.connect( &a, SIGNAL( aboutToQuit() ), mw.get(), SLOT( aboutToQuit() ) );
return a.exec();
}