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

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2007-11-01
0007  * Description : Access item position stored in database.
0008  *
0009  * SPDX-FileCopyrightText: 2007-2009 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
0010  * SPDX-FileCopyrightText: 2009-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0011  * SPDX-FileCopyrightText: 2008      by Patrick Spendrin <ps_ml at gmx dot de>
0012  *
0013  * SPDX-License-Identifier: GPL-2.0-or-later
0014  *
0015  * ============================================================ */
0016 
0017 #ifndef DIGIKAM_ITEM_POSITION_H
0018 #define DIGIKAM_ITEM_POSITION_H
0019 
0020 // Qt includes
0021 
0022 #include <QString>
0023 #include <QSharedDataPointer>
0024 #include <QSharedData>
0025 
0026 // Local includes
0027 
0028 #include "digikam_export.h"
0029 #include "coredbfields.h"
0030 
0031 namespace Digikam
0032 {
0033 
0034 class CoreDbAccess;
0035 class ItemPositionPriv;
0036 
0037 class DIGIKAM_DATABASE_EXPORT ItemPosition
0038 {
0039 
0040 public:
0041 
0042     /**
0043      * Creates a null ItemPosition object
0044      */
0045     ItemPosition();
0046 
0047     /**
0048      * Creates an ItemPosition object for the given image.
0049      * The information is read from the database.
0050      */
0051     explicit ItemPosition(qlonglong imageId);
0052     ItemPosition(const CoreDbAccess& access, qlonglong imageId);
0053 
0054     ItemPosition(const ItemPosition& other);
0055     ~ItemPosition();
0056 
0057     ItemPosition& operator=(const ItemPosition& other);
0058 
0059     bool isNull()                const;
0060     /**
0061      * An object is empty if no entry exists in the ItemPosition
0062      * table for the referenced image, or if the object is null.
0063      * An empty object is empty even if values have been set;
0064      * it becomes not empty after calling apply().
0065      */
0066     bool isEmpty()               const;
0067 
0068     /**
0069      * Returns latitude/longitude in the format as described by
0070      * the XMP specification as "GPSCoordinate":
0071      * A Text value in the form ?DDD,MM,SSk? or ?DDD,MM.mmk?.
0072      * This provides lossless storage.
0073      */
0074     QString latitude()           const;
0075     QString longitude()          const;
0076 
0077     /**
0078      * Returns latitude/longitude as a double in degrees.
0079      * North and East have a positive sign, South and West negative.
0080      * This provides high precision, with the usual floating point
0081      * concerns, and possible problems finding the exact text form when
0082      * converting _back_ to fractions.
0083      */
0084     double latitudeNumber()      const;
0085     double longitudeNumber()     const;
0086 
0087     /**
0088      * Returns the latitude/longitude in a user-presentable version,
0089      * in the form "30°45'55.123'' East"
0090      */
0091     QString latitudeFormatted()  const;
0092     QString longitudeFormatted() const;
0093 
0094     /**
0095      * Returns latitude/longitude as user-presentable numbers.
0096      * This means that degrees and minutes are integer, the seconds fractional.
0097      * Direction reference is 'N'/'S', 'E'/'W' resp.
0098      * This is for the purpose of presenting to the user, there are no guarantees on precision.
0099      * Returns true if the values have been changed.
0100      */
0101     bool latitudeUserPresentableNumbers(int* degrees, int* minutes, double* seconds, char* directionReference);
0102     bool longitudeUserPresentableNumbers(int* degrees, int* minutes, double* seconds, char* directionReference);
0103 
0104     /**
0105      * The altitude in meters
0106      */
0107     double altitude()            const;
0108 
0109     /**
0110      * Returns the altitude formatted in a user-presentable way in the form "43.45m"
0111      */
0112     QString altitudeFormatted()  const;
0113     double orientation()         const;
0114     double tilt()                const;
0115     double roll()                const;
0116     double accuracy()            const;
0117     QString description()        const;
0118 
0119     bool hasCoordinates()        const;
0120     bool hasAltitude()           const;
0121     bool hasOrientation()        const;
0122     bool hasTilt()               const;
0123     bool hasRoll()               const;
0124     bool hasAccuracy()           const;
0125 
0126     /**
0127      * Sets the latitude/longitude from the GPSCoordinate string as described by XMP.
0128      * Returns true if the format is accepted.
0129      */
0130     bool setLatitude(const QString& latitude);
0131     bool setLongitude(const QString& longitude);
0132 
0133     /**
0134      * Sets the latitude/longitude from a double floating point number,
0135      * as described for latitudeNumber() above.
0136      * Returns true if the value is valid and accepted.
0137      */
0138     bool setLatitude(double latitudeNumber);
0139     bool setLongitude(double longitudeNumber);
0140 
0141     /**
0142      * Set the altitude in meters
0143      */
0144     void setAltitude(double altitude);
0145     void setOrientation(double orientation);
0146     void setTilt(double tilt);
0147     void setRoll(double roll);
0148     void setAccuracy(double accuracy);
0149     void setDescription(const QString& description);
0150 
0151     /**
0152      * Apply all changes made to this object.
0153      * (Also called from destructor)
0154      */
0155     void apply();
0156 
0157     /**
0158      * Removes the whole data set for the referenced image
0159      * from the database.
0160      * This object and any ItemPosition object created later
0161      * will be empty.
0162      */
0163     void remove();
0164 
0165     /**
0166      * Removes the altitude for the referenced image
0167      * from the database.
0168      */
0169     void removeAltitude();
0170 
0171 private:
0172 
0173     QSharedDataPointer<ItemPositionPriv> d;
0174 };
0175 
0176 } // namespace Digikam
0177 
0178 #endif // DIGIKAM_ITEM_POSITION_H