| 1033 | } |
| 1034 | |
| 1035 | void SearchReplaceWidget::findAll() { |
| 1036 | const auto type = static_cast<DataType>(uiSearchReplace.cbDataType->currentIndex()); |
| 1037 | QString pattern1; |
| 1038 | QString pattern2; |
| 1039 | switch (type) { |
| 1040 | case DataType::Text: |
| 1041 | pattern1 = uiSearchReplace.cbValueText->currentText(); |
| 1042 | break; |
| 1043 | case DataType::Numeric: |
| 1044 | pattern1 = uiSearchReplace.cbValue1->currentText(); |
| 1045 | pattern2 = uiSearchReplace.cbValue2->currentText(); |
| 1046 | break; |
| 1047 | case DataType::DateTime: |
| 1048 | pattern1 = uiSearchReplace.dteValue1->text(); |
| 1049 | pattern1 = uiSearchReplace.dteValue2->text(); |
| 1050 | break; |
| 1051 | } |
| 1052 | |
| 1053 | if (pattern1.isEmpty()) { |
| 1054 | highlight(type, false); |
| 1055 | return; |
| 1056 | } |
| 1057 | |
| 1058 | // clear the previous selection |
| 1059 | m_view->clearSelection(); |
| 1060 | |
| 1061 | // settings |
| 1062 | const auto opText = static_cast<OperatorText>(uiSearchReplace.cbOperatorText->currentData().toInt()); |
| 1063 | const auto opNumeric = static_cast<Operator>(uiSearchReplace.cbOperator->currentData().toInt()); |
| 1064 | const auto opDateTime = static_cast<Operator>(uiSearchReplace.cbOperatorDateTime->currentData().toInt()); |
| 1065 | const auto cs = uiSearchReplace.tbMatchCase->isChecked() ? Qt::CaseSensitive : Qt::CaseInsensitive; |
| 1066 | const int colCount = m_spreadsheet->columnCount(); |
| 1067 | const int rowCount = m_spreadsheet->rowCount(); |
| 1068 | |
| 1069 | // all settings are determined -> select all cells matching the specified pattern(s) |
| 1070 | const auto& columns = m_spreadsheet->children<Column>(); |
| 1071 | bool match = false; |
| 1072 | int matchCount = 0; |
| 1073 | |
| 1074 | for (int col = 0; col < colCount; ++col) { |
| 1075 | auto* column = columns.at(col); |
| 1076 | if (!checkColumnType(column, type)) |
| 1077 | continue; |
| 1078 | |
| 1079 | for (int row = 0; row < rowCount; ++row) { |
| 1080 | match = checkColumnRow(column, type, row, opText, opNumeric, opDateTime, pattern1, pattern2, cs); |
| 1081 | if (match) { |
| 1082 | m_view->selectCell(row, col); |
| 1083 | ++matchCount; |
| 1084 | } |
| 1085 | } |
| 1086 | } |
| 1087 | |
| 1088 | if (matchCount > 0) |
| 1089 | showMessage(i18np("%1 match found", "%1 matches found", matchCount)); |
| 1090 | else |
| 1091 | showMessage(QString()); |
| 1092 | } |