| 1673 | } |
| 1674 | |
| 1675 | void DocumentPrivate::doContinueDirectionMatchSearch(DoContinueDirectionMatchSearchStruct *searchStruct) |
| 1676 | { |
| 1677 | RunningSearch *search = m_searches.value(searchStruct->searchID); |
| 1678 | |
| 1679 | if ((m_searchCancelled && !searchStruct->match) || !search) { |
| 1680 | // if the user cancelled but he just got a match, give him the match! |
| 1681 | QApplication::restoreOverrideCursor(); |
| 1682 | |
| 1683 | if (search) { |
| 1684 | search->isCurrentlySearching = false; |
| 1685 | } |
| 1686 | |
| 1687 | Q_EMIT m_parent->searchFinished(searchStruct->searchID, Document::SearchCancelled); |
| 1688 | delete searchStruct->pagesToNotify; |
| 1689 | delete searchStruct; |
| 1690 | return; |
| 1691 | } |
| 1692 | |
| 1693 | const bool forward = search->cachedType == Document::NextMatch; |
| 1694 | bool doContinue = false; |
| 1695 | // if no match found, loop through the whole doc, starting from currentPage |
| 1696 | if (!searchStruct->match) { |
| 1697 | const int pageCount = m_pagesVector.count(); |
| 1698 | if (search->pagesDone < pageCount) { |
| 1699 | doContinue = true; |
| 1700 | if (searchStruct->currentPage >= pageCount) { |
| 1701 | searchStruct->currentPage = 0; |
| 1702 | Q_EMIT m_parent->notice(i18n("Continuing search from beginning"), 3000); |
| 1703 | } else if (searchStruct->currentPage < 0) { |
| 1704 | searchStruct->currentPage = pageCount - 1; |
| 1705 | Q_EMIT m_parent->notice(i18n("Continuing search from bottom"), 3000); |
| 1706 | } |
| 1707 | } |
| 1708 | } |
| 1709 | |
| 1710 | if (doContinue) { |
| 1711 | // get page |
| 1712 | const Page *page = m_pagesVector[searchStruct->currentPage]; |
| 1713 | // request search page if needed |
| 1714 | if (!page->hasTextPage()) { |
| 1715 | m_parent->requestTextPage(page->number()); |
| 1716 | } |
| 1717 | |
| 1718 | // if found a match on the current page, end the loop |
| 1719 | searchStruct->match = page->findText(searchStruct->searchID, search->cachedString, forward ? FromTop : FromBottom, search->cachedCaseSensitivity); |
| 1720 | if (!searchStruct->match) { |
| 1721 | if (forward) { |
| 1722 | searchStruct->currentPage++; |
| 1723 | } else { |
| 1724 | searchStruct->currentPage--; |
| 1725 | } |
| 1726 | search->pagesDone++; |
| 1727 | } else { |
| 1728 | search->pagesDone = 1; |
| 1729 | } |
| 1730 | |
| 1731 | // Both of the previous if branches need to call doContinueDirectionMatchSearch |
| 1732 | QTimer::singleShot(0, m_parent, [this, searchStruct] { doContinueDirectionMatchSearch(searchStruct); }); |
no test coverage detected