| 40 | |
| 41 | |
| 42 | void CheckGroup::addCheck(const QString& checkName) |
| 43 | { |
| 44 | const int nextSplitOffset = checkName.indexOf(QRegularExpression(QStringLiteral("[-.]")), m_prefix.length()); |
| 45 | |
| 46 | // 1. check if looking at last section, if so add to current group |
| 47 | if (nextSplitOffset < 0) { |
| 48 | m_checks.append(checkName); |
| 49 | m_checksEnabledStates.append(EnabledInherited); |
| 50 | return; |
| 51 | } |
| 52 | |
| 53 | // 2. check if existing subgroup for prefix, if so add to that |
| 54 | // include separator into subgroup name |
| 55 | const auto subGroupName = QStringView{checkName}.first(nextSplitOffset + 1); |
| 56 | for (auto* subGroup : std::as_const(m_subGroups)) { |
| 57 | if (subGroup->prefix() == subGroupName) { |
| 58 | subGroup->addCheck(checkName); |
| 59 | return; |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | // 3. check if existing check with same prefix, if so create subgroup for them |
| 64 | for (int i = 0; i < m_checks.size(); ++i) { |
| 65 | const auto& listedCheckName = m_checks.at(i); |
| 66 | if (listedCheckName.startsWith(subGroupName)) { |
| 67 | auto* newSubGroup = new CheckGroup(subGroupName.toString(), this); |
| 68 | newSubGroup->addCheck(listedCheckName); |
| 69 | newSubGroup->addCheck(checkName); |
| 70 | m_subGroups.append(newSubGroup); |
| 71 | m_checks.removeAt(i); |
| 72 | m_checksEnabledStates.removeAt(i); |
| 73 | return; |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | // 4. add to current group |
| 78 | m_checks.append(checkName); |
| 79 | m_checksEnabledStates.append(EnabledInherited); |
| 80 | } |
| 81 | |
| 82 | void CheckGroup::setEnabledChecks(const QStringList& rules) |
| 83 | { |