From bfc3e46f9c39f60a9ae00d642198a28cfe1149e2 Mon Sep 17 00:00:00 2001 From: Sune Vuorela Date: Mon, 15 Apr 2024 17:02:52 +0200 Subject: [PATCH] A collection of cppcheck fixes --- generators/comicbook/document.cpp | 1 + generators/comicbook/unrar.cpp | 1 + generators/djvu/kdjvu.cpp | 2 +- generators/fictionbook/converter.h | 2 +- generators/tiff/generator_tiff.cpp | 2 +- generators/xps/generator_xps.cpp | 8 ++++---- generators/xps/generator_xps.h | 7 +++---- gui/tocmodel.cpp | 8 ++++---- part/formwidgets.h | 2 +- part/presentationwidget.cpp | 6 +++--- 10 files changed, 20 insertions(+), 19 deletions(-) diff --git a/generators/comicbook/document.cpp b/generators/comicbook/document.cpp index e31999fa2..c81caa237 100644 --- a/generators/comicbook/document.cpp +++ b/generators/comicbook/document.cpp @@ -48,6 +48,7 @@ Document::Document() : mDirectory(nullptr) , mUnrar(nullptr) , mArchive(nullptr) + , mArchiveDir(nullptr) { } diff --git a/generators/comicbook/unrar.cpp b/generators/comicbook/unrar.cpp index af92f304d..a54f7f1a5 100644 --- a/generators/comicbook/unrar.cpp +++ b/generators/comicbook/unrar.cpp @@ -107,6 +107,7 @@ UnrarHelper::~UnrarHelper() Unrar::Unrar() : QObject(nullptr) + , mProcess(nullptr) , mLoop(nullptr) , mTempDir(nullptr) { diff --git a/generators/djvu/kdjvu.cpp b/generators/djvu/kdjvu.cpp index 392390b04..370740036 100644 --- a/generators/djvu/kdjvu.cpp +++ b/generators/djvu/kdjvu.cpp @@ -542,7 +542,7 @@ void KDjVu::Private::fillBookmarksRecurse(QDomDocument &maindoc, QDomNode &curno if (dest.at(0) == QLatin1Char('#')) { dest.remove(0, 1); bool isNumber = false; - dest.toInt(&isNumber); + (void)dest.toInt(&isNumber); if (isNumber) { // it might be an actual page number, but could also be a page label // so resolve the number, and get the real page number diff --git a/generators/fictionbook/converter.h b/generators/fictionbook/converter.h index e178a8427..e3317dfc7 100644 --- a/generators/fictionbook/converter.h +++ b/generators/fictionbook/converter.h @@ -71,7 +71,7 @@ private: class DocumentInfo; DocumentInfo *mDocumentInfo; - int mSectionCounter; + int mSectionCounter = 0; QMap mSectionMap; QMap> mLocalLinks; diff --git a/generators/tiff/generator_tiff.cpp b/generators/tiff/generator_tiff.cpp index 59c06cf04..f9cf09085 100644 --- a/generators/tiff/generator_tiff.cpp +++ b/generators/tiff/generator_tiff.cpp @@ -258,7 +258,7 @@ QImage TIFFGenerator::image(Okular::PixmapRequest *request) int reqwidth = request->width(); int reqheight = request->height(); if (rotation % 2 == 1) { - qSwap(reqwidth, reqheight); + std::swap(reqwidth, reqheight); } img = image.scaled(reqwidth, reqheight, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); diff --git a/generators/xps/generator_xps.cpp b/generators/xps/generator_xps.cpp index 0bee6c623..244a7c393 100644 --- a/generators/xps/generator_xps.cpp +++ b/generators/xps/generator_xps.cpp @@ -686,7 +686,7 @@ static QString unicodeString(const QString &raw) return ret; } -void XpsPage::processGlyph(QPainter *painter, XpsRenderNode &node) +void XpsPage::processGlyph(QPainter *painter, const XpsRenderNode &node) { // TODO Currently ignored attributes: CaretStops, DeviceFontName, IsSideways, OpacityMask, Name, FixedPage.NavigateURI, xml:lang, x:key // TODO Indices is only partially implemented @@ -893,7 +893,7 @@ void XpsPage::processImageBrush(XpsRenderNode &node) node.data = QVariant::fromValue(brush); } -void XpsPage::processPath(QPainter *painter, XpsRenderNode &node) +void XpsPage::processPath(QPainter *painter, const XpsRenderNode &node) { // TODO Ignored attributes: Clip, OpacityMask, StrokeEndLineCap, StorkeStartLineCap, Name, FixedPage.NavigateURI, xml:lang, x:key, AutomationProperties.Name, AutomationProperties.HelpText, SnapsToDevicePixels // TODO Ignored child elements: RenderTransform, Clip, OpacityMask @@ -1172,7 +1172,7 @@ void XpsPage::processPathFigure(XpsRenderNode &node) } } -void XpsPage::processStartElement(QPainter *painter, XpsRenderNode &node) +void XpsPage::processStartElement(QPainter *painter, const XpsRenderNode &node) { if (node.name == QLatin1String("Canvas")) { painter->save(); @@ -1982,7 +1982,7 @@ bool XpsGenerator::loadDocument(const QString &fileName, QVector int pagesVectorOffset = 0; for (int docNum = 0; docNum < m_xpsFile->numDocuments(); ++docNum) { - XpsDocument *doc = m_xpsFile->document(docNum); + const XpsDocument *doc = m_xpsFile->document(docNum); for (int pageNum = 0; pageNum < doc->numPages(); ++pageNum) { QSizeF pageSize = doc->page(pageNum)->size(); pagesVector[pagesVectorOffset] = new Okular::Page(pagesVectorOffset, pageSize.width(), pageSize.height(), Okular::Rotation0); diff --git a/generators/xps/generator_xps.h b/generators/xps/generator_xps.h index fb63821b8..bcee64a14 100644 --- a/generators/xps/generator_xps.h +++ b/generators/xps/generator_xps.h @@ -122,10 +122,10 @@ public: private: // Methods for processing of different xml elements - void processStartElement(QPainter *painter, XpsRenderNode &node); + void processStartElement(QPainter *painter, const XpsRenderNode &node); void processEndElement(QPainter *painter, XpsRenderNode &node); - void processGlyph(QPainter *painter, XpsRenderNode &node); - void processPath(QPainter *painter, XpsRenderNode &node); + void processGlyph(QPainter *painter, const XpsRenderNode &node); + void processPath(QPainter *painter, const XpsRenderNode &node); void processPathData(XpsRenderNode &node); void processFill(XpsRenderNode &node); void processStroke(XpsRenderNode &node); @@ -142,7 +142,6 @@ private: QString m_thumbnailFileName; bool m_thumbnailMightBeAvailable; QImage m_thumbnail; - bool m_thumbnailIsLoaded; QImage *m_pageImage; bool m_pageIsRendered; diff --git a/gui/tocmodel.cpp b/gui/tocmodel.cpp index 6621613dd..63acd800b 100644 --- a/gui/tocmodel.cpp +++ b/gui/tocmodel.cpp @@ -226,7 +226,7 @@ QVariant TOCModel::data(const QModelIndex &index, int role) const QFont font; font.setBold(true); - TOCItem *lastHighlighted = d->currentPage.last(); + const TOCItem *lastHighlighted = d->currentPage.last(); // in the mobile version our parent is not a QTreeView; embolden the last highlighted item // TODO misusing parent() here, fix @@ -449,7 +449,7 @@ QString TOCModel::externalFileNameForIndex(const QModelIndex &index) const return QString(); } - TOCItem *item = static_cast(index.internalPointer()); + const TOCItem *item = static_cast(index.internalPointer()); return item->extFileName; } @@ -459,7 +459,7 @@ Okular::DocumentViewport TOCModel::viewportForIndex(const QModelIndex &index) co return Okular::DocumentViewport(); } - TOCItem *item = static_cast(index.internalPointer()); + const TOCItem *item = static_cast(index.internalPointer()); return item->viewport; } @@ -469,7 +469,7 @@ QString TOCModel::urlForIndex(const QModelIndex &index) const return QString(); } - TOCItem *item = static_cast(index.internalPointer()); + const TOCItem *item = static_cast(index.internalPointer()); return item->url; } diff --git a/part/formwidgets.h b/part/formwidgets.h index ab7617110..115b96407 100644 --- a/part/formwidgets.h +++ b/part/formwidgets.h @@ -48,7 +48,7 @@ struct RadioData { } QList ids; - QButtonGroup *group; + QButtonGroup *group = nullptr; }; class FormWidgetsController : public QObject diff --git a/part/presentationwidget.cpp b/part/presentationwidget.cpp index ba46ff731..aa2aed8a7 100644 --- a/part/presentationwidget.cpp +++ b/part/presentationwidget.cpp @@ -78,7 +78,8 @@ // a frame contains a pointer to the page object, its geometry and the // transition effect to the next frame struct PresentationFrame { - PresentationFrame() = default; + explicit PresentationFrame(const Okular::Page *_page) + : page(_page) {}; ~PresentationFrame() { @@ -335,8 +336,7 @@ void PresentationWidget::notifySetup(const QVector &pageSet, int // create the new frames float screenRatio = (float)m_height / (float)m_width; for (const Okular::Page *page : pageSet) { - PresentationFrame *frame = new PresentationFrame(); - frame->page = page; + PresentationFrame *frame = new PresentationFrame(page); const QList annotations = page->annotations(); for (Okular::Annotation *a : annotations) { if (a->subType() == Okular::Annotation::AMovie) {