Use std::unique_ptr for pdf objects

This commit is contained in:
Felix Kauselmann
2022-11-13 16:17:02 +01:00
parent 0414104067
commit be85954b0c
3 changed files with 14 additions and 35 deletions

View File

@ -796,24 +796,22 @@ bool PDFComic::load(const QString &path, const ComicDB &comic)
void PDFComic::process()
{
#if defined Q_OS_MAC && defined USE_PDFKIT
pdfComic = new MacOSXPDFComic();
pdfComic = std::make_unique<MacOSXPDFComic>();
if (!pdfComic->openComic(_path)) {
delete pdfComic;
emit errorOpening();
return;
}
#elif defined USE_PDFIUM
pdfComic = new PdfiumComic();
pdfComic = std::make_unique<PdfiumComic>();
if (!pdfComic->openComic(_path)) {
delete pdfComic;
emit errorOpening();
return;
}
#else
pdfComic = Poppler::Document::load(_path);
auto _pdfComic = Poppler::Document::load(_path);
pdfComic = std::unique_ptr<Poppler::Document>(_pdfComic);
if (!pdfComic) {
// delete pdfComic;
// pdfComic = 0;
moveToThread(QCoreApplication::instance()->thread());
emit errorOpening();
return;
@ -824,7 +822,6 @@ void PDFComic::process()
return;
}
// pdfComic->setRenderHint(Poppler::Document::Antialiasing, true);
pdfComic->setRenderHint(Poppler::Document::TextAntialiasing, true);
#endif
@ -853,7 +850,6 @@ void PDFComic::process()
int buffered_index = _index;
for (int i = buffered_index; i < nPages; i++) {
if (_invalidated) {
delete pdfComic;
moveToThread(QCoreApplication::instance()->thread());
return;
}
@ -862,14 +858,12 @@ void PDFComic::process()
}
for (int i = 0; i < buffered_index; i++) {
if (_invalidated) {
delete pdfComic;
moveToThread(QCoreApplication::instance()->thread());
return;
}
renderPage(i);
}
delete pdfComic;
moveToThread(QCoreApplication::instance()->thread());
emit imagesLoaded();
}
@ -883,10 +877,9 @@ void PDFComic::renderPage(int page)
QImage img = pdfComic->getPage(page);
if (!img.isNull()) {
#else
Poppler::Page *pdfpage = pdfComic->page(page);
std::unique_ptr<Poppler::Page> pdfpage (pdfComic->page(page));
if (pdfpage) {
QImage img = pdfpage->renderToImage(150, 150);
delete pdfpage;
#endif
QByteArray ba;
QBuffer buf(&ba);

View File

@ -165,11 +165,11 @@ class PDFComic : public Comic
private:
// pdf
#if defined Q_OS_MAC && defined USE_PDFKIT
MacOSXPDFComic *pdfComic;
std::unique_ptr<MacOSXPDFComic> pdfComic;
#elif defined USE_PDFIUM
PdfiumComic *pdfComic;
std::unique_ptr<PdfiumComic> pdfComic;
#else
Poppler::Document *pdfComic;
std::unique_ptr<Poppler::Document> pdfComic;
#endif
void renderPage(int page);
// void run();