| 2719 | } |
| 2720 | |
| 2721 | void ImageViewer::updateFilter() { |
| 2722 | string filter = mFilter->value(); |
| 2723 | string imagePart = filter; |
| 2724 | string groupPart = ""; |
| 2725 | |
| 2726 | auto colonPos = filter.find_last_of(':'); |
| 2727 | if (colonPos != string::npos) { |
| 2728 | imagePart = filter.substr(0, colonPos); |
| 2729 | groupPart = filter.substr(colonPos + 1); |
| 2730 | } |
| 2731 | |
| 2732 | // Image filtering |
| 2733 | { |
| 2734 | // Checks whether an image matches the filter. This is the case if the image name matches the image part and at least one of the |
| 2735 | // image's groups matches the group part. |
| 2736 | const auto doesImageMatch = [&](const auto& name, const auto& channelGroups) { |
| 2737 | bool doesMatch = matchesFuzzyOrRegex(name, imagePart, useRegex()); |
| 2738 | if (doesMatch) { |
| 2739 | bool anyGroupsMatch = false; |
| 2740 | for (const auto& group : channelGroups) { |
| 2741 | if (matchesFuzzyOrRegex(group.name, groupPart, useRegex())) { |
| 2742 | anyGroupsMatch = true; |
| 2743 | break; |
| 2744 | } |
| 2745 | } |
| 2746 | |
| 2747 | if (!anyGroupsMatch) { |
| 2748 | doesMatch = false; |
| 2749 | } |
| 2750 | } |
| 2751 | |
| 2752 | return doesMatch; |
| 2753 | }; |
| 2754 | |
| 2755 | vector<string> activeImageNames; |
| 2756 | size_t id = 1; |
| 2757 | for (size_t i = 0; i < mImages.size(); ++i) { |
| 2758 | ImageButton* ib = dynamic_cast<ImageButton*>(mImageButtonContainer->children()[i]); |
| 2759 | ib->set_visible(doesImageMatch(ib->caption(), mImages[i]->channelGroups())); |
| 2760 | if (ib->visible()) { |
| 2761 | ib->setId(id++); |
| 2762 | activeImageNames.emplace_back(ib->caption()); |
| 2763 | } |
| 2764 | } |
| 2765 | |
| 2766 | int beginOffset = 0, endOffset = 0; |
| 2767 | if (!activeImageNames.empty()) { |
| 2768 | string first = activeImageNames.front(); |
| 2769 | int firstSize = (int)first.size(); |
| 2770 | if (firstSize > 0) { |
| 2771 | bool allStartWithSameChar; |
| 2772 | do { |
| 2773 | int len = codePointLength(first[beginOffset]); |
| 2774 | |
| 2775 | allStartWithSameChar = ranges::all_of(activeImageNames, [&first, beginOffset, len](string_view name) { |
| 2776 | if (beginOffset + len > (int)name.size()) { |
| 2777 | return false; |
| 2778 | } |
nothing calls this directly
no test coverage detected