| 1791 | } |
| 1792 | |
| 1793 | void DocumentPrivate::doContinueAllDocumentSearch(QSet<int> *pagesToNotify, QHash<Page *, QList<RegularAreaRect *>> *pageMatches, int currentPage, int searchID) |
| 1794 | { |
| 1795 | RunningSearch *search = m_searches.value(searchID); |
| 1796 | |
| 1797 | if (m_searchCancelled || !search) { |
| 1798 | typedef QList<RegularAreaRect *> Matches; |
| 1799 | |
| 1800 | QApplication::restoreOverrideCursor(); |
| 1801 | |
| 1802 | if (search) { |
| 1803 | search->isCurrentlySearching = false; |
| 1804 | } |
| 1805 | |
| 1806 | Q_EMIT m_parent->searchFinished(searchID, Document::SearchCancelled); |
| 1807 | for (const Matches &mv : std::as_const(*pageMatches)) { |
| 1808 | qDeleteAll(mv); |
| 1809 | } |
| 1810 | delete pageMatches; |
| 1811 | delete pagesToNotify; |
| 1812 | return; |
| 1813 | } |
| 1814 | |
| 1815 | if (currentPage < m_pagesVector.count()) { |
| 1816 | // get page (from the first to the last) |
| 1817 | Page *page = m_pagesVector.at(currentPage); |
| 1818 | |
| 1819 | // request search page if needed |
| 1820 | if (!page->hasTextPage()) { |
| 1821 | int pageNumber = page->number(); // redundant? is it == currentPage ? |
| 1822 | m_parent->requestTextPage(pageNumber); |
| 1823 | } |
| 1824 | |
| 1825 | // loop on a page adding highlights for all found items |
| 1826 | RegularAreaRect *lastMatch = nullptr; |
| 1827 | while (true) { |
| 1828 | if (lastMatch) { |
| 1829 | lastMatch = page->findText(searchID, search->cachedString, NextResult, search->cachedCaseSensitivity, lastMatch); |
| 1830 | } else { |
| 1831 | lastMatch = page->findText(searchID, search->cachedString, FromTop, search->cachedCaseSensitivity); |
| 1832 | } |
| 1833 | |
| 1834 | if (!lastMatch) { |
| 1835 | break; |
| 1836 | } |
| 1837 | |
| 1838 | // add highlight rect to the matches map |
| 1839 | (*pageMatches)[page].append(lastMatch); |
| 1840 | } |
| 1841 | delete lastMatch; |
| 1842 | |
| 1843 | QTimer::singleShot(0, m_parent, [this, pagesToNotify, pageMatches, currentPage, searchID] { doContinueAllDocumentSearch(pagesToNotify, pageMatches, currentPage + 1, searchID); }); |
| 1844 | } else { |
| 1845 | // reset cursor to previous shape |
| 1846 | QApplication::restoreOverrideCursor(); |
| 1847 | |
| 1848 | search->isCurrentlySearching = false; |
| 1849 | bool foundAMatch = pageMatches->count() != 0; |
| 1850 | for (auto [key, value] : pageMatches->asKeyValueRange()) { |
no test coverage detected