QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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 
27 {
36 }
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  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 
95 QString QgsScaleBarRendererRegistry::visibleName( const QString &id ) const
96 {
97  if ( mRenderers.contains( id ) )
98  return mRenderers.value( id )->visibleName();
99 
100  return QString();
101 }
102 
103 int QgsScaleBarRendererRegistry::sortKey( const QString &id ) const
104 {
105  if ( mRenderers.contains( id ) )
106  return mRenderers.value( id )->sortKey();
107 
108  return 0;
109 }
QgsScaleBarRendererRegistry::sortKey
int sortKey(const QString &id) const
Returns the sorting key for the renderer with matching id.
Definition: qgsscalebarrendererregistry.cpp:103
qgsscalebarrendererregistry.h
QgsScaleBarRenderer::id
virtual QString id() const =0
Returns the unique ID for this renderer.
QgsTicksScaleBarRenderer::TicksUp
@ TicksUp
Render ticks above line.
Definition: qgsticksscalebarrenderer.h:36
QgsScaleBarRendererRegistry::renderers
QStringList renderers() const
Returns a list of the renderer ids currently contained in the registry.
Definition: qgsscalebarrendererregistry.cpp:43
QgsScaleBarRendererRegistry::visibleName
QString visibleName(const QString &id) const
Returns the translated, user-visible name for the renderer with matching id.
Definition: qgsscalebarrendererregistry.cpp:95
qgssteppedlinescalebarrenderer.h
qgsscalebarrenderer.h
QgsTicksScaleBarRenderer::TicksMiddle
@ TicksMiddle
Render ticks crossing line.
Definition: qgsticksscalebarrenderer.h:38
qgssingleboxscalebarrenderer.h
QgsTicksScaleBarRenderer::TicksDown
@ TicksDown
Render ticks below line.
Definition: qgsticksscalebarrenderer.h:37
QgsSingleBoxScaleBarRenderer
Definition: qgssingleboxscalebarrenderer.h:31
QgsScaleBarRendererRegistry::removeRenderer
void removeRenderer(const QString &id)
Removes the renderer with matching id from the registry.
Definition: qgsscalebarrendererregistry.cpp:79
QgsScaleBarRendererRegistry::addRenderer
void addRenderer(QgsScaleBarRenderer *renderer)
Adds a new renderer to the registry.
Definition: qgsscalebarrendererregistry.cpp:71
QgsDoubleBoxScaleBarRenderer
Definition: qgsdoubleboxscalebarrenderer.h:30
QgsScaleBarRendererRegistry::QgsScaleBarRendererRegistry
QgsScaleBarRendererRegistry()
You should not normally need to create your own scalebar renderer registry.
Definition: qgsscalebarrendererregistry.cpp:26
qgsdoubleboxscalebarrenderer.h
QgsScaleBarRenderer
Definition: qgsscalebarrenderer.h:38
QgsScaleBarRendererRegistry::sortedRendererList
QStringList sortedRendererList() const
Returns a list of the renderer ids currently contained in the registry, sorted in an order respecting...
Definition: qgsscalebarrendererregistry.cpp:48
qgshollowscalebarrenderer.h
QgsScaleBarRendererRegistry::renderer
QgsScaleBarRenderer * renderer(const QString &id) const
Creates a new scalebar renderer by id.
Definition: qgsscalebarrendererregistry.cpp:87
qgsticksscalebarrenderer.h
QgsTicksScaleBarRenderer
Definition: qgsticksscalebarrenderer.h:29
qgsnumericscalebarrenderer.h
QgsSteppedLineScaleBarRenderer
Definition: qgssteppedlinescalebarrenderer.h:30
QgsNumericScaleBarRenderer
Definition: qgsnumericscalebarrenderer.h:30
QgsHollowScaleBarRenderer
Definition: qgshollowscalebarrenderer.h:31
QgsScaleBarRendererRegistry::~QgsScaleBarRendererRegistry
~QgsScaleBarRendererRegistry()
Definition: qgsscalebarrendererregistry.cpp:38