File indexing completed on 2025-01-05 03:58:31

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2010-03-21
0007  * Description : A container to hold GPS information about an item.
0008  *
0009  * SPDX-FileCopyrightText: 2010-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0010  * SPDX-FileCopyrightText: 2010-2014 by Michael G. Hansen <mike at mghansen dot de>
0011  *
0012  * SPDX-License-Identifier: GPL-2.0-or-later
0013  *
0014  * ============================================================ */
0015 
0016 #ifndef DIGIKAM_GPS_ITEM_CONTAINER_H
0017 #define DIGIKAM_GPS_ITEM_CONTAINER_H
0018 
0019 // Qt includes
0020 
0021 #include <QVariant>
0022 #include <QDateTime>
0023 #include <QUrl>
0024 
0025 // Local includes
0026 
0027 #include "geoifacetypes.h"
0028 #include "digikam_export.h"
0029 #include "gpsdatacontainer.h"
0030 #include "metadatainfo.h"
0031 #include "rginfo.h"
0032 
0033 namespace Digikam
0034 {
0035 
0036 enum Type
0037 {
0038     TypeChild    = 1,
0039     TypeSpacer   = 2,
0040     TypeNewChild = 4
0041 };
0042 
0043 typedef struct TagData
0044 {
0045     TagData()
0046         : tagType(TypeChild)
0047     {
0048     }
0049 
0050     QString tagName;
0051     QString tipName;
0052     Type    tagType;
0053 
0054 } TagData;
0055 
0056 // --------------------------------------------------------------------------
0057 
0058 class SaveProperties
0059 {
0060 public:
0061 
0062     explicit SaveProperties()
0063       : shouldRemoveCoordinates (false),
0064         shouldRemoveAltitude    (false),
0065         shouldWriteCoordinates  (false),
0066         shouldWriteAltitude     (false),
0067         altitude                (0.0),
0068         latitude                (0.0),
0069         longitude               (0.0)
0070     {
0071     }
0072 
0073     bool  shouldRemoveCoordinates;
0074     bool  shouldRemoveAltitude;
0075     bool  shouldWriteCoordinates;
0076     bool  shouldWriteAltitude;
0077     qreal altitude;
0078     qreal latitude;
0079     qreal longitude;
0080 };
0081 
0082 // --------------------------------------------------------------------------
0083 
0084 class GPSItemModel;
0085 class DMetadata;
0086 
0087 class DIGIKAM_EXPORT GPSItemContainer
0088 {
0089 public:
0090 
0091     static const int RoleCoordinates             = Qt::UserRole + 1;
0092 
0093     static const int ColumnThumbnail             = 0;
0094     static const int ColumnFilename              = 1;
0095     static const int ColumnDateTime              = 2;
0096     static const int ColumnLatitude              = 3;
0097     static const int ColumnLongitude             = 4;
0098     static const int ColumnAltitude              = 5;
0099     static const int ColumnAccuracy              = 6;
0100     static const int ColumnTags                  = 7;
0101     static const int ColumnStatus                = 8;
0102     static const int ColumnDOP                   = 9;
0103     static const int ColumnFixType               = 10;
0104     static const int ColumnNSatellites           = 11;
0105     static const int ColumnSpeed                 = 12;
0106 
0107     static const int ColumnGPSItemContainerCount = 13;
0108 
0109 public:
0110 
0111     explicit GPSItemContainer(const QUrl& url);
0112     virtual ~GPSItemContainer();
0113 
0114     /// @name Loading and saving
0115     //@{
0116     virtual QString saveChanges();
0117     virtual bool loadImageData();
0118     //@}
0119 
0120     bool isDirty()                                                              const;
0121     QUrl url()                                                                  const;
0122     QDateTime dateTime()                                                        const;
0123 
0124     /// @name Functions used by the model
0125     //@{
0126     static void setHeaderData(GPSItemModel* const model);
0127     bool lessThan(const GPSItemContainer* const otherItem, const int column)    const;
0128     //@}
0129 
0130     /// @name GPS related functions
0131     //@{
0132     void setCoordinates(const GeoCoordinates& newCoordinates);
0133     GeoCoordinates coordinates()                                                const;
0134     GPSDataContainer gpsData()                                                  const;
0135     void setGPSData(const GPSDataContainer& container);
0136     void restoreGPSData(const GPSDataContainer& container);
0137     //@}
0138 
0139     /// @name Tag related functions
0140     //@{
0141     /**
0142      * The tags added in reverse geocoding process are stored in each image, before they end up in external tag model. This function adds them.
0143      * @param externalTagList A list containing tags.
0144      */
0145     void setTagList(const QList<QList<TagData> >& externalTagList);
0146 
0147     /**
0148      * @return Returns true is the current image has been modified and not saved.
0149      */
0150     bool isTagListDirty()                                                       const;
0151 
0152     /**
0153      * Returns the tag list of the current image.
0154      */
0155     QList<QList<TagData> > getTagList()                                         const;
0156 
0157     /**
0158      * Replaces the current tag list with the one contained in tagList.
0159      */
0160     void restoreRGTagList(const QList<QList<TagData> >& tagList);
0161 
0162     /**
0163      * Writes the current tags to XMP metadata.
0164      */
0165     void writeTagsToXmp(const bool writeXmpTags) { m_writeXmpTags = writeXmpTags; }
0166 
0167    /**
0168      * Writes the current tags to the metadata location fields.
0169      */
0170     void writeLocations(const bool writeMetaLoc) { m_writeMetaLoc = writeMetaLoc; }
0171     //@}
0172 
0173 protected:
0174 
0175     void setLocationInfo(const TagData& tagData, IptcCoreLocationInfo& locationInfo);
0176 
0177 protected:
0178 
0179     /// these are only to be called by the GPSItemModel
0180     QVariant data(const int column, const int role)                             const;
0181     void setModel(GPSItemModel* const model);
0182     void emitDataChanged();
0183     DMetadata* getMetadataForFile()                                             const;
0184     SaveProperties saveProperties()                                             const;
0185 
0186 protected:
0187 
0188     GPSItemModel*          m_model;
0189 
0190     QUrl                   m_url;
0191     QDateTime              m_dateTime;
0192 
0193     bool                   m_dirty;
0194     GPSDataContainer       m_gpsData;
0195     GPSDataContainer       m_savedState;
0196 
0197     bool                   m_tagListDirty;
0198     QList<QList<TagData> > m_tagList;
0199     QList<QList<TagData> > m_savedTagList;
0200     bool                   m_writeXmpTags;
0201     bool                   m_writeMetaLoc;
0202 
0203     friend class GPSItemModel;
0204 
0205 private:
0206 
0207     Q_DISABLE_COPY(GPSItemContainer)
0208 };
0209 
0210 } // namespace Digikam
0211 
0212 #endif // DIGIKAM_GPS_ITEM_CONTAINER_H