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

Method findPreviousSimple

src/frontend/spreadsheet/SearchReplaceWidget.cpp:664–728  ·  view source on GitHub ↗

! * search the previous 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

662 * and iterpreting everything as text. Used in the "simple search"-mode.
663 */
664bool SearchReplaceWidget::findPreviousSimple(bool proceed) {
665 const QString& pattern = uiSearch.cbFind->currentText();
666 if (pattern.isEmpty()) {
667 GuiTools::highlight(uiSearch.cbFind->lineEdit(), false);
668 showMessage(QString());
669 return true;
670 }
671
672 const auto cs = uiSearch.tbMatchCase->isChecked() ? Qt::CaseSensitive : Qt::CaseInsensitive;
673
674 // spreadsheet size and the start cell
675 const int colCount = m_spreadsheet->columnCount();
676 const int rowCount = m_spreadsheet->rowCount();
677 int curRow = m_view->firstSelectedRow();
678 int curCol = m_view->firstSelectedColumn();
679
680 if (proceed) {
681 if (curRow > 0)
682 --curRow; // not the first row yet, navigate to the previous cell
683 else {
684 // first row
685 if (curCol > 0) {
686 // not the first column yet, navigate to the last row in the previous column
687 --curCol;
688 curRow = rowCount - 1;
689 } else {
690 // first row in the first column, cannot navigate any further
691 GuiTools::highlight(uiSearch.cbFind->lineEdit(), !m_patternFound);
692 return false;
693 }
694 }
695 }
696
697 // all settings are determined -> search the next cell matching the specified pattern(s)
698 const auto& columns = m_spreadsheet->children<Column>();
699 bool startCol = true;
700 bool startRow = true;
701
702 for (int col = colCount; col >= 0; --col) {
703 if (startCol && col > curCol)
704 continue;
705
706 auto* column = columns.at(col)->asStringColumn();
707
708 for (int row = rowCount; row >= 0; --row) {
709 if (startRow && row > curRow)
710 continue;
711
712 if (column->textAt(row).contains(pattern, cs)) {
713 m_patternFound = true;
714 m_view->goToCell(row, col);
715 GuiTools::highlight(uiSearch.cbFind->lineEdit(), false);
716 return true;
717 }
718
719 startRow = false;
720 }
721

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