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 - Geolocation
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 ItemPosition ItemInfo::imagePosition() const
0024 {
0025     if (!m_data)
0026     {
0027         return ItemPosition();
0028     }
0029 
0030     ItemPosition pos(m_data->id);
0031 
0032     if (!m_data->positionsCached)
0033     {
0034         ItemInfoWriteLocker lock;
0035         m_data.data()->longitude       = pos.longitudeNumber();
0036         m_data.data()->latitude        = pos.latitudeNumber();
0037         m_data.data()->altitude        = pos.altitude();
0038         m_data.data()->hasCoordinates  = pos.hasCoordinates();
0039         m_data.data()->hasAltitude     = pos.hasAltitude();
0040         m_data.data()->positionsCached = true;
0041     }
0042 
0043     return pos;
0044 }
0045 
0046 double ItemInfo::longitudeNumber() const
0047 {
0048     if (!m_data)
0049     {
0050         return 0;
0051     }
0052 
0053     if (!m_data->positionsCached)
0054     {
0055         imagePosition();
0056     }
0057 
0058     return m_data->longitude;
0059 }
0060 
0061 double ItemInfo::latitudeNumber() const
0062 {
0063     if (!m_data)
0064     {
0065         return 0;
0066     }
0067 
0068     if (!m_data->positionsCached)
0069     {
0070         imagePosition();
0071     }
0072 
0073     return m_data->latitude;
0074 }
0075 
0076 double ItemInfo::altitudeNumber() const
0077 {
0078     if (!m_data)
0079     {
0080         return 0;
0081     }
0082 
0083     if (!m_data->positionsCached)
0084     {
0085         imagePosition();
0086     }
0087 
0088     return m_data->altitude;
0089 }
0090 
0091 bool ItemInfo::hasCoordinates() const
0092 {
0093     if (!m_data)
0094     {
0095         return false;
0096     }
0097 
0098     if (!m_data->positionsCached)
0099     {
0100         imagePosition();
0101     }
0102 
0103     return m_data->hasCoordinates;
0104 }
0105 
0106 bool ItemInfo::hasAltitude() const
0107 {
0108     if (!m_data)
0109     {
0110         return false;
0111     }
0112 
0113     if (!m_data->positionsCached)
0114     {
0115         imagePosition();
0116     }
0117 
0118     return m_data->hasAltitude;
0119 }
0120 
0121 } // namespace Digikam