! * replace a text value in text columns via "replace next" */
| 2201 | * replace a text value in text columns via "replace next" |
| 2202 | */ |
| 2203 | void SpreadsheetTest::testSearchReplaceText() { |
| 2204 | #ifdef __FreeBSD__ |
| 2205 | // ASSERT failure in QBoxLayout::insert: "index out of range" |
| 2206 | return; |
| 2207 | #endif |
| 2208 | Project project; |
| 2209 | auto* sheet = createSearchReplaceSpreadsheet(); |
| 2210 | project.addChild(sheet); |
| 2211 | |
| 2212 | // navigate to the (0,0) cell having the text value "A" |
| 2213 | auto* view = static_cast<SpreadsheetView*>(sheet->view()); |
| 2214 | view->goToCell(0, 0); |
| 2215 | |
| 2216 | // check the initial selection |
| 2217 | auto indexes = view->selectionModel()->selectedIndexes(); |
| 2218 | QCOMPARE(indexes.count(), 1); |
| 2219 | auto curIndex = indexes.constFirst(); |
| 2220 | QCOMPARE(curIndex.row(), 0); |
| 2221 | QCOMPARE(curIndex.column(), 0); |
| 2222 | |
| 2223 | // initialize the search&replace widget |
| 2224 | auto* searchReplaceWidget = new SearchReplaceWidget(sheet, view); |
| 2225 | searchReplaceWidget->setReplaceEnabled(true); |
| 2226 | searchReplaceWidget->setDataType(SearchReplaceWidget::DataType::Text); |
| 2227 | searchReplaceWidget->setOrder(SearchReplaceWidget::Order::ColumnMajor); |
| 2228 | searchReplaceWidget->setReplaceText(QLatin1String("AAA")); |
| 2229 | const auto& firstIndex = indexes.constFirst(); |
| 2230 | const auto* column = sheet->column(firstIndex.column()); |
| 2231 | const int row = firstIndex.row(); |
| 2232 | searchReplaceWidget->setInitialPattern(column->columnMode(), column->asStringColumn()->textAt(row)); |
| 2233 | |
| 2234 | // checks: the initial cell text is (0,0) with the value "A", we replace this value with "AAA" via replaceNext, |
| 2235 | // and proceed to other cells with further replaceNext calls. |
| 2236 | const auto& columns = sheet->children<Column>(); |
| 2237 | |
| 2238 | // replace next - the value in the currently selected cell should be replaced first |
| 2239 | searchReplaceWidget->replaceNext(); |
| 2240 | indexes = view->selectionModel()->selectedIndexes(); |
| 2241 | QCOMPARE(indexes.count(), 1); |
| 2242 | curIndex = indexes.constFirst(); |
| 2243 | QCOMPARE(curIndex.row(), 0); |
| 2244 | QCOMPARE(curIndex.column(), 0); |
| 2245 | QCOMPARE(columns.at(0)->textAt(0), QLatin1String("AAA")); |
| 2246 | |
| 2247 | // replace next |
| 2248 | searchReplaceWidget->replaceNext(); |
| 2249 | indexes = view->selectionModel()->selectedIndexes(); |
| 2250 | QCOMPARE(indexes.count(), 1); |
| 2251 | curIndex = indexes.constFirst(); |
| 2252 | QCOMPARE(curIndex.row(), 2); |
| 2253 | QCOMPARE(curIndex.column(), 0); |
| 2254 | QCOMPARE(columns.at(0)->textAt(2), QLatin1String("AAA")); |
| 2255 | |
| 2256 | // replace next |
| 2257 | searchReplaceWidget->replaceNext(); |
| 2258 | indexes = view->selectionModel()->selectedIndexes(); |
| 2259 | QCOMPARE(indexes.count(), 1); |
| 2260 | curIndex = indexes.constFirst(); |
nothing calls this directly
no test coverage detected