Various minor fixes

Mostly derived from cppcheck runs
This commit is contained in:
Sune Vuorela 2024-04-16 15:00:40 +02:00
parent 9f93a01268
commit 4509b7bc42
12 changed files with 114 additions and 193 deletions

View file

@ -47,12 +47,11 @@ static bool isLeftOfVector(const NormalizedPoint &a, const NormalizedPoint &b, c
static double distanceSqr(double x, double y, double xScale, double yScale, const QList<NormalizedPoint> &path)
{
double distance = DBL_MAX;
double thisDistance;
QList<NormalizedPoint>::const_iterator i = path.constBegin();
NormalizedPoint lastPoint = *i;
for (++i; i != path.constEnd(); ++i) {
thisDistance = NormalizedPoint::distanceSqr(x, y, xScale, yScale, lastPoint, (*i));
double thisDistance = NormalizedPoint::distanceSqr(x, y, xScale, yScale, lastPoint, (*i));
if (thisDistance < distance) {
distance = thisDistance;
@ -155,7 +154,7 @@ QDomElement AnnotationUtils::findChildElement(const QDomNode &parentNode, const
QRect AnnotationUtils::annotationGeometry(const Annotation *annotation, double scaleX, double scaleY)
{
const QRect rect = annotation->transformedBoundingRectangle().geometry((int)scaleX, (int)scaleY);
if (annotation->subType() == Annotation::AText && (((TextAnnotation *)annotation)->textType() == TextAnnotation::Linked)) {
if (annotation->subType() == Annotation::AText && (static_cast<const TextAnnotation *>(annotation)->textType() == TextAnnotation::Linked)) {
// To be honest i have no clue of why the 24,24 is here, maybe to make sure it's not too small?
// But why only for linked text?
const QRect rect24 = QRect((int)(annotation->transformedBoundingRectangle().left * scaleX), (int)(annotation->transformedBoundingRectangle().top * scaleY), 24, 24);
@ -1608,7 +1607,7 @@ void LineAnnotation::store(QDomNode &node, QDomDocument &document) const
lineElement.appendChild(pElement);
pElement.setAttribute(QStringLiteral("x"), QString::number(p.x));
pElement.setAttribute(QStringLiteral("y"), QString::number(p.y));
it++; // to avoid loop
++it; // to avoid loop
}
}
}

View file

@ -2503,7 +2503,6 @@ Document::OpenResult Document::openDocument(const QString &docFile, const QUrl &
p->d->m_doc = d;
}
d->m_metadataLoadingCompleted = false;
d->m_docdataMigrationNeeded = false;
// 2. load Additional Data (bookmarks, local annotations and metadata) about the document
@ -2519,7 +2518,6 @@ Document::OpenResult Document::openDocument(const QString &docFile, const QUrl &
d->loadDocumentInfo(LoadGeneralInfo);
}
d->m_metadataLoadingCompleted = true;
d->m_bookmarkManager->setUrl(d->m_url);
// 3. setup observers internal lists and data

View file

@ -106,6 +106,7 @@ class DocumentPrivate
public:
explicit DocumentPrivate(Document *parent)
: m_parent(parent)
, m_searchCancelled(false)
, m_tempFile(nullptr)
, m_docSize(-1)
, m_allocatedPixmapsTotalMemory(0)
@ -327,7 +328,6 @@ public:
bool m_annotationEditingEnabled;
bool m_annotationBeingModified; // is an annotation currently being moved or resized?
bool m_metadataLoadingCompleted;
QUndoStack *m_undoStack;
QDomNode m_prevPropsOfAnnotBeingModified;

View file

@ -37,7 +37,8 @@
using namespace Okular;
GeneratorPrivate::GeneratorPrivate()
: m_document(nullptr)
: q_ptr(nullptr)
, m_document(nullptr)
, mPixmapGenerationThread(nullptr)
, mTextPageGenerationThread(nullptr)
, mPixmapReady(true)

View file

@ -158,6 +158,7 @@ class TextDocumentConverterPrivate
public:
TextDocumentConverterPrivate()
: mParent(nullptr)
, mDocument(nullptr)
{
}

View file

@ -7,6 +7,9 @@
#ifndef _OKULAR_TEXTDOCUMENTSETTINGS_P_H_
#define _OKULAR_TEXTDOCUMENTSETTINGS_P_H_
#include <QFont>
#include <QObject>
class KFontRequester;
class Ui_TextDocumentSettings;
@ -20,7 +23,8 @@ public:
* must delete it yourself
*/
explicit TextDocumentSettingsWidgetPrivate(Ui_TextDocumentSettings *ui)
: mUi(ui)
: mFont(nullptr)
, mUi(ui)
{
}

View file

@ -207,10 +207,10 @@ Okular::TextPage *DjVuGenerator::textPage(Okular::TextRequest *request)
QList<KDjVu::TextEntity>::ConstIterator it = te.constBegin();
QList<KDjVu::TextEntity>::ConstIterator itEnd = te.constEnd();
QList<Okular::TextEntity> words;
const KDjVu::Page *djvupage = m_djvu->pages().at(page->number());
const KDjVu::Page &djvupage = m_djvu->pages().at(page->number());
for (; it != itEnd; ++it) {
const KDjVu::TextEntity &cur = *it;
words.append(Okular::TextEntity(cur.text(), Okular::NormalizedRect(cur.rect(), djvupage->width(), djvupage->height())));
words.append(Okular::TextEntity(cur.text(), Okular::NormalizedRect(cur.rect(), djvupage.width(), djvupage.height())));
}
Okular::TextPage *textpage = new Okular::TextPage(words);
return textpage;
@ -218,21 +218,21 @@ Okular::TextPage *DjVuGenerator::textPage(Okular::TextRequest *request)
void DjVuGenerator::loadPages(QVector<Okular::Page *> &pagesVector, int rotation)
{
const QVector<KDjVu::Page *> &djvu_pages = m_djvu->pages();
const QVector<KDjVu::Page> &djvu_pages = m_djvu->pages();
int numofpages = djvu_pages.count();
pagesVector.resize(numofpages);
for (int i = 0; i < numofpages; ++i) {
const KDjVu::Page *p = djvu_pages.at(i);
const KDjVu::Page &p = djvu_pages.at(i);
if (pagesVector[i]) {
delete pagesVector[i];
}
int w = p->width();
int h = p->height();
int w = p.width();
int h = p.height();
if (rotation % 2 == 1) {
qSwap(w, h);
}
Okular::Page *page = new Okular::Page(i, w, h, (Okular::Rotation)(p->orientation() + rotation));
Okular::Page *page = new Okular::Page(i, w, h, (Okular::Rotation)(p.orientation() + rotation));
pagesVector[i] = page;
QList<KDjVu::Annotation *> annots;
@ -303,9 +303,9 @@ Okular::ObjectRect *DjVuGenerator::convertKDjVuLink(int page, KDjVu::Link *link)
}
}
if (newlink) {
const KDjVu::Page *p = m_djvu->pages().at(page);
int width = p->width();
int height = p->height();
const KDjVu::Page &p = m_djvu->pages().at(page);
int width = p.width();
int height = p.height();
bool scape_orientation = false; // hack by tokoe, should always create default page
if (scape_orientation) {
qSwap(width, height);
@ -313,7 +313,7 @@ Okular::ObjectRect *DjVuGenerator::convertKDjVuLink(int page, KDjVu::Link *link)
switch (link->areaType()) {
case KDjVu::Link::RectArea:
case KDjVu::Link::EllipseArea: {
QRect r(QPoint(link->point().x(), p->height() - link->point().y() - link->size().height()), link->size());
QRect r(QPoint(link->point().x(), p.height() - link->point().y() - link->size().height()), link->size());
bool ellipse = (link->areaType() == KDjVu::Link::EllipseArea);
newrect = new Okular::ObjectRect(Okular::NormalizedRect(Okular::Utils::rotateRect(r, width, height, 0), width, height), ellipse, Okular::ObjectRect::Action, newlink);
break;

View file

@ -154,14 +154,6 @@ public:
// KdjVu::Page
KDjVu::Page::Page()
{
}
KDjVu::Page::~Page()
{
}
int KDjVu::Page::width() const
{
return m_width;
@ -451,7 +443,7 @@ public:
ddjvu_document_t *m_djvu_document;
ddjvu_format_t *m_format;
QVector<KDjVu::Page *> m_pages;
QVector<KDjVu::Page> m_pages;
QVector<ddjvu_page_t *> m_pages_cache;
QList<ImageCacheItem *> mImgCache;
@ -717,12 +709,13 @@ bool KDjVu::openFile(const QString &fileName)
return false;
}
KDjVu::Page *p = new KDjVu::Page();
p->m_width = info.width;
p->m_height = info.height;
p->m_dpi = info.dpi;
KDjVu::Page p;
;
p.m_width = info.width;
p.m_height = info.height;
p.m_dpi = info.dpi;
#if DDJVUAPI_VERSION >= 18
p->m_orientation = flipRotation(info.rotation);
p.m_orientation = flipRotation(info.rotation);
#else
p->m_orientation = 0;
#endif
@ -743,7 +736,6 @@ void KDjVu::closeFile()
delete d->m_docBookmarks;
d->m_docBookmarks = nullptr;
// deleting the pages
qDeleteAll(d->m_pages);
d->m_pages.clear();
// releasing the djvu pages
QVector<ddjvu_page_t *>::Iterator it = d->m_pages_cache.begin(), itEnd = d->m_pages_cache.end();
@ -871,7 +863,7 @@ void KDjVu::linksAndAnnotationsForPage(int pageNum, QList<KDjVu::Link *> *links,
}
}
const QVector<KDjVu::Page *> &KDjVu::pages() const
const QVector<KDjVu::Page> &KDjVu::pages() const
{
return d->m_pages;
}
@ -1045,7 +1037,7 @@ QList<KDjVu::TextEntity> KDjVu::textEntities(int page, const QString &granularit
QList<KDjVu::TextEntity> ret;
int height = d->m_pages.at(page)->height();
int height = d->m_pages.at(page).height();
QQueue<miniexp_t> queue;
queue.enqueue(r);

View file

@ -42,20 +42,16 @@ public:
friend class KDjVu;
public:
~Page();
int width() const;
int height() const;
int dpi() const;
int orientation() const;
private:
Page();
int m_width;
int m_height;
int m_dpi;
int m_orientation;
int m_width = 0;
int m_height = 0;
int m_dpi = 0;
int m_orientation = 0;
};
/**
@ -81,7 +77,7 @@ public:
QPolygon polygon() const;
private:
LinkArea m_area;
LinkArea m_area = UnknownArea;
QPoint m_point;
QSize m_size;
QPolygon m_poly;
@ -221,10 +217,9 @@ public:
/**
* The pages of the current document, or an empty vector otherwise.
* \note KDjVu handles the pages, so you don't need to delete them manually
* \return a vector with the pages of the current document
*/
const QVector<KDjVu::Page *> &pages() const;
const QVector<KDjVu::Page> &pages() const;
/**
* Get the metadata for the specified \p key, or a null variant otherwise.

View file

@ -259,9 +259,7 @@ private:
QList<XpsPage *> m_pages;
QString m_thumbnailFileName;
bool m_thumbnailMightBeAvailable;
QImage m_thumbnail;
bool m_thumbnailIsLoaded;
QString m_corePropertiesFileName;

View file

@ -146,64 +146,64 @@ public:
// the document, pageviewItems and the 'visible cache'
PageView *q;
Okular::Document *document;
Okular::Document *document = nullptr;
QVector<PageViewItem *> items;
QList<PageViewItem *> visibleItems;
MagnifierView *magnifierView;
// view layout (columns in Settings), zoom and mouse
PageView::ZoomMode zoomMode;
float zoomFactor;
PageView::ZoomMode zoomMode = PageView::ZoomFitWidth;
float zoomFactor = 1.0;
QPoint mouseGrabOffset;
QPointF mousePressPos;
QPointF mouseSelectPos;
QPointF previousMouseMovePos;
qreal mouseMidLastY;
bool mouseSelecting;
bool mouseSelecting = false;
QRect mouseSelectionRect;
QColor mouseSelectionColor;
bool mouseTextSelecting;
bool mouseTextSelecting = false;
QSet<int> pagesWithTextSelection;
bool mouseOnRect;
int mouseMode;
MouseAnnotation *mouseAnnotation;
bool mouseOnRect = false;
int mouseMode = 0;
MouseAnnotation *mouseAnnotation = nullptr;
// table selection
QList<double> tableSelectionCols;
QList<double> tableSelectionRows;
QList<TableSelectionPart> tableSelectionParts;
bool tableDividersGuessed;
bool tableDividersGuessed = false;
int lastSourceLocationViewportPageNumber;
double lastSourceLocationViewportNormalizedX;
double lastSourceLocationViewportNormalizedY;
int lastSourceLocationViewportPageNumber = -1;
double lastSourceLocationViewportNormalizedX = 0.0;
double lastSourceLocationViewportNormalizedY = 0.0;
// for everything except PgUp/PgDn and scroll to arbitrary locations
const int baseShortScrollDuration = 100;
int currentShortScrollDuration;
int currentShortScrollDuration = baseShortScrollDuration;
// for PgUp/PgDn and scroll to arbitrary locations
const int baseLongScrollDuration = baseShortScrollDuration * 2;
int currentLongScrollDuration;
int currentLongScrollDuration = baseLongScrollDuration;
// auto scroll
int scrollIncrement;
QTimer *autoScrollTimer;
int scrollIncrement = 0;
QTimer *autoScrollTimer = nullptr;
// annotations
PageViewAnnotator *annotator;
PageViewAnnotator *annotator = nullptr;
// text annotation dialogs list
QSet<AnnotWindow *> m_annowindows;
// other stuff
QTimer *delayResizeEventTimer;
bool dirtyLayout;
bool blockViewport; // prevents changes to viewport
bool blockPixmapsRequest; // prevent pixmap requests
PageViewMessage *messageWindow; // in pageviewutils.h
bool m_formsVisible;
FormWidgetsController *formsWidgetController;
QTimer *delayResizeEventTimer = nullptr;
bool dirtyLayout = false;
bool blockViewport = false; // prevents changes to viewport
bool blockPixmapsRequest = false; // prevent pixmap requests
PageViewMessage *messageWindow = nullptr; // in pageviewutils.h
bool m_formsVisible = false;
FormWidgetsController *formsWidgetController = nullptr;
#if HAVE_SPEECH
OkularTTS *m_tts;
OkularTTS *m_tts = nullptr;
#endif
QTimer *refreshTimer;
QTimer *refreshTimer = nullptr;
QSet<int> refreshPages;
// bbox state for Trim to Selection mode
@ -221,62 +221,59 @@ public:
QTimer leftClickTimer;
// actions
QAction *aRotateClockwise;
QAction *aRotateCounterClockwise;
QAction *aRotateOriginal;
KActionMenu *aTrimMode;
KToggleAction *aTrimMargins;
KToggleAction *aReadingDirection;
QAction *aMouseNormal;
QAction *aMouseZoom;
QAction *aMouseSelect;
QAction *aMouseTextSelect;
QAction *aMouseTableSelect;
QAction *aMouseMagnifier;
KToggleAction *aTrimToSelection;
QAction *aSignature;
KSelectAction *aZoom;
QAction *aZoomIn;
QAction *aZoomOut;
QAction *aZoomActual;
KToggleAction *aZoomFitWidth;
KToggleAction *aZoomFitPage;
KToggleAction *aZoomAutoFit;
KActionMenu *aViewModeMenu;
QActionGroup *viewModeActionGroup;
ColorModeMenu *aColorModeMenu;
KToggleAction *aViewContinuous;
QAction *aPrevAction;
KToggleAction *aToggleForms;
QAction *aSpeakDoc;
QAction *aSpeakPage;
QAction *aSpeakStop;
QAction *aSpeakPauseResume;
KActionCollection *actionCollection;
QActionGroup *mouseModeActionGroup;
ToggleActionMenu *aMouseModeMenu;
QAction *aFitWindowToPage;
QAction *aRotateClockwise = nullptr;
QAction *aRotateCounterClockwise = nullptr;
QAction *aRotateOriginal = nullptr;
KActionMenu *aTrimMode = nullptr;
KToggleAction *aTrimMargins = nullptr;
KToggleAction *aReadingDirection = nullptr;
QAction *aMouseNormal = nullptr;
QAction *aMouseZoom = nullptr;
QAction *aMouseSelect = nullptr;
QAction *aMouseTextSelect = nullptr;
QAction *aMouseTableSelect = nullptr;
QAction *aMouseMagnifier = nullptr;
KToggleAction *aTrimToSelection = nullptr;
QAction *aSignature = nullptr;
KSelectAction *aZoom = nullptr;
QAction *aZoomIn = nullptr;
QAction *aZoomOut = nullptr;
QAction *aZoomActual = nullptr;
KToggleAction *aZoomFitWidth = nullptr;
KToggleAction *aZoomFitPage = nullptr;
KToggleAction *aZoomAutoFit = nullptr;
KActionMenu *aViewModeMenu = nullptr;
QActionGroup *viewModeActionGroup = nullptr;
ColorModeMenu *aColorModeMenu = nullptr;
KToggleAction *aViewContinuous = nullptr;
QAction *aPrevAction = nullptr;
KToggleAction *aToggleForms = nullptr;
QAction *aSpeakDoc = nullptr;
QAction *aSpeakPage = nullptr;
QAction *aSpeakStop = nullptr;
QAction *aSpeakPauseResume = nullptr;
KActionCollection *actionCollection = nullptr;
QActionGroup *mouseModeActionGroup = nullptr;
ToggleActionMenu *aMouseModeMenu = nullptr;
QAction *aFitWindowToPage = nullptr;
int setting_viewCols;
bool rtl_Mode;
int setting_viewCols = 0;
bool rtl_Mode = false;
// Keep track of whether tablet pen is currently pressed down
bool penDown;
bool penDown = false;
// Keep track of mouse over link object
const Okular::ObjectRect *mouseOverLinkObject;
const Okular::ObjectRect *mouseOverLinkObject = nullptr;
QScroller *scroller;
QScroller *scroller = nullptr;
bool pinchZoomActive;
bool pinchZoomActive = false;
// The remaining scroll from the previous zoom event
QPointF remainingScroll;
};
PageViewPrivate::PageViewPrivate(PageView *qq)
: q(qq)
#if HAVE_SPEECH
, m_tts(nullptr)
#endif
{
}
@ -327,72 +324,13 @@ PageView::PageView(QWidget *parent, Okular::Document *document)
// create and initialize private storage structure
d = new PageViewPrivate(this);
d->document = document;
d->aRotateClockwise = nullptr;
d->aRotateCounterClockwise = nullptr;
d->aRotateOriginal = nullptr;
d->aViewModeMenu = nullptr;
d->zoomMode = PageView::ZoomFitWidth;
d->zoomFactor = 1.0;
d->mouseSelecting = false;
d->mouseTextSelecting = false;
d->mouseOnRect = false;
d->mouseMode = Okular::Settings::mouseMode();
d->mouseAnnotation = new MouseAnnotation(this, document);
d->tableDividersGuessed = false;
d->lastSourceLocationViewportPageNumber = -1;
d->lastSourceLocationViewportNormalizedX = 0.0;
d->lastSourceLocationViewportNormalizedY = 0.0;
d->currentShortScrollDuration = d->baseShortScrollDuration;
d->currentLongScrollDuration = d->baseLongScrollDuration;
d->scrollIncrement = 0;
d->autoScrollTimer = nullptr;
d->annotator = nullptr;
d->dirtyLayout = false;
d->blockViewport = false;
d->blockPixmapsRequest = false;
d->messageWindow = new PageViewMessage(this);
d->m_formsVisible = false;
d->formsWidgetController = nullptr;
#if HAVE_SPEECH
d->m_tts = nullptr;
#endif
d->refreshTimer = nullptr;
d->aRotateClockwise = nullptr;
d->aRotateCounterClockwise = nullptr;
d->aRotateOriginal = nullptr;
d->aTrimMode = nullptr;
d->aTrimMargins = nullptr;
d->aTrimToSelection = nullptr;
d->aReadingDirection = nullptr;
d->aMouseNormal = nullptr;
d->aMouseZoom = nullptr;
d->aMouseSelect = nullptr;
d->aMouseTextSelect = nullptr;
d->aSignature = nullptr;
d->aZoomFitWidth = nullptr;
d->aZoomFitPage = nullptr;
d->aZoomAutoFit = nullptr;
d->aViewModeMenu = nullptr;
d->aViewContinuous = nullptr;
d->viewModeActionGroup = nullptr;
d->aColorModeMenu = nullptr;
d->aPrevAction = nullptr;
d->aToggleForms = nullptr;
d->aSpeakDoc = nullptr;
d->aSpeakPage = nullptr;
d->aSpeakStop = nullptr;
d->aSpeakPauseResume = nullptr;
d->actionCollection = nullptr;
d->setting_viewCols = Okular::Settings::viewColumns();
d->rtl_Mode = Okular::Settings::rtlReadingDirection();
d->mouseModeActionGroup = nullptr;
d->aMouseModeMenu = nullptr;
d->penDown = false;
d->aMouseMagnifier = nullptr;
d->aFitWindowToPage = nullptr;
d->trimBoundingBox = Okular::NormalizedRect(); // Null box
d->pinchZoomActive = false;
d->remainingScroll = QPointF(0.0, 0.0);
switch (Okular::Settings::zoomMode()) {
case 0: {

View file

@ -33,20 +33,15 @@
class Sidebar::Private
{
public:
Private()
: sideWidget(nullptr)
, bottomWidget(nullptr)
, splitterSizesSet(false)
{
}
Private() = default;
QSplitter *splitter;
QTabWidget *viewChooserTabs;
QWidget *sideContainer;
QVBoxLayout *vlay;
QWidget *sideWidget;
QWidget *bottomWidget;
bool splitterSizesSet;
QSplitter *splitter = nullptr;
QTabWidget *viewChooserTabs = nullptr;
QWidget *sideContainer = nullptr;
QVBoxLayout *vlay = nullptr;
QWidget *sideWidget = nullptr;
QWidget *bottomWidget = nullptr;
bool splitterSizesSet = false;
};
Sidebar::Sidebar(QWidget *parent)