diff options
author | Marc Mutz <marc.mutz@qt.io> | 2022-10-05 08:22:39 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2022-10-11 17:36:36 +0200 |
commit | 39ebe4abccdc4e059a0e310a331f3fc392c84009 (patch) | |
tree | aeca91ed813d6675693fcb9e71d8336c3d303cab /src/pdf | |
parent | 555beb85735f8ce92fdbff7358a6659820e4819c (diff) | |
download | qtwebengine-39ebe4abccdc4e059a0e310a331f3fc392c84009.tar.gz |
Port from container::count() and length() to size() - V4
This is a semantic patch using ClangTidyTransformator as in
qtbase/df9d882d41b741fef7c5beeddb0abe9d904443d8, but extended to
handle typedefs and accesses through pointers, too:
const std::string o = "object";
auto hasTypeIgnoringPointer = [](auto type) { return anyOf(hasType(type), hasType(pointsTo(type))); };
auto derivedFromAnyOfClasses = [&](ArrayRef<StringRef> classes) {
auto exprOfDeclaredType = [&](auto decl) {
return expr(hasTypeIgnoringPointer(hasUnqualifiedDesugaredType(recordType(hasDeclaration(decl))))).bind(o);
};
return exprOfDeclaredType(cxxRecordDecl(isSameOrDerivedFrom(hasAnyName(classes))));
};
auto renameMethod = [&] (ArrayRef<StringRef> classes,
StringRef from, StringRef to) {
return makeRule(cxxMemberCallExpr(on(derivedFromAnyOfClasses(classes)),
callee(cxxMethodDecl(hasName(from), parameterCountIs(0)))),
changeTo(cat(access(o, cat(to)), "()")),
cat("use '", to, "' instead of '", from, "'"));
};
renameMethod(<classes>, "count", "size");
renameMethod(<classes>, "length", "size");
a.k.a qt-port-to-std-compatible-api V4 with config Scope: 'Container'.
Change-Id: I3e6fef8eca212da0c4f0b464545ba96183b4476f
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'src/pdf')
-rw-r--r-- | src/pdf/qpdfbookmarkmodel.cpp | 4 | ||||
-rw-r--r-- | src/pdf/qpdfdocument.cpp | 8 | ||||
-rw-r--r-- | src/pdf/qpdflinkmodel.cpp | 2 | ||||
-rw-r--r-- | src/pdf/qpdfpagenavigator.cpp | 22 | ||||
-rw-r--r-- | src/pdf/qpdfsearchmodel.cpp | 22 |
5 files changed, 29 insertions, 29 deletions
diff --git a/src/pdf/qpdfbookmarkmodel.cpp b/src/pdf/qpdfbookmarkmodel.cpp index 7b984a300..c9035f21a 100644 --- a/src/pdf/qpdfbookmarkmodel.cpp +++ b/src/pdf/qpdfbookmarkmodel.cpp @@ -50,7 +50,7 @@ public: int childCount() const { - return m_childNodes.count(); + return m_childNodes.size(); } int row() const @@ -172,7 +172,7 @@ struct QPdfBookmarkModelPrivate const int titleLength = int(FPDFBookmark_GetTitle(bookmark, nullptr, 0)); QList<char16_t> titleBuffer(titleLength); - FPDFBookmark_GetTitle(bookmark, titleBuffer.data(), quint32(titleBuffer.length())); + FPDFBookmark_GetTitle(bookmark, titleBuffer.data(), quint32(titleBuffer.size())); const FPDF_DEST dest = FPDFBookmark_GetDest(document, bookmark); const int pageNumber = FPDFDest_GetDestPageIndex(document, dest); diff --git a/src/pdf/qpdfdocument.cpp b/src/pdf/qpdfdocument.cpp index b738296ae..9b8d20d3b 100644 --- a/src/pdf/qpdfdocument.cpp +++ b/src/pdf/qpdfdocument.cpp @@ -639,7 +639,7 @@ QVariant QPdfDocument::metaData(MetaDataField field) const const unsigned long len = FPDF_GetMetaText(d->doc, fieldName.constData(), nullptr, 0); QList<ushort> buf(len); - FPDF_GetMetaText(d->doc, fieldName.constData(), buf.data(), buf.length()); + FPDF_GetMetaText(d->doc, fieldName.constData(), buf.data(), buf.size()); lock.unlock(); QString text = QString::fromUtf16(reinterpret_cast<const char16_t *>(buf.data())); @@ -969,7 +969,7 @@ QPdfSelection QPdfDocument::getSelectionAtIndex(int page, int startIndex, int ma QString text; if (maxLength > 0) { text = d->getText(textPage, startIndex, maxLength); - rectCount = FPDFText_CountRects(textPage, startIndex, text.length()); + rectCount = FPDFText_CountRects(textPage, startIndex, text.size()); for (int i = 0; i < rectCount; ++i) { double l, r, b, t; FPDFText_GetRect(textPage, i, &l, &t, &r, &b); @@ -984,12 +984,12 @@ QPdfSelection QPdfDocument::getSelectionAtIndex(int page, int startIndex, int ma if (bounds.isEmpty()) hull = QRectF(d->getCharPosition(textPage, pageHeight, startIndex), QSizeF()); qCDebug(qLcDoc) << "on page" << page << "at index" << startIndex << "maxLength" << maxLength - << "got" << text.length() << "chars," << rectCount << "rects within" << hull; + << "got" << text.size() << "chars," << rectCount << "rects within" << hull; FPDFText_ClosePage(textPage); FPDF_ClosePage(pdfPage); - return QPdfSelection(text, bounds, hull, startIndex, startIndex + text.length()); + return QPdfSelection(text, bounds, hull, startIndex, startIndex + text.size()); } /*! diff --git a/src/pdf/qpdflinkmodel.cpp b/src/pdf/qpdflinkmodel.cpp index 349e6a40b..c98a8723e 100644 --- a/src/pdf/qpdflinkmodel.cpp +++ b/src/pdf/qpdflinkmodel.cpp @@ -68,7 +68,7 @@ int QPdfLinkModel::rowCount(const QModelIndex &parent) const { Q_D(const QPdfLinkModel); Q_UNUSED(parent); - return d->links.count(); + return d->links.size(); } /*! \internal diff --git a/src/pdf/qpdfpagenavigator.cpp b/src/pdf/qpdfpagenavigator.cpp index 9e807e5cd..253c1dff8 100644 --- a/src/pdf/qpdfpagenavigator.cpp +++ b/src/pdf/qpdfpagenavigator.cpp @@ -62,7 +62,7 @@ QPdfPageNavigator::~QPdfPageNavigator() */ void QPdfPageNavigator::forward() { - if (d->currentHistoryIndex >= d->pageHistory.count() - 1) + if (d->currentHistoryIndex >= d->pageHistory.size() - 1) return; const bool backAvailableWas = backAvailable(); const bool forwardAvailableWas = forwardAvailable(); @@ -122,7 +122,7 @@ void QPdfPageNavigator::back() */ int QPdfPageNavigator::currentPage() const { - if (d->currentHistoryIndex < 0 || d->currentHistoryIndex >= d->pageHistory.count()) + if (d->currentHistoryIndex < 0 || d->currentHistoryIndex >= d->pageHistory.size()) return -1; // only until ctor or clear() runs return d->pageHistory.at(d->currentHistoryIndex)->page; } @@ -136,7 +136,7 @@ int QPdfPageNavigator::currentPage() const */ QPointF QPdfPageNavigator::currentLocation() const { - if (d->currentHistoryIndex < 0 || d->currentHistoryIndex >= d->pageHistory.count()) + if (d->currentHistoryIndex < 0 || d->currentHistoryIndex >= d->pageHistory.size()) return QPointF(); return d->pageHistory.at(d->currentHistoryIndex)->location; } @@ -149,14 +149,14 @@ QPointF QPdfPageNavigator::currentLocation() const */ qreal QPdfPageNavigator::currentZoom() const { - if (d->currentHistoryIndex < 0 || d->currentHistoryIndex >= d->pageHistory.count()) + if (d->currentHistoryIndex < 0 || d->currentHistoryIndex >= d->pageHistory.size()) return 1; return d->pageHistory.at(d->currentHistoryIndex)->zoom; } QPdfLink QPdfPageNavigator::currentLink() const { - if (d->currentHistoryIndex < 0 || d->currentHistoryIndex >= d->pageHistory.count()) + if (d->currentHistoryIndex < 0 || d->currentHistoryIndex >= d->pageHistory.size()) return QPdfLink(); return QPdfLink(d->pageHistory.at(d->currentHistoryIndex).data()); } @@ -195,9 +195,9 @@ void QPdfPageNavigator::jump(QPdfLink destination) const bool forwardAvailableWas = forwardAvailable(); if (!d->changing) { if (d->currentHistoryIndex >= 0 && forwardAvailableWas) - d->pageHistory.remove(d->currentHistoryIndex + 1, d->pageHistory.count() - d->currentHistoryIndex - 1); + d->pageHistory.remove(d->currentHistoryIndex + 1, d->pageHistory.size() - d->currentHistoryIndex - 1); d->pageHistory.append(destination.d); - d->currentHistoryIndex = d->pageHistory.count() - 1; + d->currentHistoryIndex = d->pageHistory.size() - 1; } if (zoomChange) emit currentZoomChanged(currentZoom()); @@ -251,9 +251,9 @@ void QPdfPageNavigator::jump(int page, const QPointF &location, qreal zoom) const bool forwardAvailableWas = forwardAvailable(); if (!d->changing) { if (d->currentHistoryIndex >= 0 && forwardAvailableWas) - d->pageHistory.remove(d->currentHistoryIndex + 1, d->pageHistory.count() - d->currentHistoryIndex - 1); + d->pageHistory.remove(d->currentHistoryIndex + 1, d->pageHistory.size() - d->currentHistoryIndex - 1); d->pageHistory.append(QExplicitlySharedDataPointer<QPdfLinkPrivate>(new QPdfLinkPrivate(page, location, zoom))); - d->currentHistoryIndex = d->pageHistory.count() - 1; + d->currentHistoryIndex = d->pageHistory.size() - 1; } if (zoomChange) emit currentZoomChanged(currentZoom()); @@ -293,7 +293,7 @@ void QPdfPageNavigator::jump(int page, const QPointF &location, qreal zoom) */ void QPdfPageNavigator::update(int page, const QPointF &location, qreal zoom) { - if (d->currentHistoryIndex < 0 || d->currentHistoryIndex >= d->pageHistory.count()) + if (d->currentHistoryIndex < 0 || d->currentHistoryIndex >= d->pageHistory.size()) return; int currentPageWas = currentPage(); QPointF currentLocationWas = currentLocation(); @@ -340,7 +340,7 @@ bool QPdfPageNavigator::backAvailable() const */ bool QPdfPageNavigator::forwardAvailable() const { - return d->currentHistoryIndex < d->pageHistory.count() - 1; + return d->currentHistoryIndex < d->pageHistory.size() - 1; } /*! diff --git a/src/pdf/qpdfsearchmodel.cpp b/src/pdf/qpdfsearchmodel.cpp index e8946ea86..a8946ccfe 100644 --- a/src/pdf/qpdfsearchmodel.cpp +++ b/src/pdf/qpdfsearchmodel.cpp @@ -161,7 +161,7 @@ QList<QPdfLink> QPdfSearchModel::resultsOnPage(int page) const { Q_D(const QPdfSearchModel); const_cast<QPdfSearchModelPrivate *>(d)->doSearch(page); - if (d->searchResults.count() <= page) + if (d->searchResults.size() <= page) return {}; return d->searchResults[page]; } @@ -207,7 +207,7 @@ void QPdfSearchModel::timerEvent(QTimerEvent *event) return; if (!d->document || d->nextPageToUpdate >= d->document->pageCount()) { if (d->document) - qCDebug(qLcS) << "done updating search results on" << d->searchResults.count() << "pages"; + qCDebug(qLcS) << "done updating search results on" << d->searchResults.size() << "pages"; killTimer(d->updateTimerId); d->updateTimerId = -1; } @@ -234,7 +234,7 @@ void QPdfSearchModelPrivate::clearResults() bool QPdfSearchModelPrivate::doSearch(int page) { - if (page < 0 || page >= pagesSearched.count() || searchString.isEmpty()) + if (page < 0 || page >= pagesSearched.size() || searchString.isEmpty()) return false; if (pagesSearched[page]) return true; @@ -298,7 +298,7 @@ bool QPdfSearchModelPrivate::doSearch(int page) if (si < 0) qWarning() << "search string" << searchString << "not found in context" << context; contextBefore = context.mid(0, si); - contextAfter = context.mid(si + searchString.length()); + contextAfter = context.mid(si + searchString.size()); } } if (!rects.isEmpty()) @@ -308,15 +308,15 @@ bool QPdfSearchModelPrivate::doSearch(int page) FPDFText_ClosePage(textPage); FPDF_ClosePage(pdfPage); qCDebug(qLcS) << searchString << "took" << timer.elapsed() << "ms to find" - << newSearchResults.count() << "results on page" << page; + << newSearchResults.size() << "results on page" << page; pagesSearched[page] = true; searchResults[page] = newSearchResults; - if (newSearchResults.count() > 0) { + if (newSearchResults.size() > 0) { int rowsBefore = rowsBeforePage(page); - qCDebug(qLcS) << "from row" << rowsBefore << "rowCount" << rowCountSoFar << "increasing by" << newSearchResults.count(); - rowCountSoFar += newSearchResults.count(); - q->beginInsertRows(QModelIndex(), rowsBefore, rowsBefore + newSearchResults.count() - 1); + qCDebug(qLcS) << "from row" << rowsBefore << "rowCount" << rowCountSoFar << "increasing by" << newSearchResults.size(); + rowCountSoFar += newSearchResults.size(); + q->beginInsertRows(QModelIndex(), rowsBefore, rowsBefore + newSearchResults.size() - 1); q->endInsertRows(); } return true; @@ -332,7 +332,7 @@ QPdfSearchModelPrivate::PageAndIndex QPdfSearchModelPrivate::pageAndIndexForResu for (int page = 0; page < pageCount; ++page) { if (!pagesSearched[page]) doSearch(page); - totalSoFar += searchResults[page].count(); + totalSoFar += searchResults[page].size(); if (totalSoFar > resultIndex) return {page, resultIndex - previousTotalSoFar}; previousTotalSoFar = totalSoFar; @@ -344,7 +344,7 @@ int QPdfSearchModelPrivate::rowsBeforePage(int page) { int ret = 0; for (int i = 0; i < page; ++i) - ret += searchResults[i].count(); + ret += searchResults[i].size(); return ret; } |