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

Method findNextSimple

src/frontend/spreadsheet/SearchReplaceWidget.cpp:592–657  ·  view source on GitHub ↗

simple find functions ! * search the next cell in the column-major order that matches * to the specified pattern. The search is done ignoring the data type * and iterpreting everything as text. Used in the "simple search"-mode. */

Source from the content-addressed store, hash-verified

590 * and iterpreting everything as text. Used in the "simple search"-mode.
591 */
592bool SearchReplaceWidget::findNextSimple(bool proceed) {
593 const QString& pattern = uiSearch.cbFind->currentText();
594 if (pattern.isEmpty()) {
595 GuiTools::highlight(uiSearch.cbFind->lineEdit(), false);
596 return true;
597 }
598
599 const auto cs = uiSearch.tbMatchCase->isChecked() ? Qt::CaseSensitive : Qt::CaseInsensitive;
600
601 // spreadsheet size and the start cell
602 const int colCount = m_spreadsheet->columnCount();
603 const int rowCount = m_spreadsheet->rowCount();
604 int curRow = m_view->firstSelectedRow();
605 int curCol = m_view->firstSelectedColumn();
606
607 if (proceed) {
608 if (curRow != rowCount - 1)
609 ++curRow; // not the last row yet, navigate to the next row
610 else {
611 // last row
612 if (curCol != colCount - 1) {
613 // not the last column yet, navigate to the first row in the next column
614 ++curCol;
615 curRow = 0;
616 } else {
617 // last row in the last column, cannot navigate any further
618 GuiTools::highlight(uiSearch.cbFind->lineEdit(), !m_patternFound);
619 return false;
620 }
621 }
622 }
623
624 // all settings are determined -> search the next cell matching the specified pattern(s)
625 const auto& columns = m_spreadsheet->children<Column>();
626 bool startCol = true;
627 bool startRow = true;
628
629 // search in the column-major order ignoring the data type
630 // and iterpreting everything as text
631 for (int col = 0; col < colCount; ++col) {
632 if (startCol && col < curCol)
633 continue;
634
635 auto* column = columns.at(col)->asStringColumn();
636
637 for (int row = 0; row < rowCount; ++row) {
638 if (startRow && row < curRow)
639 continue;
640
641 if (column->textAt(row).contains(pattern, cs)) {
642 m_patternFound = true;
643 m_view->goToCell(row, col);
644 GuiTools::highlight(uiSearch.cbFind->lineEdit(), false);
645 return true;
646 }
647
648 startRow = false;
649 }

Callers 1

testSearchSimple00Method · 0.80

Calls 12

currentTextMethod · 0.80
lineEditMethod · 0.80
asStringColumnMethod · 0.80
QStringClass · 0.50
isEmptyMethod · 0.45
columnCountMethod · 0.45
rowCountMethod · 0.45
firstSelectedRowMethod · 0.45
firstSelectedColumnMethod · 0.45
containsMethod · 0.45
textAtMethod · 0.45
goToCellMethod · 0.45

Tested by 1

testSearchSimple00Method · 0.64