Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rawpointer removal #169

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/control/externprogram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/

CAExternProgram::CAExternProgram(bool bRcvStdErr /* = true */, bool bRcvStdOut /* = true */)
: _poExternProgram(new QProcess())
: _poExternProgram(std::make_unique<QProcess>())
{
_bRcvStdErr = bRcvStdErr;
_oParamDelimiter = " ";
Expand Down
6 changes: 3 additions & 3 deletions src/control/helpctl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ bool CAHelpCtl::showUsersGuide(QString chapter, QWidget* helpWidget)
void CAHelpCtl::displayHelp(QUrl url, QWidget* helpWidget)
{
#ifdef QT_WEBENGINEWIDGETS_LIB
CAHelpBrowser* browser = nullptr;
std::unique_ptr<CAHelpBrowser> browser;
if (!helpWidget) {
browser = new CAHelpBrowser;
browser = std::make_unique<CAHelpBrowser>();
browser->setAttribute(Qt::WA_DeleteOnClose);
} else if (dynamic_cast<CAMainWin*>(helpWidget)) {
browser = static_cast<CAMainWin*>(helpWidget)->helpWidget();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use smart pointet for helpWidget too?

browser = std::unique_ptr<CAHelpBrowser>(static_cast<CAMainWin*>(helpWidget)->helpWidget());
static_cast<CAMainWin*>(helpWidget)->helpDock()->show();
}

Expand Down
4 changes: 2 additions & 2 deletions src/control/mainwinprogressctl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ void CAMainWinProgressCtl::startProgress(CAFile &f)
_updateTimer.reset();
}

_updateTimer = std::make_unique<QTimer>(new QTimer());
_updateTimer = std::make_unique<QTimer>();
_updateTimer->setInterval(150);
_updateTimer->setSingleShot(false);

connect(_updateTimer.get(), SIGNAL(timeout()), this, SLOT(on_updateTimer_timeout()));

_bar = std::make_unique<CAProgressStatusBar>(new CAProgressStatusBar(_mainWin.get()));
_bar = std::make_unique<CAProgressStatusBar>(_mainWin.get());
_mainWin->statusBar()->addWidget(_bar.get());
connect(_bar.get(), SIGNAL(cancelButtonClicked(bool)), this, SLOT(on_cancelButton_clicked(bool)));

Expand Down
2 changes: 1 addition & 1 deletion src/control/resourcectl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
(eg. audio file of a theme), staff (eg. svg images in contemporary music),
voice etc.
You can simply add a resource by calling
CADocument::addResource( new CAResource( "/home/user/title.jpeg", "My image") );
CADocument::addResource( make_shared<CAResource>( "/home/user/title.jpeg", "My image") );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::make_shared


CAResourceContainer takes care of creating copies for non-linked resources.
It picks a random unique name for a new resource in the system temporary file.
Expand Down
34 changes: 11 additions & 23 deletions src/control/typesetctl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,17 @@

CATypesetCtl::CATypesetCtl()
{
_poTypesetter = new CAExternProgram;
_poConvPS2PDF = new CAExternProgram;
_poTypesetter = std::make_unique<CAExternProgram>();
_poConvPS2PDF = std::make_unique<CAExternProgram>();
_poExport = nullptr;
_poOutputFile = nullptr;
_bPDFConversion = false;
_bOutputFileNameFirst = false;
connect(_poTypesetter, SIGNAL(programExited(int)), this, SLOT(typsetterExited(int)));
connect(_poTypesetter, SIGNAL(nextOutput(const QByteArray&)), this, SLOT(rcvTypesetterOutput(const QByteArray&)));
connect(_poTypesetter.get(), SIGNAL(programExited(int)), this, SLOT(typsetterExited(int)));
connect(_poTypesetter.get(), SIGNAL(nextOutput(const QByteArray&)), this, SLOT(rcvTypesetterOutput(const QByteArray&)));
}

// Destructor
CATypesetCtl::~CATypesetCtl()
{
if (_poTypesetter)
delete _poTypesetter;
_poTypesetter = nullptr;
if (_poConvPS2PDF)
delete _poConvPS2PDF;
_poConvPS2PDF = nullptr;
if (_poOutputFile)
delete _poOutputFile;
_poOutputFile = nullptr;
}
CATypesetCtl::~CATypesetCtl() = default;

/*!
Defines the typesetter executable name to be run
Expand Down Expand Up @@ -156,10 +144,10 @@ void CATypesetCtl::exportDocument(CADocument* poDoc)
/// \todo: Add export options to the document directly ?
if (_poExport) {
if (_poOutputFile) {
delete _poOutputFile;
_poOutputFile.reset();
_poTypesetter->clearParameters();
}
_poOutputFile = new QTemporaryFile;
_poOutputFile = std::make_unique<QTemporaryFile>();
// Create the unique file as the file name is only defined when opening the file
_poOutputFile->open();
// Add the input file name as default parameter.
Expand All @@ -169,7 +157,7 @@ void CATypesetCtl::exportDocument(CADocument* poDoc)
// Only add output file name as first parameter file name if it is needed
if (true == _bOutputFileNameFirst)
_poTypesetter->addParameter(_oOutputFileName, false);
_poExport->setStreamToDevice(_poOutputFile);
_poExport->setStreamToDevice(_poOutputFile.get());
_poExport->exportDocument(poDoc);
// @ToDo use signal/slot mechanism to wait for the file
_poExport->wait();
Expand All @@ -191,10 +179,10 @@ void CATypesetCtl::exportSheet(CASheet* poSheet)
/// \todo: Add export options to the document directly ?
if (_poExport) {
if (_poOutputFile) {
delete _poOutputFile;
_poOutputFile.reset();
_poTypesetter->clearParameters();
}
_poOutputFile = new QTemporaryFile;
_poOutputFile = std::make_unique<QTemporaryFile>();
// Create the unique file as the file name is only defined when opening the file
_poOutputFile->open();
// Add the input file name as default parameter.
Expand All @@ -204,7 +192,7 @@ void CATypesetCtl::exportSheet(CASheet* poSheet)
// Only add output file name as first parameter file name if it is needed
if (true == _bOutputFileNameFirst)
_poTypesetter->addParameter(_oOutputFileName, false);
_poExport->setStreamToDevice(_poOutputFile);
_poExport->setStreamToDevice(_poOutputFile.get());
_poExport->exportSheet(poSheet);
// @ToDo use signal/slot mechanism to wait for the file
_poExport->wait();
Expand Down
8 changes: 5 additions & 3 deletions src/control/typesetctl.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include <QVariant>
#include <QVector>

#include <memory>

// Forward declarations
class CAExternProgram;
class CAExport;
Expand Down Expand Up @@ -57,12 +59,12 @@ protected slots:
protected:
bool createPDF();

CAExternProgram* _poTypesetter; // Transforms exported file to pdf / postscript
CAExternProgram* _poConvPS2PDF; // Transforms postscripts files to pdf if needed
std::unique_ptr<CAExternProgram> _poTypesetter; // Transforms exported file to pdf / postscript
std::unique_ptr<CAExternProgram> _poConvPS2PDF; // Transforms postscripts files to pdf if needed
CAExport* _poExport; // Transforms canorus document to typesetter format
QVector<QVariant> _oExpOptList; // List of options for export
QVector<QVariant> _oTSetOptList; // List of options for typesetter
QTemporaryFile* _poOutputFile; // Output file for pdf (also used for exported file)
std::unique_ptr<QTemporaryFile> _poOutputFile; // Output file for pdf (also used for exported file)
QString _oOutputFileName; // Output file name for pdf (temporary file deletes it on close)
bool _bPDFConversion; // Do a conversion from postscript to pdf
bool _bOutputFileNameFirst; // File name as first parameter ? (Default: No)
Expand Down
Loading