Commit d0e96aa2 authored by Shawn Rutledge's avatar Shawn Rutledge
Browse files

Use a timer to update PdfSearchModel in the background


Change-Id: I855150578c9127b175c5907500d057b704fe5e0e
Reviewed-by: default avatarShawn Rutledge <shawn.rutledge@qt.io>
Showing with 21 additions and 0 deletions
...@@ -85,6 +85,7 @@ Q_SIGNALS: ...@@ -85,6 +85,7 @@ Q_SIGNALS:
protected: protected:
void updatePage(int page); void updatePage(int page);
void timerEvent(QTimerEvent *event) override;
private: private:
QHash<int, QByteArray> m_roleNames; QHash<int, QByteArray> m_roleNames;
......
...@@ -77,6 +77,8 @@ public: ...@@ -77,6 +77,8 @@ public:
QVector<bool> pagesSearched; QVector<bool> pagesSearched;
QVector<QVector<QPdfSearchResult>> searchResults; QVector<QVector<QPdfSearchResult>> searchResults;
int rowCountSoFar = 0; int rowCountSoFar = 0;
int updateTimerId = -1;
int nextPageToUpdate = 0;
}; };
QT_END_NAMESPACE QT_END_NAMESPACE
......
...@@ -51,6 +51,7 @@ QT_BEGIN_NAMESPACE ...@@ -51,6 +51,7 @@ QT_BEGIN_NAMESPACE
Q_LOGGING_CATEGORY(qLcS, "qt.pdf.search") Q_LOGGING_CATEGORY(qLcS, "qt.pdf.search")
static const int UpdateTimerInterval = 100;
static const int ContextChars = 20; static const int ContextChars = 20;
static const double CharacterHitTolerance = 6.0; static const double CharacterHitTolerance = 6.0;
...@@ -164,12 +165,27 @@ void QPdfSearchModel::setDocument(QPdfDocument *document) ...@@ -164,12 +165,27 @@ void QPdfSearchModel::setDocument(QPdfDocument *document)
d->clearResults(); d->clearResults();
} }
void QPdfSearchModel::timerEvent(QTimerEvent *event)
{
Q_D(QPdfSearchModel);
if (event->timerId() != d->updateTimerId)
return;
if (!d->document || d->nextPageToUpdate >= d->document->pageCount()) {
if (d->document)
qCDebug(qLcS, "done updating search results on %d pages", d->searchResults.count());
killTimer(d->updateTimerId);
d->updateTimerId = -1;
}
d->doSearch(d->nextPageToUpdate++);
}
QPdfSearchModelPrivate::QPdfSearchModelPrivate() QPdfSearchModelPrivate::QPdfSearchModelPrivate()
{ {
} }
void QPdfSearchModelPrivate::clearResults() void QPdfSearchModelPrivate::clearResults()
{ {
Q_Q(QPdfSearchModel);
rowCountSoFar = 0; rowCountSoFar = 0;
searchResults.clear(); searchResults.clear();
pagesSearched.clear(); pagesSearched.clear();
...@@ -180,6 +196,8 @@ void QPdfSearchModelPrivate::clearResults() ...@@ -180,6 +196,8 @@ void QPdfSearchModelPrivate::clearResults()
searchResults.resize(0); searchResults.resize(0);
pagesSearched.resize(0); pagesSearched.resize(0);
} }
nextPageToUpdate = 0;
updateTimerId = q->startTimer(UpdateTimerInterval);
} }
bool QPdfSearchModelPrivate::doSearch(int page) bool QPdfSearchModelPrivate::doSearch(int page)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment