! * extended search for Text, row-major order */
| 1850 | * extended search for Text, row-major order |
| 1851 | */ |
| 1852 | void SpreadsheetTest::testSearchExtended01() { |
| 1853 | #ifdef __FreeBSD__ |
| 1854 | // ASSERT failure in QBoxLayout::insert: "index out of range" |
| 1855 | return; |
| 1856 | #endif |
| 1857 | Project project; |
| 1858 | auto* sheet = createSearchReplaceSpreadsheet(); |
| 1859 | project.addChild(sheet); |
| 1860 | |
| 1861 | // navigate to the (0,0) cell having the text value "A" |
| 1862 | auto* view = static_cast<SpreadsheetView*>(sheet->view()); |
| 1863 | view->goToCell(0, 0); |
| 1864 | |
| 1865 | // check the initial selection |
| 1866 | auto indexes = view->selectionModel()->selectedIndexes(); |
| 1867 | QCOMPARE(indexes.count(), 1); |
| 1868 | auto curIndex = indexes.constFirst(); |
| 1869 | QCOMPARE(curIndex.row(), 0); |
| 1870 | QCOMPARE(curIndex.column(), 0); |
| 1871 | |
| 1872 | // initialize the search&replace widget |
| 1873 | auto* searchReplaceWidget = new SearchReplaceWidget(sheet, view); |
| 1874 | searchReplaceWidget->setReplaceEnabled(true); |
| 1875 | searchReplaceWidget->setDataType(SearchReplaceWidget::DataType::Text); |
| 1876 | searchReplaceWidget->setOrder(SearchReplaceWidget::Order::RowMajor); |
| 1877 | const auto& firstIndex = indexes.constFirst(); |
| 1878 | const auto* column = sheet->column(firstIndex.column()); |
| 1879 | const int row = firstIndex.row(); |
| 1880 | searchReplaceWidget->setInitialPattern(column->columnMode(), column->asStringColumn()->textAt(row)); |
| 1881 | |
| 1882 | // checks: the initial cell text is "A", we navigate with 'next' |
| 1883 | // and then back with 'prev' in the row-major order looking for "A" |
| 1884 | |
| 1885 | // next |
| 1886 | searchReplaceWidget->findNext(true); |
| 1887 | indexes = view->selectionModel()->selectedIndexes(); |
| 1888 | QCOMPARE(indexes.count(), 1); |
| 1889 | curIndex = indexes.constFirst(); |
| 1890 | QCOMPARE(curIndex.row(), 1); |
| 1891 | QCOMPARE(curIndex.column(), 2); |
| 1892 | |
| 1893 | // next |
| 1894 | searchReplaceWidget->findNext(true); |
| 1895 | indexes = view->selectionModel()->selectedIndexes(); |
| 1896 | QCOMPARE(indexes.count(), 1); |
| 1897 | curIndex = indexes.constFirst(); |
| 1898 | QCOMPARE(curIndex.row(), 2); |
| 1899 | QCOMPARE(curIndex.column(), 0); |
| 1900 | |
| 1901 | // next, last matching cell reached |
| 1902 | searchReplaceWidget->findNext(true); |
| 1903 | indexes = view->selectionModel()->selectedIndexes(); |
| 1904 | QCOMPARE(indexes.count(), 1); |
| 1905 | curIndex = indexes.constFirst(); |
| 1906 | QCOMPARE(curIndex.row(), 2); |
| 1907 | QCOMPARE(curIndex.column(), 0); |
| 1908 | |
| 1909 | // previous |
nothing calls this directly
no test coverage detected