Raw -> Smart Pointers for musredit qt5.

This commit is contained in:
2023-10-24 09:22:42 +02:00
parent a90af4c342
commit e376e9a2e6
10 changed files with 84 additions and 92 deletions

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.
@ -109,16 +109,14 @@ PTextEdit::PTextEdit( QWidget *parent )
// enable file system watcher. Needed to get notification if the msr-file is changed outside of musrfit at runtime
fFileSystemWatcherActive = true;
fFileSystemWatcher = new QFileSystemWatcher();
fFileSystemWatcher = std::make_unique<QFileSystemWatcher>();
if (fFileSystemWatcher == nullptr) {
QMessageBox::information(this, "**ERROR**", "Couldn't invoke QFileSystemWatcher!");
} else {
connect( fFileSystemWatcher, SIGNAL(fileChanged(const QString&)), this, SLOT(fileChanged(const QString&)));
connect( fFileSystemWatcher.get(), SIGNAL(fileChanged(const QString&)), this, SLOT(fileChanged(const QString&)));
}
// initialize stuff
fMusrT0Action = nullptr;
fMsr2DataParam = nullptr;
fFindReplaceData = nullptr;
@ -129,9 +127,9 @@ PTextEdit::PTextEdit( QWidget *parent )
setupMusrActions();
setupHelpActions();
fTabWidget = new QTabWidget( this );
fTabWidget = std::make_unique<QTabWidget>( this );
fTabWidget->setMovable(true); // allows to shuffle around tabs
setCentralWidget( fTabWidget );
setCentralWidget( fTabWidget.get() );
textFamily(fAdmin->getFontName());
textSize(QString("%1").arg(fAdmin->getFontSize()));
@ -152,7 +150,7 @@ PTextEdit::PTextEdit( QWidget *parent )
fileNew();
}
connect( fTabWidget, SIGNAL( currentChanged(int) ), this, SLOT( applyFontSettings(int) ));
connect( fTabWidget.get(), SIGNAL( currentChanged(int) ), this, SLOT( applyFontSettings(int) ));
fLastDirInUse = fAdmin->getDefaultSavePath();
}
@ -164,14 +162,6 @@ PTextEdit::PTextEdit( QWidget *parent )
*/
void PTextEdit::aboutToQuit()
{
if (fAdmin) {
delete fAdmin;
fAdmin = nullptr;
}
if (fMusrT0Action) {
delete fMusrT0Action;
fMusrT0Action = nullptr;
}
if (fMsr2DataParam) {
delete fMsr2DataParam;
fMsr2DataParam = nullptr;
@ -650,33 +640,33 @@ void PTextEdit::setupTextActions()
tb->setWindowTitle( "Format Actions" );
addToolBar( tb );
fComboFont = new QComboBox();
fComboFont = std::make_unique<QComboBox>();
fComboFont->setEditable(true);
QFontDatabase db;
fComboFont->addItems( db.families() );
connect( fComboFont, SIGNAL( activated( const QString & ) ),
connect( fComboFont.get(), SIGNAL( activated( const QString & ) ),
this, SLOT( textFamily( const QString & ) ) );
QLineEdit *edit = fComboFont->lineEdit();
if (edit == nullptr) {
return;
}
edit->setText( fAdmin->getFontName() );
tb->addWidget(fComboFont);
tb->addWidget(fComboFont.get());
fComboSize = new QComboBox( tb );
fComboSize = std::make_unique<QComboBox>( tb );
fComboSize->setEditable(true);
QList<int> sizes = db.standardSizes();
QList<int>::Iterator it = sizes.begin();
for ( ; it != sizes.end(); ++it )
fComboSize->addItem( QString::number( *it ) );
connect( fComboSize, SIGNAL( activated( const QString & ) ),
connect( fComboSize.get(), SIGNAL( activated( const QString & ) ),
this, SLOT( textSize( const QString & ) ) );
edit = fComboSize->lineEdit();
if (edit == nullptr) {
return;
}
edit->setText( QString("%1").arg(fAdmin->getFontSize()) );
tb->addWidget(fComboSize);
tb->addWidget(fComboSize.get());
}
//----------------------------------------------------------------------------------------------------
@ -868,19 +858,19 @@ void PTextEdit::setupMusrActions()
iconName = QString(":/icons/musrt0-dark.svg");
else
iconName = QString(":/icons/musrt0-plain.svg");
fMusrT0Action = new QAction( QIcon( QPixmap(iconName) ), tr( "&T0" ), this );
fMusrT0Action = std::make_unique<QAction>( QIcon( QPixmap(iconName) ), tr( "&T0" ), this );
fMusrT0Action->setStatusTip( tr("Start musrt0") );
connect( fMusrT0Action, SIGNAL( triggered() ), this, SLOT( musrT0() ) );
menu->addAction(fMusrT0Action);
fActions["musrt0"] = fMusrT0Action;
connect( fMusrT0Action.get(), SIGNAL( triggered() ), this, SLOT( musrT0() ) );
menu->addAction(fMusrT0Action.get());
fActions["musrt0"] = fMusrT0Action.get();
if (!fDarkToolBarIcon) { // tool bar icon is not dark, even though the theme is (ubuntu)
iconName = QString(":/icons/musrt0-plain.svg");
a = new QAction( QIcon( QPixmap(iconName) ), tr( "&T0" ), this );
connect( a, SIGNAL( triggered() ), this, SLOT( musrT0() ) );
}
tb->addAction(fMusrT0Action);
tb->addAction(fMusrT0Action.get());
fMusrT0Action->setEnabled(fAdmin->getEnableMusrT0Flag());
fActions["musrt0-tb"] = fMusrT0Action;
fActions["musrt0-tb"] = fMusrT0Action.get();
// musrFT
if (fDarkMenuIcon)
@ -982,7 +972,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
@ -1022,6 +1012,9 @@ void PTextEdit::load( const QString &f, const int index )
*/
PSubTextEdit *PTextEdit::currentEditor() const
{
if (fTabWidget == nullptr)
return nullptr;
if ( fTabWidget->currentWidget() ) {
if (fTabWidget->currentWidget()->inherits( "PSubTextEdit" )) {
return dynamic_cast<PSubTextEdit*>(fTabWidget->currentWidget());
@ -1163,7 +1156,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" ) );
@ -2715,7 +2708,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.");