QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
qgscoordinatenumericformat.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgscoordinatenumericformat.h
3  --------------------------
4  begin : April 2022
5  copyright : (C) 2022 by Nyall Dawson
6  email : nyall dot dawson at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 #ifndef QGSCOORDINATENUMERICFORMAT_H
16 #define QGSCOORDINATENUMERICFORMAT_H
17 
18 #include "qgis_core.h"
19 #include "qgis_sip.h"
20 #include "qgsbasicnumericformat.h"
21 
29 {
30  Q_GADGET
31 
32  public:
33 
37  enum class AngleFormat
38  {
39  DegreesMinutesSeconds,
40  DegreesMinutes,
41  DecimalDegrees,
42  };
43  Q_ENUM( AngleFormat )
44 
45 
49 
50  QString id() const override;
51  QString visibleName() const override;
52  int sortKey() override;
53  double suggestSampleValue() const override;
54  QString formatDouble( double value, const QgsNumericFormatContext &context ) const override;
56  QgsNumericFormat *create( const QVariantMap &configuration, const QgsReadWriteContext &context ) const override SIP_FACTORY;
57  QVariantMap configuration( const QgsReadWriteContext &context ) const override;
58 
65  AngleFormat angleFormat() const;
66 
73  void setAngleFormat( AngleFormat format );
74 
80  bool showLeadingZeros() const;
81 
87  void setShowLeadingZeros( bool show );
88 
94  bool showDegreeLeadingZeros() const;
95 
101  void setShowDegreeLeadingZeros( bool show );
102 
108  bool showDirectionalSuffix() const;
109 
115  void setShowDirectionalSuffix( bool show );
116 
117  void setConfiguration( const QVariantMap &configuration, const QgsReadWriteContext &context ) override;
118 
119  private:
120 
121  AngleFormat mAngleFormat = AngleFormat::DecimalDegrees;
122  bool mShowLeadingZeros = false;
123  bool mShowLeadingDegreeZeros = false;
124  bool mUseSuffix = true;
125 
126  QString formatLongitude( double value, std::basic_stringstream<wchar_t> &ss, const QgsNumericFormatContext &context ) const;
127  QString formatLatitude( double value, std::basic_stringstream<wchar_t> &ss, const QgsNumericFormatContext &context ) const;
128 
129  QString formatLatitudeAsDegreesMinutesSeconds( double val, std::basic_stringstream<wchar_t> &ss, const QgsNumericFormatContext &context ) const;
130  QString formatLongitudeAsDegreesMinutesSeconds( double val, std::basic_stringstream<wchar_t> &ss, const QgsNumericFormatContext &context ) const;
131 
132  QString formatLatitudeAsDegreesMinutes( double val, std::basic_stringstream<wchar_t> &ss, const QgsNumericFormatContext &context ) const;
133  QString formatLongitudeAsDegreesMinutes( double val, std::basic_stringstream<wchar_t> &ss, const QgsNumericFormatContext &context ) const;
134 
135  QString formatLatitudeAsDegrees( double val, std::basic_stringstream<wchar_t> &ss, const QgsNumericFormatContext &context ) const;
136  QString formatLongitudeAsDegrees( double val, std::basic_stringstream<wchar_t> &ss, const QgsNumericFormatContext &context ) const;
137 
138  void trimTrailingZeros( QString &input, const QgsNumericFormatContext &context ) const;
139 
140 };
141 
142 #endif // QGSCOORDINATENUMERICFORMAT_H
QgsBasicNumericFormat::clone
QgsNumericFormat * clone() const override
Clones the format, returning a new object.
Definition: qgsbasicnumericformat.cpp:138
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:34
QgsGeographicCoordinateNumericFormat
A numeric formatter which returns a text representation of a geographic coordinate (latitude or longi...
Definition: qgscoordinatenumericformat.h:28
QgsBasicNumericFormat::id
QString id() const override
Returns a unique id for this numeric format.
Definition: qgsbasicnumericformat.cpp:44
QgsNumericFormat
A numeric formatter allows for formatting a numeric value for display, using a variety of different f...
Definition: qgsnumericformat.h:259
QgsBasicNumericFormat
A numeric formatter which returns a simple text representation of a value.
Definition: qgsbasicnumericformat.h:31
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
qgis_sip.h
QgsBasicNumericFormat::sortKey
int sortKey() override
Returns a sorting key value, where formats with a lower sort key will be shown earlier in lists.
Definition: qgsbasicnumericformat.cpp:54
QgsNumericFormat::suggestSampleValue
virtual double suggestSampleValue() const
Returns a suggested sample value which nicely represents the current format configuration.
Definition: qgsnumericformat.cpp:53
qgsbasicnumericformat.h
QgsGeographicCoordinateNumericFormat::AngleFormat
AngleFormat
Angle format options.
Definition: qgscoordinatenumericformat.h:50
QgsBasicNumericFormat::formatDouble
QString formatDouble(double value, const QgsNumericFormatContext &context) const override
Returns a formatted string representation of a numeric double value.
Definition: qgsbasicnumericformat.cpp:59
QgsBasicNumericFormat::visibleName
QString visibleName() const override
Returns the translated, user-visible name for this format.
Definition: qgsbasicnumericformat.cpp:49
QgsNumericFormatContext
A context for numeric formats.
Definition: qgsnumericformat.h:34