File indexing completed on 2024-05-12 15:55:22

0001 // SPDX-FileCopyrightText: 2021 Johannes Zarl-Zierl <johannes@zarl-zierl.at>
0002 //
0003 // SPDX-License-Identifier: LicenseRef-KDE-Accepted-GPL
0004 
0005 #ifndef WILDCARDCATEGORYMATCHER_H
0006 #define WILDCARDCATEGORYMATCHER_H
0007 
0008 #include "SimpleCategoryMatcher.h"
0009 
0010 #include <QRegularExpression>
0011 
0012 namespace DB
0013 {
0014 
0015 /**
0016  * @brief The WildcardCategoryMatcher class matches any tag in any plain category.
0017  * It can be used to search over all categories when the user is not sure which category a tag belongs to.
0018  *
0019  * @note At initialisation, a list of categories and matching tags is compiled.
0020  * Therefore, the matcher can only match against tags that exist when it is initialized.
0021  */
0022 class WildcardCategoryMatcher : public SimpleCategoryMatcher
0023 {
0024 public:
0025     /**
0026      * @brief regularExpression
0027      * @return the regular expression set by setRegularExpression
0028      */
0029     QRegularExpression regularExpression() const;
0030     /**
0031      * @brief Set a new match expression and compile a list of matching tags.
0032      * @param re a regular expression matching against the desired tags
0033      */
0034     void setRegularExpression(const QRegularExpression &re);
0035     bool eval(ImageInfoPtr, QMap<QString, StringSet> &alreadyMatched) override;
0036     /**
0037      * @brief evaluate the matcher for an image
0038      * @param info
0039      * @return \c true, if the ImageInfo is matched, \c false otherwise
0040      */
0041     bool eval(const ImageInfoPtr info) const;
0042     void debug(int level) const override;
0043 
0044 private:
0045     QRegularExpression m_re;
0046     QHash<QString, StringSet> m_matchingTags; ///< The hash contains a list of matching tags for every category with matching tags.
0047 };
0048 
0049 }
0050 
0051 #endif /* WILDCARDCATEGORYMATCHER_H */
0052 
0053 // vi:expandtab:tabstop=4 shiftwidth=4: