More cppcheck fixes

This commit is contained in:
Sune Vuorela 2024-06-20 15:33:16 +02:00
parent 0bd2c9cfa0
commit d211a6a9e9
29 changed files with 96 additions and 110 deletions

View File

@ -182,13 +182,12 @@ QString DocumentPrivate::pagesSizeString() const
}
// Multiple page sizes
QString sizeString;
QHash<QString, int> pageSizeFrequencies;
// Compute frequencies of each page size
for (int i = 0; i < m_pagesVector.count(); ++i) {
const Page *p = m_pagesVector.at(i);
sizeString = localizedSize(QSizeF(p->width(), p->height()));
QString sizeString = localizedSize(QSizeF(p->width(), p->height()));
pageSizeFrequencies[sizeString] = pageSizeFrequencies.value(sizeString, 0) + 1;
}
@ -1106,7 +1105,7 @@ void DocumentPrivate::performModifyPageAnnotation(int page, Annotation *annotati
AnnotationProxy *proxy = iface ? iface->annotationProxy() : nullptr;
// find out the page
Page *kp = m_pagesVector[page];
const Page *kp = m_pagesVector[page];
if (!m_generator || !kp) {
return;
}
@ -1145,7 +1144,7 @@ void DocumentPrivate::performSetAnnotationContents(const QString &newContents, A
switch (annot->subType()) {
// If it's an in-place TextAnnotation, set the inplace text
case Okular::Annotation::AText: {
Okular::TextAnnotation *txtann = static_cast<Okular::TextAnnotation *>(annot);
const Okular::TextAnnotation *txtann = static_cast<Okular::TextAnnotation *>(annot);
if (txtann->textType() == Okular::TextAnnotation::InPlace) {
appearanceChanged = true;
}
@ -1153,7 +1152,7 @@ void DocumentPrivate::performSetAnnotationContents(const QString &newContents, A
}
// If it's a LineAnnotation, check if caption text is visible
case Okular::Annotation::ALine: {
Okular::LineAnnotation *lineann = static_cast<Okular::LineAnnotation *>(annot);
const Okular::LineAnnotation *lineann = static_cast<Okular::LineAnnotation *>(annot);
if (lineann->showCaption()) {
appearanceChanged = true;
}
@ -1182,7 +1181,7 @@ void DocumentPrivate::recalculateForms()
const QList<Okular::FormField *> forms = p->formFields();
for (FormField *form : forms) {
if (form->id() == formId) {
Action *action = form->additionalAction(FormField::CalculateField);
const Action *action = form->additionalAction(FormField::CalculateField);
if (action) {
FormFieldText *fft = dynamic_cast<FormFieldText *>(form);
std::shared_ptr<Event> event;
@ -1337,7 +1336,7 @@ void DocumentPrivate::sendGeneratorPixmapRequest()
const int currentViewportPage = (*m_viewportIterator).pageNumber;
int maxDistance = INT_MAX; // Default: No maximum
if (memoryToFree) {
AllocatedPixmap *pixmapToReplace = searchLowestPriorityPixmap(true);
const AllocatedPixmap *pixmapToReplace = searchLowestPriorityPixmap(true);
if (pixmapToReplace) {
maxDistance = qAbs(pixmapToReplace->page - currentViewportPage);
}
@ -1518,7 +1517,7 @@ void DocumentPrivate::sendGeneratorPixmapRequest()
void DocumentPrivate::rotationFinished(int page, Okular::Page *okularPage)
{
Okular::Page *wantedPage = m_pagesVector.value(page, nullptr);
const Okular::Page *wantedPage = m_pagesVector.value(page, nullptr);
if (!wantedPage || wantedPage != okularPage) {
return;
}
@ -1694,7 +1693,7 @@ void DocumentPrivate::doContinueDirectionMatchSearch(void *doContinueDirectionMa
if (doContinue) {
// get page
Page *page = m_pagesVector[searchStruct->currentPage];
const Page *page = m_pagesVector[searchStruct->currentPage];
// request search page if needed
if (!page->hasTextPage()) {
m_parent->requestTextPage(page->number());
@ -2643,9 +2642,9 @@ void Document::closeDocument()
// ideally we would just do that in the BackendOpaqueAction destructor
// but that's too late in the cleanup process, i.e. the generator has already closed its document
// and the document generator is nullptr
for (Page *p : std::as_const(d->m_pagesVector)) {
for (const Page *p : std::as_const(d->m_pagesVector)) {
const QList<ObjectRect *> &oRects = p->objectRects();
for (ObjectRect *oRect : oRects) {
for (const ObjectRect *oRect : oRects) {
if (oRect->objectType() == ObjectRect::Action) {
const Action *a = static_cast<const Action *>(oRect->object());
const BackendOpaqueAction *backendAction = dynamic_cast<const BackendOpaqueAction *>(a);
@ -2854,7 +2853,7 @@ bool Document::isOpened() const
bool Document::canConfigurePrinter() const
{
if (d->m_generator) {
Okular::PrintInterface *iface = qobject_cast<Okular::PrintInterface *>(d->m_generator);
const Okular::PrintInterface *iface = qobject_cast<Okular::PrintInterface *>(d->m_generator);
return iface ? true : false;
} else {
return false;
@ -3332,10 +3331,10 @@ void Document::requestPixmaps(const QList<PixmapRequest *> &requests, PixmapRequ
QSet<DocumentObserver *> observersPixmapCleared;
// 1. [CLEAN STACK] remove previous requests of requesterID
DocumentObserver *requesterObserver = requests.first()->observer();
const DocumentObserver *requesterObserver = requests.first()->observer();
QSet<int> requestedPages;
{
for (PixmapRequest *request : requests) {
for (const PixmapRequest *request : requests) {
Q_ASSERT(request->observer() == requesterObserver);
requestedPages.insert(request->pageNumber());
}
@ -3843,7 +3842,7 @@ void Document::searchText(int searchID, const QString &text, bool fromStart, Qt:
const int viewportPage = (*d->m_viewportIterator).pageNumber;
const int fromStartSearchPage = forward ? 0 : d->m_pagesVector.count() - 1;
int currentPage = fromStart ? fromStartSearchPage : ((s->continueOnPage != -1) ? s->continueOnPage : viewportPage);
Page *lastPage = fromStart ? nullptr : d->m_pagesVector[currentPage];
const Page *lastPage = fromStart ? nullptr : d->m_pagesVector[currentPage];
int pagesDone = 0;
// continue checking last TextPage first (if it is the current page)
@ -5059,7 +5058,7 @@ void Document::unregisterView(View *view)
return;
}
Document *viewDoc = view->viewDocument();
const Document *viewDoc = view->viewDocument();
if (!viewDoc || viewDoc != this) {
return;
}
@ -5306,18 +5305,16 @@ bool Document::extractArchivedFile(const QString &destFileName)
QPageLayout::Orientation Document::orientation() const
{
double width, height;
int landscape, portrait;
const Okular::Page *currentPage;
// if some pages are landscape and others are not, the most common wins, as
// QPrinter does not accept a per-page setting
landscape = 0;
portrait = 0;
for (uint i = 0; i < pages(); i++) {
currentPage = page(i);
width = currentPage->width();
height = currentPage->height();
const Okular::Page *currentPage = page(i);
double width = currentPage->width();
double height = currentPage->height();
if (currentPage->orientation() == Okular::Rotation90 || currentPage->orientation() == Okular::Rotation270) {
std::swap(width, height);
}

View File

@ -282,7 +282,7 @@ bool Page::hasObjectRect(double x, double y, double xScale, double yScale) const
return false;
}
for (ObjectRect *rect : m_rects) {
for (const ObjectRect *rect : m_rects) {
if (rect->distanceSqr(x, y, xScale, yScale) < distanceConsideredEqual) {
return true;
}
@ -302,7 +302,7 @@ bool Page::hasHighlights(int s_id) const
return true;
}
// iterate on the highlights list to find an entry by id
for (HighlightAreaRect *highlight : m_highlights) {
for (const HighlightAreaRect *highlight : m_highlights) {
if (highlight->s_id == s_id) {
return true;
}

View File

@ -233,7 +233,7 @@ std::shared_ptr<Event> Event::createFormCalculateEvent(FormField *target, Page *
ret->setTargetPage(targetPage);
ret->setTargetName(targetName);
FormFieldText *fft = dynamic_cast<FormFieldText *>(target);
const FormFieldText *fft = dynamic_cast<FormFieldText *>(target);
if (fft) {
ret->setValue(QVariant(fft->text()));
}
@ -248,7 +248,7 @@ std::shared_ptr<Event> Event::createFormatEvent(FormField *target, Page *targetP
ret->setTargetPage(targetPage);
ret->setTargetName(targetName);
FormFieldText *fft = dynamic_cast<FormFieldText *>(target);
const FormFieldText *fft = dynamic_cast<FormFieldText *>(target);
if (fft) {
ret->setValue(QVariant(fft->text()));
}
@ -262,7 +262,7 @@ std::shared_ptr<Event> Event::createKeystrokeEvent(FormField *target, Page *targ
ret->setTarget(target);
ret->setTargetPage(targetPage);
FormFieldText *fft = dynamic_cast<FormFieldText *>(target);
const FormFieldText *fft = dynamic_cast<FormFieldText *>(target);
if (fft) {
ret->setReturnCode(true);
ret->setValue(QVariant(fft->text()));
@ -278,7 +278,7 @@ std::shared_ptr<Event> Event::createFormFocusEvent(FormField *target, Page *targ
ret->setTargetName(targetName);
ret->setShiftModifier(QApplication::keyboardModifiers() & Qt::ShiftModifier);
FormFieldText *fft = dynamic_cast<FormFieldText *>(target);
const FormFieldText *fft = dynamic_cast<FormFieldText *>(target);
if (fft) {
ret->setValue(QVariant(fft->text()));
}
@ -293,7 +293,7 @@ std::shared_ptr<Event> Event::createFormValidateEvent(FormField *target, Page *t
ret->setTargetName(targetName);
ret->setShiftModifier(QApplication::keyboardModifiers() & Qt::ShiftModifier);
FormFieldText *fft = dynamic_cast<FormFieldText *>(target);
const FormFieldText *fft = dynamic_cast<FormFieldText *>(target);
if (fft) {
ret->setValue(QVariant(fft->text()));
ret->setReturnCode(true);
@ -315,4 +315,4 @@ std::shared_ptr<Event> Event::createDocEvent(Event::EventType type)
std::shared_ptr<Event> ret = std::make_shared<Event>(type);
// TODO set target name.
return ret;
}
}

View File

@ -376,7 +376,7 @@ QJSValue JSApp::okular_popUpMenuEx(const QJSValue &arguments)
return {};
}
QAction *result = m.exec(QCursor::pos());
const QAction *result = m.exec(QCursor::pos());
return result ? result->property(kResultProperty).toString() : QString();
}

View File

@ -169,14 +169,14 @@ QJSValue JSDocument::getField(const QString &cName) const
// Document.getPageLabel()
QString JSDocument::getPageLabel(int nPage) const
{
Page *p = m_doc->m_pagesVector.value(nPage);
const Page *p = m_doc->m_pagesVector.value(nPage);
return p ? p->label() : QString();
}
// Document.getPageRotation()
int JSDocument::getPageRotation(int nPage) const
{
Page *p = m_doc->m_pagesVector.value(nPage);
const Page *p = m_doc->m_pagesVector.value(nPage);
return p ? p->orientation() * 90 : 0;
}

View File

@ -73,7 +73,6 @@ QJSValue JSEvent::target() const
}
case Event::DocOpen: {
return qjsEngine(this)->globalObject().property(QStringLiteral("Doc"));
break;
}
default: {
}

View File

@ -166,9 +166,7 @@ QList<TextDocumentGeneratorPrivate::LinkInfo> TextDocumentGeneratorPrivate::gene
{
QList<LinkInfo> result;
for (int i = 0; i < mLinkPositions.count(); ++i) {
const LinkPosition &linkPosition = mLinkPositions[i];
for (const LinkPosition &linkPosition : mLinkPositions) {
const QVector<QRectF> rects = TextDocumentUtils::calculateBoundingRects(mDocument, linkPosition.startPosition, linkPosition.endPosition);
for (int i = 0; i < rects.count(); ++i) {

View File

@ -186,7 +186,7 @@ void TextPage::append(const QString &text, const NormalizedRect &area)
{
if (!text.isEmpty()) {
if (!d->m_words.isEmpty()) {
TextEntity &lastEntity = d->m_words.last();
const TextEntity &lastEntity = d->m_words.last();
// Unicode Normalization Form KC (NFKC) may alter characters, for example ⑥ to 6, so we use NFC
const QString concatText = lastEntity.text() + text.normalized(QString::NormalizationForm_C);
if (concatText != concatText.normalized(QString::NormalizationForm_C)) {
@ -296,7 +296,7 @@ std::unique_ptr<RegularAreaRect> TextPage::textArea(const TextSelection &sel) co
*/
auto ret = std::make_unique<RegularAreaRect>();
PagePrivate *pagePrivate = PagePrivate::get(d->m_page);
const PagePrivate *pagePrivate = PagePrivate::get(d->m_page);
const QTransform matrix = pagePrivate ? pagePrivate->rotationMatrix() : QTransform();
const double scaleX = d->m_page->width();
const double scaleY = d->m_page->height();
@ -642,7 +642,7 @@ static int stringLengthAdaptedWithHyphen(const QString &str, TextEntity::List::C
RegularAreaRect *TextPagePrivate::searchPointToArea(const SearchPoint *sp)
{
PagePrivate *pagePrivate = PagePrivate::get(m_page);
const PagePrivate *pagePrivate = PagePrivate::get(m_page);
const QTransform matrix = pagePrivate ? pagePrivate->rotationMatrix() : QTransform();
RegularAreaRect *ret = new RegularAreaRect;

View File

@ -138,9 +138,8 @@ void Okular::copyQIODevice(QIODevice *from, QIODevice *to)
{
QByteArray buffer(65536, '\0');
qint64 read = 0;
qint64 written = 0;
while ((read = from->read(buffer.data(), buffer.size())) > 0) {
written = to->write(buffer.constData(), read);
qint64 written = to->write(buffer.constData(), read);
if (read != written) {
break;
}

View File

@ -196,10 +196,7 @@ Okular::TextPage *DjVuGenerator::textPage(Okular::TextRequest *request)
{
userMutex()->lock();
const Okular::Page *page = request->page();
QList<KDjVu::TextEntity> te;
if (te.isEmpty()) {
te = m_djvu->textEntities(page->number(), QStringLiteral("word"));
}
QList<KDjVu::TextEntity> te = m_djvu->textEntities(page->number(), QStringLiteral("word"));
if (te.isEmpty()) {
te = m_djvu->textEntities(page->number(), QStringLiteral("line"));
}
@ -230,7 +227,7 @@ void DjVuGenerator::loadPages(QVector<Okular::Page *> &pagesVector, int rotation
int w = p.width();
int h = p.height();
if (rotation % 2 == 1) {
qSwap(w, h);
std::swap(w, h);
}
Okular::Page *page = new Okular::Page(i, w, h, (Okular::Rotation)(p.orientation() + rotation));
pagesVector[i] = page;
@ -279,7 +276,7 @@ Okular::ObjectRect *DjVuGenerator::convertKDjVuLink(int page, KDjVu::Link *link)
Okular::ObjectRect *newrect = nullptr;
switch (link->type()) {
case KDjVu::Link::PageLink: {
KDjVu::PageLink *l = static_cast<KDjVu::PageLink *>(link);
const KDjVu::PageLink *l = static_cast<KDjVu::PageLink *>(link);
bool ok = true;
QString target = l->page();
if ((target.length() > 0) && target.at(0) == QLatin1Char('#')) {
@ -296,7 +293,7 @@ Okular::ObjectRect *DjVuGenerator::convertKDjVuLink(int page, KDjVu::Link *link)
break;
}
case KDjVu::Link::UrlLink: {
KDjVu::UrlLink *l = static_cast<KDjVu::UrlLink *>(link);
const KDjVu::UrlLink *l = static_cast<KDjVu::UrlLink *>(link);
QString url = l->url();
newlink = new Okular::BrowseAction(QUrl(url));
break;
@ -308,7 +305,7 @@ Okular::ObjectRect *DjVuGenerator::convertKDjVuLink(int page, KDjVu::Link *link)
int height = p.height();
bool scape_orientation = false; // hack by tokoe, should always create default page
if (scape_orientation) {
qSwap(width, height);
std::swap(width, height);
}
switch (link->areaType()) {
case KDjVu::Link::RectArea:
@ -325,7 +322,7 @@ Okular::ObjectRect *DjVuGenerator::convertKDjVuLink(int page, KDjVu::Link *link)
int x = poly.at(i).x();
int y = poly.at(i).y();
if (scape_orientation) {
qSwap(x, y);
std::swap(x, y);
} else {
y = height - y;
}
@ -365,7 +362,7 @@ Okular::Annotation *DjVuGenerator::convertKDjVuAnnotation(int w, int h, KDjVu::A
break;
}
case KDjVu::Annotation::LineAnnotation: {
KDjVu::LineAnnotation *lineann = static_cast<KDjVu::LineAnnotation *>(ann);
const KDjVu::LineAnnotation *lineann = static_cast<KDjVu::LineAnnotation *>(ann);
Okular::LineAnnotation *newlineann = new Okular::LineAnnotation();
// boundary
QPoint a(lineann->point().x(), h - lineann->point().y());

View File

@ -124,7 +124,7 @@ static bool find_replace_or_add_second_in_pair(miniexp_t theexp, const char *whi
if (id == QLatin1String(which)) {
miniexp_t reversed = miniexp_reverse(cur);
miniexp_rplaca(reversed, replacement);
cur = miniexp_reverse(reversed);
miniexp_reverse(reversed);
return true;
}
exp = miniexp_cdr(exp);
@ -865,7 +865,7 @@ QImage KDjVu::image(int page, int width, int height, int rotation)
bool found = false;
QList<ImageCacheItem *>::Iterator it = d->mImgCache.begin(), itEnd = d->mImgCache.end();
for (; (it != itEnd) && !found; ++it) {
ImageCacheItem *cur = *it;
const ImageCacheItem *cur = *it;
if ((cur->page == page) && (rotation % 2 == 0 ? cur->width == width && cur->height == height : cur->width == height && cur->height == width)) {
found = true;
}

View File

@ -18,7 +18,6 @@ public:
explicit TeXFont(TeXFontDefinition *_parent)
{
parent = _parent;
errorMessage.clear();
}
virtual ~TeXFont();
@ -38,7 +37,7 @@ public:
// Checksum of the font. Used e.g. by PK fonts. This field is filled
// in by the constructor, or set to 0.0, if the font format does not
// contain checksums.
quint32 checksum;
quint32 checksum = 0;
// If the font or if some glyphs could not be loaded, error messages
// will be put here.

View File

@ -597,7 +597,7 @@ void TeXFont_PK::read_PK_char(unsigned int ch)
// that is, big endian. Since XWindows needs little endian, we
// need to change the bit order now.
unsigned char *bitmapData = (unsigned char *)characterBitmaps[ch]->bits;
unsigned char *endOfData = bitmapData + characterBitmaps[ch]->bytes_wide * characterBitmaps[ch]->h;
const unsigned char *endOfData = bitmapData + characterBitmaps[ch]->bytes_wide * characterBitmaps[ch]->h;
while (bitmapData < endOfData) {
*bitmapData = bitflip[*bitmapData];
bitmapData++;

View File

@ -603,13 +603,13 @@ void dviRenderer::prescan_parseSpecials(char *cp, quint8 *)
void dviRenderer::prescan_setChar(unsigned int ch)
{
TeXFontDefinition *fontp = currinf.fontp;
const TeXFontDefinition *fontp = currinf.fontp;
if (fontp == nullptr) {
return;
}
if (currinf.set_char_p == &dviRenderer::set_char) {
glyph *g = ((TeXFont *)(currinf.fontp->font))->getGlyph(ch, true, globalColor);
const glyph *g = ((TeXFont *)(currinf.fontp->font))->getGlyph(ch, true, globalColor);
if (g == nullptr) {
return;
}
@ -618,7 +618,7 @@ void dviRenderer::prescan_setChar(unsigned int ch)
}
if (currinf.set_char_p == &dviRenderer::set_vf_char) {
macro *m = &currinf.fontp->macrotable[ch];
const macro *m = &currinf.fontp->macrotable[ch];
if (m->pos == nullptr) {
return;
}
@ -638,7 +638,6 @@ void dviRenderer::prescan(parseSpecials specialParser)
}
qint32 RRtmp = 0, WWtmp = 0, XXtmp = 0, YYtmp = 0, ZZtmp = 0;
quint8 ch;
double fontPixelPerDVIunit = dviFile->getCmPerDVIunit() * 1200.0 / 2.54;
stack.clear();
@ -647,7 +646,7 @@ void dviRenderer::prescan(parseSpecials specialParser)
currinf.set_char_p = &dviRenderer::set_no_char;
for (;;) {
ch = readUINT8();
quint8 ch = readUINT8();
if (ch <= (unsigned char)(SETCHAR0 + 127)) {
prescan_setChar(ch);

View File

@ -162,7 +162,7 @@ bool fontPool::areFontsLocated()
// Is there a font whose name we did not try to find out yet?
QList<TeXFontDefinition *>::const_iterator cit_fontp = fontList.constBegin();
for (; cit_fontp != fontList.constEnd(); ++cit_fontp) {
TeXFontDefinition *fontp = *cit_fontp;
const TeXFontDefinition *fontp = *cit_fontp;
if (!fontp->isLocated()) {
return false;
}

View File

@ -60,9 +60,8 @@ pageSize::pageSize(const SimplePageSize &s)
bool pageSize::setPageSize(const QString &name)
{
// See if we can recognize the string
QString currentName;
for (int i = 0; staticList[i].name != nullptr; i++) {
currentName = QString::fromLocal8Bit(staticList[i].name);
QString currentName = QString::fromLocal8Bit(staticList[i].name);
if (currentName == name) {
currentSize = i;
// Set page width/height accordingly

View File

@ -268,10 +268,9 @@ void ghostscript_interface::gs_generate_graphics_file(const quint16 page, const
// No. Check is the reason is that the device is not compiled into
// ghostscript. If so, try again with another device.
QString GSoutput;
proc.setReadChannel(QProcess::StandardOutput);
while (proc.canReadLine()) {
GSoutput = QString::fromLocal8Bit(proc.readLine());
QString GSoutput = QString::fromLocal8Bit(proc.readLine());
if (GSoutput.contains(QStringLiteral("Unknown device"))) {
qCDebug(OkularDviDebug) << QString::fromLatin1(
"The version of ghostview installed on this computer does not support "

View File

@ -142,7 +142,6 @@ static void draw_line(pixnum *run, int lineNum, pagenode *pn)
t32bits acc; /* pixel accumulator */
int nacc; /* number of valid bits in acc */
int tot; /* total pixels in line */
int n;
lineNum += pn->stripnum * pn->rowsperstrip;
if (lineNum >= pn->size.height()) {
@ -158,7 +157,7 @@ static void draw_line(pixnum *run, int lineNum, pagenode *pn)
pix = pn->inverse ? ~0 : 0;
tot = 0;
while (tot < pn->size.width()) {
n = *r++;
int n = *r++;
tot += n;
/* Watch out for buffer overruns, e.g. when n == 65535. */
if (tot > pn->size.width()) {
@ -202,7 +201,7 @@ static void draw_line(pixnum *run, int lineNum, pagenode *pn)
static bool get_image(pagenode *pn)
{
unsigned char *data = getstrip(pn, 0);
const unsigned char *data = getstrip(pn, 0);
if (!data) {
return false;
}
@ -219,8 +218,9 @@ static bool get_image(pagenode *pn)
class FaxDocument::Private
{
public:
explicit Private(FaxDocument *parent)
explicit Private(FaxDocument *parent, FaxDocument::DocumentType type)
: mParent(parent)
, mType(type)
{
mPageNode.size = QSize(1728, 0);
}
@ -231,7 +231,7 @@ public:
};
FaxDocument::FaxDocument(const QString &fileName, DocumentType type)
: d(new Private(this))
: d(new Private(this, type))
{
d->mPageNode.filename = fileName;
d->mPageNode.strips = nullptr;
@ -242,7 +242,6 @@ FaxDocument::FaxDocument(const QString &fileName, DocumentType type)
d->mPageNode.data = nullptr;
d->mPageNode.dataOrig = nullptr;
d->mPageNode.imageData = nullptr;
d->mType = type;
if (d->mType == G3) {
d->mPageNode.expander = g31expand; // or g32expand?!?

View File

@ -63,9 +63,9 @@ public:
QPoint dpi; /* DPI horz/vert */
void (*expander)(class pagenode *, drawfunc);
unsigned int bytes_per_line;
QString filename; /* The name of the file to be opened */
QImage image; /* The final image */
uchar *imageData; /* The temporary raw image data */
QString filename; /* The name of the file to be opened */
QImage image; /* The final image */
uchar *imageData = nullptr; /* The temporary raw image data */
};
/* page orientation flags */

View File

@ -132,7 +132,7 @@ QImage KIMGIOGenerator::image(Okular::PixmapRequest *request)
int width = request->width();
int height = request->height();
if (request->page()->rotation() % 2 == 1) {
qSwap(width, height);
std::swap(width, height);
}
return m_img.scaled(width, height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);

View File

@ -411,7 +411,7 @@ static Poppler::Annotation *createPopplerAnnotationFromOkularAnnotation(const Ok
return pHighlightAnnotation;
}
static Poppler::Annotation *createPopplerAnnotationFromOkularAnnotation(const Okular::StampAnnotation *oStampAnnotation, Poppler::Page *page)
static Poppler::Annotation *createPopplerAnnotationFromOkularAnnotation(const Okular::StampAnnotation *oStampAnnotation, const Poppler::Page *page)
{
Poppler::StampAnnotation *pStampAnnotation = new Poppler::StampAnnotation();
@ -969,7 +969,7 @@ Okular::Annotation *createAnnotationFromPopplerAnnotation(Poppler::Annotation *p
break;
}
case Poppler::Annotation::ARichMedia: {
Poppler::RichMediaAnnotation *richmediaann = static_cast<Poppler::RichMediaAnnotation *>(popplerAnnotation);
const Poppler::RichMediaAnnotation *richmediaann = static_cast<Poppler::RichMediaAnnotation *>(popplerAnnotation);
const QPair<Okular::Movie *, Okular::EmbeddedFile *> result = createMovieFromPopplerRichMedia(richmediaann);
if (result.first) {

View File

@ -138,7 +138,7 @@ Poppler::FormFieldIcon PopplerFormFieldButton::icon() const
void PopplerFormFieldButton::setIcon(Okular::FormField *field)
{
if (field->type() == Okular::FormField::FormButton) {
PopplerFormFieldButton *button = static_cast<PopplerFormFieldButton *>(field);
const PopplerFormFieldButton *button = static_cast<PopplerFormFieldButton *>(field);
m_field->setIcon(button->icon());
}
}

View File

@ -849,7 +849,7 @@ void PDFGenerator::loadPages(QVector<Okular::Page *> &pagesVector, int rotation,
break;
}
if (rotation % 2 == 1) {
qSwap(w, h);
std::swap(w, h);
}
// init a Okular::page, add transition and annotation information
page = new Okular::Page(i, w, h, orientation);
@ -1203,7 +1203,7 @@ QImage PDFGenerator::image(Okular::PixmapRequest *request)
double pageWidth = page->width(), pageHeight = page->height();
if (page->rotation() % 2) {
qSwap(pageWidth, pageHeight);
std::swap(pageWidth, pageHeight);
}
qreal fakeDpiX = request->width() / pageWidth * dpi().width();

View File

@ -67,7 +67,7 @@ int okular_tiffCloseProc(thandle_t handle)
toff_t okular_tiffSizeProc(thandle_t handle)
{
QIODevice *device = static_cast<QIODevice *>(handle);
const QIODevice *device = static_cast<QIODevice *>(handle);
return device->size();
}

View File

@ -190,9 +190,9 @@ void AnnotationModelPrivate::notifyPageChanged(int page, int flags)
// => lookup and remove the annotations
if (annItem->children.count() > annots.count()) {
for (int i = annItem->children.count(); i > 0; --i) {
Okular::Annotation *ref = annItem->children.at(i - 1)->annotation;
const Okular::Annotation *ref = annItem->children.at(i - 1)->annotation;
bool found = false;
for (Okular::Annotation *annot : annots) {
for (const Okular::Annotation *annot : annots) {
if (annot == ref) {
found = true;
break;
@ -419,7 +419,7 @@ Okular::Annotation *AnnotationModel::annotationForIndex(const QModelIndex &index
return nullptr;
}
AnnItem *item = static_cast<AnnItem *>(index.internalPointer());
const AnnItem *item = static_cast<AnnItem *>(index.internalPointer());
return item->annotation;
}

View File

@ -187,7 +187,7 @@ void FormWidgetsController::slotButtonClicked(QAbstractButton *button)
button->group()->setExclusive(wasExclusive);
}
pageNumber = check->pageItem()->pageNumber();
} else if (RadioButtonEdit *radio = qobject_cast<RadioButtonEdit *>(button)) {
} else if (const RadioButtonEdit *radio = qobject_cast<RadioButtonEdit *>(button)) {
pageNumber = radio->pageItem()->pageNumber();
}
@ -220,10 +220,10 @@ void FormWidgetsController::slotFormButtonsChangedByUndoRedo(int pageNumber, con
int id = formButton->id();
QAbstractButton *button = m_buttons[id];
int itemPageNumber = -1;
if (CheckBoxEdit *check = qobject_cast<CheckBoxEdit *>(button)) {
if (const CheckBoxEdit *check = qobject_cast<CheckBoxEdit *>(button)) {
itemPageNumber = check->pageItem()->pageNumber();
Q_EMIT refreshFormWidget(check->formField());
} else if (RadioButtonEdit *radio = qobject_cast<RadioButtonEdit *>(button)) {
} else if (const RadioButtonEdit *radio = qobject_cast<RadioButtonEdit *>(button)) {
itemPageNumber = radio->pageItem()->pageNumber();
}
// temporarily disable exclusiveness of the button group
@ -1058,7 +1058,6 @@ void ComboEdit::slotValueChanged()
if (text != prevText) {
Q_EMIT m_controller->formComboChangedByWidget(pageItem()->pageNumber(), form, currentText(), cursorPos, m_prevCursorPos, m_prevAnchorPos);
}
prevText = text;
m_prevCursorPos = cursorPos;
m_prevAnchorPos = cursorPos;
if (lineEdit()->hasSelectedText()) {
@ -1291,7 +1290,7 @@ void SignatureEdit::signUnsignedSignature()
return;
}
Okular::FormFieldSignature *formSignature = static_cast<Okular::FormFieldSignature *>(formField());
const Okular::FormFieldSignature *formSignature = static_cast<Okular::FormFieldSignature *>(formField());
PageView *pageView = static_cast<PageView *>(parent()->parent());
SignaturePartUtils::signUnsignedSignature(formSignature, pageView, pageView->document());
}

View File

@ -61,7 +61,7 @@ public:
void KTreeViewSearchLine::Private::rowsInserted(const QModelIndex &parentIndex, int start, int end) const
{
QAbstractItemModel *model = qobject_cast<QAbstractItemModel *>(parent->sender());
const QAbstractItemModel *model = qobject_cast<QAbstractItemModel *>(parent->sender());
if (!model) {
return;
}

View File

@ -2027,7 +2027,7 @@ void PageView::keyPressEvent(QKeyEvent *e)
// move/scroll page by using keys
// When the shift key is held down, scroll ten times faster
int stepsize = e->modifiers() & Qt::ShiftModifier ? 10 : 1;
int stepsize = (e->modifiers() & Qt::ShiftModifier) ? 10 : 1;
switch (e->key()) {
case Qt::Key_J:
case Qt::Key_Down:
@ -2495,7 +2495,7 @@ void PageView::mousePressEvent(QMouseEvent *e)
copyToClipboard->setText(i18n("Copy forbidden by DRM"));
}
QAction *choice = menu.exec(e->globalPosition().toPoint());
const QAction *choice = menu.exec(e->globalPosition().toPoint());
if (choice == copyToClipboard) {
copyTextSelection();
}
@ -2692,7 +2692,7 @@ void PageView::mouseReleaseEvent(QMouseEvent *e)
if (rightButton && !d->mouseSelecting) {
break;
}
PageViewItem *pageItem = pickItemOnPoint(eventPos.x(), eventPos.y());
const PageViewItem *pageItem = pickItemOnPoint(eventPos.x(), eventPos.y());
// ensure end point rests within a page, or ignore
if (!pageItem) {
break;
@ -2748,7 +2748,7 @@ void PageView::mouseReleaseEvent(QMouseEvent *e)
// if mouse is released and selection is null this is a rightClick
if (rightButton && !d->mouseSelecting) {
PageViewItem *pageItem = pickItemOnPoint(eventPos.x(), eventPos.y());
const PageViewItem *pageItem = pickItemOnPoint(eventPos.x(), eventPos.y());
Q_EMIT rightClick(pageItem ? pageItem->page() : nullptr, e->globalPosition().toPoint());
break;
}
@ -2827,7 +2827,7 @@ void PageView::mouseReleaseEvent(QMouseEvent *e)
menu.addAction(new OKMenuTitle(&menu, i18n("Image (%1 by %2 pixels)", selectionRect.width(), selectionRect.height())));
imageToClipboard = menu.addAction(QIcon::fromTheme(QStringLiteral("image-x-generic")), i18n("Copy to Clipboard"));
imageToFile = menu.addAction(QIcon::fromTheme(QStringLiteral("document-save")), i18n("Save to File..."));
QAction *choice = menu.exec(e->globalPosition().toPoint());
const QAction *choice = menu.exec(e->globalPosition().toPoint());
// check if the user really selected an action
if (choice) {
// IMAGE operation chosen
@ -2903,7 +2903,7 @@ void PageView::mouseReleaseEvent(QMouseEvent *e)
// if mouse is released and selection is null this is a rightClick
if (rightButton && !d->mouseSelecting) {
PageViewItem *pageItem = pickItemOnPoint(eventPos.x(), eventPos.y());
const PageViewItem *pageItem = pickItemOnPoint(eventPos.x(), eventPos.y());
Q_EMIT rightClick(pageItem ? pageItem->page() : nullptr, e->globalPosition().toPoint());
break;
}
@ -3033,7 +3033,7 @@ void PageView::mouseReleaseEvent(QMouseEvent *e)
if (menu) {
menu->setObjectName(QStringLiteral("PopupMenu"));
QAction *choice = menu->exec(e->globalPosition().toPoint());
const QAction *choice = menu->exec(e->globalPosition().toPoint());
// check if the user really selected an action
if (choice) {
if (choice == textToClipboard) {
@ -3161,7 +3161,7 @@ void PageView::mouseDoubleClickEvent(QMouseEvent *e)
{
if (e->button() == Qt::LeftButton) {
const QPoint eventPos = contentAreaPoint(e->pos());
PageViewItem *pageItem = pickItemOnPoint(eventPos.x(), eventPos.y());
const PageViewItem *pageItem = pickItemOnPoint(eventPos.x(), eventPos.y());
if (pageItem) {
// find out normalized mouse coords inside current item
double nX = pageItem->absToPageX(eventPos.x());
@ -3244,7 +3244,7 @@ void PageView::wheelEvent(QWheelEvent *e)
}
} else {
// When the shift key is held down, scroll ten times faster
int multiplier = e->modifiers() & Qt::ShiftModifier ? 10 : 1;
int multiplier = (e->modifiers() & Qt::ShiftModifier) ? 10 : 1;
if (delta != 0 && delta % QWheelEvent::DefaultDeltasPerStep == 0) {
// number of scroll wheel steps Qt gives to us at the same time
@ -3273,7 +3273,7 @@ bool PageView::viewportEvent(QEvent *e)
d->mouseAnnotation->routeTooltipEvent(he);
} else {
const QPoint eventPos = contentAreaPoint(he->pos());
PageViewItem *pageItem = pickItemOnPoint(eventPos.x(), eventPos.y());
const PageViewItem *pageItem = pickItemOnPoint(eventPos.x(), eventPos.y());
const Okular::ObjectRect *rect = nullptr;
const Okular::Action *link = nullptr;
if (pageItem) {
@ -3350,9 +3350,9 @@ std::vector<std::unique_ptr<Okular::RegularAreaRect>> PageView::textSelections(c
}
}
PageViewItem *a = pickItemOnPoint((int)(direction_ne_sw ? selectionRect.right() : selectionRect.left()), (int)selectionRect.top());
const PageViewItem *a = pickItemOnPoint((int)(direction_ne_sw ? selectionRect.right() : selectionRect.left()), (int)selectionRect.top());
int min = a && (a->pageNumber() != tmpmax) ? a->pageNumber() : tmpmin;
PageViewItem *b = pickItemOnPoint((int)(direction_ne_sw ? selectionRect.left() : selectionRect.right()), (int)selectionRect.bottom());
const PageViewItem *b = pickItemOnPoint((int)(direction_ne_sw ? selectionRect.left() : selectionRect.right()), (int)selectionRect.bottom());
int max = b && (b->pageNumber() != tmpmin) ? b->pageNumber() : tmpmax;
QList<int> affectedItemsIds;
@ -3365,16 +3365,16 @@ std::vector<std::unique_ptr<Okular::RegularAreaRect>> PageView::textSelections(c
firstpage = affectedItemsIds.first();
if (affectedItemsIds.count() == 1) {
PageViewItem *item = d->items[affectedItemsIds.first()];
const PageViewItem *item = d->items[affectedItemsIds.first()];
selectionRect.translate(-item->uncroppedGeometry().topLeft());
ret.push_back(textSelectionForItem(item, direction_ne_sw ? selectionRect.topRight() : selectionRect.topLeft(), direction_ne_sw ? selectionRect.bottomLeft() : selectionRect.bottomRight()));
} else if (affectedItemsIds.count() > 1) {
// first item
PageViewItem *first = d->items[affectedItemsIds.first()];
const PageViewItem *first = d->items[affectedItemsIds.first()];
QRect geom = first->croppedGeometry().intersected(selectionRect).translated(-first->uncroppedGeometry().topLeft());
ret.push_back(textSelectionForItem(first, selectionRect.bottom() > geom.height() ? (direction_ne_sw ? geom.topRight() : geom.topLeft()) : (direction_ne_sw ? geom.bottomRight() : geom.bottomLeft()), QPoint()));
// last item
PageViewItem *last = d->items[affectedItemsIds.last()];
const PageViewItem *last = d->items[affectedItemsIds.last()];
geom = last->croppedGeometry().intersected(selectionRect).translated(-last->uncroppedGeometry().topLeft());
// the last item needs to appended at last...
std::unique_ptr<Okular::RegularAreaRect> lastArea =
@ -4522,7 +4522,7 @@ void PageView::slotRelayoutPages()
// set all items geometry and resize contents. handle 'continuous' and 'single' modes separately
PageViewItem *currentItem = d->items[qMax(0, (int)d->document->currentPage())];
const PageViewItem *currentItem = d->items[qMax(0, (int)d->document->currentPage())];
// Here we find out column's width and row's height to compute a table
// so we can place widgets 'centered in virtual cells'.

View File

@ -1302,7 +1302,9 @@ void PresentationWidget::generateOverlay()
color = pal.color(QPalette::Active, QPalette::Highlight);
int sRed = color.red(), sGreen = color.green(), sBlue = color.blue();
// pointers
unsigned int *data = reinterpret_cast<unsigned int *>(image.bits()), *shadowData = reinterpret_cast<unsigned int *>(shadow.bits()), pixels = image.width() * image.height();
unsigned int *data = reinterpret_cast<unsigned int *>(image.bits());
const unsigned int *shadowData = reinterpret_cast<unsigned int *>(shadow.bits());
unsigned int pixels = image.width() * image.height();
// cache data (reduce computation time to 26%!)
int c1 = -1, c2 = -1, cR = 0, cG = 0, cB = 0, cA = 0;
// foreach pixel
@ -1649,7 +1651,7 @@ void PresentationWidget::slotChangeDrawingToolEngine(const QDomElement &element)
void PresentationWidget::slotAddDrawingToolActions()
{
DrawingToolActions *drawingToolActions = qobject_cast<DrawingToolActions *>(sender());
const DrawingToolActions *drawingToolActions = qobject_cast<DrawingToolActions *>(sender());
const QList<QAction *> actionsList = drawingToolActions->actions();
for (QAction *action : actionsList) {
@ -2262,7 +2264,7 @@ void PresentationWidget::slotProcessMovieAction(const Okular::MovieAction *actio
return;
}
Okular::Movie *movie = movieAnnotation->movie();
const Okular::Movie *movie = movieAnnotation->movie();
if (!movie) {
return;
}