File indexing completed on 2025-01-19 03:53:37

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2005-04-21
0007  * Description : Handling access to one item and associated data - similarity
0008  *
0009  * SPDX-FileCopyrightText: 2005      by Renchi Raju <renchi dot raju at gmail dot com>
0010  * SPDX-FileCopyrightText: 2007-2013 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
0011  * SPDX-FileCopyrightText: 2009-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0012  * SPDX-FileCopyrightText: 2013      by Michael G. Hansen <mike at mghansen dot de>
0013  *
0014  * SPDX-License-Identifier: GPL-2.0-or-later
0015  *
0016  * ============================================================ */
0017 
0018 #include "iteminfo_p.h"
0019 
0020 namespace Digikam
0021 {
0022 
0023 double ItemInfo::similarityTo(const qlonglong imageId) const
0024 {
0025     return imageExtendedProperties().similarityTo(imageId);
0026 }
0027 
0028 double ItemInfo::currentSimilarity() const
0029 {
0030     if (!m_data)
0031     {
0032         return 0;
0033     }
0034 
0035     return m_data->currentSimilarity;
0036 }
0037 
0038 qlonglong ItemInfo::currentReferenceImage() const
0039 {
0040     if (!m_data)
0041     {
0042         return -1;
0043     }
0044 
0045     return m_data->currentReferenceImage;
0046 }
0047 
0048 QList<ItemInfo> ItemInfo::fromUniqueHash(const QString& uniqueHash, qlonglong fileSize)
0049 {
0050     QList<ItemScanInfo> scanInfos = CoreDbAccess().db()->getIdenticalFiles(uniqueHash, fileSize);
0051     QList<ItemInfo> infos;
0052 
0053     Q_FOREACH (const ItemScanInfo& scanInfo, scanInfos)
0054     {
0055         infos << ItemInfo(scanInfo.id);
0056     }
0057 
0058     return infos;
0059 }
0060 
0061 uint ItemInfo::hash() const
0062 {
0063     if (!m_data)
0064     {
0065         return ::qHash((int)0);
0066     }
0067 
0068     return ::qHash(m_data->id);
0069 }
0070 
0071 QString ItemInfo::uniqueHash() const
0072 {
0073     if (!m_data)
0074     {
0075         return QString();
0076     }
0077 
0078     RETURN_IF_CACHED(uniqueHash)
0079 
0080     QVariantList values = CoreDbAccess().db()->getImagesFields(m_data->id, DatabaseFields::UniqueHash);
0081 
0082     STORE_IN_CACHE_AND_RETURN(uniqueHash, values.first().toString())
0083 }
0084 
0085 } // namespace Digikam