QGIS API Documentation 3.99.0-Master (21b3aa880ba)
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
22#include "qgsscalebarrenderer.h"
26
38
40{
41 qDeleteAll( mRenderers );
42}
43
45{
46 return mRenderers.keys();
47}
48
50{
51 QStringList ids = mRenderers.keys();
52
53 std::sort( ids.begin(), ids.end(), [this]( const QString & a, const QString & b )->bool
54 {
55 if ( sortKey( a ) < sortKey( b ) )
56 return true;
57 else if ( sortKey( a ) > sortKey( b ) )
58 return false;
59 else
60 {
61 const int res = QString::localeAwareCompare( visibleName( a ), visibleName( b ) );
62 if ( res < 0 )
63 return true;
64 else if ( res > 0 )
65 return false;
66 }
67 return false;
68 } );
69 return ids;
70}
71
73{
74 if ( !renderer )
75 return;
76
77 mRenderers.insert( renderer->id(), renderer );
78}
79
81{
82 if ( QgsScaleBarRenderer *renderer = mRenderers.take( id ) )
83 {
84 delete renderer;
85 }
86}
87
89{
90 if ( mRenderers.contains( id ) )
91 return mRenderers.value( id )->clone();
92
93 return nullptr;
94}
95
96QString QgsScaleBarRendererRegistry::visibleName( const QString &id ) const
97{
98 if ( mRenderers.contains( id ) )
99 return mRenderers.value( id )->visibleName();
100
101 return QString();
102}
103
104int QgsScaleBarRendererRegistry::sortKey( const QString &id ) const
105{
106 if ( mRenderers.contains( id ) )
107 return mRenderers.value( id )->sortKey();
108
109 return 0;
110}
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 visibleName() const =0
Returns the user friendly, translated name for the renderer.
virtual QgsScaleBarRenderer * clone() const =0
Returns a clone of the 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.