MCPcopy Create free account
hub / github.com/KDE/labplot / testSearchReplaceNumeric

Method testSearchReplaceNumeric

tests/spreadsheet/SpreadsheetTest.cpp:2137–2198  ·  view source on GitHub ↗

! * replace a numeric value in int and double columns via "replace next" */

Source from the content-addressed store, hash-verified

2135 * replace a numeric value in int and double columns via "replace next"
2136 */
2137void SpreadsheetTest::testSearchReplaceNumeric() {
2138#ifdef __FreeBSD__
2139 // ASSERT failure in QBoxLayout::insert: "index out of range"
2140 return;
2141#endif
2142 Project project;
2143 auto* sheet = createSearchReplaceSpreadsheet();
2144 project.addChild(sheet);
2145
2146 // navigate to the (1,1) cell having the numeric value 2
2147 auto* view = static_cast<SpreadsheetView*>(sheet->view());
2148 view->goToCell(1, 1);
2149
2150 // check the initial selection
2151 auto indexes = view->selectionModel()->selectedIndexes();
2152 QCOMPARE(indexes.count(), 1);
2153 auto curIndex = indexes.constFirst();
2154 QCOMPARE(curIndex.row(), 1);
2155 QCOMPARE(curIndex.column(), 1);
2156
2157 // initialize the search&replace widget
2158 auto* searchReplaceWidget = new SearchReplaceWidget(sheet, view);
2159 searchReplaceWidget->setReplaceEnabled(true);
2160 searchReplaceWidget->setDataType(SearchReplaceWidget::DataType::Numeric);
2161 searchReplaceWidget->setOrder(SearchReplaceWidget::Order::ColumnMajor);
2162 searchReplaceWidget->setReplaceText(QLatin1String("5"));
2163 const auto& firstIndex = indexes.constFirst();
2164 const auto* column = sheet->column(firstIndex.column());
2165 const int row = firstIndex.row();
2166 searchReplaceWidget->setInitialPattern(column->columnMode(), column->asStringColumn()->textAt(row));
2167
2168 // checks: the initial cell text is (1,1) with the value 2, we replace this value with 5 via replaceNext,
2169 // and proceed to other cells with further replaceNext calls.
2170 const auto& columns = sheet->children<Column>();
2171
2172 // replace next - the value in the currently selected cell should be replaced first
2173 searchReplaceWidget->replaceNext();
2174 indexes = view->selectionModel()->selectedIndexes();
2175 QCOMPARE(indexes.count(), 1);
2176 curIndex = indexes.constFirst();
2177 QCOMPARE(curIndex.row(), 1);
2178 QCOMPARE(curIndex.column(), 1);
2179 QCOMPARE(columns.at(1)->integerAt(1), 5);
2180
2181 // replace next
2182 searchReplaceWidget->replaceNext();
2183 indexes = view->selectionModel()->selectedIndexes();
2184 QCOMPARE(indexes.count(), 1);
2185 curIndex = indexes.constFirst();
2186 QCOMPARE(curIndex.row(), 3);
2187 QCOMPARE(curIndex.column(), 1);
2188 QCOMPARE(columns.at(1)->integerAt(1), 5);
2189
2190 // replace next
2191 searchReplaceWidget->replaceNext();
2192 indexes = view->selectionModel()->selectedIndexes();
2193 QCOMPARE(indexes.count(), 1);
2194 curIndex = indexes.constFirst();

Callers

nothing calls this directly

Calls 15

selectionModelMethod · 0.80
setReplaceEnabledMethod · 0.80
setOrderMethod · 0.80
setReplaceTextMethod · 0.80
setInitialPatternMethod · 0.80
asStringColumnMethod · 0.80
replaceNextMethod · 0.80
addChildMethod · 0.45
viewMethod · 0.45
goToCellMethod · 0.45
countMethod · 0.45
rowMethod · 0.45

Tested by

no test coverage detected