QGIS API Documentation 3.37.0-Master (fdefdf9c27f)
qgslocaldefaultsettings.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgslocaldefaultsettings.cpp
3 -----------------------------
4 begin : January 2020
5 copyright : (C) 2020 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
19#include "qgis.h"
20#include "qgsreadwritecontext.h"
21
22#include <QSettings>
23#include <memory>
24
26{
27 const QVariantMap config = format->configuration( QgsReadWriteContext() );
28
29 QSettings s;
30 s.beginGroup( QStringLiteral( "defaults/bearing_format" ) );
31 for ( auto it = config.constBegin(); it != config.constEnd(); ++it )
32 {
33 s.setValue( it.key(), it.value() );
34 }
35 s.endGroup();
36}
37
39{
40 QVariantMap config;
41 QSettings s;
42 s.beginGroup( QStringLiteral( "defaults/bearing_format" ) );
43 const QStringList keys = s.childKeys();
44 for ( const QString &key : keys )
45 {
46 const QVariant value = s.value( key );
47 config.insert( key, value );
48 }
49 s.endGroup();
50
51 std::unique_ptr< QgsBearingNumericFormat > res = std::make_unique< QgsBearingNumericFormat >();
52 res->setConfiguration( config, QgsReadWriteContext() );
53 return res.release();
54}
55
57{
58 const QVariantMap config = format->configuration( QgsReadWriteContext() );
59
60 QSettings s;
61 s.beginGroup( QStringLiteral( "defaults/coordinate_format" ) );
62 for ( auto it = config.constBegin(); it != config.constEnd(); ++it )
63 {
64 s.setValue( it.key(), it.value() );
65 }
66 s.endGroup();
67}
68
70{
71 QVariantMap config;
72 QSettings s;
73 s.beginGroup( QStringLiteral( "defaults/coordinate_format" ) );
74 const QStringList keys = s.childKeys();
75 for ( const QString &key : keys )
76 {
77 const QVariant value = s.value( key );
78 config.insert( key, value );
79 }
80 s.endGroup();
81
82 std::unique_ptr< QgsGeographicCoordinateNumericFormat > res = std::make_unique< QgsGeographicCoordinateNumericFormat >();
83 res->setConfiguration( config, QgsReadWriteContext() );
84 return res.release();
85}
A numeric formatter which returns a text representation of a direction/bearing.
QVariantMap configuration(const QgsReadWriteContext &context) const override
Returns the current configuration of the formatter.
A numeric formatter which returns a text representation of a geographic coordinate (latitude or longi...
QVariantMap configuration(const QgsReadWriteContext &context) const override
Returns the current configuration of the formatter.
static QgsGeographicCoordinateNumericFormat * geographicCoordinateFormat()
Returns the default geographic coordinate format, which controls how geographic coordinates are displ...
static void setBearingFormat(const QgsBearingNumericFormat *format)
Sets the default bearing format, which controls how angular bearings are displayed.
static void setGeographicCoordinateFormat(const QgsGeographicCoordinateNumericFormat *format)
Sets the default geographic coordinate format, which controls how geographic coordinates are displaye...
static QgsBearingNumericFormat * bearingFormat()
Returns the default bearing format, which controls how angular bearings are displayed.
The class is used as a container of context for various read/write operations on other objects.