File indexing completed on 2025-01-05 03:56:22
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2009-07-13 0007 * Description : caption values container 0008 * 0009 * SPDX-FileCopyrightText: 2009-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0010 * 0011 * SPDX-License-Identifier: GPL-2.0-or-later 0012 * 0013 * ============================================================ */ 0014 0015 #include "captionvalues.h" 0016 0017 namespace Digikam 0018 { 0019 0020 CaptionValues::CaptionValues() 0021 { 0022 } 0023 0024 CaptionValues::~CaptionValues() 0025 { 0026 } 0027 0028 bool CaptionValues::operator==(const CaptionValues& val) const 0029 { 0030 bool b1 = (author == val.author); 0031 bool b2 = (caption == val.caption); 0032 // bool b3 = (date == val.date); 0033 0034 return (b1 && b2 /*&& b3*/); 0035 } 0036 0037 QDebug operator<<(QDebug dbg, const CaptionValues& val) 0038 { 0039 dbg.nospace() << "CaptionValues::caption: " 0040 << val.caption << ", "; 0041 dbg.nospace() << "CaptionValues::author: " 0042 << val.author << ", "; 0043 dbg.nospace() << "CaptionValues::date: " 0044 << val.date; 0045 0046 return dbg.space(); 0047 } 0048 0049 // -------------------------------------------------------------------- 0050 0051 CaptionsMap::CaptionsMap() 0052 { 0053 } 0054 0055 CaptionsMap::~CaptionsMap() 0056 { 0057 } 0058 0059 void CaptionsMap::setData(const MetaEngine::AltLangMap& comments, 0060 const MetaEngine::AltLangMap& authors, 0061 const QString& commonAuthor, 0062 const MetaEngine::AltLangMap& dates) 0063 { 0064 fromAltLangMap(comments); 0065 setAuthorsList(authors, commonAuthor); 0066 setDatesList(dates); 0067 } 0068 0069 MetaEngine::AltLangMap CaptionsMap::toAltLangMap() const 0070 { 0071 MetaEngine::AltLangMap map; 0072 0073 for (CaptionsMap::const_iterator it = constBegin() ; it != constEnd() ; ++it) 0074 { 0075 map.insert(it.key(), (*it).caption); 0076 } 0077 0078 return map; 0079 } 0080 0081 void CaptionsMap::fromAltLangMap(const MetaEngine::AltLangMap& map) 0082 { 0083 clear(); 0084 0085 for (MetaEngine::AltLangMap::const_iterator it = map.constBegin() ; it != map.constEnd() ; ++it) 0086 { 0087 CaptionValues val; 0088 val.caption = it.value(); 0089 insert(it.key(), val); 0090 } 0091 } 0092 0093 MetaEngine::AltLangMap CaptionsMap::authorsList() const 0094 { 0095 MetaEngine::AltLangMap map; 0096 0097 for (CaptionsMap::const_iterator it = constBegin() ; it != constEnd() ; ++it) 0098 { 0099 map.insert(it.key(), (*it).author); 0100 } 0101 0102 return map; 0103 } 0104 0105 void CaptionsMap::setAuthorsList(const MetaEngine::AltLangMap& map, const QString& commonAuthor) 0106 { 0107 for (CaptionsMap::iterator it = begin() ; it != end() ; ++it) 0108 { 0109 MetaEngine::AltLangMap::const_iterator authorIt = map.find(it.key()); 0110 0111 if (authorIt != map.constEnd()) 0112 { 0113 (*it).author = authorIt.value(); 0114 } 0115 else if (!commonAuthor.isNull()) 0116 { 0117 (*it).author = commonAuthor; 0118 } 0119 } 0120 } 0121 0122 MetaEngine::AltLangMap CaptionsMap::datesList() const 0123 { 0124 MetaEngine::AltLangMap map; 0125 0126 for (CaptionsMap::const_iterator it = constBegin() ; it != constEnd() ; ++it) 0127 { 0128 map.insert(it.key(), (*it).date.toString(Qt::ISODate)); 0129 } 0130 0131 return map; 0132 } 0133 0134 void CaptionsMap::setDatesList(const MetaEngine::AltLangMap& map) 0135 { 0136 for (MetaEngine::AltLangMap::const_iterator it = map.constBegin() ; it != map.constEnd() ; ++it) 0137 { 0138 CaptionsMap::iterator val = find(it.key()); 0139 0140 if (val != end()) 0141 { 0142 (*val).date = QDateTime::fromString(it.value(), Qt::ISODate); 0143 } 0144 } 0145 } 0146 0147 } // namespace Digikam