QGIS API Documentation 4.1.0-Master (60fea48833c)
Loading...
Searching...
No Matches
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"
21
29{
30 Q_GADGET
31
32 public:
36 enum class AngleFormat
37 {
38 DegreesMinutesSeconds,
39 DegreesMinutes,
40 DecimalDegrees,
41 };
42 Q_ENUM( AngleFormat )
43
44
48
49 QString id() const override;
50 QString visibleName() const override;
51 int sortKey() override;
52 double suggestSampleValue() const override;
53 QString formatDouble( double value, const QgsNumericFormatContext &context ) const override;
55 QgsNumericFormat *create( const QVariantMap &configuration, const QgsReadWriteContext &context ) const override SIP_FACTORY;
56 QVariantMap configuration( const QgsReadWriteContext &context ) const override;
57
64 AngleFormat angleFormat() const;
65
72 void setAngleFormat( AngleFormat format );
73
79 bool showLeadingZeros() const;
80
86 void setShowLeadingZeros( bool show );
87
93 bool showDegreeLeadingZeros() const;
94
100 void setShowDegreeLeadingZeros( bool show );
101
107 bool showDirectionalSuffix() const;
108
114 void setShowDirectionalSuffix( bool show );
115
116 void setConfiguration( const QVariantMap &configuration, const QgsReadWriteContext &context ) override;
117
118 private:
119 AngleFormat mAngleFormat = AngleFormat::DecimalDegrees;
120 bool mShowLeadingZeros = false;
121 bool mShowLeadingDegreeZeros = false;
122 bool mUseSuffix = true;
123
124 QString formatLongitude( double value, std::basic_stringstream<wchar_t> &ss, const QgsNumericFormatContext &context ) const;
125 QString formatLatitude( double value, std::basic_stringstream<wchar_t> &ss, const QgsNumericFormatContext &context ) const;
126
127 QString formatLatitudeAsDegreesMinutesSeconds( double val, std::basic_stringstream<wchar_t> &ss, const QgsNumericFormatContext &context ) const;
128 QString formatLongitudeAsDegreesMinutesSeconds( double val, std::basic_stringstream<wchar_t> &ss, const QgsNumericFormatContext &context ) const;
129
130 QString formatLatitudeAsDegreesMinutes( double val, std::basic_stringstream<wchar_t> &ss, const QgsNumericFormatContext &context ) const;
131 QString formatLongitudeAsDegreesMinutes( double val, std::basic_stringstream<wchar_t> &ss, const QgsNumericFormatContext &context ) const;
132
133 QString formatLatitudeAsDegrees( double val, std::basic_stringstream<wchar_t> &ss, const QgsNumericFormatContext &context ) const;
134 QString formatLongitudeAsDegrees( double val, std::basic_stringstream<wchar_t> &ss, const QgsNumericFormatContext &context ) const;
135
136 void trimTrailingZeros( QString &input, const QgsNumericFormatContext &context ) const;
137};
138
139#endif // QGSCOORDINATENUMERICFORMAT_H
QgsBasicNumericFormat()
Default constructor.
QString id() const override
Returns a unique id for this numeric format.
QString visibleName() const override
Returns the translated, user-visible name for this format.
int sortKey() override
Returns a sorting key value, where formats with a lower sort key will be shown earlier in lists.
QgsNumericFormat * clone() const override
Clones the format, returning a new object.
QString formatDouble(double value, const QgsNumericFormatContext &context) const override
Returns a formatted string representation of a numeric double value.
A numeric formatter which returns a text representation of a geographic coordinate (latitude or longi...
A context for numeric formats.
Abstract base class for numeric formatters, which allow for formatting a numeric value for display.
virtual double suggestSampleValue() const
Returns a suggested sample value which nicely represents the current format configuration.
A container for the context for various read/write operations on objects.
#define SIP_FACTORY
Definition qgis_sip.h:83