Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qquickpdfsearchmodel.cpp
Go to the documentation of this file.
1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5#include <QtCore/qloggingcategory.h>
6
8
9Q_LOGGING_CATEGORY(qLcSearch, "qt.pdf.search")
10
11
14
24 : QPdfSearchModel(parent)
25{
27 this, &QQuickPdfSearchModel::onResultsChanged);
28}
29
34
36{
37 return m_quickDocument;
38}
39
41{
42 if (document == m_quickDocument || !document)
43 return;
44
45 m_quickDocument = document;
47}
48
82{
83 QList<QPolygonF> ret;
84 const auto result = currentResultLink();
85 if (result.page() != m_currentPage)
86 return ret;
87 for (auto rect : result.rectangles())
88 ret << QPolygonF(rect);
89 return ret;
90}
91
99{
100 QRectF ret;
101 const auto result = currentResultLink();
102 if (result.page() != m_currentPage)
103 return ret;
104 auto rects = result.rectangles();
105 if (!rects.isEmpty()) {
106 ret = rects.takeFirst();
107 for (auto rect : rects)
108 ret = ret.united(rect);
109 }
110 return ret;
111}
112
113void QQuickPdfSearchModel::onResultsChanged()
114{
117}
118
147{
148 return const_cast<QQuickPdfSearchModel *>(this)->boundingPolygonsOnPage(m_currentPage);
149}
150
178{
179 if (!document() || searchString().isEmpty() || page < 0 || page > document()->document()->pageCount())
180 return {};
181
183
184 QList<QPolygonF> ret;
186 for (const auto &result : m) {
187 for (const auto &rect : result.rectangles())
188 ret << QPolygonF(rect);
189 }
190
191 return ret;
192}
193
201{
202 if (m_currentPage == currentPage || !document())
203 return;
204
205 const auto pageCount = document()->document()->pageCount();
206 if (currentPage < 0)
207 currentPage = pageCount - 1;
208 else if (currentPage >= pageCount)
209 currentPage = 0;
210
211 m_currentPage = currentPage;
212 if (!m_suspendSignals) {
214 onResultsChanged();
215 }
216}
217
226{
227 if (m_currentResult == currentResult)
228 return;
229
230 const int currentResultWas = m_currentResult;
231 const int currentPageWas = m_currentPage;
232 const int resultCount = rowCount({});
233
234 // wrap around at the ends
235 if (currentResult >= resultCount) {
236 currentResult = 0;
237 } else if (currentResult < 0) {
238 currentResult = resultCount - 1;
239 }
240
242 if (link.isValid()) {
243 setCurrentPage(link.page());
244 m_currentResult = currentResult;
249 qCDebug(qLcSearch) << "currentResult was" << currentResultWas
250 << "requested" << currentResult << "on page" << currentPageWas
251 << "->" << m_currentResult << "on page" << m_currentPage;
252 } else {
253 qWarning() << "failed to find result" << currentResult << "in range 0 ->" << resultCount;
254 }
255}
256
263{
264 return resultAtIndex(m_currentResult);
265}
266
281
282#include "moc_qquickpdfsearchmodel_p.cpp"
\inmodule QtCore
Definition qobject.h:103
int pageCount
This property holds the number of pages in the loaded document or 0 if no document is loaded.
The QPdfSearchModel class searches for a string in a PDF document and holds the results.
QString searchString
the string to search for
int rowCount(const QModelIndex &parent) const override
\reimp
QPdfLink resultAtIndex(int index) const
Returns a result found by index in the \l document, regardless of the page on which it was found.
void setDocument(QPdfDocument *document)
void updatePage(int page)
void searchStringChanged()
QList< QPdfLink > resultsOnPage(int page) const
Returns the list of all results found on the given page.
The QPolygonF class provides a list of points using floating point precision.
Definition qpolygon.h:96
QQuickPdfDocument * document
QList< QPolygonF > currentPageBoundingPolygons
void setDocument(QQuickPdfDocument *document)
void setCurrentResult(int currentResult)
\qmlproperty int PdfSearchModel::currentResult
void currentResultLinkChanged()
void currentResultBoundingPolygonsChanged()
~QQuickPdfSearchModel() override
Q_INVOKABLE QList< QPolygonF > boundingPolygonsOnPage(int page)
\qmlmethod list<list<point>> PdfSearchModel::boundingPolygonsOnPage(int page)
QList< QPolygonF > currentResultBoundingPolygons
void currentResultBoundingRectChanged()
void currentPageBoundingPolygonsChanged()
void setCurrentPage(int currentPage)
\qmlproperty int PdfSearchModel::currentPage
\inmodule QtCore\reentrant
Definition qrect.h:484
rect
[4]
Combined button and popup list for selecting options.
#define qWarning
Definition qlogging.h:166
#define Q_LOGGING_CATEGORY(name,...)
#define qCDebug(category,...)
return ret
const GLfloat * m
GLuint64EXT * result
[6]
#define emit
connect(quitButton, &QPushButton::clicked, &app, &QCoreApplication::quit, Qt::QueuedConnection)
QByteArray page
[45]