File indexing completed on 2024-05-19 04:23:36
0001 // SPDX-FileCopyrightText: 2003-2020 The KPhotoAlbum Development Team 0002 // SPDX-FileCopyrightText: 2022 Johannes Zarl-Zierl <johannes@zarl-zierl.at> 0003 // 0004 // SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 0006 #include "ValueCategoryMatcher.h" 0007 0008 #include <DB/ImageDB.h> 0009 #include <DB/MemberMap.h> 0010 #include <kpabase/Logging.h> 0011 0012 void DB::ValueCategoryMatcher::debug(int level) const 0013 { 0014 qCDebug(DBCategoryMatcherLog, "%s%s: %s", qPrintable(spaces(level)), qPrintable(m_category), qPrintable(m_option)); 0015 } 0016 0017 DB::ValueCategoryMatcher::ValueCategoryMatcher(const QString &category, const QString &value) 0018 { 0019 // Unescape doubled "&"s and restore the original value 0020 QString unEscapedValue = value; 0021 unEscapedValue.replace(QString::fromUtf8("&&"), QString::fromUtf8("&")); 0022 0023 m_category = category; 0024 m_option = unEscapedValue; 0025 0026 const MemberMap &map = DB::ImageDB::instance()->memberMap(); 0027 const QStringList members = map.members(m_category, m_option, true); 0028 m_members = StringSet(members.begin(), members.end()); 0029 } 0030 0031 bool DB::ValueCategoryMatcher::eval(ImageInfoPtr info, QMap<QString, StringSet> &alreadyMatched) 0032 { 0033 // Only add the tag _option to the alreadyMatched tags, 0034 // and omit the tags in _members 0035 if (m_shouldPrepareMatchedSet) 0036 alreadyMatched[m_category].insert(m_option); 0037 0038 if (info->hasCategoryInfo(m_category, m_option)) { 0039 return true; 0040 } 0041 0042 if (info->hasCategoryInfo(m_category, m_members)) 0043 return true; 0044 return false; 0045 } 0046 0047 // vi:expandtab:tabstop=4 shiftwidth=4: