QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
Loading...
Searching...
No Matches
qgsscalebarrendererregistry.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsscalebarrendererregistry.cpp
3 -----------------------
4 begin : March 2020
5 copyright : (C) 2020 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7
8 ***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
16
18#include "qgsscalebarrenderer.h"
25
37
39{
40 qDeleteAll( mRenderers );
41}
42
44{
45 return mRenderers.keys();
46}
47
49{
50 QStringList ids = mRenderers.keys();
51
52 std::sort( ids.begin(), ids.end(), [ = ]( const QString & a, const QString & b )->bool
53 {
54 if ( sortKey( a ) < sortKey( b ) )
55 return true;
56 else if ( sortKey( a ) > sortKey( b ) )
57 return false;
58 else
59 {
60 const int res = QString::localeAwareCompare( visibleName( a ), visibleName( b ) );
61 if ( res < 0 )
62 return true;
63 else if ( res > 0 )
64 return false;
65 }
66 return false;
67 } );
68 return ids;
69}
70
72{
73 if ( !renderer )
74 return;
75
76 mRenderers.insert( renderer->id(), renderer );
77}
78
80{
81 if ( QgsScaleBarRenderer *renderer = mRenderers.take( id ) )
82 {
83 delete renderer;
84 }
85}
86
88{
89 if ( mRenderers.contains( id ) )
90 return mRenderers.value( id )->clone();
91
92 return nullptr;
93}
94
95QString QgsScaleBarRendererRegistry::visibleName( const QString &id ) const
96{
97 if ( mRenderers.contains( id ) )
98 return mRenderers.value( id )->visibleName();
99
100 return QString();
101}
102
103int QgsScaleBarRendererRegistry::sortKey( const QString &id ) const
104{
105 if ( mRenderers.contains( id ) )
106 return mRenderers.value( id )->sortKey();
107
108 return 0;
109}
Double box with alternating colors.
Scalebar style that draws a single box with alternating color for the segments, with horizontal lines...
A scale bar style that draws text in the form of '1:XXXXX'.
void addRenderer(QgsScaleBarRenderer *renderer)
Adds a new renderer to the registry.
QStringList sortedRendererList() const
Returns a list of the renderer ids currently contained in the registry, sorted in an order respecting...
QStringList renderers() const
Returns a list of the renderer ids currently contained in the registry.
int sortKey(const QString &id) const
Returns the sorting key for the renderer with matching id.
QString visibleName(const QString &id) const
Returns the translated, user-visible name for the renderer with matching id.
QgsScaleBarRendererRegistry()
You should not normally need to create your own scalebar renderer registry.
QgsScaleBarRenderer * renderer(const QString &id) const
Creates a new scalebar renderer by id.
void removeRenderer(const QString &id)
Removes the renderer with matching id from the registry.
Abstract base class for scale bar renderers.
virtual QString id() const =0
Returns the unique ID for this renderer.
Scalebar style that draws a single box with alternating color for the segments.
Scalebar style that draws a stepped line representation of a scalebar.
A scale bar that draws segments using short ticks.
@ TicksUp
Render ticks above line.
@ TicksMiddle
Render ticks crossing line.
@ TicksDown
Render ticks below line.