! * extended search for Text, column-major order */
| 1765 | * extended search for Text, column-major order |
| 1766 | */ |
| 1767 | void SpreadsheetTest::testSearchExtended00() { |
| 1768 | #ifdef __FreeBSD__ |
| 1769 | // ASSERT failure in QBoxLayout::insert: "index out of range" |
| 1770 | return; |
| 1771 | #endif |
| 1772 | Project project; |
| 1773 | auto* sheet = createSearchReplaceSpreadsheet(); |
| 1774 | project.addChild(sheet); |
| 1775 | |
| 1776 | // navigate to the (0,0) cell having the text value "A" |
| 1777 | auto* view = static_cast<SpreadsheetView*>(sheet->view()); |
| 1778 | view->goToCell(0, 0); |
| 1779 | |
| 1780 | // check the initial selection |
| 1781 | auto indexes = view->selectionModel()->selectedIndexes(); |
| 1782 | QCOMPARE(indexes.count(), 1); |
| 1783 | auto curIndex = indexes.constFirst(); |
| 1784 | QCOMPARE(curIndex.row(), 0); |
| 1785 | QCOMPARE(curIndex.column(), 0); |
| 1786 | |
| 1787 | // initialize the search&replace widget |
| 1788 | auto* searchReplaceWidget = new SearchReplaceWidget(sheet, view); |
| 1789 | searchReplaceWidget->setReplaceEnabled(true); |
| 1790 | searchReplaceWidget->setDataType(SearchReplaceWidget::DataType::Text); |
| 1791 | searchReplaceWidget->setOrder(SearchReplaceWidget::Order::ColumnMajor); |
| 1792 | const auto& firstIndex = indexes.constFirst(); |
| 1793 | const auto* column = sheet->column(firstIndex.column()); |
| 1794 | const int row = firstIndex.row(); |
| 1795 | searchReplaceWidget->setInitialPattern(column->columnMode(), column->asStringColumn()->textAt(row)); |
| 1796 | |
| 1797 | // checks: the initial cell text is "A", we navigate with 'next' |
| 1798 | // and then back with 'prev' in the column-major order looking for "A" |
| 1799 | |
| 1800 | // next |
| 1801 | searchReplaceWidget->findNext(true); |
| 1802 | indexes = view->selectionModel()->selectedIndexes(); |
| 1803 | QCOMPARE(indexes.count(), 1); |
| 1804 | curIndex = indexes.constFirst(); |
| 1805 | QCOMPARE(curIndex.row(), 2); |
| 1806 | QCOMPARE(curIndex.column(), 0); |
| 1807 | |
| 1808 | // next |
| 1809 | searchReplaceWidget->findNext(true); |
| 1810 | indexes = view->selectionModel()->selectedIndexes(); |
| 1811 | QCOMPARE(indexes.count(), 1); |
| 1812 | curIndex = indexes.constFirst(); |
| 1813 | QCOMPARE(curIndex.row(), 1); |
| 1814 | QCOMPARE(curIndex.column(), 2); |
| 1815 | |
| 1816 | // next, last matching cell reached |
| 1817 | searchReplaceWidget->findNext(true); |
| 1818 | indexes = view->selectionModel()->selectedIndexes(); |
| 1819 | QCOMPARE(indexes.count(), 1); |
| 1820 | curIndex = indexes.constFirst(); |
| 1821 | QCOMPARE(curIndex.row(), 1); |
| 1822 | QCOMPARE(curIndex.column(), 2); |
| 1823 | |
| 1824 | // previous |
nothing calls this directly
no test coverage detected