24QQuickPdfSearchModel::QQuickPdfSearchModel(QObject *parent)
25 : QPdfSearchModel(parent)
27 connect(
this, &QPdfSearchModel::searchStringChanged,
28 this, &QQuickPdfSearchModel::onResultsChanged);
178QList<QPolygonF> QQuickPdfSearchModel::boundingPolygonsOnPage(
int page)
180 if (!document() || searchString().isEmpty() || page < 0 || page > document()->document()->pageCount())
185 QList<QPolygonF> ret;
186 const auto m = QPdfSearchModel::resultsOnPage(page);
187 for (
const auto &result : m) {
188 for (
const auto &rect : result.rectangles())
189 ret << QPolygonF(rect);
201void QQuickPdfSearchModel::setCurrentPage(
int currentPage)
203 if (m_currentPage == currentPage || !document())
206 const auto pageCount = document()->document()->pageCount();
208 currentPage = pageCount - 1;
209 else if (currentPage >= pageCount)
212 m_currentPage = currentPage;
213 if (!m_suspendSignals) {
214 emit currentPageChanged();
226void QQuickPdfSearchModel::setCurrentResult(
int currentResult)
228 if (m_currentResult == currentResult)
231 const int currentResultWas = m_currentResult;
232 const int currentPageWas = m_currentPage;
233 const int resultCount = rowCount({});
236 if (currentResult >= resultCount) {
238 }
else if (currentResult < 0) {
239 currentResult = resultCount - 1;
242 const QPdfLink link = resultAtIndex(currentResult);
243 if (link.isValid()) {
244 setCurrentPage(link.page());
245 m_currentResult = currentResult;
246 emit currentResultChanged();
247 emit currentResultLinkChanged();
248 emit currentResultBoundingPolygonsChanged();
249 emit currentResultBoundingRectChanged();
250 qCDebug(qLcSearch) <<
"currentResult was" << currentResultWas
251 <<
"requested" << currentResult <<
"on page" << currentPageWas
252 <<
"->" << m_currentResult <<
"on page" << m_currentPage;
254 qWarning() <<
"failed to find result" << currentResult <<
"in range 0 ->" << resultCount;