| 891 | } |
| 892 | |
| 893 | bool SearchReplaceWidget::findPrevious(bool proceed) { |
| 894 | // search pattern(s) |
| 895 | const auto type = static_cast<DataType>(uiSearchReplace.cbDataType->currentIndex()); |
| 896 | QString pattern1; |
| 897 | QString pattern2; |
| 898 | switch (type) { |
| 899 | case DataType::Text: |
| 900 | pattern1 = uiSearchReplace.cbValueText->currentText(); |
| 901 | addCurrentTextToHistory(uiSearchReplace.cbValueText); |
| 902 | break; |
| 903 | case DataType::Numeric: |
| 904 | pattern1 = uiSearchReplace.cbValue1->currentText(); |
| 905 | pattern2 = uiSearchReplace.cbValue2->currentText(); |
| 906 | addCurrentTextToHistory(uiSearchReplace.cbValue1); |
| 907 | addCurrentTextToHistory(uiSearchReplace.cbValue2); |
| 908 | break; |
| 909 | case DataType::DateTime: |
| 910 | pattern1 = uiSearchReplace.dteValue1->text(); |
| 911 | pattern2 = uiSearchReplace.dteValue2->text(); |
| 912 | break; |
| 913 | } |
| 914 | |
| 915 | if (pattern1.isEmpty()) { |
| 916 | highlight(type, false); |
| 917 | return true; |
| 918 | } |
| 919 | |
| 920 | // settings |
| 921 | const auto opText = static_cast<OperatorText>(uiSearchReplace.cbOperatorText->currentData().toInt()); |
| 922 | const auto opNumeric = static_cast<Operator>(uiSearchReplace.cbOperator->currentData().toInt()); |
| 923 | const auto opDateTime = static_cast<Operator>(uiSearchReplace.cbOperatorDateTime->currentData().toInt()); |
| 924 | const auto cs = uiSearchReplace.tbMatchCase->isChecked() ? Qt::CaseSensitive : Qt::CaseInsensitive; |
| 925 | const bool columnMajor = (uiSearchReplace.cbOrder->currentIndex() == 0); |
| 926 | |
| 927 | // spreadsheet size and the start cell |
| 928 | const int colCount = m_spreadsheet->columnCount(); |
| 929 | const int rowCount = m_spreadsheet->rowCount(); |
| 930 | int curRow = m_view->firstSelectedRow(); |
| 931 | int curCol = m_view->firstSelectedColumn(); |
| 932 | |
| 933 | if (columnMajor && proceed) { |
| 934 | if (curRow > 0) |
| 935 | --curRow; // not the first row yet, navigate to the previous cell |
| 936 | else { |
| 937 | // first row |
| 938 | if (curCol > 0) { |
| 939 | // not the first column yet, navigate to the last row in the previous column |
| 940 | --curCol; |
| 941 | curRow = rowCount - 1; |
| 942 | } else { |
| 943 | // first row in the first column, cannot navigate any further |
| 944 | highlight(type, !m_patternFound); |
| 945 | return false; |
| 946 | } |
| 947 | } |
| 948 | } |
| 949 | |
| 950 | if (!columnMajor && proceed) { |