QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
qgslayoutitemscalebar.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgslayoutitemscalebar.cpp
3  -------------------------
4  begin : November 2017
5  copyright : (C) 2017 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 
17 #include "qgslayoutitemscalebar.h"
18 #include "qgslayoutitemregistry.h"
20 #include "qgslayoutitemmap.h"
21 #include "qgslayout.h"
22 #include "qgslayoututils.h"
23 #include "qgsdistancearea.h"
25 #include "qgsscalebarrenderer.h"
26 #include "qgsmapsettings.h"
27 #include "qgsrectangle.h"
28 #include "qgsproject.h"
29 #include "qgssymbollayerutils.h"
30 #include "qgsfontutils.h"
31 #include "qgsunittypes.h"
32 #include "qgssettings.h"
33 #include "qgsstyleentityvisitor.h"
34 #include "qgsnumericformat.h"
36 #include "qgslinesymbollayer.h"
37 #include "qgsfillsymbollayer.h"
38 
39 #include <QDomDocument>
40 #include <QDomElement>
41 #include <QFontMetricsF>
42 #include <QPainter>
43 
44 #include <cmath>
45 
47  : QgsLayoutItem( layout )
48 {
51 }
52 
54 {
56 }
57 
59 {
60  return QgsApplication::getThemeIcon( QStringLiteral( "/mLayoutItemScaleBar.svg" ) );
61 }
62 
64 {
65  return new QgsLayoutItemScaleBar( layout );
66 }
67 
69 {
71  return QgsLayoutSize( mStyle->calculateBoxSize( context, mSettings, createScaleContext() ), QgsUnitTypes::LayoutMillimeters );
72 }
73 
75 {
76  if ( !mStyle )
77  return;
78 
80  {
81  // compatibility code - ScalebarLineColor and ScalebarLineWidth are deprecated
83  std::unique_ptr< QgsLineSymbol > sym( mSettings.lineSymbol()->clone() );
86  sym->setWidth( mDataDefinedProperties.valueAsDouble( QgsLayoutObject::ScalebarLineWidth, expContext, mSettings.lineWidth() ) );
88  sym->setColor( mDataDefinedProperties.valueAsColor( QgsLayoutObject::ScalebarLineColor, expContext, mSettings.lineColor() ) );
90  mSettings.setLineSymbol( sym.release() );
91  }
93  {
94  // compatibility code - ScalebarLineColor and ScalebarLineWidth are deprecated
96  std::unique_ptr< QgsFillSymbol > sym( mSettings.fillSymbol()->clone() );
98  sym->setColor( mDataDefinedProperties.valueAsColor( QgsLayoutObject::ScalebarFillColor, expContext, mSettings.fillColor() ) );
100  mSettings.setFillSymbol( sym.release() );
101  }
103  {
104  // compatibility code - ScalebarLineColor and ScalebarLineWidth are deprecated
106  std::unique_ptr< QgsFillSymbol > sym( mSettings.alternateFillSymbol()->clone() );
108  sym->setColor( mDataDefinedProperties.valueAsColor( QgsLayoutObject::ScalebarFillColor2, expContext, mSettings.fillColor2() ) );
110  mSettings.setAlternateFillSymbol( sym.release() );
111  }
112 
113  mStyle->draw( context.renderContext(), mSettings, createScaleContext() );
114 }
115 
117 {
118  if ( !mStyle )
119  {
120  mSettings.setNumberOfSegments( nSegments );
121  return;
122  }
123  mSettings.setNumberOfSegments( nSegments );
125 }
126 
128 {
129  if ( !mStyle )
130  {
131  mSettings.setUnitsPerSegment( units );
132  return;
133  }
134  mSettings.setUnitsPerSegment( units );
135  refreshSegmentMillimeters();
137 }
138 
140 {
141  if ( !mStyle )
142  {
143  mSettings.setSegmentSizeMode( mode );
144  return;
145  }
146  mSettings.setSegmentSizeMode( mode );
147  refreshSegmentMillimeters();
149 }
150 
152 {
153  if ( !mStyle )
154  {
155  mSettings.setMinimumBarWidth( minWidth );
156  return;
157  }
158  mSettings.setMinimumBarWidth( minWidth );
159  refreshSegmentMillimeters();
161 }
162 
164 {
165  if ( !mStyle )
166  {
167  mSettings.setMaximumBarWidth( maxWidth );
168  return;
169  }
170  mSettings.setMaximumBarWidth( maxWidth );
171  refreshSegmentMillimeters();
173 }
174 
176 {
177  return mSettings.textFormat();
178 }
179 
181 {
182  mSettings.setTextFormat( format );
183  refreshItemSize();
184  emit changed();
185 }
186 
188 {
189  return mSettings.lineSymbol();
190 }
191 
193 {
194  mSettings.setLineSymbol( symbol );
195 }
196 
198 {
199  return mSettings.divisionLineSymbol();
200 }
201 
203 {
204  mSettings.setDivisionLineSymbol( symbol );
205 }
206 
208 {
209  return mSettings.subdivisionLineSymbol();
210 }
211 
213 {
214  mSettings.setSubdivisionLineSymbol( symbol );
215 }
216 
218 {
219  return mSettings.fillSymbol();
220 }
221 
223 {
224  mSettings.setFillSymbol( symbol );
225 }
226 
228 {
229  return mSettings.alternateFillSymbol();
230 }
231 
233 {
234  mSettings.setAlternateFillSymbol( symbol );
235 }
236 
238 {
239  if ( !mStyle )
240  {
241  mSettings.setNumberOfSegmentsLeft( nSegmentsLeft );
242  return;
243  }
244  mSettings.setNumberOfSegmentsLeft( nSegmentsLeft );
246 }
247 
249 {
250  if ( !mStyle )
251  {
252  mSettings.setBoxContentSpace( space );
253  return;
254  }
255  mSettings.setBoxContentSpace( space );
256  refreshItemSize();
257 }
258 
260 {
261  disconnectCurrentMap();
262 
263  mMap = map;
264 
265  if ( !map )
266  {
267  return;
268  }
269 
270  connect( mMap, &QgsLayoutItemMap::extentChanged, this, &QgsLayoutItemScaleBar::updateScale );
271  connect( mMap, &QObject::destroyed, this, &QgsLayoutItemScaleBar::disconnectCurrentMap );
272 
273  refreshSegmentMillimeters();
274  emit changed();
275 }
276 
277 void QgsLayoutItemScaleBar::disconnectCurrentMap()
278 {
279  if ( !mMap )
280  {
281  return;
282  }
283 
284  disconnect( mMap, &QgsLayoutItemMap::extentChanged, this, &QgsLayoutItemScaleBar::updateScale );
285  disconnect( mMap, &QObject::destroyed, this, &QgsLayoutItemScaleBar::disconnectCurrentMap );
286  mMap = nullptr;
287 }
288 
290 {
292 
293  bool forceUpdate = false;
294  //updates data defined properties and redraws item to match
296  {
297  forceUpdate = true;
298  }
300  {
301  forceUpdate = true;
302  }
304  {
305  forceUpdate = true;
306  }
308  {
309  forceUpdate = true;
310  }
311  if ( forceUpdate )
312  {
313  refreshItemSize();
314  update();
315  }
316 
318 }
319 
320 void QgsLayoutItemScaleBar::refreshSegmentMillimeters()
321 {
322  if ( mMap )
323  {
324  //get mm dimension of composer map
325  QRectF composerItemRect = mMap->rect();
326 
327  switch ( mSettings.segmentSizeMode() )
328  {
330  {
331  //calculate size depending on mNumUnitsPerSegment
332  mSegmentMillimeters = composerItemRect.width() / mapWidth() * mSettings.unitsPerSegment();
333  break;
334  }
335 
337  {
338  if ( mSettings.maximumBarWidth() < mSettings.minimumBarWidth() )
339  {
340  mSegmentMillimeters = 0;
341  }
342  else
343  {
344  double nSegments = ( mSettings.numberOfSegmentsLeft() != 0 ) + mSettings.numberOfSegments();
345  // unitsPerSegments which fit minBarWidth resp. maxBarWidth
346  double minUnitsPerSeg = ( mSettings.minimumBarWidth() * mapWidth() ) / ( nSegments * composerItemRect.width() );
347  double maxUnitsPerSeg = ( mSettings.maximumBarWidth() * mapWidth() ) / ( nSegments * composerItemRect.width() );
348  mSettings.setUnitsPerSegment( QgsLayoutUtils::calculatePrettySize( minUnitsPerSeg, maxUnitsPerSeg ) );
349  mSegmentMillimeters = composerItemRect.width() / mapWidth() * mSettings.unitsPerSegment();
350  }
351  break;
352  }
353  }
354  }
355 }
356 
357 double QgsLayoutItemScaleBar::mapWidth() const
358 {
359  if ( !mMap )
360  {
361  return 0.0;
362  }
363 
364  QgsRectangle mapExtent = mMap->extent();
365  if ( mSettings.units() == QgsUnitTypes::DistanceUnknownUnit )
366  {
367  return mapExtent.width();
368  }
369  else
370  {
371  QgsDistanceArea da;
372  da.setSourceCrs( mMap->crs(), mLayout->project()->transformContext() );
373  da.setEllipsoid( mLayout->project()->ellipsoid() );
374 
376  double measure = da.measureLine( QgsPointXY( mapExtent.xMinimum(), mapExtent.yMinimum() ),
377  QgsPointXY( mapExtent.xMaximum(), mapExtent.yMinimum() ) );
378  measure /= QgsUnitTypes::fromUnitToUnitFactor( mSettings.units(), units );
379  return measure;
380  }
381 }
382 
383 QgsScaleBarRenderer::ScaleBarContext QgsLayoutItemScaleBar::createScaleContext() const
384 {
386  scaleContext.size = rect().size();
387  scaleContext.segmentWidth = mSegmentMillimeters;
388  scaleContext.scale = mMap ? mMap->scale() : 1.0;
389  scaleContext.flags = mStyle->flags();
390  return scaleContext;
391 }
392 
394 {
395  mSettings.setLabelVerticalPlacement( placement );
396  refreshItemSize();
397  emit changed();
398 }
399 
401 {
402  mSettings.setLabelHorizontalPlacement( placement );
403  refreshItemSize();
404  emit changed();
405 }
406 
408 {
409  mSettings.setAlignment( a );
410  refreshItemSize();
411  emit changed();
412 }
413 
415 {
416  mSettings.setUnits( u );
417  refreshSegmentMillimeters();
418  refreshItemSize();
419  emit changed();
420 }
421 
422 Qt::PenJoinStyle QgsLayoutItemScaleBar::lineJoinStyle() const
423 {
425  return mSettings.lineJoinStyle();
427 }
428 
429 void QgsLayoutItemScaleBar::setLineJoinStyle( Qt::PenJoinStyle style )
430 {
432  if ( mSettings.lineJoinStyle() == style )
433  {
434  //no change
435  return;
436  }
437  mSettings.setLineJoinStyle( style );
439  update();
440  emit changed();
441 }
442 
443 Qt::PenCapStyle QgsLayoutItemScaleBar::lineCapStyle() const
444 {
446  return mSettings.lineCapStyle();
448 }
449 
450 void QgsLayoutItemScaleBar::setLineCapStyle( Qt::PenCapStyle style )
451 {
453  if ( mSettings.lineCapStyle() == style )
454  {
455  //no change
456  return;
457  }
458  mSettings.setLineCapStyle( style );
460  update();
461  emit changed();
462 }
463 
465 {
466  //style
467  mStyle = qgis::make_unique< QgsSingleBoxScaleBarRenderer >();
468 
469  //default to no background
470  setBackgroundEnabled( false );
471 
472  //get default composer font from settings
473  QgsSettings settings;
474  QString defaultFontString = settings.value( QStringLiteral( "LayoutDesigner/defaultFont" ), QVariant(), QgsSettings::Gui ).toString();
475  QgsTextFormat format;
476  QFont f;
477  if ( !defaultFontString.isEmpty() )
478  {
479  f.setFamily( defaultFontString );
480  }
481  format.setFont( f );
482  format.setSize( 12.0 );
484 
485  mSettings.setTextFormat( format );
486 
488  refreshItemSize();
489 
490  emit changed();
491 }
492 
494 {
495  return renderer->applyDefaultSettings( mSettings );
496 }
497 
499 {
500  if ( !mMap )
502 
504  // start with crs units
507  {
508  // geographic CRS, use metric units
510  }
511 
512  // try to pick reasonable choice between metric / imperial units
513  double widthInSelectedUnits = mapWidth();
514  double initialUnitsPerSegment = widthInSelectedUnits / 10.0; //default scalebar width equals half the map width
515  switch ( unit )
516  {
518  {
519  if ( initialUnitsPerSegment > 1000.0 )
520  {
522  }
523  break;
524  }
526  {
527  if ( initialUnitsPerSegment > 5419.95 )
528  {
530  }
531  break;
532  }
533  default:
534  break;
535  }
536 
537  return unit;
538 }
539 
541 {
542  mSettings.setUnits( units );
543  if ( mMap )
544  {
545  double upperMagnitudeMultiplier = 1.0;
546  double widthInSelectedUnits = mapWidth();
547  double initialUnitsPerSegment = widthInSelectedUnits / 10.0; //default scalebar width equals half the map width
548  mSettings.setUnitsPerSegment( initialUnitsPerSegment );
549 
551  upperMagnitudeMultiplier = 1;
552 
553  double segmentWidth = initialUnitsPerSegment / upperMagnitudeMultiplier;
554  int segmentMagnitude = std::floor( std::log10( segmentWidth ) );
555  double unitsPerSegment = upperMagnitudeMultiplier * ( std::pow( 10.0, segmentMagnitude ) );
556  double multiplier = std::floor( ( widthInSelectedUnits / ( unitsPerSegment * 10.0 ) ) / 2.5 ) * 2.5;
557 
558  if ( multiplier > 0 )
559  {
560  unitsPerSegment = unitsPerSegment * multiplier;
561  }
562  mSettings.setUnitsPerSegment( unitsPerSegment );
563  mSettings.setMapUnitsPerScaleBarUnit( upperMagnitudeMultiplier );
564 
565  mSettings.setNumberOfSegments( 2 );
566  mSettings.setNumberOfSegmentsLeft( 0 );
567  }
568 
569  refreshSegmentMillimeters();
571  emit changed();
572 }
573 
575 {
576  if ( !mStyle )
577  return;
578 
580  double widthMM = mStyle->calculateBoxSize( context, mSettings, createScaleContext() ).width();
581  QgsLayoutSize currentSize = sizeWithUnits();
582  currentSize.setWidth( mLayout->renderContext().measurementConverter().convert( QgsLayoutMeasurement( widthMM, QgsUnitTypes::LayoutMillimeters ), currentSize.units() ).length() );
583  attemptResize( currentSize );
584  update();
585  emit changed();
586 }
587 
589 {
590  //Don't adjust box size for numeric scale bars:
591  if ( mStyle && mStyle->id() != QLatin1String( "Numeric" ) )
592  {
593  refreshItemSize();
594  }
595  QgsLayoutItem::update();
596 }
597 
598 void QgsLayoutItemScaleBar::updateScale()
599 {
600  refreshSegmentMillimeters();
601  //Don't adjust box size for numeric scale bars:
602  if ( mStyle && mStyle->id() != QLatin1String( "Numeric" ) )
603  {
605  }
606  update();
607 }
608 
609 void QgsLayoutItemScaleBar::setStyle( const QString &styleName )
610 {
611  //switch depending on style name
612  std::unique_ptr< QgsScaleBarRenderer> renderer( QgsApplication::scaleBarRendererRegistry()->renderer( styleName ) );
613  if ( renderer )
614  {
615  mStyle = std::move( renderer );
616  }
617  refreshItemSize();
618  emit changed();
619 }
620 
622 {
623  if ( mStyle )
624  {
625  return mStyle->id();
626  }
627  else
628  {
629  return QString();
630  }
631 }
632 
634 {
635  return mSettings.numericFormat();
636 }
637 
639 {
640  mSettings.setNumericFormat( format );
641 }
642 
644 {
645  return mSettings.textFormat().font();
646 }
647 
648 void QgsLayoutItemScaleBar::setFont( const QFont &font )
649 {
651  mSettings.setFont( font );
653  refreshItemSize();
654  emit changed();
655 }
656 
658 {
659  QColor color = mSettings.textFormat().color();
660  color.setAlphaF( mSettings.textFormat().opacity() );
661  return color;
662 }
663 
664 void QgsLayoutItemScaleBar::setFontColor( const QColor &color )
665 {
666  mSettings.textFormat().setColor( color );
667  mSettings.textFormat().setOpacity( color.alphaF() );
668 }
669 
671 {
673  return mSettings.fillColor();
675 }
676 
677 void QgsLayoutItemScaleBar::setFillColor( const QColor &color )
678 {
680  mSettings.setFillColor( color );
682 }
683 
685 {
687  return mSettings.fillColor2();
689 }
690 
691 void QgsLayoutItemScaleBar::setFillColor2( const QColor &color )
692 {
694  mSettings.setFillColor2( color );
696 }
697 
699 {
701  return mSettings.lineColor();
703 }
704 
705 void QgsLayoutItemScaleBar::setLineColor( const QColor &color )
706 {
708  mSettings.setLineColor( color );
710 }
711 
713 {
715  return mSettings.lineWidth();
717 }
718 
720 {
722  mSettings.setLineWidth( width );
724 }
725 
727 {
729  return mSettings.pen();
731 }
732 
734 {
736  return mSettings.brush();
738 }
739 
741 {
743  return mSettings.brush2();
745 }
746 
747 bool QgsLayoutItemScaleBar::writePropertiesToElement( QDomElement &composerScaleBarElem, QDomDocument &doc, const QgsReadWriteContext &rwContext ) const
748 {
749  composerScaleBarElem.setAttribute( QStringLiteral( "height" ), QString::number( mSettings.height() ) );
750  composerScaleBarElem.setAttribute( QStringLiteral( "labelBarSpace" ), QString::number( mSettings.labelBarSpace() ) );
751  composerScaleBarElem.setAttribute( QStringLiteral( "boxContentSpace" ), QString::number( mSettings.boxContentSpace() ) );
752  composerScaleBarElem.setAttribute( QStringLiteral( "numSegments" ), mSettings.numberOfSegments() );
753  composerScaleBarElem.setAttribute( QStringLiteral( "numSegmentsLeft" ), mSettings.numberOfSegmentsLeft() );
754  composerScaleBarElem.setAttribute( QStringLiteral( "numSubdivisions" ), mSettings.numberOfSubdivisions() );
755  composerScaleBarElem.setAttribute( QStringLiteral( "subdivisionsHeight" ), mSettings.subdivisionsHeight() );
756  composerScaleBarElem.setAttribute( QStringLiteral( "numUnitsPerSegment" ), QString::number( mSettings.unitsPerSegment() ) );
757  composerScaleBarElem.setAttribute( QStringLiteral( "segmentSizeMode" ), mSettings.segmentSizeMode() );
758  composerScaleBarElem.setAttribute( QStringLiteral( "minBarWidth" ), mSettings.minimumBarWidth() );
759  composerScaleBarElem.setAttribute( QStringLiteral( "maxBarWidth" ), mSettings.maximumBarWidth() );
760  composerScaleBarElem.setAttribute( QStringLiteral( "segmentMillimeters" ), QString::number( mSegmentMillimeters ) );
761  composerScaleBarElem.setAttribute( QStringLiteral( "numMapUnitsPerScaleBarUnit" ), QString::number( mSettings.mapUnitsPerScaleBarUnit() ) );
762 
763  QDomElement textElem = mSettings.textFormat().writeXml( doc, rwContext );
764  composerScaleBarElem.appendChild( textElem );
765 
767  // kept just for allowing projects to open in QGIS < 3.14, remove for 4.0
768  composerScaleBarElem.setAttribute( QStringLiteral( "outlineWidth" ), QString::number( mSettings.lineWidth() ) );
769  composerScaleBarElem.setAttribute( QStringLiteral( "lineJoinStyle" ), QgsSymbolLayerUtils::encodePenJoinStyle( mSettings.lineJoinStyle() ) );
770  composerScaleBarElem.setAttribute( QStringLiteral( "lineCapStyle" ), QgsSymbolLayerUtils::encodePenCapStyle( mSettings.lineCapStyle() ) );
771  //pen color
772  QDomElement strokeColorElem = doc.createElement( QStringLiteral( "strokeColor" ) );
773  strokeColorElem.setAttribute( QStringLiteral( "red" ), QString::number( mSettings.lineColor().red() ) );
774  strokeColorElem.setAttribute( QStringLiteral( "green" ), QString::number( mSettings.lineColor().green() ) );
775  strokeColorElem.setAttribute( QStringLiteral( "blue" ), QString::number( mSettings.lineColor().blue() ) );
776  strokeColorElem.setAttribute( QStringLiteral( "alpha" ), QString::number( mSettings.lineColor().alpha() ) );
777  composerScaleBarElem.appendChild( strokeColorElem );
779 
780  composerScaleBarElem.setAttribute( QStringLiteral( "unitLabel" ), mSettings.unitLabel() );
781  composerScaleBarElem.setAttribute( QStringLiteral( "unitType" ), QgsUnitTypes::encodeUnit( mSettings.units() ) );
782 
783  QDomElement numericFormatElem = doc.createElement( QStringLiteral( "numericFormat" ) );
784  mSettings.numericFormat()->writeXml( numericFormatElem, doc, rwContext );
785  composerScaleBarElem.appendChild( numericFormatElem );
786 
787  //style
788  if ( mStyle )
789  {
790  composerScaleBarElem.setAttribute( QStringLiteral( "style" ), mStyle->id() );
791  }
792 
793  //map id
794  if ( mMap )
795  {
796  composerScaleBarElem.setAttribute( QStringLiteral( "mapUuid" ), mMap->uuid() );
797  }
798 
799  //colors
800 
802  // kept just for allowing projects to open in QGIS < 3.14, remove for 4.0
803 
804  //fill color
805  QDomElement fillColorElem = doc.createElement( QStringLiteral( "fillColor" ) );
806  fillColorElem.setAttribute( QStringLiteral( "red" ), QString::number( mSettings.fillColor().red() ) );
807  fillColorElem.setAttribute( QStringLiteral( "green" ), QString::number( mSettings.fillColor().green() ) );
808  fillColorElem.setAttribute( QStringLiteral( "blue" ), QString::number( mSettings.fillColor().blue() ) );
809  fillColorElem.setAttribute( QStringLiteral( "alpha" ), QString::number( mSettings.fillColor().alpha() ) );
810  composerScaleBarElem.appendChild( fillColorElem );
811 
812  //fill color 2
813  QDomElement fillColor2Elem = doc.createElement( QStringLiteral( "fillColor2" ) );
814  fillColor2Elem.setAttribute( QStringLiteral( "red" ), QString::number( mSettings.fillColor2().red() ) );
815  fillColor2Elem.setAttribute( QStringLiteral( "green" ), QString::number( mSettings.fillColor2().green() ) );
816  fillColor2Elem.setAttribute( QStringLiteral( "blue" ), QString::number( mSettings.fillColor2().blue() ) );
817  fillColor2Elem.setAttribute( QStringLiteral( "alpha" ), QString::number( mSettings.fillColor2().alpha() ) );
818  composerScaleBarElem.appendChild( fillColor2Elem );
819 
821 
822  //label vertical/horizontal placement
823  composerScaleBarElem.setAttribute( QStringLiteral( "labelVerticalPlacement" ), QString::number( static_cast< int >( mSettings.labelVerticalPlacement() ) ) );
824  composerScaleBarElem.setAttribute( QStringLiteral( "labelHorizontalPlacement" ), QString::number( static_cast< int >( mSettings.labelHorizontalPlacement() ) ) );
825 
826  //alignment
827  composerScaleBarElem.setAttribute( QStringLiteral( "alignment" ), QString::number( static_cast< int >( mSettings.alignment() ) ) );
828 
829  QDomElement lineSymbol = doc.createElement( QStringLiteral( "lineSymbol" ) );
830  const QDomElement symbolElem = QgsSymbolLayerUtils::saveSymbol( QString(),
831  mSettings.lineSymbol(),
832  doc,
833  rwContext );
834  lineSymbol.appendChild( symbolElem );
835  composerScaleBarElem.appendChild( lineSymbol );
836 
837  QDomElement divisionSymbol = doc.createElement( QStringLiteral( "divisionLineSymbol" ) );
838  const QDomElement divisionSymbolElem = QgsSymbolLayerUtils::saveSymbol( QString(),
839  mSettings.divisionLineSymbol(),
840  doc,
841  rwContext );
842  divisionSymbol.appendChild( divisionSymbolElem );
843  composerScaleBarElem.appendChild( divisionSymbol );
844 
845  QDomElement subdivisionSymbol = doc.createElement( QStringLiteral( "subdivisionLineSymbol" ) );
846  const QDomElement subdivisionSymbolElem = QgsSymbolLayerUtils::saveSymbol( QString(),
847  mSettings.subdivisionLineSymbol(),
848  doc,
849  rwContext );
850  subdivisionSymbol.appendChild( subdivisionSymbolElem );
851  composerScaleBarElem.appendChild( subdivisionSymbol );
852 
853  QDomElement fillSymbol1Elem = doc.createElement( QStringLiteral( "fillSymbol1" ) );
854  const QDomElement symbol1Elem = QgsSymbolLayerUtils::saveSymbol( QString(),
855  mSettings.fillSymbol(),
856  doc,
857  rwContext );
858  fillSymbol1Elem.appendChild( symbol1Elem );
859  composerScaleBarElem.appendChild( fillSymbol1Elem );
860 
861  QDomElement fillSymbol2Elem = doc.createElement( QStringLiteral( "fillSymbol2" ) );
862  const QDomElement symbol2Elem = QgsSymbolLayerUtils::saveSymbol( QString(),
863  mSettings.alternateFillSymbol(),
864  doc,
865  rwContext );
866  fillSymbol2Elem.appendChild( symbol2Elem );
867  composerScaleBarElem.appendChild( fillSymbol2Elem );
868 
869  return true;
870 }
871 
872 bool QgsLayoutItemScaleBar::readPropertiesFromElement( const QDomElement &itemElem, const QDomDocument &, const QgsReadWriteContext &context )
873 {
874  mSettings.setHeight( itemElem.attribute( QStringLiteral( "height" ), QStringLiteral( "5.0" ) ).toDouble() );
875  mSettings.setLabelBarSpace( itemElem.attribute( QStringLiteral( "labelBarSpace" ), QStringLiteral( "3.0" ) ).toDouble() );
876  mSettings.setBoxContentSpace( itemElem.attribute( QStringLiteral( "boxContentSpace" ), QStringLiteral( "1.0" ) ).toDouble() );
877  mSettings.setNumberOfSegments( itemElem.attribute( QStringLiteral( "numSegments" ), QStringLiteral( "2" ) ).toInt() );
878  mSettings.setNumberOfSegmentsLeft( itemElem.attribute( QStringLiteral( "numSegmentsLeft" ), QStringLiteral( "0" ) ).toInt() );
879  mSettings.setNumberOfSubdivisions( itemElem.attribute( QStringLiteral( "numSubdivisions" ), QStringLiteral( "1" ) ).toInt() );
880  mSettings.setSubdivisionsHeight( itemElem.attribute( QStringLiteral( "subdivisionsHeight" ), QStringLiteral( "1.5" ) ).toDouble() );
881  mSettings.setUnitsPerSegment( itemElem.attribute( QStringLiteral( "numUnitsPerSegment" ), QStringLiteral( "1.0" ) ).toDouble() );
882  mSettings.setSegmentSizeMode( static_cast<QgsScaleBarSettings::SegmentSizeMode>( itemElem.attribute( QStringLiteral( "segmentSizeMode" ), QStringLiteral( "0" ) ).toInt() ) );
883  mSettings.setMinimumBarWidth( itemElem.attribute( QStringLiteral( "minBarWidth" ), QStringLiteral( "50" ) ).toDouble() );
884  mSettings.setMaximumBarWidth( itemElem.attribute( QStringLiteral( "maxBarWidth" ), QStringLiteral( "150" ) ).toDouble() );
885  mSegmentMillimeters = itemElem.attribute( QStringLiteral( "segmentMillimeters" ), QStringLiteral( "0.0" ) ).toDouble();
886  mSettings.setMapUnitsPerScaleBarUnit( itemElem.attribute( QStringLiteral( "numMapUnitsPerScaleBarUnit" ), QStringLiteral( "1.0" ) ).toDouble() );
887 
888  QDomElement lineSymbolElem = itemElem.firstChildElement( QStringLiteral( "lineSymbol" ) );
889  bool foundLineSymbol = false;
890  if ( !lineSymbolElem.isNull() )
891  {
892  QDomElement symbolElem = lineSymbolElem.firstChildElement( QStringLiteral( "symbol" ) );
893  std::unique_ptr< QgsLineSymbol > lineSymbol( QgsSymbolLayerUtils::loadSymbol<QgsLineSymbol>( symbolElem, context ) );
894  if ( lineSymbol )
895  {
896  mSettings.setLineSymbol( lineSymbol.release() );
897  foundLineSymbol = true;
898  }
899  }
900  QDomElement divisionSymbolElem = itemElem.firstChildElement( QStringLiteral( "divisionLineSymbol" ) );
901  if ( !divisionSymbolElem.isNull() )
902  {
903  QDomElement symbolElem = divisionSymbolElem.firstChildElement( QStringLiteral( "symbol" ) );
904  std::unique_ptr< QgsLineSymbol > lineSymbol( QgsSymbolLayerUtils::loadSymbol<QgsLineSymbol>( symbolElem, context ) );
905  if ( lineSymbol )
906  {
907  mSettings.setDivisionLineSymbol( lineSymbol.release() );
908  }
909  }
910  else if ( foundLineSymbol )
911  {
912  mSettings.setDivisionLineSymbol( mSettings.lineSymbol()->clone() );
913  }
914  QDomElement subdivisionSymbolElem = itemElem.firstChildElement( QStringLiteral( "subdivisionLineSymbol" ) );
915  if ( !subdivisionSymbolElem.isNull() )
916  {
917  QDomElement symbolElem = subdivisionSymbolElem.firstChildElement( QStringLiteral( "symbol" ) );
918  std::unique_ptr< QgsLineSymbol > lineSymbol( QgsSymbolLayerUtils::loadSymbol<QgsLineSymbol>( symbolElem, context ) );
919  if ( lineSymbol )
920  {
921  mSettings.setSubdivisionLineSymbol( lineSymbol.release() );
922  }
923  }
924  else if ( foundLineSymbol )
925  {
926  mSettings.setSubdivisionLineSymbol( mSettings.lineSymbol()->clone() );
927  }
928 
929  if ( !foundLineSymbol )
930  {
931  // old project compatibility
932  std::unique_ptr< QgsLineSymbol > lineSymbol = qgis::make_unique< QgsLineSymbol >();
933  std::unique_ptr< QgsSimpleLineSymbolLayer > lineSymbolLayer = qgis::make_unique< QgsSimpleLineSymbolLayer >();
934  lineSymbolLayer->setWidth( itemElem.attribute( QStringLiteral( "outlineWidth" ), QStringLiteral( "0.3" ) ).toDouble() );
935  lineSymbolLayer->setWidthUnit( QgsUnitTypes::RenderMillimeters );
936  lineSymbolLayer->setPenJoinStyle( QgsSymbolLayerUtils::decodePenJoinStyle( itemElem.attribute( QStringLiteral( "lineJoinStyle" ), QStringLiteral( "miter" ) ) ) );
937  lineSymbolLayer->setPenCapStyle( QgsSymbolLayerUtils::decodePenCapStyle( itemElem.attribute( QStringLiteral( "lineCapStyle" ), QStringLiteral( "square" ) ) ) );
938 
939  //stroke color
940  QDomNodeList strokeColorList = itemElem.elementsByTagName( QStringLiteral( "strokeColor" ) );
941  if ( !strokeColorList.isEmpty() )
942  {
943  QDomElement strokeColorElem = strokeColorList.at( 0 ).toElement();
944  bool redOk, greenOk, blueOk, alphaOk;
945  int strokeRed, strokeGreen, strokeBlue, strokeAlpha;
946 
947  strokeRed = strokeColorElem.attribute( QStringLiteral( "red" ) ).toDouble( &redOk );
948  strokeGreen = strokeColorElem.attribute( QStringLiteral( "green" ) ).toDouble( &greenOk );
949  strokeBlue = strokeColorElem.attribute( QStringLiteral( "blue" ) ).toDouble( &blueOk );
950  strokeAlpha = strokeColorElem.attribute( QStringLiteral( "alpha" ) ).toDouble( &alphaOk );
951 
952  if ( redOk && greenOk && blueOk && alphaOk )
953  {
954  lineSymbolLayer->setColor( QColor( strokeRed, strokeGreen, strokeBlue, strokeAlpha ) );
955  }
956  }
957  else
958  {
959  lineSymbolLayer->setColor( QColor( itemElem.attribute( QStringLiteral( "penColor" ), QStringLiteral( "#000000" ) ) ) );
960  }
961 
962  // need to translate the deprecated ScalebarLineWidth and ScalebarLineColor properties to symbol properties,
963  // and then remove them from the scalebar so they don't interfere and apply to other compatibility workarounds
964  lineSymbolLayer->setDataDefinedProperty( QgsSymbolLayer::PropertyStrokeWidth, dataDefinedProperties().property( QgsLayoutObject::ScalebarLineWidth ) );
966  lineSymbolLayer->setDataDefinedProperty( QgsSymbolLayer::PropertyStrokeColor, dataDefinedProperties().property( QgsLayoutObject::ScalebarLineColor ) );
968 
969  lineSymbol->changeSymbolLayer( 0, lineSymbolLayer.release() );
970  mSettings.setLineSymbol( lineSymbol->clone() );
971  mSettings.setDivisionLineSymbol( lineSymbol->clone() );
972  mSettings.setSubdivisionLineSymbol( lineSymbol.release() );
973  }
974 
975  mSettings.setUnitLabel( itemElem.attribute( QStringLiteral( "unitLabel" ) ) );
976 
977  QDomNodeList textFormatNodeList = itemElem.elementsByTagName( QStringLiteral( "text-style" ) );
978  if ( !textFormatNodeList.isEmpty() )
979  {
980  QDomElement textFormatElem = textFormatNodeList.at( 0 ).toElement();
981  mSettings.textFormat().readXml( textFormatElem, context );
982  }
983  else
984  {
985  QFont f;
986  if ( !QgsFontUtils::setFromXmlChildNode( f, itemElem, QStringLiteral( "scaleBarFont" ) ) )
987  {
988  f.fromString( itemElem.attribute( QStringLiteral( "font" ), QString() ) );
989  }
990  mSettings.textFormat().setFont( f );
991  if ( f.pointSizeF() > 0 )
992  {
993  mSettings.textFormat().setSize( f.pointSizeF() );
995  }
996  else if ( f.pixelSize() > 0 )
997  {
998  mSettings.textFormat().setSize( f.pixelSize() );
1000  }
1001  }
1002 
1003  QDomNodeList numericFormatNodeList = itemElem.elementsByTagName( QStringLiteral( "numericFormat" ) );
1004  if ( !numericFormatNodeList.isEmpty() )
1005  {
1006  QDomElement numericFormatElem = numericFormatNodeList.at( 0 ).toElement();
1007  mSettings.setNumericFormat( QgsApplication::numericFormatRegistry()->createFromXml( numericFormatElem, context ) );
1008  }
1009 
1010  QDomElement fillSymbol1Elem = itemElem.firstChildElement( QStringLiteral( "fillSymbol1" ) );
1011  bool foundFillSymbol1 = false;
1012  if ( !fillSymbol1Elem.isNull() )
1013  {
1014  QDomElement symbolElem = fillSymbol1Elem.firstChildElement( QStringLiteral( "symbol" ) );
1015  std::unique_ptr< QgsFillSymbol > fillSymbol( QgsSymbolLayerUtils::loadSymbol<QgsFillSymbol>( symbolElem, context ) );
1016  if ( fillSymbol )
1017  {
1018  mSettings.setFillSymbol( fillSymbol.release() );
1019  foundFillSymbol1 = true;
1020  }
1021  }
1022  if ( !foundFillSymbol1 )
1023  {
1024  // old project compatibility
1025  std::unique_ptr< QgsFillSymbol > fillSymbol = qgis::make_unique< QgsFillSymbol >();
1026  std::unique_ptr< QgsSimpleFillSymbolLayer > fillSymbolLayer = qgis::make_unique< QgsSimpleFillSymbolLayer >();
1027  fillSymbolLayer->setStrokeStyle( Qt::NoPen );
1028 
1029  //fill color
1030  QDomNodeList fillColorList = itemElem.elementsByTagName( QStringLiteral( "fillColor" ) );
1031  if ( !fillColorList.isEmpty() )
1032  {
1033  QDomElement fillColorElem = fillColorList.at( 0 ).toElement();
1034  bool redOk, greenOk, blueOk, alphaOk;
1035  int fillRed, fillGreen, fillBlue, fillAlpha;
1036 
1037  fillRed = fillColorElem.attribute( QStringLiteral( "red" ) ).toDouble( &redOk );
1038  fillGreen = fillColorElem.attribute( QStringLiteral( "green" ) ).toDouble( &greenOk );
1039  fillBlue = fillColorElem.attribute( QStringLiteral( "blue" ) ).toDouble( &blueOk );
1040  fillAlpha = fillColorElem.attribute( QStringLiteral( "alpha" ) ).toDouble( &alphaOk );
1041 
1042  if ( redOk && greenOk && blueOk && alphaOk )
1043  {
1044  fillSymbolLayer->setColor( QColor( fillRed, fillGreen, fillBlue, fillAlpha ) );
1045  }
1046  }
1047  else
1048  {
1049  fillSymbolLayer->setColor( QColor( itemElem.attribute( QStringLiteral( "brushColor" ), QStringLiteral( "#000000" ) ) ) );
1050  }
1051 
1052  // need to translate the deprecated ScalebarFillColor property to symbol properties,
1053  // and then remove them from the scalebar so they don't interfere and apply to other compatibility workarounds
1054  fillSymbolLayer->setDataDefinedProperty( QgsSymbolLayer::PropertyFillColor, dataDefinedProperties().property( QgsLayoutObject::ScalebarFillColor ) );
1056 
1057  fillSymbol->changeSymbolLayer( 0, fillSymbolLayer.release() );
1058  mSettings.setFillSymbol( fillSymbol.release() );
1059  }
1060 
1061  QDomElement fillSymbol2Elem = itemElem.firstChildElement( QStringLiteral( "fillSymbol2" ) );
1062  bool foundFillSymbol2 = false;
1063  if ( !fillSymbol2Elem.isNull() )
1064  {
1065  QDomElement symbolElem = fillSymbol2Elem.firstChildElement( QStringLiteral( "symbol" ) );
1066  std::unique_ptr< QgsFillSymbol > fillSymbol( QgsSymbolLayerUtils::loadSymbol<QgsFillSymbol>( symbolElem, context ) );
1067  if ( fillSymbol )
1068  {
1069  mSettings.setAlternateFillSymbol( fillSymbol.release() );
1070  foundFillSymbol2 = true;
1071  }
1072  }
1073  if ( !foundFillSymbol2 )
1074  {
1075  // old project compatibility
1076  std::unique_ptr< QgsFillSymbol > fillSymbol = qgis::make_unique< QgsFillSymbol >();
1077  std::unique_ptr< QgsSimpleFillSymbolLayer > fillSymbolLayer = qgis::make_unique< QgsSimpleFillSymbolLayer >();
1078  fillSymbolLayer->setStrokeStyle( Qt::NoPen );
1079 
1080  //fill color 2
1081 
1082  QDomNodeList fillColor2List = itemElem.elementsByTagName( QStringLiteral( "fillColor2" ) );
1083  if ( !fillColor2List.isEmpty() )
1084  {
1085  QDomElement fillColor2Elem = fillColor2List.at( 0 ).toElement();
1086  bool redOk, greenOk, blueOk, alphaOk;
1087  int fillRed, fillGreen, fillBlue, fillAlpha;
1088 
1089  fillRed = fillColor2Elem.attribute( QStringLiteral( "red" ) ).toDouble( &redOk );
1090  fillGreen = fillColor2Elem.attribute( QStringLiteral( "green" ) ).toDouble( &greenOk );
1091  fillBlue = fillColor2Elem.attribute( QStringLiteral( "blue" ) ).toDouble( &blueOk );
1092  fillAlpha = fillColor2Elem.attribute( QStringLiteral( "alpha" ) ).toDouble( &alphaOk );
1093 
1094  if ( redOk && greenOk && blueOk && alphaOk )
1095  {
1096  fillSymbolLayer->setColor( QColor( fillRed, fillGreen, fillBlue, fillAlpha ) );
1097  }
1098  }
1099  else
1100  {
1101  fillSymbolLayer->setColor( QColor( itemElem.attribute( QStringLiteral( "brush2Color" ), QStringLiteral( "#ffffff" ) ) ) );
1102  }
1103 
1104  // need to translate the deprecated ScalebarFillColor2 property to symbol properties,
1105  // and then remove them from the scalebar so they don't interfere and apply to other compatibility workarounds
1106  fillSymbolLayer->setDataDefinedProperty( QgsSymbolLayer::PropertyFillColor, dataDefinedProperties().property( QgsLayoutObject::ScalebarFillColor2 ) );
1108 
1109  fillSymbol->changeSymbolLayer( 0, fillSymbolLayer.release() );
1110  mSettings.setAlternateFillSymbol( fillSymbol.release() );
1111 
1112  }
1113 
1114  //font color
1115  QDomNodeList textColorList = itemElem.elementsByTagName( QStringLiteral( "textColor" ) );
1116  if ( !textColorList.isEmpty() )
1117  {
1118  QDomElement textColorElem = textColorList.at( 0 ).toElement();
1119  bool redOk, greenOk, blueOk, alphaOk;
1120  int textRed, textGreen, textBlue, textAlpha;
1121 
1122  textRed = textColorElem.attribute( QStringLiteral( "red" ) ).toDouble( &redOk );
1123  textGreen = textColorElem.attribute( QStringLiteral( "green" ) ).toDouble( &greenOk );
1124  textBlue = textColorElem.attribute( QStringLiteral( "blue" ) ).toDouble( &blueOk );
1125  textAlpha = textColorElem.attribute( QStringLiteral( "alpha" ) ).toDouble( &alphaOk );
1126 
1127  if ( redOk && greenOk && blueOk && alphaOk )
1128  {
1129  mSettings.textFormat().setColor( QColor( textRed, textGreen, textBlue, textAlpha ) );
1130  }
1131  }
1132  else if ( itemElem.hasAttribute( QStringLiteral( "fontColor" ) ) )
1133  {
1134  QColor c;
1135  c.setNamedColor( itemElem.attribute( QStringLiteral( "fontColor" ), QStringLiteral( "#000000" ) ) );
1136  mSettings.textFormat().setColor( c );
1137  }
1138 
1139  //style
1140  setStyle( itemElem.attribute( QStringLiteral( "style" ), QString() ) );
1141 
1142  //call attemptResize after setStyle to ensure the appropriate size limitations are applied
1143  attemptResize( QgsLayoutSize::decodeSize( itemElem.attribute( QStringLiteral( "size" ) ) ) );
1144 
1145  if ( itemElem.attribute( QStringLiteral( "unitType" ) ).isEmpty() )
1146  {
1148  switch ( itemElem.attribute( QStringLiteral( "units" ) ).toInt() )
1149  {
1150  case 0:
1152  break;
1153  case 1:
1155  break;
1156  case 2:
1158  break;
1159  case 3:
1161  break;
1162  }
1163  mSettings.setUnits( u );
1164  }
1165  else
1166  {
1167  mSettings.setUnits( QgsUnitTypes::decodeDistanceUnit( itemElem.attribute( QStringLiteral( "unitType" ) ) ) );
1168  }
1169 
1170  mSettings.setLabelVerticalPlacement( static_cast< QgsScaleBarSettings::LabelVerticalPlacement >( itemElem.attribute( QStringLiteral( "labelVerticalPlacement" ), QStringLiteral( "0" ) ).toInt() ) );
1171  mSettings.setLabelHorizontalPlacement( static_cast< QgsScaleBarSettings::LabelHorizontalPlacement >( itemElem.attribute( QStringLiteral( "labelHorizontalPlacement" ), QStringLiteral( "0" ) ).toInt() ) );
1172 
1173  mSettings.setAlignment( static_cast< QgsScaleBarSettings::Alignment >( itemElem.attribute( QStringLiteral( "alignment" ), QStringLiteral( "0" ) ).toInt() ) );
1174 
1175  //map
1176  disconnectCurrentMap();
1177  mMap = nullptr;
1178  mMapUuid = itemElem.attribute( QStringLiteral( "mapUuid" ) );
1179  return true;
1180 }
1181 
1182 
1184 {
1185  if ( mLayout && !mMapUuid.isEmpty() )
1186  {
1187  disconnectCurrentMap();
1188  mMap = qobject_cast< QgsLayoutItemMap * >( mLayout->itemByUuid( mMapUuid, true ) );
1189  if ( mMap )
1190  {
1191  connect( mMap, &QgsLayoutItemMap::extentChanged, this, &QgsLayoutItemScaleBar::updateScale );
1192  connect( mMap, &QObject::destroyed, this, &QgsLayoutItemScaleBar::disconnectCurrentMap );
1193  }
1194  }
1195 
1196  updateScale();
1197 }
1198 
1200 {
1201  QgsStyleTextFormatEntity entity( mSettings.textFormat() );
1202  if ( !visitor->visit( QgsStyleEntityVisitorInterface::StyleLeaf( &entity, uuid(), displayName() ) ) )
1203  return false;
1204 
1205  return true;
1206 }
1207 
1209 {
1211 }
QgsScaleBarSettings::SegmentSizeMode
SegmentSizeMode
Modes for setting size for scale bar segments.
Definition: qgsscalebarsettings.h:58
QgsScaleBarSettings::setLabelBarSpace
void setLabelBarSpace(double space)
Sets the spacing (in millimeters) between labels and the scalebar.
Definition: qgsscalebarsettings.h:568
QgsScaleBarSettings::setNumberOfSegments
void setNumberOfSegments(int segments)
Sets the number of segments included in the scalebar.
Definition: qgsscalebarsettings.h:107
QgsScaleBarSettings::fillColor2
Q_DECL_DEPRECATED QColor fillColor2() const
Returns the secondary color used for fills in the scalebar.
Definition: qgsscalebarsettings.cpp:127
QgsLayoutObject::ScalebarFillColor2
@ ScalebarFillColor2
Scalebar secondary fill color (deprecated, use data defined properties on scalebar fill symbol 2 inst...
Definition: qgslayoutobject.h:197
QgsLayoutItemScaleBar::pen
Q_DECL_DEPRECATED QPen pen() const
Returns the pen used for drawing outlines in the scalebar.
Definition: qgslayoutitemscalebar.cpp:726
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition: qgsexpressioncontext.h:370
QgsScaleBarSettings::height
double height() const
Returns the scalebar height (in millimeters).
Definition: qgsscalebarsettings.h:550
QgsLayoutItemScaleBar::setFontColor
Q_DECL_DEPRECATED void setFontColor(const QColor &color)
Sets the color used for drawing text in the scalebar.
Definition: qgslayoutitemscalebar.cpp:664
QgsLayoutObject::layout
const QgsLayout * layout() const
Returns the layout the object is attached to.
Definition: qgslayoutobject.cpp:126
QgsLayoutItemScaleBar::setFont
Q_DECL_DEPRECATED void setFont(const QFont &font)
Sets the font used for drawing text in the scalebar.
Definition: qgslayoutitemscalebar.cpp:648
qgsscalebarrendererregistry.h
QgsScaleBarSettings::mapUnitsPerScaleBarUnit
double mapUnitsPerScaleBarUnit() const
Returns the number of map units per scale bar unit used by the scalebar.
Definition: qgsscalebarsettings.h:243
qgsnumericformatregistry.h
QgsAbstractPropertyCollection::valueAsDouble
double valueAsDouble(int key, const QgsExpressionContext &context, double defaultValue=0.0, bool *ok=nullptr) const
Calculates the current value of the property with the specified key and interprets it as a double.
Definition: qgspropertycollection.cpp:66
QgsScaleBarSettings::lineSymbol
QgsLineSymbol * lineSymbol() const
Returns the line symbol used to render the scalebar (only used for some scalebar types).
Definition: qgsscalebarsettings.cpp:191
QgsCoordinateReferenceSystem::mapUnits
Q_GADGET QgsUnitTypes::DistanceUnit mapUnits
Definition: qgscoordinatereferencesystem.h:209
QgsTextFormat::setFont
void setFont(const QFont &font)
Sets the font used for rendering text.
Definition: qgstextformat.cpp:177
QgsProperty
A store for object properties.
Definition: qgsproperty.h:232
QgsScaleBarRenderer::ScaleBarContext
Contains parameters regarding scalebar calculations.
Definition: qgsscalebarrenderer.h:71
QgsLayoutItem::refreshItemSize
void refreshItemSize()
Refreshes an item's size by rechecking it against any possible item fixed or minimum sizes.
Definition: qgslayoutitem.cpp:1268
QgsApplication::getThemeIcon
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon.
Definition: qgsapplication.cpp:626
QgsLayoutSize::units
QgsUnitTypes::LayoutUnit units() const
Returns the units for the size.
Definition: qgslayoutsize.h:103
QgsLayoutItemScaleBar::setAlignment
void setAlignment(QgsScaleBarSettings::Alignment alignment)
Sets the scalebar alignment.
Definition: qgslayoutitemscalebar.cpp:407
QgsSettings::value
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
Definition: qgssettings.cpp:174
QgsLayoutItemScaleBar::QgsLayoutItemScaleBar
QgsLayoutItemScaleBar(QgsLayout *layout)
Constructor for QgsLayoutItemScaleBar, with the specified parent layout.
Definition: qgslayoutitemscalebar.cpp:46
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:35
qgsrectangle.h
QgsUnitTypes::DistanceUnknownUnit
@ DistanceUnknownUnit
Unknown distance unit.
Definition: qgsunittypes.h:78
QgsLayoutItemScaleBar::setSegmentSizeMode
void setSegmentSizeMode(QgsScaleBarSettings::SegmentSizeMode mode)
Sets the size mode for scale bar segments.
Definition: qgslayoutitemscalebar.cpp:139
QgsScaleBarSettings::setAlignment
void setAlignment(Alignment alignment)
Sets the scalebar alignment.
Definition: qgsscalebarsettings.h:620
QgsLayoutObject::ScalebarLineColor
@ ScalebarLineColor
Scalebar line color (deprecated, use data defined properties on scalebar line symbol instead)
Definition: qgslayoutobject.h:198
QgsLayoutItemMap::extentChanged
void extentChanged()
Emitted when the map's extent changes.
crs
const QgsCoordinateReferenceSystem & crs
Definition: qgswfsgetfeature.cpp:51
QgsLayoutItemScaleBar::update
void update()
Adjusts the scale bar box size and updates the item.
Definition: qgslayoutitemscalebar.cpp:588
QgsLayoutItemScaleBar::setFillSymbol
void setFillSymbol(QgsFillSymbol *symbol)
Sets the primary fill symbol used to render the scalebar (only used for some scalebar types).
Definition: qgslayoutitemscalebar.cpp:222
QgsLayoutItemScaleBar::lineSymbol
QgsLineSymbol * lineSymbol() const
Returns the line symbol used to render the scalebar (only used for some scalebar types).
Definition: qgslayoutitemscalebar.cpp:187
QgsLineSymbol::clone
QgsLineSymbol * clone() const override
Returns a deep copy of this symbol.
Definition: qgssymbol.cpp:2193
QgsSymbolLayer::PropertyFillColor
@ PropertyFillColor
Fill color.
Definition: qgssymbollayer.h:135
QgsScaleBarSettings::setUnitsPerSegment
void setUnitsPerSegment(double units)
Sets the number of scalebar units per segment.
Definition: qgsscalebarsettings.h:169
QgsUnitTypes::RenderPoints
@ RenderPoints
Points (e.g., for font sizes)
Definition: qgsunittypes.h:172
qgssymbollayerutils.h
QgsLayoutItemScaleBar::setLineJoinStyle
Q_DECL_DEPRECATED void setLineJoinStyle(Qt::PenJoinStyle style)
Sets the join style used when drawing the lines in the scalebar.
Definition: qgslayoutitemscalebar.cpp:429
QgsLayoutItemScaleBar::setBoxContentSpace
void setBoxContentSpace(double space)
Sets the space (margin) between the scalebar box and content in millimeters.
Definition: qgslayoutitemscalebar.cpp:248
QgsScaleBarSettings::setLabelHorizontalPlacement
void setLabelHorizontalPlacement(LabelHorizontalPlacement placement)
Sets the horizontal placement of text labels.
Definition: qgsscalebarsettings.h:596
QgsRectangle::yMinimum
double yMinimum() const SIP_HOLDGIL
Returns the y minimum value (bottom side of rectangle).
Definition: qgsrectangle.h:177
QgsSymbolLayerUtils::encodePenCapStyle
static QString encodePenCapStyle(Qt::PenCapStyle style)
Definition: qgssymbollayerutils.cpp:223
QgsScaleBarSettings::lineWidth
Q_DECL_DEPRECATED double lineWidth() const
Returns the line width in millimeters for lines in the scalebar.
Definition: qgsscalebarsettings.cpp:150
QgsLayoutItemScaleBar::setLinkedMap
void setLinkedMap(QgsLayoutItemMap *map)
Sets the map item linked to the scalebar.
Definition: qgslayoutitemscalebar.cpp:259
QgsLayoutItemRenderContext
Contains settings and helpers relating to a render of a QgsLayoutItem.
Definition: qgslayoutitem.h:45
QgsUnitTypes::toAbbreviatedString
static Q_INVOKABLE QString toAbbreviatedString(QgsUnitTypes::DistanceUnit unit)
Returns a translated abbreviation representing a distance unit.
Definition: qgsunittypes.cpp:269
QgsLayoutItemScaleBar::finalizeRestoreFromXml
void finalizeRestoreFromXml() override
Called after all pending items have been restored from XML.
Definition: qgslayoutitemscalebar.cpp:1183
QgsScaleBarSettings::setLineCapStyle
Q_DECL_DEPRECATED void setLineCapStyle(Qt::PenCapStyle style)
Sets the cap style used when drawing the lines in the scalebar.
Definition: qgsscalebarsettings.cpp:312
QgsLayoutItemScaleBar::units
QgsUnitTypes::DistanceUnit units() const
Returns the distance units used by the scalebar.
Definition: qgslayoutitemscalebar.h:546
QgsLayoutItemScaleBar::setLineSymbol
void setLineSymbol(QgsLineSymbol *symbol)
Sets the line symbol used to render the scalebar (only used for some scalebar types).
Definition: qgslayoutitemscalebar.cpp:192
QgsLayoutObject::mDataDefinedProperties
QgsPropertyCollection mDataDefinedProperties
Definition: qgslayoutobject.h:345
QgsLayoutItemScaleBar::setLineWidth
Q_DECL_DEPRECATED void setLineWidth(double width)
Sets the line width in millimeters for lines in the scalebar.
Definition: qgslayoutitemscalebar.cpp:719
QgsRenderContext
Contains information about the context of a rendering operation.
Definition: qgsrendercontext.h:58
QgsScaleBarSettings::fillSymbol
QgsFillSymbol * fillSymbol() const
Returns the primary fill symbol used to render the scalebar (only used for some scalebar types).
Definition: qgsscalebarsettings.cpp:221
QgsStyleEntityVisitorInterface
An interface for classes which can visit style entity (e.g.
Definition: qgsstyleentityvisitor.h:34
qgsunittypes.h
QgsLayoutItemScaleBar::divisionLineSymbol
QgsLineSymbol * divisionLineSymbol() const
Returns the line symbol used to render the scalebar divisions (only used for some scalebar types).
Definition: qgslayoutitemscalebar.cpp:197
QgsLayoutItemScaleBar::setLineColor
Q_DECL_DEPRECATED void setLineColor(const QColor &color)
Sets the color used for lines in the scalebar.
Definition: qgslayoutitemscalebar.cpp:705
QgsLayoutItem::refreshDataDefinedProperty
virtual void refreshDataDefinedProperty(QgsLayoutObject::DataDefinedProperty property=QgsLayoutObject::AllProperties)
Refreshes a data defined property for the item by reevaluating the property's value and redrawing the...
Definition: qgslayoutitem.cpp:1081
QgsUnitTypes::RenderMillimeters
@ RenderMillimeters
Millimeters.
Definition: qgsunittypes.h:168
qgsscalebarrenderer.h
QgsSettings
This class is a composition of two QSettings instances:
Definition: qgssettings.h:62
QgsScaleBarSettings::LabelHorizontalPlacement
LabelHorizontalPlacement
Label horizontal placement.
Definition: qgsscalebarsettings.h:76
QgsLayoutItemScaleBar::setMaximumBarWidth
void setMaximumBarWidth(double maxWidth)
Sets the maximum width (in millimeters) for scale bar segments.
Definition: qgslayoutitemscalebar.cpp:163
QgsNumericFormat
A numeric formatter allows for formatting a numeric value for display, using a variety of different f...
Definition: qgsnumericformat.h:218
QgsLayoutItemScaleBar::accept
bool accept(QgsStyleEntityVisitorInterface *visitor) const override
Accepts the specified style entity visitor, causing it to visit all style entities associated with th...
Definition: qgslayoutitemscalebar.cpp:1199
qgsmapsettings.h
qgsfontutils.h
QgsLayoutSize::decodeSize
static QgsLayoutSize decodeSize(const QString &string)
Decodes a size from a string.
Definition: qgslayoutsize.cpp:57
QgsLayoutItemScaleBar::setLabelHorizontalPlacement
void setLabelHorizontalPlacement(QgsScaleBarSettings::LabelHorizontalPlacement placement)
Sets the horizontal placement of text labels.
Definition: qgslayoutitemscalebar.cpp:400
QgsUnitTypes::DistanceUnit
DistanceUnit
Units of distance.
Definition: qgsunittypes.h:68
QgsScaleBarSettings::setMaximumBarWidth
void setMaximumBarWidth(double width)
Sets the maximum width (in millimeters) for scale bar segments.
Definition: qgsscalebarsettings.h:225
QgsSymbolLayer::PropertyStrokeColor
@ PropertyStrokeColor
Stroke color.
Definition: qgssymbollayer.h:136
qgssingleboxscalebarrenderer.h
QgsScaleBarSettings::SegmentSizeFitWidth
@ SegmentSizeFitWidth
Scale bar segment size is calculated to fit a size range.
Definition: qgsscalebarsettings.h:60
QgsLayoutItemScaleBar::applyDefaultRendererSettings
bool applyDefaultRendererSettings(QgsScaleBarRenderer *renderer)
Applies any default settings relating to the specified renderer to the item.
Definition: qgslayoutitemscalebar.cpp:493
QgsLayoutObject::changed
void changed()
Emitted when the object's properties change.
QgsUnitTypes::DistanceKilometers
@ DistanceKilometers
Kilometers.
Definition: qgsunittypes.h:70
QgsLayoutItemScaleBar::textFormat
QgsTextFormat textFormat() const
Returns the text format used for drawing text in the scalebar.
Definition: qgslayoutitemscalebar.cpp:175
QgsLayoutItem::sizeWithUnits
QgsLayoutSize sizeWithUnits() const
Returns the item's current size, including units.
Definition: qgslayoutitem.h:671
QgsRectangle
A rectangle specified with double values.
Definition: qgsrectangle.h:42
QgsStyleEntityVisitorInterface::StyleLeaf
Contains information relating to the style entity currently being visited.
Definition: qgsstyleentityvisitor.h:61
QgsScaleBarSettings::setNumberOfSubdivisions
void setNumberOfSubdivisions(int subdivisions)
Sets the number of subdivisions for segments included in the right part of the scalebar (only used fo...
Definition: qgsscalebarsettings.h:143
QgsLayoutItemScaleBar::numericFormat
const QgsNumericFormat * numericFormat() const
Returns the numeric format used for numbers in the scalebar.
Definition: qgslayoutitemscalebar.cpp:633
QgsLayoutItemScaleBar::font
Q_DECL_DEPRECATED QFont font() const
Returns the font used for drawing text in the scalebar.
Definition: qgslayoutitemscalebar.cpp:643
QgsLayoutItemScaleBar::writePropertiesToElement
bool writePropertiesToElement(QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const override
Stores item state within an XML DOM element.
Definition: qgslayoutitemscalebar.cpp:747
QgsScaleBarSettings::segmentSizeMode
SegmentSizeMode segmentSizeMode() const
Returns the size mode for the scale bar segments.
Definition: qgsscalebarsettings.h:177
QgsTextFormat::color
QColor color() const
Returns the color that text will be rendered in.
Definition: qgstextformat.cpp:232
QgsScaleBarSettings::setUnits
void setUnits(QgsUnitTypes::DistanceUnit units)
Sets the distance units used by the scalebar.
Definition: qgsscalebarsettings.h:237
qgslayoututils.h
QgsScaleBarSettings::subdivisionsHeight
double subdivisionsHeight() const
Returns the scalebar subdivisions height (in millimeters) for segments included in the right part of ...
Definition: qgsscalebarsettings.h:150
QgsScaleBarSettings::setFont
Q_DECL_DEPRECATED void setFont(const QFont &font)
Sets the font used for drawing text in the scalebar.
Definition: qgsscalebarsettings.h:296
QgsScaleBarRenderer::ScaleBarContext::size
QSizeF size
Destination size for scalebar.
Definition: qgsscalebarrenderer.h:84
QgsLayoutUtils::createRenderContextForLayout
static QgsRenderContext createRenderContextForLayout(QgsLayout *layout, QPainter *painter, double dpi=-1)
Creates a render context suitable for the specified layout and painter destination.
Definition: qgslayoututils.cpp:138
QgsUnitTypes::decodeDistanceUnit
static Q_INVOKABLE QgsUnitTypes::DistanceUnit decodeDistanceUnit(const QString &string, bool *ok=nullptr)
Decodes a distance unit from a string.
Definition: qgsunittypes.cpp:165
QgsLayoutItemScaleBar::setNumberOfSegments
void setNumberOfSegments(int segments)
Sets the number of segments included in the scalebar.
Definition: qgslayoutitemscalebar.cpp:116
QgsScaleBarSettings::labelBarSpace
double labelBarSpace() const
Returns the spacing (in millimeters) between labels and the scalebar.
Definition: qgsscalebarsettings.h:562
Q_NOWARN_DEPRECATED_POP
#define Q_NOWARN_DEPRECATED_POP
Definition: qgis.h:797
QgsRectangle::xMaximum
double xMaximum() const SIP_HOLDGIL
Returns the x maximum value (right side of rectangle).
Definition: qgsrectangle.h:162
QgsUnitTypes::fromUnitToUnitFactor
static Q_INVOKABLE double fromUnitToUnitFactor(QgsUnitTypes::DistanceUnit fromUnit, QgsUnitTypes::DistanceUnit toUnit)
Returns the conversion factor between the specified distance units.
Definition: qgsunittypes.cpp:352
QgsTextFormat
Container for all settings relating to text rendering.
Definition: qgstextformat.h:40
QgsTextFormat::setColor
void setColor(const QColor &color)
Sets the color that text will be rendered in.
Definition: qgstextformat.cpp:237
QgsDistanceArea::setEllipsoid
bool setEllipsoid(const QString &ellipsoid)
Sets the ellipsoid by its acronym.
Definition: qgsdistancearea.cpp:66
QgsLayoutItemScaleBar::fillColor
Q_DECL_DEPRECATED QColor fillColor() const
Returns the color used for fills in the scalebar.
Definition: qgslayoutitemscalebar.cpp:670
QgsScaleBarRenderer::applyDefaultSettings
virtual bool applyDefaultSettings(QgsScaleBarSettings &settings) const
Applies any default settings relating to the scalebar to the passed settings object.
Definition: qgsscalebarrenderer.cpp:301
QgsLayoutObject::AllProperties
@ AllProperties
All properties for item.
Definition: qgslayoutobject.h:135
QgsLayoutItemScaleBar::lineColor
Q_DECL_DEPRECATED QColor lineColor() const
Returns the color used for lines in the scalebar.
Definition: qgslayoutitemscalebar.cpp:698
QgsScaleBarSettings::alignment
Alignment alignment() const
Returns the scalebar alignment.
Definition: qgsscalebarsettings.h:614
QgsLayoutItemScaleBar::unitsPerSegment
double unitsPerSegment() const
Returns the number of scalebar units per segment.
Definition: qgslayoutitemscalebar.h:125
QgsLayoutItemScaleBar::setLabelVerticalPlacement
void setLabelVerticalPlacement(QgsScaleBarSettings::LabelVerticalPlacement placement)
Sets the vertical placement of text labels.
Definition: qgslayoutitemscalebar.cpp:393
QgsSymbol::changeSymbolLayer
bool changeSymbolLayer(int index, QgsSymbolLayer *layer)
Deletes the current layer at the specified index and replaces it with layer.
Definition: qgssymbol.cpp:438
QgsScaleBarSettings::boxContentSpace
double boxContentSpace() const
Returns the spacing (margin) between the scalebar box and content in millimeters.
Definition: qgsscalebarsettings.h:602
QgsScaleBarSettings::brush2
Q_DECL_DEPRECATED QBrush brush2() const
Returns the secondary brush for the scalebar.
Definition: qgsscalebarsettings.cpp:262
QgsUnitTypes::encodeUnit
static Q_INVOKABLE QString encodeUnit(QgsUnitTypes::DistanceUnit unit)
Encodes a distance unit to a string.
Definition: qgsunittypes.cpp:122
QgsLayoutUtils::calculatePrettySize
static double calculatePrettySize(double minimumSize, double maximumSize)
Calculates a "pretty" size which falls between the range [minimumSize, maximumSize].
Definition: qgslayoututils.cpp:448
QgsScaleBarSettings::setHeight
void setHeight(double height)
Sets the scalebar height (in millimeters).
Definition: qgsscalebarsettings.h:556
QgsScaleBarSettings::setFillColor2
Q_DECL_DEPRECATED void setFillColor2(const QColor &color)
Sets the secondary color used for fills in the scalebar.
Definition: qgsscalebarsettings.cpp:132
QgsScaleBarSettings::lineCapStyle
Q_DECL_DEPRECATED Qt::PenCapStyle lineCapStyle() const
Returns the cap style used for drawing lines in the scalebar.
Definition: qgsscalebarsettings.cpp:303
QgsScaleBarSettings::SegmentSizeFixed
@ SegmentSizeFixed
Scale bar segment size is fixed to a map unit.
Definition: qgsscalebarsettings.h:59
QgsLayoutItem::ExportLayerBehavior
ExportLayerBehavior
Behavior of item when exporting to layered outputs.
Definition: qgslayoutitem.h:428
QgsUnitTypes::DistanceDegrees
@ DistanceDegrees
Degrees, for planar geographic CRS distance measurements.
Definition: qgsunittypes.h:75
QgsScaleBarSettings::Alignment
Alignment
Scalebar alignment.
Definition: qgsscalebarsettings.h:48
QgsScaleBarSettings::numberOfSegments
int numberOfSegments() const
Returns the number of segments included in the scalebar.
Definition: qgsscalebarsettings.h:100
QgsScaleBarSettings::setUnitLabel
void setUnitLabel(const QString &label)
Sets the label for units.
Definition: qgsscalebarsettings.h:261
QgsScaleBarSettings::setTextFormat
void setTextFormat(const QgsTextFormat &format)
Sets the text format used for drawing text in the scalebar.
Definition: qgsscalebarsettings.h:282
QgsLayoutItemScaleBar::setSubdivisionLineSymbol
void setSubdivisionLineSymbol(QgsLineSymbol *symbol)
Sets the line symbol used to render the scalebar subdivisions (only used for some scalebar types).
Definition: qgslayoutitemscalebar.cpp:212
QgsScaleBarSettings::labelVerticalPlacement
LabelVerticalPlacement labelVerticalPlacement() const
Returns the vertical placement of text labels.
Definition: qgsscalebarsettings.h:575
QgsScaleBarSettings::textFormat
QgsTextFormat & textFormat()
Returns the text format used for drawing text in the scalebar.
Definition: qgsscalebarsettings.h:268
QgsLayoutItemScaleBar::setUnits
void setUnits(QgsUnitTypes::DistanceUnit units)
Sets the distance units used by the scalebar.
Definition: qgslayoutitemscalebar.cpp:414
QgsLayoutItemScaleBar::fillSymbol
QgsFillSymbol * fillSymbol() const
Returns the primary fill symbol used to render the scalebar (only used for some scalebar types).
Definition: qgslayoutitemscalebar.cpp:217
QgsScaleBarSettings::fillColor
Q_DECL_DEPRECATED QColor fillColor() const
Returns the color used for fills in the scalebar.
Definition: qgsscalebarsettings.cpp:117
QgsDistanceArea::measureLine
double measureLine(const QVector< QgsPointXY > &points) const
Measures the length of a line with multiple segments.
Definition: qgsdistancearea.cpp:273
QgsLayoutItemScaleBar::setFillColor
Q_DECL_DEPRECATED void setFillColor(const QColor &color)
Sets the color used for fills in the scalebar.
Definition: qgslayoutitemscalebar.cpp:677
QgsLayoutItem::setBackgroundEnabled
void setBackgroundEnabled(bool drawBackground)
Sets whether this item has a background drawn under it or not.
Definition: qgslayoutitem.cpp:886
QgsDistanceArea::lengthUnits
QgsUnitTypes::DistanceUnit lengthUnits() const
Returns the units of distance for length calculations made by this object.
Definition: qgsdistancearea.cpp:789
QgsScaleBarRenderer::ScaleBarContext::scale
double scale
Scale denominator.
Definition: qgsscalebarrenderer.h:87
QgsLayoutItemScaleBar::lineCapStyle
Q_DECL_DEPRECATED Qt::PenCapStyle lineCapStyle() const
Returns the cap style used for drawing lines in the scalebar.
Definition: qgslayoutitemscalebar.cpp:443
QgsScaleBarSettings::pen
Q_DECL_DEPRECATED QPen pen() const
Returns the pen used for drawing outlines in the scalebar.
Definition: qgsscalebarsettings.cpp:164
QgsLineSymbol
A line symbol type, for rendering LineString and MultiLineString geometries.
Definition: qgssymbol.h:1131
QgsLayoutItemMap::extent
QgsRectangle extent() const
Returns the current map extent.
Definition: qgslayoutitemmap.cpp:265
QgsUnitTypes::DistanceFeet
@ DistanceFeet
Imperial feet.
Definition: qgsunittypes.h:71
QgsScaleBarRenderer
Abstract base class for scale bar renderers.
Definition: qgsscalebarrenderer.h:39
QgsUnitTypes::DistanceMeters
@ DistanceMeters
Meters.
Definition: qgsunittypes.h:69
QgsStyleTextFormatEntity
A text format entity for QgsStyle databases.
Definition: qgsstyle.h:1264
QgsScaleBarSettings::setLineColor
Q_DECL_DEPRECATED void setLineColor(const QColor &color)
Sets the color used for lines in the scalebar.
Definition: qgsscalebarsettings.cpp:142
QgsLayoutItemScaleBar::readPropertiesFromElement
bool readPropertiesFromElement(const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context) override
Sets item state from a DOM element.
Definition: qgslayoutitemscalebar.cpp:872
QgsTextFormat::opacity
double opacity() const
Returns the text's opacity.
Definition: qgstextformat.cpp:243
QgsScaleBarSettings::units
QgsUnitTypes::DistanceUnit units() const
Returns the distance units used by the scalebar.
Definition: qgsscalebarsettings.h:231
QgsLayoutItemScaleBar::setMinimumBarWidth
void setMinimumBarWidth(double minWidth)
Sets the minimum width (in millimeters) for scale bar segments.
Definition: qgslayoutitemscalebar.cpp:151
QgsScaleBarSettings::setLineWidth
Q_DECL_DEPRECATED void setLineWidth(double width)
Sets the line width in millimeters for lines in the scalebar.
Definition: qgsscalebarsettings.cpp:155
QgsScaleBarSettings::numberOfSegmentsLeft
int numberOfSegmentsLeft() const
Returns the number of segments included in the left part of the scalebar.
Definition: qgsscalebarsettings.h:114
QgsLayoutItemScaleBar::subdivisionLineSymbol
QgsLineSymbol * subdivisionLineSymbol() const
Returns the line symbol used to render the scalebar subdivisions (only used for some scalebar types).
Definition: qgslayoutitemscalebar.cpp:207
QgsScaleBarSettings::setMapUnitsPerScaleBarUnit
void setMapUnitsPerScaleBarUnit(double units)
Sets the number of map units per scale bar unit used by the scalebar.
Definition: qgsscalebarsettings.h:249
QgsTextFormat::readXml
void readXml(const QDomElement &elem, const QgsReadWriteContext &context)
Read settings from a DOM element.
Definition: qgstextformat.cpp:406
QgsLayoutItemScaleBar::icon
QIcon icon() const override
Returns the item's icon.
Definition: qgslayoutitemscalebar.cpp:58
QgsScaleBarSettings::maximumBarWidth
double maximumBarWidth() const
Returns the maximum width (in millimeters) for scale bar segments.
Definition: qgsscalebarsettings.h:215
QgsLayoutItem
Base class for graphical items within a QgsLayout.
Definition: qgslayoutitem.h:113
QgsRectangle::xMinimum
double xMinimum() const SIP_HOLDGIL
Returns the x minimum value (left side of rectangle).
Definition: qgsrectangle.h:167
QgsDistanceArea::setSourceCrs
void setSourceCrs(const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context)
Sets source spatial reference system crs.
Definition: qgsdistancearea.cpp:60
QgsScaleBarSettings::setLineSymbol
void setLineSymbol(QgsLineSymbol *symbol)
Sets the line symbol used to render the scalebar (only used for some scalebar types).
Definition: qgsscalebarsettings.cpp:196
qgsfillsymbollayer.h
QgsSymbolLayer::PropertyStrokeWidth
@ PropertyStrokeWidth
Stroke width.
Definition: qgssymbollayer.h:137
QgsScaleBarSettings::setFillColor
Q_DECL_DEPRECATED void setFillColor(const QColor &color)
Sets the color used for fills in the scalebar.
Definition: qgsscalebarsettings.cpp:122
QgsLayoutItemScaleBar::applyDefaultSize
void applyDefaultSize(QgsUnitTypes::DistanceUnit units=QgsUnitTypes::DistanceMeters)
Applies the default size to the scale bar (scale bar 1/5 of map item width)
Definition: qgslayoutitemscalebar.cpp:540
QgsScaleBarSettings::setSubdivisionLineSymbol
void setSubdivisionLineSymbol(QgsLineSymbol *symbol)
Sets the line symbol used to render the scalebar subdivisions (only used for some scalebar types).
Definition: qgsscalebarsettings.cpp:216
QgsScaleBarSettings::lineColor
Q_DECL_DEPRECATED QColor lineColor() const
Returns the color used for lines in the scalebar.
Definition: qgsscalebarsettings.cpp:137
qgslayout.h
QgsLayoutItemMap::crs
QgsCoordinateReferenceSystem crs() const
Returns coordinate reference system used for rendering the map.
Definition: qgslayoutitemmap.cpp:292
QgsLayoutItemScaleBar::setStyle
void setStyle(const QString &name)
Sets the scale bar style by name.
Definition: qgslayoutitemscalebar.cpp:609
QgsCoordinateReferenceSystem
This class represents a coordinate reference system (CRS).
Definition: qgscoordinatereferencesystem.h:206
QgsLayoutObject::ScalebarLineWidth
@ ScalebarLineWidth
Scalebar line width (deprecated, use data defined properties on scalebar line symbol instead)
Definition: qgslayoutobject.h:199
QgsScaleBarSettings::brush
Q_DECL_DEPRECATED QBrush brush() const
Returns the primary brush used for filling the scalebar.
Definition: qgsscalebarsettings.cpp:241
QgsLayoutItemRegistry::LayoutScaleBar
@ LayoutScaleBar
Scale bar item.
Definition: qgslayoutitemregistry.h:324
QgsScaleBarSettings::setLabelVerticalPlacement
void setLabelVerticalPlacement(LabelVerticalPlacement placement)
Sets the vertical placement of text labels.
Definition: qgsscalebarsettings.h:582
QgsLayoutItemScaleBar::setLineCapStyle
Q_DECL_DEPRECATED void setLineCapStyle(Qt::PenCapStyle style)
Sets the cap style used when drawing the lines in the scalebar.
Definition: qgslayoutitemscalebar.cpp:450
QgsUnitTypes::RenderPixels
@ RenderPixels
Pixels.
Definition: qgsunittypes.h:170
QgsScaleBarSettings::setSubdivisionsHeight
void setSubdivisionsHeight(double height)
Sets the scalebar subdivisions height (in millimeters) for segments included in the right part of the...
Definition: qgsscalebarsettings.h:157
QgsScaleBarRenderer::ScaleBarContext::segmentWidth
double segmentWidth
The width, in millimeters, of each individual segment drawn.
Definition: qgsscalebarrenderer.h:77
qgsnumericformat.h
QgsLayoutItemScaleBar::setNumericFormat
void setNumericFormat(QgsNumericFormat *format)
Sets the numeric format used for numbers in the scalebar.
Definition: qgslayoutitemscalebar.cpp:638
QgsPointXY
A class to represent a 2D point.
Definition: qgspointxy.h:44
QgsSymbolLayerUtils::decodePenCapStyle
static Qt::PenCapStyle decodePenCapStyle(const QString &str)
Definition: qgssymbollayerutils.cpp:238
QgsLayoutItemMap
Layout graphical items for displaying a map.
Definition: qgslayoutitemmap.h:318
QgsLayoutItemScaleBar::setFillColor2
Q_DECL_DEPRECATED void setFillColor2(const QColor &color)
Sets the secondary color used for fills in the scalebar.
Definition: qgslayoutitemscalebar.cpp:691
QgsLayoutObject::dataDefinedProperties
QgsPropertyCollection & dataDefinedProperties()
Returns a reference to the object's property collection, used for data defined overrides.
Definition: qgslayoutobject.h:245
QgsLayoutItemScaleBar::lineJoinStyle
Q_DECL_DEPRECATED Qt::PenJoinStyle lineJoinStyle() const
Returns the join style used for drawing lines in the scalebar.
Definition: qgslayoutitemscalebar.cpp:422
QgsLayoutItemScaleBar::resizeToMinimumWidth
void resizeToMinimumWidth()
Resizes the scale bar to its minimum width, without changing the height.
Definition: qgslayoutitemscalebar.cpp:574
QgsLayoutSize::setWidth
void setWidth(const double width)
Sets the width for the size.
Definition: qgslayoutsize.h:83
QgsLayoutItemScaleBar::lineWidth
Q_DECL_DEPRECATED double lineWidth() const
Returns the line width in millimeters for lines in the scalebar.
Definition: qgslayoutitemscalebar.cpp:712
QgsFontUtils::setFromXmlChildNode
static bool setFromXmlChildNode(QFont &font, const QDomElement &element, const QString &childNode)
Sets the properties of a font to match the properties stored in an XML child node.
Definition: qgsfontutils.cpp:348
QgsLayoutItemRenderContext::renderContext
QgsRenderContext & renderContext()
Returns a reference to the context's render context.
Definition: qgslayoutitem.h:72
QgsLayoutItem::uuid
virtual QString uuid() const
Returns the item identification string.
Definition: qgslayoutitem.h:343
QgsLayoutItemScaleBar::refreshDataDefinedProperty
void refreshDataDefinedProperty(QgsLayoutObject::DataDefinedProperty property=QgsLayoutObject::AllProperties) override
Refreshes a data defined property for the item by reevaluating the property's value and redrawing the...
Definition: qgslayoutitemscalebar.cpp:289
QgsScaleBarSettings::lineJoinStyle
Q_DECL_DEPRECATED Qt::PenJoinStyle lineJoinStyle() const
Returns the join style used for drawing lines in the scalebar.
Definition: qgsscalebarsettings.cpp:283
QgsScaleBarSettings::divisionLineSymbol
QgsLineSymbol * divisionLineSymbol() const
Returns the line symbol used to render the scalebar divisions (only used for some scalebar types).
Definition: qgsscalebarsettings.cpp:201
qgslinesymbollayer.h
QgsLayoutItemScaleBar::guessUnits
QgsUnitTypes::DistanceUnit guessUnits() const
Attempts to guess the most reasonable unit choice for the scalebar, given the current linked map's sc...
Definition: qgslayoutitemscalebar.cpp:498
QgsScaleBarSettings::setMinimumBarWidth
void setMinimumBarWidth(double width)
Sets the minimum width (in millimeters) for scale bar segments.
Definition: qgsscalebarsettings.h:205
QgsLayoutObject::mLayout
QPointer< QgsLayout > mLayout
Definition: qgslayoutobject.h:343
QgsScaleBarSettings::subdivisionLineSymbol
QgsLineSymbol * subdivisionLineSymbol() const
Returns the line symbol used to render the scalebar subdivisions (only used for some scalebar types).
Definition: qgsscalebarsettings.cpp:211
QgsScaleBarSettings::numberOfSubdivisions
int numberOfSubdivisions() const
Returns the number of subdivisions for segments included in the right part of the scalebar (only used...
Definition: qgsscalebarsettings.h:132
c
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
Definition: porting_processing.dox:1
QgsLayout
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition: qgslayout.h:50
QgsRectangle::width
double width() const SIP_HOLDGIL
Returns the width of the rectangle.
Definition: qgsrectangle.h:202
QgsScaleBarSettings::setBoxContentSpace
void setBoxContentSpace(double space)
Sets the space (margin) between the scalebar box and content in millimeters.
Definition: qgsscalebarsettings.h:608
QgsLayoutItem::displayName
virtual QString displayName() const
Gets item display name.
Definition: qgslayoutitem.cpp:107
QgsLayoutItemScaleBar::fillColor2
Q_DECL_DEPRECATED QColor fillColor2() const
Returns the secondary color used for fills in the scalebar.
Definition: qgslayoutitemscalebar.cpp:684
QgsScaleBarSettings::unitsPerSegment
double unitsPerSegment() const
Returns the number of scalebar units per segment.
Definition: qgsscalebarsettings.h:163
QgsTextFormat::setOpacity
void setOpacity(double opacity)
Sets the text's opacity.
Definition: qgstextformat.cpp:248
QgsLayoutItemScaleBar::brush
Q_DECL_DEPRECATED QBrush brush() const
Returns the primary brush for the scalebar.
Definition: qgslayoutitemscalebar.cpp:733
qgssettings.h
QgsScaleBarSettings::setFillSymbol
void setFillSymbol(QgsFillSymbol *symbol)
Sets the primary fill symbol used to render the scalebar (only used for some scalebar types).
Definition: qgsscalebarsettings.cpp:226
QgsFillSymbol::clone
QgsFillSymbol * clone() const override
Returns a deep copy of this symbol.
Definition: qgssymbol.cpp:2317
QgsFillSymbol
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
Definition: qgssymbol.h:1234
QgsLayoutItemMap::scale
double scale() const
Returns the map scale.
Definition: qgslayoutitemmap.cpp:156
QgsScaleBarSettings::setLineJoinStyle
Q_DECL_DEPRECATED void setLineJoinStyle(Qt::PenJoinStyle style)
Sets the join style used when drawing the lines in the scalebar.
Definition: qgsscalebarsettings.cpp:292
QgsLayoutItemScaleBar::setUnitsPerSegment
void setUnitsPerSegment(double units)
Sets the number of scalebar units per segment.
Definition: qgslayoutitemscalebar.cpp:127
QgsLayoutItem::attemptResize
virtual void attemptResize(const QgsLayoutSize &size, bool includesFrame=false)
Attempts to resize the item to a specified target size.
Definition: qgslayoutitem.cpp:428
QgsApplication::numericFormatRegistry
static QgsNumericFormatRegistry * numericFormatRegistry()
Gets the registry of available numeric formats.
Definition: qgsapplication.cpp:2273
QgsSymbolLayerUtils::decodePenJoinStyle
static Qt::PenJoinStyle decodePenJoinStyle(const QString &str)
Definition: qgssymbollayerutils.cpp:188
QgsTextFormat::font
QFont font() const
Returns the font used for rendering text.
Definition: qgstextformat.cpp:151
QgsStyleEntityVisitorInterface::visit
virtual bool visit(const QgsStyleEntityVisitorInterface::StyleLeaf &entity)
Called when the visitor will visit a style entity.
Definition: qgsstyleentityvisitor.h:153
QgsLayoutItemScaleBar::minimumSize
QgsLayoutSize minimumSize() const override
Returns the minimum allowed size of the item, if applicable, or an empty size if item can be freely r...
Definition: qgslayoutitemscalebar.cpp:68
QgsTextFormat::setSizeUnit
void setSizeUnit(QgsUnitTypes::RenderUnit unit)
Sets the units for the size of rendered text.
Definition: qgstextformat.cpp:204
QgsLayoutSize
This class provides a method of storing sizes, consisting of a width and height, for use in QGIS layo...
Definition: qgslayoutsize.h:41
QgsUnitTypes::DistanceMiles
@ DistanceMiles
Terrestrial miles.
Definition: qgsunittypes.h:74
QgsLayoutItemScaleBar::alternateFillSymbol
QgsFillSymbol * alternateFillSymbol() const
Returns the secondary fill symbol used to render the scalebar (only used for some scalebar types).
Definition: qgslayoutitemscalebar.cpp:227
QgsLayoutItemScaleBar::setDivisionLineSymbol
void setDivisionLineSymbol(QgsLineSymbol *symbol)
Sets the line symbol used to render the scalebar divisions (only used for some scalebar types).
Definition: qgslayoutitemscalebar.cpp:202
QgsDistanceArea
A general purpose distance and area calculator, capable of performing ellipsoid based calculations.
Definition: qgsdistancearea.h:50
qgsdistancearea.h
QgsNumericFormat::writeXml
void writeXml(QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const
Writes the format to an XML element.
Definition: qgsnumericformat.cpp:45
QgsSymbolLayerUtils::encodePenJoinStyle
static QString encodePenJoinStyle(Qt::PenJoinStyle style)
Definition: qgssymbollayerutils.cpp:173
QgsScaleBarSettings::setDivisionLineSymbol
void setDivisionLineSymbol(QgsLineSymbol *symbol)
Sets the line symbol used to render the scalebar divisions (only used for some scalebar types).
Definition: qgsscalebarsettings.cpp:206
QgsUnitTypes::DistanceNauticalMiles
@ DistanceNauticalMiles
Nautical miles.
Definition: qgsunittypes.h:72
QgsPropertyCollection::setProperty
void setProperty(int key, const QgsProperty &property)
Adds a property to the collection and takes ownership of it.
Definition: qgspropertycollection.cpp:187
QgsUnitTypes::LayoutMillimeters
@ LayoutMillimeters
Millimeters.
Definition: qgsunittypes.h:182
QgsLayoutItemScaleBar::style
QString style() const
Returns the scale bar style name.
Definition: qgslayoutitemscalebar.cpp:621
QgsLayoutItemScaleBar
A layout item subclass for scale bars.
Definition: qgslayoutitemscalebar.h:36
QgsScaleBarSettings::labelHorizontalPlacement
LabelHorizontalPlacement labelHorizontalPlacement() const
Returns the horizontal placement of text labels.
Definition: qgsscalebarsettings.h:589
QgsLayoutItemScaleBar::type
int type() const override
Definition: qgslayoutitemscalebar.cpp:53
QgsTextFormat::setSize
void setSize(double size)
Sets the size for rendered text.
Definition: qgstextformat.cpp:226
QgsScaleBarSettings::setAlternateFillSymbol
void setAlternateFillSymbol(QgsFillSymbol *symbol)
Sets the secondary fill symbol used to render the scalebar (only used for some scalebar types).
Definition: qgsscalebarsettings.cpp:236
QgsScaleBarSettings::unitLabel
QString unitLabel() const
Returns the label for units.
Definition: qgsscalebarsettings.h:255
QgsScaleBarSettings::setNumberOfSegmentsLeft
void setNumberOfSegmentsLeft(int segments)
Sets the number of segments included in the left part of the scalebar.
Definition: qgsscalebarsettings.h:121
QgsLayoutItemScaleBar::fontColor
Q_DECL_DEPRECATED QColor fontColor() const
Returns the color used for drawing text in the scalebar.
Definition: qgslayoutitemscalebar.cpp:657
QgsLayoutItemScaleBar::applyDefaultSettings
void applyDefaultSettings()
Applies the default scalebar settings to the scale bar.
Definition: qgslayoutitemscalebar.cpp:464
qgslayoutitemregistry.h
QgsScaleBarSettings::numericFormat
const QgsNumericFormat * numericFormat() const
Returns the numeric format used for numbers in the scalebar.
Definition: qgsscalebarsettings.cpp:323
Q_NOWARN_DEPRECATED_PUSH
#define Q_NOWARN_DEPRECATED_PUSH
Definition: qgis.h:796
QgsLayoutItemScaleBar::brush2
Q_DECL_DEPRECATED QBrush brush2() const
Returns the secondary brush for the scalebar.
Definition: qgslayoutitemscalebar.cpp:740
QgsLayoutObject::ScalebarFillColor
@ ScalebarFillColor
Scalebar fill color (deprecated, use data defined properties on scalebar fill symbol 1 instead)
Definition: qgslayoutobject.h:196
QgsLayoutItemScaleBar::draw
void draw(QgsLayoutItemRenderContext &context) override
Draws the item's contents using the specified item render context.
Definition: qgslayoutitemscalebar.cpp:74
QgsLayoutItemScaleBar::exportLayerBehavior
ExportLayerBehavior exportLayerBehavior() const override
Returns the behavior of this item during exporting to layered exports (e.g.
Definition: qgslayoutitemscalebar.cpp:1208
QgsScaleBarSettings::alternateFillSymbol
QgsFillSymbol * alternateFillSymbol() const
Returns the secondary fill symbol used to render the scalebar (only used for some scalebar types).
Definition: qgsscalebarsettings.cpp:231
QgsScaleBarSettings::minimumBarWidth
double minimumBarWidth() const
Returns the minimum width (in millimeters) for scale bar segments.
Definition: qgsscalebarsettings.h:195
QgsScaleBarSettings::setNumericFormat
void setNumericFormat(QgsNumericFormat *format)
Sets the numeric format used for numbers in the scalebar.
Definition: qgsscalebarsettings.cpp:328
QgsLayoutItem::CanGroupWithItemsOfSameType
@ CanGroupWithItemsOfSameType
Item can only be placed on layers with other items of the same type, but multiple items of this type ...
Definition: qgslayoutitem.h:430
QgsScaleBarSettings::setSegmentSizeMode
void setSegmentSizeMode(SegmentSizeMode mode)
Sets the size mode for scale bar segments.
Definition: qgsscalebarsettings.h:185
qgslayoutitemscalebar.h
QgsLayoutItem::createExpressionContext
QgsExpressionContext createExpressionContext() const override
This method needs to be reimplemented in all classes which implement this interface and return an exp...
Definition: qgslayoutitem.cpp:1158
QgsTextFormat::writeXml
QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context) const
Write settings into a DOM element.
Definition: qgstextformat.cpp:555
QgsSymbolLayerUtils::saveSymbol
static QDomElement saveSymbol(const QString &symbolName, const QgsSymbol *symbol, QDomDocument &doc, const QgsReadWriteContext &context)
Writes a symbol definition to XML.
Definition: qgssymbollayerutils.cpp:1182
QgsLayoutItemScaleBar::setTextFormat
void setTextFormat(const QgsTextFormat &format)
Sets the text format used for drawing text in the scalebar.
Definition: qgslayoutitemscalebar.cpp:180
qgsproject.h
QgsLayoutMeasurement
This class provides a method of storing measurements for use in QGIS layouts using a variety of diffe...
Definition: qgslayoutmeasurement.h:34
QgsLayoutItemScaleBar::setNumberOfSegmentsLeft
void setNumberOfSegmentsLeft(int segments)
Sets the number of segments included in the left part of the scalebar.
Definition: qgslayoutitemscalebar.cpp:237
QgsScaleBarRenderer::ScaleBarContext::flags
Flags flags
Scalebar renderer flags.
Definition: qgsscalebarrenderer.h:90
QgsLayoutObject::DataDefinedProperty
DataDefinedProperty
Data defined properties for different item types.
Definition: qgslayoutobject.h:133
qgsstyleentityvisitor.h
QgsSettings::Gui
@ Gui
Definition: qgssettings.h:71
QgsAbstractPropertyCollection::valueAsColor
QColor valueAsColor(int key, const QgsExpressionContext &context, const QColor &defaultColor=QColor(), bool *ok=nullptr) const
Calculates the current value of the property with the specified key and interprets it as a color.
Definition: qgspropertycollection.cpp:54
QgsLayoutItemScaleBar::setAlternateFillSymbol
void setAlternateFillSymbol(QgsFillSymbol *symbol)
Sets the secondary fill symbol used to render the scalebar (only used for some scalebar types).
Definition: qgslayoutitemscalebar.cpp:232
qgslayoutitemmap.h
QgsLayoutItemScaleBar::setUnitLabel
void setUnitLabel(const QString &label)
Sets the label for units.
Definition: qgslayoutitemscalebar.h:211
QgsApplication::scaleBarRendererRegistry
static QgsScaleBarRendererRegistry * scaleBarRendererRegistry()
Gets the registry of available scalebar renderers.
Definition: qgsapplication.cpp:2293
QgsLayoutItemScaleBar::create
static QgsLayoutItemScaleBar * create(QgsLayout *layout)
Returns a new scale bar item for the specified layout.
Definition: qgslayoutitemscalebar.cpp:63
QgsScaleBarSettings::LabelVerticalPlacement
LabelVerticalPlacement
Label vertical placement.
Definition: qgsscalebarsettings.h:67