QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 "qgsmessagelog.h"
28 #include "qgsrectangle.h"
29 #include "qgsproject.h"
30 #include "qgssymbollayerutils.h"
31 #include "qgsfontutils.h"
32 #include "qgsunittypes.h"
33 #include "qgssettings.h"
34 #include "qgsstyleentityvisitor.h"
35 #include "qgsnumericformat.h"
37 #include "qgslinesymbollayer.h"
38 #include "qgsfillsymbollayer.h"
39 #include "qgslinesymbol.h"
40 #include "qgsfillsymbol.h"
41 
42 #include <QDomDocument>
43 #include <QDomElement>
44 #include <QFontMetricsF>
45 #include <QPainter>
46 
47 #include <cmath>
48 
50  : QgsLayoutItem( layout )
51 {
54 }
55 
57 {
59 }
60 
62 {
63  return QgsApplication::getThemeIcon( QStringLiteral( "/mLayoutItemScaleBar.svg" ) );
64 }
65 
67 {
68  return new QgsLayoutItemScaleBar( layout );
69 }
70 
72 {
74  return QgsLayoutSize( mStyle->calculateBoxSize( context, mSettings, createScaleContext() ), QgsUnitTypes::LayoutMillimeters );
75 }
76 
78 {
79  if ( !mStyle )
80  return;
81 
83  {
84  // compatibility code - ScalebarLineColor and ScalebarLineWidth are deprecated
85  const QgsExpressionContext expContext = createExpressionContext();
86  std::unique_ptr< QgsLineSymbol > sym( mSettings.lineSymbol()->clone() );
89  sym->setWidth( mDataDefinedProperties.valueAsDouble( QgsLayoutObject::ScalebarLineWidth, expContext, mSettings.lineWidth() ) );
91  sym->setColor( mDataDefinedProperties.valueAsColor( QgsLayoutObject::ScalebarLineColor, expContext, mSettings.lineColor() ) );
93  mSettings.setLineSymbol( sym.release() );
94  }
96  {
97  // compatibility code - ScalebarLineColor and ScalebarLineWidth are deprecated
98  const QgsExpressionContext expContext = createExpressionContext();
99  std::unique_ptr< QgsFillSymbol > sym( mSettings.fillSymbol()->clone() );
101  sym->setColor( mDataDefinedProperties.valueAsColor( QgsLayoutObject::ScalebarFillColor, expContext, mSettings.fillColor() ) );
103  mSettings.setFillSymbol( sym.release() );
104  }
106  {
107  // compatibility code - ScalebarLineColor and ScalebarLineWidth are deprecated
108  const QgsExpressionContext expContext = createExpressionContext();
109  std::unique_ptr< QgsFillSymbol > sym( mSettings.alternateFillSymbol()->clone() );
111  sym->setColor( mDataDefinedProperties.valueAsColor( QgsLayoutObject::ScalebarFillColor2, expContext, mSettings.fillColor2() ) );
113  mSettings.setAlternateFillSymbol( sym.release() );
114  }
115 
116  mStyle->draw( context.renderContext(), mSettings, createScaleContext() );
117 }
118 
120 {
121  if ( !mStyle )
122  {
123  mSettings.setNumberOfSegments( nSegments );
124  return;
125  }
126  mSettings.setNumberOfSegments( nSegments );
128 }
129 
131 {
132  if ( !mStyle )
133  {
134  mSettings.setUnitsPerSegment( units );
135  return;
136  }
137  mSettings.setUnitsPerSegment( units );
138  refreshSegmentMillimeters();
140 }
141 
142 
144 {
145  if ( !mStyle )
146  {
147  mSettings.setSegmentSizeMode( mode );
148  return;
149  }
150  mSettings.setSegmentSizeMode( mode );
151  refreshSegmentMillimeters();
153 }
154 
156 {
157  if ( !mStyle )
158  {
159  mSettings.setMinimumBarWidth( minWidth );
160  return;
161  }
162  mSettings.setMinimumBarWidth( minWidth );
163  refreshSegmentMillimeters();
165 }
166 
168 {
169  if ( !mStyle )
170  {
171  mSettings.setMaximumBarWidth( maxWidth );
172  return;
173  }
174  mSettings.setMaximumBarWidth( maxWidth );
175  refreshSegmentMillimeters();
177 }
178 
180 {
181  return mSettings.textFormat();
182 }
183 
185 {
186  mSettings.setTextFormat( format );
187  refreshItemSize();
188  emit changed();
189 }
190 
192 {
193  return mSettings.lineSymbol();
194 }
195 
197 {
198  mSettings.setLineSymbol( symbol );
199 }
200 
202 {
203  return mSettings.divisionLineSymbol();
204 }
205 
207 {
208  mSettings.setDivisionLineSymbol( symbol );
209 }
210 
212 {
213  return mSettings.subdivisionLineSymbol();
214 }
215 
217 {
218  mSettings.setSubdivisionLineSymbol( symbol );
219 }
220 
222 {
223  return mSettings.fillSymbol();
224 }
225 
227 {
228  mSettings.setFillSymbol( symbol );
229 }
230 
232 {
233  return mSettings.alternateFillSymbol();
234 }
235 
237 {
238  mSettings.setAlternateFillSymbol( symbol );
239 }
240 
242 {
243  if ( !mStyle )
244  {
245  mSettings.setNumberOfSegmentsLeft( nSegmentsLeft );
246  return;
247  }
248  mSettings.setNumberOfSegmentsLeft( nSegmentsLeft );
250 }
251 
253 {
254  if ( !mStyle )
255  {
256  mSettings.setBoxContentSpace( space );
257  return;
258  }
259  mSettings.setBoxContentSpace( space );
260  refreshItemSize();
261 }
262 
264 {
265  disconnectCurrentMap();
266 
267  mMap = map;
268 
269  if ( !map )
270  {
271  return;
272  }
273 
274  connect( mMap, &QgsLayoutItemMap::extentChanged, this, &QgsLayoutItemScaleBar::updateScale );
275  connect( mMap, &QObject::destroyed, this, &QgsLayoutItemScaleBar::disconnectCurrentMap );
276 
277  refreshSegmentMillimeters();
278  emit changed();
279 }
280 
281 void QgsLayoutItemScaleBar::disconnectCurrentMap()
282 {
283  if ( !mMap )
284  {
285  return;
286  }
287 
288  disconnect( mMap, &QgsLayoutItemMap::extentChanged, this, &QgsLayoutItemScaleBar::updateScale );
289  disconnect( mMap, &QObject::destroyed, this, &QgsLayoutItemScaleBar::disconnectCurrentMap );
290  mMap = nullptr;
291 }
292 
293 void QgsLayoutItemScaleBar::refreshUnitsPerSegment( const QgsExpressionContext *context )
294 {
296  {
297  double unitsPerSegment = mSettings.unitsPerSegment();
298  bool ok = false;
300 
301  if ( !ok )
302  {
303  QgsMessageLog::logMessage( tr( "Scalebar units per segment expression eval error" ) );
304  }
305  else
306  {
308  }
309  }
310 }
311 
312 void QgsLayoutItemScaleBar::refreshMinimumBarWidth( const QgsExpressionContext *context )
313 {
315  {
316  double minimumBarWidth = mSettings.minimumBarWidth();
317 
318  bool ok = false;
320 
321  if ( !ok )
322  {
323  QgsMessageLog::logMessage( tr( "Scalebar minimum segment width expression eval error" ) );
324  }
325  else
326  {
328  }
329  }
330 }
331 
332 void QgsLayoutItemScaleBar::refreshMaximumBarWidth( const QgsExpressionContext *context )
333 {
335  {
336  double maximumBarWidth = mSettings.maximumBarWidth();
337 
338  bool ok = false;
340 
341  if ( !ok )
342  {
343  QgsMessageLog::logMessage( tr( "Scalebar maximum segment width expression eval error" ) );
344  }
345  else
346  {
348  }
349  }
350 }
351 
352 void QgsLayoutItemScaleBar::refreshNumberOfSegmentsLeft( const QgsExpressionContext *context )
353 {
355  {
356  int leftSegments = mSettings.numberOfSegmentsLeft();
357 
358  bool ok = false;
359  leftSegments = mDataDefinedProperties.valueAsInt( QgsLayoutObject::ScalebarLeftSegments, *context, leftSegments, &ok );
360 
361  if ( !ok )
362  {
363  QgsMessageLog::logMessage( tr( "Scalebar left segment count expression eval error" ) );
364  }
365  else
366  {
367  setNumberOfSegmentsLeft( leftSegments );
368  }
369  }
370 }
371 
372 void QgsLayoutItemScaleBar::refreshNumberOfSegmentsRight( const QgsExpressionContext *context )
373 {
375  {
376  int rightSegments = mSettings.numberOfSegments();
377 
378  bool ok = false;
379  rightSegments = mDataDefinedProperties.valueAsInt( QgsLayoutObject::ScalebarRightSegments, *context, rightSegments, &ok );
380 
381  if ( !ok )
382  {
383  QgsMessageLog::logMessage( tr( "Scalebar left segment count expression eval error" ) );
384  }
385  else
386  {
387  setNumberOfSegments( rightSegments );
388  }
389  }
390 }
391 
393 {
395 
396  bool forceUpdate = false;
397 
398  if ( ( property == QgsLayoutObject::ScalebarHeight || property == QgsLayoutObject::AllProperties )
400  {
401  double height = mSettings.height();
402 
403  bool ok = false;
405 
406  if ( !ok )
407  {
408  QgsMessageLog::logMessage( tr( "Scalebar height expression eval error" ) );
409  }
410  else
411  {
412  setHeight( height );
413  }
414 
415  forceUpdate = true;
416  }
417 
420  {
421  double height = mSettings.subdivisionsHeight();
422 
423  bool ok = false;
425 
426  if ( !ok )
427  {
428  QgsMessageLog::logMessage( tr( "Scalebar subdivision height expression eval error" ) );
429  }
430  else
431  {
433  }
434 
435  forceUpdate = true;
436  }
437 
439  {
440  refreshNumberOfSegmentsLeft( &context );
441  forceUpdate = true;
442  }
443 
445  {
446  refreshNumberOfSegmentsRight( &context );
447  forceUpdate = true;
448  }
449 
452  {
453  int segments = mSettings.numberOfSubdivisions();
454 
455  bool ok = false;
457 
458  if ( !ok )
459  {
460  QgsMessageLog::logMessage( tr( "Scalebar number of subdivisions expression eval error" ) );
461  }
462  else
463  {
464  setNumberOfSubdivisions( segments );
465  }
466 
467  forceUpdate = true;
468  }
469 
470 
472  {
473  refreshUnitsPerSegment( &context );
474  forceUpdate = true;
475  }
476 
478  {
479  refreshMinimumBarWidth( &context );
480  forceUpdate = true;
481  }
482 
484  {
485  refreshMaximumBarWidth( &context );
486  forceUpdate = true;
487  }
488 
489  // updates data defined properties and redraws item to match
490  // -- Deprecated --
492  {
493  forceUpdate = true;
494  }
496  {
497  forceUpdate = true;
498  }
500  {
501  forceUpdate = true;
502  }
504  {
505  forceUpdate = true;
506  }
507 
508  if ( forceUpdate )
509  {
510  refreshItemSize();
511  update();
512  }
513 
515 }
516 
517 void QgsLayoutItemScaleBar::refreshSegmentMillimeters()
518 {
519  if ( mMap )
520  {
521  //get mm dimension of composer map
522  const QRectF composerItemRect = mMap->rect();
523 
524  switch ( mSettings.segmentSizeMode() )
525  {
527  {
528  //calculate size depending on mNumUnitsPerSegment
529  mSegmentMillimeters = composerItemRect.width() / mapWidth() * mSettings.unitsPerSegment();
530  break;
531  }
532 
534  {
535  if ( mSettings.maximumBarWidth() < mSettings.minimumBarWidth() )
536  {
537  mSegmentMillimeters = 0;
538  }
539  else
540  {
541  const double nSegments = ( mSettings.numberOfSegmentsLeft() != 0 ) + mSettings.numberOfSegments();
542  // unitsPerSegments which fit minBarWidth resp. maxBarWidth
543  const double minUnitsPerSeg = ( mSettings.minimumBarWidth() * mapWidth() ) / ( nSegments * composerItemRect.width() );
544  const double maxUnitsPerSeg = ( mSettings.maximumBarWidth() * mapWidth() ) / ( nSegments * composerItemRect.width() );
545  mSettings.setUnitsPerSegment( QgsLayoutUtils::calculatePrettySize( minUnitsPerSeg, maxUnitsPerSeg ) );
546  mSegmentMillimeters = composerItemRect.width() / mapWidth() * mSettings.unitsPerSegment();
547  }
548  break;
549  }
550  }
551  }
552 }
553 
554 double QgsLayoutItemScaleBar::mapWidth() const
555 {
556  if ( !mMap )
557  {
558  return 0.0;
559  }
560 
561  const QgsRectangle mapExtent = mMap->extent();
562  if ( mSettings.units() == QgsUnitTypes::DistanceUnknownUnit )
563  {
564  return mapExtent.width();
565  }
566  else
567  {
568  QgsDistanceArea da;
569  da.setSourceCrs( mMap->crs(), mLayout->project()->transformContext() );
570  da.setEllipsoid( mLayout->project()->ellipsoid() );
571 
573  double measure = da.measureLine( QgsPointXY( mapExtent.xMinimum(), mapExtent.yMinimum() ),
574  QgsPointXY( mapExtent.xMaximum(), mapExtent.yMinimum() ) );
575  measure /= QgsUnitTypes::fromUnitToUnitFactor( mSettings.units(), units );
576  return measure;
577  }
578 }
579 
580 QgsScaleBarRenderer::ScaleBarContext QgsLayoutItemScaleBar::createScaleContext() const
581 {
583  scaleContext.size = rect().size();
584  scaleContext.segmentWidth = mSegmentMillimeters;
585  scaleContext.scale = mMap ? mMap->scale() : 1.0;
586  scaleContext.flags = mStyle->flags();
587  return scaleContext;
588 }
589 
591 {
592  mSettings.setLabelVerticalPlacement( placement );
593  refreshItemSize();
594  emit changed();
595 }
596 
598 {
599  mSettings.setLabelHorizontalPlacement( placement );
600  refreshItemSize();
601  emit changed();
602 }
603 
605 {
606  mSettings.setAlignment( a );
607  refreshItemSize();
608  emit changed();
609 }
610 
612 {
613  mSettings.setUnits( u );
614  refreshSegmentMillimeters();
615  refreshItemSize();
616  emit changed();
617 }
618 
619 Qt::PenJoinStyle QgsLayoutItemScaleBar::lineJoinStyle() const
620 {
622  return mSettings.lineJoinStyle();
624 }
625 
626 void QgsLayoutItemScaleBar::setLineJoinStyle( Qt::PenJoinStyle style )
627 {
629  if ( mSettings.lineJoinStyle() == style )
630  {
631  //no change
632  return;
633  }
634  mSettings.setLineJoinStyle( style );
636  update();
637  emit changed();
638 }
639 
640 Qt::PenCapStyle QgsLayoutItemScaleBar::lineCapStyle() const
641 {
643  return mSettings.lineCapStyle();
645 }
646 
647 void QgsLayoutItemScaleBar::setLineCapStyle( Qt::PenCapStyle style )
648 {
650  if ( mSettings.lineCapStyle() == style )
651  {
652  //no change
653  return;
654  }
655  mSettings.setLineCapStyle( style );
657  update();
658  emit changed();
659 }
660 
662 {
663  //style
664  mStyle = std::make_unique< QgsSingleBoxScaleBarRenderer >();
665 
666  //default to no background
667  setBackgroundEnabled( false );
668 
669  //get default composer font from settings
670  const QgsSettings settings;
671  const QString defaultFontString = settings.value( QStringLiteral( "LayoutDesigner/defaultFont" ), QVariant(), QgsSettings::Gui ).toString();
672  QgsTextFormat format;
673  QFont f;
674  if ( !defaultFontString.isEmpty() )
675  {
676  f.setFamily( defaultFontString );
677  }
678  format.setFont( f );
679  format.setSize( 12.0 );
681 
682  mSettings.setTextFormat( format );
683 
685  refreshItemSize();
686 
687  emit changed();
688 }
689 
691 {
692  return renderer->applyDefaultSettings( mSettings );
693 }
694 
696 {
697  if ( !mMap )
699 
700  const QgsCoordinateReferenceSystem crs = mMap->crs();
701  // start with crs units
704  {
705  // geographic CRS, use metric units
707  }
708 
709  // try to pick reasonable choice between metric / imperial units
710  const double widthInSelectedUnits = mapWidth();
711  const double initialUnitsPerSegment = widthInSelectedUnits / 10.0; //default scalebar width equals half the map width
712  switch ( unit )
713  {
715  {
716  if ( initialUnitsPerSegment > 1000.0 )
717  {
719  }
720  break;
721  }
723  {
724  if ( initialUnitsPerSegment > 5419.95 )
725  {
727  }
728  break;
729  }
730  default:
731  break;
732  }
733 
734  return unit;
735 }
736 
738 {
739  mSettings.setUnits( units );
740  if ( mMap )
741  {
742  double upperMagnitudeMultiplier = 1.0;
743  const double widthInSelectedUnits = mapWidth();
744  const double initialUnitsPerSegment = widthInSelectedUnits / 10.0; //default scalebar width equals half the map width
745  mSettings.setUnitsPerSegment( initialUnitsPerSegment );
746 
748  upperMagnitudeMultiplier = 1;
749 
750  const double segmentWidth = initialUnitsPerSegment / upperMagnitudeMultiplier;
751  const int segmentMagnitude = std::floor( std::log10( segmentWidth ) );
752  double unitsPerSegment = upperMagnitudeMultiplier * ( std::pow( 10.0, segmentMagnitude ) );
753  const double multiplier = std::floor( ( widthInSelectedUnits / ( unitsPerSegment * 10.0 ) ) / 2.5 ) * 2.5;
754 
755  if ( multiplier > 0 )
756  {
757  unitsPerSegment = unitsPerSegment * multiplier;
758  }
759  mSettings.setUnitsPerSegment( unitsPerSegment );
760  mSettings.setMapUnitsPerScaleBarUnit( upperMagnitudeMultiplier );
761 
762  mSettings.setNumberOfSegments( 2 );
763  mSettings.setNumberOfSegmentsLeft( 0 );
764  }
765 
766  refreshSegmentMillimeters();
768  emit changed();
769 }
770 
772 {
773  if ( !mStyle )
774  return;
775 
777  const double widthMM = mStyle->calculateBoxSize( context, mSettings, createScaleContext() ).width();
778  QgsLayoutSize currentSize = sizeWithUnits();
779  currentSize.setWidth( mLayout->renderContext().measurementConverter().convert( QgsLayoutMeasurement( widthMM, QgsUnitTypes::LayoutMillimeters ), currentSize.units() ).length() );
780  attemptResize( currentSize );
781  update();
782  emit changed();
783 }
784 
786 {
787  //Don't adjust box size for numeric scale bars:
788  if ( mStyle && mStyle->id() != QLatin1String( "Numeric" ) )
789  {
790  refreshItemSize();
791  }
792  QgsLayoutItem::update();
793 }
794 
795 void QgsLayoutItemScaleBar::updateScale()
796 {
797  refreshSegmentMillimeters();
798  //Don't adjust box size for numeric scale bars:
799  if ( mStyle && mStyle->id() != QLatin1String( "Numeric" ) )
800  {
802  }
803  update();
804 }
805 
806 void QgsLayoutItemScaleBar::setStyle( const QString &styleName )
807 {
808  //switch depending on style name
809  std::unique_ptr< QgsScaleBarRenderer> renderer( QgsApplication::scaleBarRendererRegistry()->renderer( styleName ) );
810  if ( renderer )
811  {
812  mStyle = std::move( renderer );
813  }
814  refreshItemSize();
815  emit changed();
816 }
817 
819 {
820  if ( mStyle )
821  {
822  return mStyle->id();
823  }
824  else
825  {
826  return QString();
827  }
828 }
829 
831 {
832  return mSettings.numericFormat();
833 }
834 
836 {
837  mSettings.setNumericFormat( format );
838 }
839 
841 {
842  return mSettings.textFormat().font();
843 }
844 
845 void QgsLayoutItemScaleBar::setFont( const QFont &font )
846 {
848  mSettings.setFont( font );
850  refreshItemSize();
851  emit changed();
852 }
853 
855 {
856  QColor color = mSettings.textFormat().color();
857  color.setAlphaF( mSettings.textFormat().opacity() );
858  return color;
859 }
860 
861 void QgsLayoutItemScaleBar::setFontColor( const QColor &color )
862 {
863  mSettings.textFormat().setColor( color );
864  mSettings.textFormat().setOpacity( color.alphaF() );
865 }
866 
868 {
870  return mSettings.fillColor();
872 }
873 
874 void QgsLayoutItemScaleBar::setFillColor( const QColor &color )
875 {
877  mSettings.setFillColor( color );
879 }
880 
882 {
884  return mSettings.fillColor2();
886 }
887 
888 void QgsLayoutItemScaleBar::setFillColor2( const QColor &color )
889 {
891  mSettings.setFillColor2( color );
893 }
894 
896 {
898  return mSettings.lineColor();
900 }
901 
902 void QgsLayoutItemScaleBar::setLineColor( const QColor &color )
903 {
905  mSettings.setLineColor( color );
907 }
908 
910 {
912  return mSettings.lineWidth();
914 }
915 
917 {
919  mSettings.setLineWidth( width );
921 }
922 
924 {
926  return mSettings.pen();
928 }
929 
931 {
933  return mSettings.brush();
935 }
936 
938 {
940  return mSettings.brush2();
942 }
943 
944 bool QgsLayoutItemScaleBar::writePropertiesToElement( QDomElement &composerScaleBarElem, QDomDocument &doc, const QgsReadWriteContext &rwContext ) const
945 {
946  composerScaleBarElem.setAttribute( QStringLiteral( "height" ), QString::number( mSettings.height() ) );
947  composerScaleBarElem.setAttribute( QStringLiteral( "labelBarSpace" ), QString::number( mSettings.labelBarSpace() ) );
948  composerScaleBarElem.setAttribute( QStringLiteral( "boxContentSpace" ), QString::number( mSettings.boxContentSpace() ) );
949  composerScaleBarElem.setAttribute( QStringLiteral( "numSegments" ), mSettings.numberOfSegments() );
950  composerScaleBarElem.setAttribute( QStringLiteral( "numSegmentsLeft" ), mSettings.numberOfSegmentsLeft() );
951  composerScaleBarElem.setAttribute( QStringLiteral( "numSubdivisions" ), mSettings.numberOfSubdivisions() );
952  composerScaleBarElem.setAttribute( QStringLiteral( "subdivisionsHeight" ), mSettings.subdivisionsHeight() );
953  composerScaleBarElem.setAttribute( QStringLiteral( "numUnitsPerSegment" ), QString::number( mSettings.unitsPerSegment() ) );
954  composerScaleBarElem.setAttribute( QStringLiteral( "segmentSizeMode" ), mSettings.segmentSizeMode() );
955  composerScaleBarElem.setAttribute( QStringLiteral( "minBarWidth" ), mSettings.minimumBarWidth() );
956  composerScaleBarElem.setAttribute( QStringLiteral( "maxBarWidth" ), mSettings.maximumBarWidth() );
957  composerScaleBarElem.setAttribute( QStringLiteral( "segmentMillimeters" ), QString::number( mSegmentMillimeters ) );
958  composerScaleBarElem.setAttribute( QStringLiteral( "numMapUnitsPerScaleBarUnit" ), QString::number( mSettings.mapUnitsPerScaleBarUnit() ) );
959 
960  const QDomElement textElem = mSettings.textFormat().writeXml( doc, rwContext );
961  composerScaleBarElem.appendChild( textElem );
962 
964  // kept just for allowing projects to open in QGIS < 3.14, remove for 4.0
965  composerScaleBarElem.setAttribute( QStringLiteral( "outlineWidth" ), QString::number( mSettings.lineWidth() ) );
966  composerScaleBarElem.setAttribute( QStringLiteral( "lineJoinStyle" ), QgsSymbolLayerUtils::encodePenJoinStyle( mSettings.lineJoinStyle() ) );
967  composerScaleBarElem.setAttribute( QStringLiteral( "lineCapStyle" ), QgsSymbolLayerUtils::encodePenCapStyle( mSettings.lineCapStyle() ) );
968  //pen color
969  QDomElement strokeColorElem = doc.createElement( QStringLiteral( "strokeColor" ) );
970  strokeColorElem.setAttribute( QStringLiteral( "red" ), QString::number( mSettings.lineColor().red() ) );
971  strokeColorElem.setAttribute( QStringLiteral( "green" ), QString::number( mSettings.lineColor().green() ) );
972  strokeColorElem.setAttribute( QStringLiteral( "blue" ), QString::number( mSettings.lineColor().blue() ) );
973  strokeColorElem.setAttribute( QStringLiteral( "alpha" ), QString::number( mSettings.lineColor().alpha() ) );
974  composerScaleBarElem.appendChild( strokeColorElem );
976 
977  composerScaleBarElem.setAttribute( QStringLiteral( "unitLabel" ), mSettings.unitLabel() );
978  composerScaleBarElem.setAttribute( QStringLiteral( "unitType" ), QgsUnitTypes::encodeUnit( mSettings.units() ) );
979 
980  QDomElement numericFormatElem = doc.createElement( QStringLiteral( "numericFormat" ) );
981  mSettings.numericFormat()->writeXml( numericFormatElem, doc, rwContext );
982  composerScaleBarElem.appendChild( numericFormatElem );
983 
984  //style
985  if ( mStyle )
986  {
987  composerScaleBarElem.setAttribute( QStringLiteral( "style" ), mStyle->id() );
988  }
989 
990  //map id
991  if ( mMap )
992  {
993  composerScaleBarElem.setAttribute( QStringLiteral( "mapUuid" ), mMap->uuid() );
994  }
995 
996  //colors
997 
999  // kept just for allowing projects to open in QGIS < 3.14, remove for 4.0
1000 
1001  //fill color
1002  QDomElement fillColorElem = doc.createElement( QStringLiteral( "fillColor" ) );
1003  fillColorElem.setAttribute( QStringLiteral( "red" ), QString::number( mSettings.fillColor().red() ) );
1004  fillColorElem.setAttribute( QStringLiteral( "green" ), QString::number( mSettings.fillColor().green() ) );
1005  fillColorElem.setAttribute( QStringLiteral( "blue" ), QString::number( mSettings.fillColor().blue() ) );
1006  fillColorElem.setAttribute( QStringLiteral( "alpha" ), QString::number( mSettings.fillColor().alpha() ) );
1007  composerScaleBarElem.appendChild( fillColorElem );
1008 
1009  //fill color 2
1010  QDomElement fillColor2Elem = doc.createElement( QStringLiteral( "fillColor2" ) );
1011  fillColor2Elem.setAttribute( QStringLiteral( "red" ), QString::number( mSettings.fillColor2().red() ) );
1012  fillColor2Elem.setAttribute( QStringLiteral( "green" ), QString::number( mSettings.fillColor2().green() ) );
1013  fillColor2Elem.setAttribute( QStringLiteral( "blue" ), QString::number( mSettings.fillColor2().blue() ) );
1014  fillColor2Elem.setAttribute( QStringLiteral( "alpha" ), QString::number( mSettings.fillColor2().alpha() ) );
1015  composerScaleBarElem.appendChild( fillColor2Elem );
1016 
1018 
1019  //label vertical/horizontal placement
1020  composerScaleBarElem.setAttribute( QStringLiteral( "labelVerticalPlacement" ), QString::number( static_cast< int >( mSettings.labelVerticalPlacement() ) ) );
1021  composerScaleBarElem.setAttribute( QStringLiteral( "labelHorizontalPlacement" ), QString::number( static_cast< int >( mSettings.labelHorizontalPlacement() ) ) );
1022 
1023  //alignment
1024  composerScaleBarElem.setAttribute( QStringLiteral( "alignment" ), QString::number( static_cast< int >( mSettings.alignment() ) ) );
1025 
1026  QDomElement lineSymbol = doc.createElement( QStringLiteral( "lineSymbol" ) );
1027  const QDomElement symbolElem = QgsSymbolLayerUtils::saveSymbol( QString(),
1028  mSettings.lineSymbol(),
1029  doc,
1030  rwContext );
1031  lineSymbol.appendChild( symbolElem );
1032  composerScaleBarElem.appendChild( lineSymbol );
1033 
1034  QDomElement divisionSymbol = doc.createElement( QStringLiteral( "divisionLineSymbol" ) );
1035  const QDomElement divisionSymbolElem = QgsSymbolLayerUtils::saveSymbol( QString(),
1036  mSettings.divisionLineSymbol(),
1037  doc,
1038  rwContext );
1039  divisionSymbol.appendChild( divisionSymbolElem );
1040  composerScaleBarElem.appendChild( divisionSymbol );
1041 
1042  QDomElement subdivisionSymbol = doc.createElement( QStringLiteral( "subdivisionLineSymbol" ) );
1043  const QDomElement subdivisionSymbolElem = QgsSymbolLayerUtils::saveSymbol( QString(),
1044  mSettings.subdivisionLineSymbol(),
1045  doc,
1046  rwContext );
1047  subdivisionSymbol.appendChild( subdivisionSymbolElem );
1048  composerScaleBarElem.appendChild( subdivisionSymbol );
1049 
1050  QDomElement fillSymbol1Elem = doc.createElement( QStringLiteral( "fillSymbol1" ) );
1051  const QDomElement symbol1Elem = QgsSymbolLayerUtils::saveSymbol( QString(),
1052  mSettings.fillSymbol(),
1053  doc,
1054  rwContext );
1055  fillSymbol1Elem.appendChild( symbol1Elem );
1056  composerScaleBarElem.appendChild( fillSymbol1Elem );
1057 
1058  QDomElement fillSymbol2Elem = doc.createElement( QStringLiteral( "fillSymbol2" ) );
1059  const QDomElement symbol2Elem = QgsSymbolLayerUtils::saveSymbol( QString(),
1060  mSettings.alternateFillSymbol(),
1061  doc,
1062  rwContext );
1063  fillSymbol2Elem.appendChild( symbol2Elem );
1064  composerScaleBarElem.appendChild( fillSymbol2Elem );
1065 
1066  return true;
1067 }
1068 
1069 
1070 bool QgsLayoutItemScaleBar::readPropertiesFromElement( const QDomElement &itemElem, const QDomDocument &, const QgsReadWriteContext &context )
1071 {
1072  mSettings.setHeight( itemElem.attribute( QStringLiteral( "height" ), QStringLiteral( "5.0" ) ).toDouble() );
1073  mSettings.setLabelBarSpace( itemElem.attribute( QStringLiteral( "labelBarSpace" ), QStringLiteral( "3.0" ) ).toDouble() );
1074  mSettings.setBoxContentSpace( itemElem.attribute( QStringLiteral( "boxContentSpace" ), QStringLiteral( "1.0" ) ).toDouble() );
1075  mSettings.setNumberOfSegments( itemElem.attribute( QStringLiteral( "numSegments" ), QStringLiteral( "2" ) ).toInt() );
1076  mSettings.setNumberOfSegmentsLeft( itemElem.attribute( QStringLiteral( "numSegmentsLeft" ), QStringLiteral( "0" ) ).toInt() );
1077  mSettings.setNumberOfSubdivisions( itemElem.attribute( QStringLiteral( "numSubdivisions" ), QStringLiteral( "1" ) ).toInt() );
1078  mSettings.setSubdivisionsHeight( itemElem.attribute( QStringLiteral( "subdivisionsHeight" ), QStringLiteral( "1.5" ) ).toDouble() );
1079  mSettings.setUnitsPerSegment( itemElem.attribute( QStringLiteral( "numUnitsPerSegment" ), QStringLiteral( "1.0" ) ).toDouble() );
1080  mSettings.setSegmentSizeMode( static_cast<QgsScaleBarSettings::SegmentSizeMode>( itemElem.attribute( QStringLiteral( "segmentSizeMode" ), QStringLiteral( "0" ) ).toInt() ) );
1081  mSettings.setMinimumBarWidth( itemElem.attribute( QStringLiteral( "minBarWidth" ), QStringLiteral( "50" ) ).toDouble() );
1082  mSettings.setMaximumBarWidth( itemElem.attribute( QStringLiteral( "maxBarWidth" ), QStringLiteral( "150" ) ).toDouble() );
1083  mSegmentMillimeters = itemElem.attribute( QStringLiteral( "segmentMillimeters" ), QStringLiteral( "0.0" ) ).toDouble();
1084  mSettings.setMapUnitsPerScaleBarUnit( itemElem.attribute( QStringLiteral( "numMapUnitsPerScaleBarUnit" ), QStringLiteral( "1.0" ) ).toDouble() );
1085 
1086  const QDomElement lineSymbolElem = itemElem.firstChildElement( QStringLiteral( "lineSymbol" ) );
1087  bool foundLineSymbol = false;
1088  if ( !lineSymbolElem.isNull() )
1089  {
1090  const QDomElement symbolElem = lineSymbolElem.firstChildElement( QStringLiteral( "symbol" ) );
1091  std::unique_ptr< QgsLineSymbol > lineSymbol( QgsSymbolLayerUtils::loadSymbol<QgsLineSymbol>( symbolElem, context ) );
1092  if ( lineSymbol )
1093  {
1094  mSettings.setLineSymbol( lineSymbol.release() );
1095  foundLineSymbol = true;
1096  }
1097  }
1098  const QDomElement divisionSymbolElem = itemElem.firstChildElement( QStringLiteral( "divisionLineSymbol" ) );
1099  if ( !divisionSymbolElem.isNull() )
1100  {
1101  const QDomElement symbolElem = divisionSymbolElem.firstChildElement( QStringLiteral( "symbol" ) );
1102  std::unique_ptr< QgsLineSymbol > lineSymbol( QgsSymbolLayerUtils::loadSymbol<QgsLineSymbol>( symbolElem, context ) );
1103  if ( lineSymbol )
1104  {
1105  mSettings.setDivisionLineSymbol( lineSymbol.release() );
1106  }
1107  }
1108  else if ( foundLineSymbol )
1109  {
1110  mSettings.setDivisionLineSymbol( mSettings.lineSymbol()->clone() );
1111  }
1112  const QDomElement subdivisionSymbolElem = itemElem.firstChildElement( QStringLiteral( "subdivisionLineSymbol" ) );
1113  if ( !subdivisionSymbolElem.isNull() )
1114  {
1115  const QDomElement symbolElem = subdivisionSymbolElem.firstChildElement( QStringLiteral( "symbol" ) );
1116  std::unique_ptr< QgsLineSymbol > lineSymbol( QgsSymbolLayerUtils::loadSymbol<QgsLineSymbol>( symbolElem, context ) );
1117  if ( lineSymbol )
1118  {
1119  mSettings.setSubdivisionLineSymbol( lineSymbol.release() );
1120  }
1121  }
1122  else if ( foundLineSymbol )
1123  {
1124  mSettings.setSubdivisionLineSymbol( mSettings.lineSymbol()->clone() );
1125  }
1126 
1127  if ( !foundLineSymbol )
1128  {
1129  // old project compatibility
1130  std::unique_ptr< QgsLineSymbol > lineSymbol = std::make_unique< QgsLineSymbol >();
1131  std::unique_ptr< QgsSimpleLineSymbolLayer > lineSymbolLayer = std::make_unique< QgsSimpleLineSymbolLayer >();
1132  lineSymbolLayer->setWidth( itemElem.attribute( QStringLiteral( "outlineWidth" ), QStringLiteral( "0.3" ) ).toDouble() );
1133  lineSymbolLayer->setWidthUnit( QgsUnitTypes::RenderMillimeters );
1134  lineSymbolLayer->setPenJoinStyle( QgsSymbolLayerUtils::decodePenJoinStyle( itemElem.attribute( QStringLiteral( "lineJoinStyle" ), QStringLiteral( "miter" ) ) ) );
1135  lineSymbolLayer->setPenCapStyle( QgsSymbolLayerUtils::decodePenCapStyle( itemElem.attribute( QStringLiteral( "lineCapStyle" ), QStringLiteral( "square" ) ) ) );
1136 
1137  //stroke color
1138  const QDomNodeList strokeColorList = itemElem.elementsByTagName( QStringLiteral( "strokeColor" ) );
1139  if ( !strokeColorList.isEmpty() )
1140  {
1141  const QDomElement strokeColorElem = strokeColorList.at( 0 ).toElement();
1142  bool redOk, greenOk, blueOk, alphaOk;
1143  int strokeRed, strokeGreen, strokeBlue, strokeAlpha;
1144 
1145  strokeRed = strokeColorElem.attribute( QStringLiteral( "red" ) ).toDouble( &redOk );
1146  strokeGreen = strokeColorElem.attribute( QStringLiteral( "green" ) ).toDouble( &greenOk );
1147  strokeBlue = strokeColorElem.attribute( QStringLiteral( "blue" ) ).toDouble( &blueOk );
1148  strokeAlpha = strokeColorElem.attribute( QStringLiteral( "alpha" ) ).toDouble( &alphaOk );
1149 
1150  if ( redOk && greenOk && blueOk && alphaOk )
1151  {
1152  lineSymbolLayer->setColor( QColor( strokeRed, strokeGreen, strokeBlue, strokeAlpha ) );
1153  }
1154  }
1155  else
1156  {
1157  lineSymbolLayer->setColor( QColor( itemElem.attribute( QStringLiteral( "penColor" ), QStringLiteral( "#000000" ) ) ) );
1158  }
1159 
1160  // need to translate the deprecated ScalebarLineWidth and ScalebarLineColor properties to symbol properties,
1161  // and then remove them from the scalebar so they don't interfere and apply to other compatibility workarounds
1162  lineSymbolLayer->setDataDefinedProperty( QgsSymbolLayer::PropertyStrokeWidth, dataDefinedProperties().property( QgsLayoutObject::ScalebarLineWidth ) );
1164  lineSymbolLayer->setDataDefinedProperty( QgsSymbolLayer::PropertyStrokeColor, dataDefinedProperties().property( QgsLayoutObject::ScalebarLineColor ) );
1166 
1167  lineSymbol->changeSymbolLayer( 0, lineSymbolLayer.release() );
1168  mSettings.setLineSymbol( lineSymbol->clone() );
1169  mSettings.setDivisionLineSymbol( lineSymbol->clone() );
1170  mSettings.setSubdivisionLineSymbol( lineSymbol.release() );
1171  }
1172 
1173  mSettings.setUnitLabel( itemElem.attribute( QStringLiteral( "unitLabel" ) ) );
1174 
1175  const QDomNodeList textFormatNodeList = itemElem.elementsByTagName( QStringLiteral( "text-style" ) );
1176  if ( !textFormatNodeList.isEmpty() )
1177  {
1178  const QDomElement textFormatElem = textFormatNodeList.at( 0 ).toElement();
1179  mSettings.textFormat().readXml( textFormatElem, context );
1180  }
1181  else
1182  {
1183  QFont f;
1184  if ( !QgsFontUtils::setFromXmlChildNode( f, itemElem, QStringLiteral( "scaleBarFont" ) ) )
1185  {
1186  f.fromString( itemElem.attribute( QStringLiteral( "font" ), QString() ) );
1187  }
1188  mSettings.textFormat().setFont( f );
1189  if ( f.pointSizeF() > 0 )
1190  {
1191  mSettings.textFormat().setSize( f.pointSizeF() );
1193  }
1194  else if ( f.pixelSize() > 0 )
1195  {
1196  mSettings.textFormat().setSize( f.pixelSize() );
1198  }
1199  }
1200 
1201  const QDomNodeList numericFormatNodeList = itemElem.elementsByTagName( QStringLiteral( "numericFormat" ) );
1202  if ( !numericFormatNodeList.isEmpty() )
1203  {
1204  const QDomElement numericFormatElem = numericFormatNodeList.at( 0 ).toElement();
1205  mSettings.setNumericFormat( QgsApplication::numericFormatRegistry()->createFromXml( numericFormatElem, context ) );
1206  }
1207 
1208  const QDomElement fillSymbol1Elem = itemElem.firstChildElement( QStringLiteral( "fillSymbol1" ) );
1209  bool foundFillSymbol1 = false;
1210  if ( !fillSymbol1Elem.isNull() )
1211  {
1212  const QDomElement symbolElem = fillSymbol1Elem.firstChildElement( QStringLiteral( "symbol" ) );
1213  std::unique_ptr< QgsFillSymbol > fillSymbol( QgsSymbolLayerUtils::loadSymbol<QgsFillSymbol>( symbolElem, context ) );
1214  if ( fillSymbol )
1215  {
1216  mSettings.setFillSymbol( fillSymbol.release() );
1217  foundFillSymbol1 = true;
1218  }
1219  }
1220  if ( !foundFillSymbol1 )
1221  {
1222  // old project compatibility
1223  std::unique_ptr< QgsFillSymbol > fillSymbol = std::make_unique< QgsFillSymbol >();
1224  std::unique_ptr< QgsSimpleFillSymbolLayer > fillSymbolLayer = std::make_unique< QgsSimpleFillSymbolLayer >();
1225  fillSymbolLayer->setStrokeStyle( Qt::NoPen );
1226 
1227  //fill color
1228  const QDomNodeList fillColorList = itemElem.elementsByTagName( QStringLiteral( "fillColor" ) );
1229  if ( !fillColorList.isEmpty() )
1230  {
1231  const QDomElement fillColorElem = fillColorList.at( 0 ).toElement();
1232  bool redOk, greenOk, blueOk, alphaOk;
1233  int fillRed, fillGreen, fillBlue, fillAlpha;
1234 
1235  fillRed = fillColorElem.attribute( QStringLiteral( "red" ) ).toDouble( &redOk );
1236  fillGreen = fillColorElem.attribute( QStringLiteral( "green" ) ).toDouble( &greenOk );
1237  fillBlue = fillColorElem.attribute( QStringLiteral( "blue" ) ).toDouble( &blueOk );
1238  fillAlpha = fillColorElem.attribute( QStringLiteral( "alpha" ) ).toDouble( &alphaOk );
1239 
1240  if ( redOk && greenOk && blueOk && alphaOk )
1241  {
1242  fillSymbolLayer->setColor( QColor( fillRed, fillGreen, fillBlue, fillAlpha ) );
1243  }
1244  }
1245  else
1246  {
1247  fillSymbolLayer->setColor( QColor( itemElem.attribute( QStringLiteral( "brushColor" ), QStringLiteral( "#000000" ) ) ) );
1248  }
1249 
1250  // need to translate the deprecated ScalebarFillColor property to symbol properties,
1251  // and then remove them from the scalebar so they don't interfere and apply to other compatibility workarounds
1252  fillSymbolLayer->setDataDefinedProperty( QgsSymbolLayer::PropertyFillColor, dataDefinedProperties().property( QgsLayoutObject::ScalebarFillColor ) );
1254 
1255  fillSymbol->changeSymbolLayer( 0, fillSymbolLayer.release() );
1256  mSettings.setFillSymbol( fillSymbol.release() );
1257  }
1258 
1259  const QDomElement fillSymbol2Elem = itemElem.firstChildElement( QStringLiteral( "fillSymbol2" ) );
1260  bool foundFillSymbol2 = false;
1261  if ( !fillSymbol2Elem.isNull() )
1262  {
1263  const QDomElement symbolElem = fillSymbol2Elem.firstChildElement( QStringLiteral( "symbol" ) );
1264  std::unique_ptr< QgsFillSymbol > fillSymbol( QgsSymbolLayerUtils::loadSymbol<QgsFillSymbol>( symbolElem, context ) );
1265  if ( fillSymbol )
1266  {
1267  mSettings.setAlternateFillSymbol( fillSymbol.release() );
1268  foundFillSymbol2 = true;
1269  }
1270  }
1271  if ( !foundFillSymbol2 )
1272  {
1273  // old project compatibility
1274  std::unique_ptr< QgsFillSymbol > fillSymbol = std::make_unique< QgsFillSymbol >();
1275  std::unique_ptr< QgsSimpleFillSymbolLayer > fillSymbolLayer = std::make_unique< QgsSimpleFillSymbolLayer >();
1276  fillSymbolLayer->setStrokeStyle( Qt::NoPen );
1277 
1278  //fill color 2
1279 
1280  const QDomNodeList fillColor2List = itemElem.elementsByTagName( QStringLiteral( "fillColor2" ) );
1281  if ( !fillColor2List.isEmpty() )
1282  {
1283  const QDomElement fillColor2Elem = fillColor2List.at( 0 ).toElement();
1284  bool redOk, greenOk, blueOk, alphaOk;
1285  int fillRed, fillGreen, fillBlue, fillAlpha;
1286 
1287  fillRed = fillColor2Elem.attribute( QStringLiteral( "red" ) ).toDouble( &redOk );
1288  fillGreen = fillColor2Elem.attribute( QStringLiteral( "green" ) ).toDouble( &greenOk );
1289  fillBlue = fillColor2Elem.attribute( QStringLiteral( "blue" ) ).toDouble( &blueOk );
1290  fillAlpha = fillColor2Elem.attribute( QStringLiteral( "alpha" ) ).toDouble( &alphaOk );
1291 
1292  if ( redOk && greenOk && blueOk && alphaOk )
1293  {
1294  fillSymbolLayer->setColor( QColor( fillRed, fillGreen, fillBlue, fillAlpha ) );
1295  }
1296  }
1297  else
1298  {
1299  fillSymbolLayer->setColor( QColor( itemElem.attribute( QStringLiteral( "brush2Color" ), QStringLiteral( "#ffffff" ) ) ) );
1300  }
1301 
1302  // need to translate the deprecated ScalebarFillColor2 property to symbol properties,
1303  // and then remove them from the scalebar so they don't interfere and apply to other compatibility workarounds
1304  fillSymbolLayer->setDataDefinedProperty( QgsSymbolLayer::PropertyFillColor, dataDefinedProperties().property( QgsLayoutObject::ScalebarFillColor2 ) );
1306 
1307  fillSymbol->changeSymbolLayer( 0, fillSymbolLayer.release() );
1308  mSettings.setAlternateFillSymbol( fillSymbol.release() );
1309 
1310  }
1311 
1312  //font color
1313  const QDomNodeList textColorList = itemElem.elementsByTagName( QStringLiteral( "textColor" ) );
1314  if ( !textColorList.isEmpty() )
1315  {
1316  const QDomElement textColorElem = textColorList.at( 0 ).toElement();
1317  bool redOk, greenOk, blueOk, alphaOk;
1318  int textRed, textGreen, textBlue, textAlpha;
1319 
1320  textRed = textColorElem.attribute( QStringLiteral( "red" ) ).toDouble( &redOk );
1321  textGreen = textColorElem.attribute( QStringLiteral( "green" ) ).toDouble( &greenOk );
1322  textBlue = textColorElem.attribute( QStringLiteral( "blue" ) ).toDouble( &blueOk );
1323  textAlpha = textColorElem.attribute( QStringLiteral( "alpha" ) ).toDouble( &alphaOk );
1324 
1325  if ( redOk && greenOk && blueOk && alphaOk )
1326  {
1327  mSettings.textFormat().setColor( QColor( textRed, textGreen, textBlue, textAlpha ) );
1328  }
1329  }
1330  else if ( itemElem.hasAttribute( QStringLiteral( "fontColor" ) ) )
1331  {
1332  QColor c;
1333  c.setNamedColor( itemElem.attribute( QStringLiteral( "fontColor" ), QStringLiteral( "#000000" ) ) );
1334  mSettings.textFormat().setColor( c );
1335  }
1336 
1337  //style
1338  setStyle( itemElem.attribute( QStringLiteral( "style" ), QString() ) );
1339 
1340  //call attemptResize after setStyle to ensure the appropriate size limitations are applied
1341  attemptResize( QgsLayoutSize::decodeSize( itemElem.attribute( QStringLiteral( "size" ) ) ) );
1342 
1343  if ( itemElem.attribute( QStringLiteral( "unitType" ) ).isEmpty() )
1344  {
1346  switch ( itemElem.attribute( QStringLiteral( "units" ) ).toInt() )
1347  {
1348  case 0:
1350  break;
1351  case 1:
1353  break;
1354  case 2:
1356  break;
1357  case 3:
1359  break;
1360  }
1361  mSettings.setUnits( u );
1362  }
1363  else
1364  {
1365  mSettings.setUnits( QgsUnitTypes::decodeDistanceUnit( itemElem.attribute( QStringLiteral( "unitType" ) ) ) );
1366  }
1367 
1368  mSettings.setLabelVerticalPlacement( static_cast< QgsScaleBarSettings::LabelVerticalPlacement >( itemElem.attribute( QStringLiteral( "labelVerticalPlacement" ), QStringLiteral( "0" ) ).toInt() ) );
1369  mSettings.setLabelHorizontalPlacement( static_cast< QgsScaleBarSettings::LabelHorizontalPlacement >( itemElem.attribute( QStringLiteral( "labelHorizontalPlacement" ), QStringLiteral( "0" ) ).toInt() ) );
1370 
1371  mSettings.setAlignment( static_cast< QgsScaleBarSettings::Alignment >( itemElem.attribute( QStringLiteral( "alignment" ), QStringLiteral( "0" ) ).toInt() ) );
1372 
1373  //map
1374  disconnectCurrentMap();
1375  mMap = nullptr;
1376  mMapUuid = itemElem.attribute( QStringLiteral( "mapUuid" ) );
1377  return true;
1378 }
1379 
1380 
1382 {
1383  if ( mLayout && !mMapUuid.isEmpty() )
1384  {
1385  disconnectCurrentMap();
1386  mMap = qobject_cast< QgsLayoutItemMap * >( mLayout->itemByUuid( mMapUuid, true ) );
1387  if ( mMap )
1388  {
1389  connect( mMap, &QgsLayoutItemMap::extentChanged, this, &QgsLayoutItemScaleBar::updateScale );
1390  connect( mMap, &QObject::destroyed, this, &QgsLayoutItemScaleBar::disconnectCurrentMap );
1391  }
1392  }
1393 
1394  updateScale();
1395 }
1396 
1398 {
1399  QgsStyleTextFormatEntity entity( mSettings.textFormat() );
1400  if ( !visitor->visit( QgsStyleEntityVisitorInterface::StyleLeaf( &entity, uuid(), displayName() ) ) )
1401  return false;
1402 
1403  return true;
1404 }
1405 
1407 {
1409 }
QgsScaleBarSettings::SegmentSizeMode
SegmentSizeMode
Modes for setting size for scale bar segments.
Definition: qgsscalebarsettings.h:57
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:129
QgsLayoutObject::ScalebarFillColor2
@ ScalebarFillColor2
Scalebar secondary fill color (deprecated, use data defined properties on scalebar fill symbol 2 inst...
Definition: qgslayoutobject.h:205
QgsLayoutItemScaleBar::pen
Q_DECL_DEPRECATED QPen pen() const
Returns the pen used for drawing outlines in the scalebar.
Definition: qgslayoutitemscalebar.cpp:923
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition: qgsexpressioncontext.h:406
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:861
QgsLayoutObject::layout
const QgsLayout * layout() const
Returns the layout the object is attached to.
Definition: qgslayoutobject.cpp:216
QgsLayoutItemScaleBar::setFont
Q_DECL_DEPRECATED void setFont(const QFont &font)
Sets the font used for drawing text in the scalebar.
Definition: qgslayoutitemscalebar.cpp:845
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:193
QgsTextFormat::setFont
void setFont(const QFont &font)
Sets the font used for rendering text.
Definition: qgstextformat.cpp:207
QgsProperty
A store for object properties.
Definition: qgsproperty.h:230
QgsScaleBarRenderer::ScaleBarContext
Contains parameters regarding scalebar calculations.
Definition: qgsscalebarrenderer.h:70
QgsLayoutItem::refreshItemSize
void refreshItemSize()
Refreshes an item's size by rechecking it against any possible item fixed or minimum sizes.
Definition: qgslayoutitem.cpp:1269
QgsLayoutSize::units
QgsUnitTypes::LayoutUnit units() const
Returns the units for the size.
Definition: qgslayoutsize.h:103
QgsAbstractPropertyCollection::valueAsInt
int valueAsInt(int key, const QgsExpressionContext &context, int defaultValue=0, bool *ok=nullptr) const
Calculates the current value of the property with the specified key and interprets it as an integer.
Definition: qgspropertycollection.cpp:77
QgsLayoutItemScaleBar::setAlignment
void setAlignment(QgsScaleBarSettings::Alignment alignment)
Sets the scalebar alignment.
Definition: qgslayoutitemscalebar.cpp:604
QgsSettings::value
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
Definition: qgssettings.cpp:161
QgsLayoutItemScaleBar::QgsLayoutItemScaleBar
QgsLayoutItemScaleBar(QgsLayout *layout)
Constructor for QgsLayoutItemScaleBar, with the specified parent layout.
Definition: qgslayoutitemscalebar.cpp:49
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:34
qgsrectangle.h
QgsUnitTypes::DistanceUnknownUnit
@ DistanceUnknownUnit
Unknown distance unit.
Definition: qgsunittypes.h:78
QgsLayoutObject::ScalebarRightSegments
@ ScalebarRightSegments
Number of segments on the right of 0 (since QGIS 3.26)
Definition: qgslayoutobject.h:197
QgsLayoutItemScaleBar::setSegmentSizeMode
void setSegmentSizeMode(QgsScaleBarSettings::SegmentSizeMode mode)
Sets the size mode for scale bar segments.
Definition: qgslayoutitemscalebar.cpp:143
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:206
QgsLayoutItemMap::extentChanged
void extentChanged()
Emitted when the map's extent changes.
crs
const QgsCoordinateReferenceSystem & crs
Definition: qgswfsgetfeature.cpp:105
QgsLayoutItemScaleBar::update
void update()
Adjusts the scale bar box size and updates the item.
Definition: qgslayoutitemscalebar.cpp:785
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:226
QgsLayoutItemScaleBar::lineSymbol
QgsLineSymbol * lineSymbol() const
Returns the line symbol used to render the scalebar (only used for some scalebar types).
Definition: qgslayoutitemscalebar.cpp:191
QgsLineSymbol::clone
QgsLineSymbol * clone() const override
Returns a deep copy of this symbol.
Definition: qgslinesymbol.cpp:303
QgsSymbolLayer::PropertyFillColor
@ PropertyFillColor
Fill color.
Definition: qgssymbollayer.h:147
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:173
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:626
QgsLayoutItemScaleBar::setBoxContentSpace
void setBoxContentSpace(double space)
Sets the space (margin) between the scalebar box and content in millimeters.
Definition: qgslayoutitemscalebar.cpp:252
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:198
QgsSymbolLayerUtils::encodePenCapStyle
static QString encodePenCapStyle(Qt::PenCapStyle style)
Definition: qgssymbollayerutils.cpp:235
QgsScaleBarSettings::lineWidth
Q_DECL_DEPRECATED double lineWidth() const
Returns the line width in millimeters for lines in the scalebar.
Definition: qgsscalebarsettings.cpp:152
QgsLayoutItemScaleBar::setLinkedMap
void setLinkedMap(QgsLayoutItemMap *map)
Sets the map item linked to the scalebar.
Definition: qgslayoutitemscalebar.cpp:263
QgsLayoutItemRenderContext
Contains settings and helpers relating to a render of a QgsLayoutItem.
Definition: qgslayoutitem.h:44
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:1381
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:314
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:196
QgsLayoutObject::mDataDefinedProperties
QgsPropertyCollection mDataDefinedProperties
Definition: qgslayoutobject.h:365
QgsLayoutItemScaleBar::setLineWidth
Q_DECL_DEPRECATED void setLineWidth(double width)
Sets the line width in millimeters for lines in the scalebar.
Definition: qgslayoutitemscalebar.cpp:916
QgsRenderContext
Contains information about the context of a rendering operation.
Definition: qgsrendercontext.h:59
QgsScaleBarSettings::fillSymbol
QgsFillSymbol * fillSymbol() const
Returns the primary fill symbol used to render the scalebar (only used for some scalebar types).
Definition: qgsscalebarsettings.cpp:223
QgsStyleEntityVisitorInterface
An interface for classes which can visit style entity (e.g. symbol) nodes (using the visitor pattern)...
Definition: qgsstyleentityvisitor.h:33
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:201
QgsLayoutItemScaleBar::setLineColor
Q_DECL_DEPRECATED void setLineColor(const QColor &color)
Sets the color used for lines in the scalebar.
Definition: qgslayoutitemscalebar.cpp:902
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:1082
QgsUnitTypes::RenderMillimeters
@ RenderMillimeters
Millimeters.
Definition: qgsunittypes.h:169
qgsscalebarrenderer.h
QgsSettings
This class is a composition of two QSettings instances:
Definition: qgssettings.h:61
QgsScaleBarSettings::LabelHorizontalPlacement
LabelHorizontalPlacement
Label horizontal placement.
Definition: qgsscalebarsettings.h:75
QgsLayoutItemScaleBar::setMaximumBarWidth
void setMaximumBarWidth(double maxWidth)
Sets the maximum width (in millimeters) for scale bar segments.
Definition: qgslayoutitemscalebar.cpp:167
QgsNumericFormat
A numeric formatter allows for formatting a numeric value for display, using a variety of different f...
Definition: qgsnumericformat.h:259
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:1397
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:597
QgsUnitTypes::DistanceUnit
DistanceUnit
Units of distance.
Definition: qgsunittypes.h:67
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:148
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:690
QgsLayoutObject::changed
void changed()
Emitted when the object's properties change.
QgsLayoutItemScaleBar::setHeight
void setHeight(double height)
Sets the scalebar height (in millimeters).
Definition: qgslayoutitemscalebar.h:464
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:179
QgsLayoutItem::sizeWithUnits
QgsLayoutSize sizeWithUnits() const
Returns the item's current size, including units.
Definition: qgslayoutitem.h:673
QgsRectangle
A rectangle specified with double values.
Definition: qgsrectangle.h:41
QgsStyleEntityVisitorInterface::StyleLeaf
Contains information relating to the style entity currently being visited.
Definition: qgsstyleentityvisitor.h:60
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:830
QgsLayoutItemScaleBar::font
Q_DECL_DEPRECATED QFont font() const
Returns the font used for drawing text in the scalebar.
Definition: qgslayoutitemscalebar.cpp:840
QgsLayoutItemScaleBar::writePropertiesToElement
bool writePropertiesToElement(QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const override
Stores item state within an XML DOM element.
Definition: qgslayoutitemscalebar.cpp:944
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:297
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:141
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:119
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:2820
QgsRectangle::xMaximum
double xMaximum() const SIP_HOLDGIL
Returns the x maximum value (right side of rectangle).
Definition: qgsrectangle.h:183
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:302
QgsDistanceArea::setEllipsoid
bool setEllipsoid(const QString &ellipsoid)
Sets the ellipsoid by its acronym.
Definition: qgsdistancearea.cpp:89
QgsLayoutItemScaleBar::fillColor
Q_DECL_DEPRECATED QColor fillColor() const
Returns the color used for fills in the scalebar.
Definition: qgslayoutitemscalebar.cpp:867
QgsScaleBarRenderer::applyDefaultSettings
virtual bool applyDefaultSettings(QgsScaleBarSettings &settings) const
Applies any default settings relating to the scalebar to the passed settings object.
Definition: qgsscalebarrenderer.cpp:294
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:895
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:590
QgsSymbol::changeSymbolLayer
bool changeSymbolLayer(int index, QgsSymbolLayer *layer)
Deletes the current layer at the specified index and replaces it with layer.
Definition: qgssymbol.cpp:778
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:264
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:458
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:134
QgsScaleBarSettings::lineCapStyle
Q_DECL_DEPRECATED Qt::PenCapStyle lineCapStyle() const
Returns the cap style used for drawing lines in the scalebar.
Definition: qgsscalebarsettings.cpp:305
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:429
QgsUnitTypes::DistanceDegrees
@ DistanceDegrees
Degrees, for planar geographic CRS distance measurements.
Definition: qgsunittypes.h:75
QgsScaleBarSettings::Alignment
Alignment
Scalebar alignment.
Definition: qgsscalebarsettings.h:47
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:216
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:611
QgsLayoutObject::ScalebarRightSegmentSubdivisions
@ ScalebarRightSegmentSubdivisions
Number of subdivisions per segment on right of 0 (since QGIS 3.26)
Definition: qgslayoutobject.h:202
QgsLayoutItemScaleBar::fillSymbol
QgsFillSymbol * fillSymbol() const
Returns the primary fill symbol used to render the scalebar (only used for some scalebar types).
Definition: qgslayoutitemscalebar.cpp:221
QgsScaleBarSettings::fillColor
Q_DECL_DEPRECATED QColor fillColor() const
Returns the color used for fills in the scalebar.
Definition: qgsscalebarsettings.cpp:119
QgsLayoutObject::ScalebarMinimumWidth
@ ScalebarMinimumWidth
Scalebar segment minimum width (since QGIS 3.26)
Definition: qgslayoutobject.h:199
QgsLayoutItemScaleBar::setSubdivisionsHeight
void setSubdivisionsHeight(double height)
Sets the scalebar subdivisions height (in millimeters) for segments included in the right part of the...
Definition: qgslayoutitemscalebar.h:119
QgsLayoutItemScaleBar::height
double height() const
Returns the scalebar height (in millimeters).
Definition: qgslayoutitemscalebar.h:458
QgsLayoutObject::ScalebarSegmentWidth
@ ScalebarSegmentWidth
Scalebar width in map units of a single segment (since QGIS 3.26)
Definition: qgslayoutobject.h:198
QgsDistanceArea::measureLine
double measureLine(const QVector< QgsPointXY > &points) const
Measures the length of a line with multiple segments.
Definition: qgsdistancearea.cpp:298
QgsLayoutItemScaleBar::setFillColor
Q_DECL_DEPRECATED void setFillColor(const QColor &color)
Sets the color used for fills in the scalebar.
Definition: qgslayoutitemscalebar.cpp:874
QgsLayoutObject::ScalebarLeftSegments
@ ScalebarLeftSegments
Number of segments on the left of 0 (since QGIS 3.26)
Definition: qgslayoutobject.h:196
QgsLayoutItem::setBackgroundEnabled
void setBackgroundEnabled(bool drawBackground)
Sets whether this item has a background drawn under it or not.
Definition: qgslayoutitem.cpp:887
QgsDistanceArea::lengthUnits
QgsUnitTypes::DistanceUnit lengthUnits() const
Returns the units of distance for length calculations made by this object.
Definition: qgsdistancearea.cpp:790
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:640
QgsScaleBarSettings::pen
Q_DECL_DEPRECATED QPen pen() const
Returns the pen used for drawing outlines in the scalebar.
Definition: qgsscalebarsettings.cpp:166
QgsLineSymbol
A line symbol type, for rendering LineString and MultiLineString geometries.
Definition: qgslinesymbol.h:29
QgsLayoutItemMap::extent
QgsRectangle extent() const
Returns the current map extent.
Definition: qgslayoutitemmap.cpp:281
QgsUnitTypes::DistanceFeet
@ DistanceFeet
Imperial feet.
Definition: qgsunittypes.h:71
QgsMessageLog::logMessage
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
Definition: qgsmessagelog.cpp:27
QgsScaleBarRenderer
Abstract base class for scale bar renderers.
Definition: qgsscalebarrenderer.h:38
QgsUnitTypes::DistanceMeters
@ DistanceMeters
Meters.
Definition: qgsunittypes.h:69
QgsStyleTextFormatEntity
A text format entity for QgsStyle databases.
Definition: qgsstyle.h:1404
QgsScaleBarSettings::setLineColor
Q_DECL_DEPRECATED void setLineColor(const QColor &color)
Sets the color used for lines in the scalebar.
Definition: qgsscalebarsettings.cpp:144
QgsLayoutItemScaleBar::readPropertiesFromElement
bool readPropertiesFromElement(const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context) override
Sets item state from a DOM element.
Definition: qgslayoutitemscalebar.cpp:1070
QgsTextFormat::opacity
double opacity() const
Returns the text's opacity.
Definition: qgstextformat.cpp:308
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:155
QgsScaleBarSettings::setLineWidth
Q_DECL_DEPRECATED void setLineWidth(double width)
Sets the line width in millimeters for lines in the scalebar.
Definition: qgsscalebarsettings.cpp:157
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:211
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:488
QgsLayoutItemScaleBar::icon
QIcon icon() const override
Returns the item's icon.
Definition: qgslayoutitemscalebar.cpp:61
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:112
QgsRectangle::xMinimum
double xMinimum() const SIP_HOLDGIL
Returns the x minimum value (left side of rectangle).
Definition: qgsrectangle.h:188
QgsDistanceArea::setSourceCrs
void setSourceCrs(const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context)
Sets source spatial reference system crs.
Definition: qgsdistancearea.cpp:83
QgsScaleBarSettings::setLineSymbol
void setLineSymbol(QgsLineSymbol *symbol)
Sets the line symbol used to render the scalebar (only used for some scalebar types).
Definition: qgsscalebarsettings.cpp:198
qgsfillsymbollayer.h
QgsSymbolLayer::PropertyStrokeWidth
@ PropertyStrokeWidth
Stroke width.
Definition: qgssymbollayer.h:149
QgsScaleBarSettings::setFillColor
Q_DECL_DEPRECATED void setFillColor(const QColor &color)
Sets the color used for fills in the scalebar.
Definition: qgsscalebarsettings.cpp:124
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:737
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:218
QgsLayoutObject::ScalebarHeight
@ ScalebarHeight
Scalebar height (since QGIS 3.26)
Definition: qgslayoutobject.h:201
QgsScaleBarSettings::lineColor
Q_DECL_DEPRECATED QColor lineColor() const
Returns the color used for lines in the scalebar.
Definition: qgsscalebarsettings.cpp:139
qgslayout.h
QgsLayoutItemMap::crs
QgsCoordinateReferenceSystem crs() const
Returns coordinate reference system used for rendering the map.
Definition: qgslayoutitemmap.cpp:308
QgsLayoutItemScaleBar::setStyle
void setStyle(const QString &name)
Sets the scale bar style by name.
Definition: qgslayoutitemscalebar.cpp:806
QgsCoordinateReferenceSystem
This class represents a coordinate reference system (CRS).
Definition: qgscoordinatereferencesystem.h:211
QgsLayoutObject::ScalebarLineWidth
@ ScalebarLineWidth
Scalebar line width (deprecated, use data defined properties on scalebar line symbol instead)
Definition: qgslayoutobject.h:207
QgsScaleBarSettings::brush
Q_DECL_DEPRECATED QBrush brush() const
Returns the primary brush used for filling the scalebar.
Definition: qgsscalebarsettings.cpp:243
QgsLayoutItemRegistry::LayoutScaleBar
@ LayoutScaleBar
Scale bar item.
Definition: qgslayoutitemregistry.h:354
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:647
QgsUnitTypes::RenderPixels
@ RenderPixels
Pixels.
Definition: qgsunittypes.h:171
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:835
QgsPointXY
A class to represent a 2D point.
Definition: qgspointxy.h:58
QgsSymbolLayerUtils::decodePenCapStyle
static Qt::PenCapStyle decodePenCapStyle(const QString &str)
Definition: qgssymbollayerutils.cpp:250
QgsLayoutItemMap
Layout graphical items for displaying a map.
Definition: qgslayoutitemmap.h:317
QgsLayoutItemScaleBar::setFillColor2
Q_DECL_DEPRECATED void setFillColor2(const QColor &color)
Sets the secondary color used for fills in the scalebar.
Definition: qgslayoutitemscalebar.cpp:888
QgsLayoutObject::dataDefinedProperties
QgsPropertyCollection & dataDefinedProperties()
Returns a reference to the object's property collection, used for data defined overrides.
Definition: qgslayoutobject.h:265
QgsLayoutItemScaleBar::lineJoinStyle
Q_DECL_DEPRECATED Qt::PenJoinStyle lineJoinStyle() const
Returns the join style used for drawing lines in the scalebar.
Definition: qgslayoutitemscalebar.cpp:619
QgsLayoutItemScaleBar::resizeToMinimumWidth
void resizeToMinimumWidth()
Resizes the scale bar to its minimum width, without changing the height.
Definition: qgslayoutitemscalebar.cpp:771
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:909
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:400
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:345
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:392
QgsScaleBarSettings::lineJoinStyle
Q_DECL_DEPRECATED Qt::PenJoinStyle lineJoinStyle() const
Returns the join style used for drawing lines in the scalebar.
Definition: qgsscalebarsettings.cpp:285
QgsCoordinateReferenceSystem::mapUnits
QgsUnitTypes::DistanceUnit mapUnits
Definition: qgscoordinatereferencesystem.h:215
QgsScaleBarSettings::divisionLineSymbol
QgsLineSymbol * divisionLineSymbol() const
Returns the line symbol used to render the scalebar divisions (only used for some scalebar types).
Definition: qgsscalebarsettings.cpp:203
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:695
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:363
QgsScaleBarSettings::subdivisionLineSymbol
QgsLineSymbol * subdivisionLineSymbol() const
Returns the line symbol used to render the scalebar subdivisions (only used for some scalebar types).
Definition: qgsscalebarsettings.cpp:213
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:223
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:881
QgsScaleBarSettings::unitsPerSegment
double unitsPerSegment() const
Returns the number of scalebar units per segment.
Definition: qgsscalebarsettings.h:163
QgsLayoutItemScaleBar::setNumberOfSubdivisions
void setNumberOfSubdivisions(int subdivisions)
Sets the number of subdivisions for segments included in the right part of the scalebar (only used fo...
Definition: qgslayoutitemscalebar.h:105
QgsTextFormat::setOpacity
void setOpacity(double opacity)
Sets the text's opacity.
Definition: qgstextformat.cpp:313
QgsLayoutItemScaleBar::brush
Q_DECL_DEPRECATED QBrush brush() const
Returns the primary brush for the scalebar.
Definition: qgslayoutitemscalebar.cpp:930
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:228
QgsFillSymbol::clone
QgsFillSymbol * clone() const override
Returns a deep copy of this symbol.
Definition: qgsfillsymbol.cpp:144
QgsFillSymbol
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
Definition: qgsfillsymbol.h:29
QgsLayoutItemMap::scale
double scale() const
Returns the map scale.
Definition: qgslayoutitemmap.cpp:172
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:294
QgsLayoutItemScaleBar::setUnitsPerSegment
void setUnitsPerSegment(double units)
Sets the number of scalebar units per segment.
Definition: qgslayoutitemscalebar.cpp:130
QgsLayoutItem::attemptResize
virtual void attemptResize(const QgsLayoutSize &size, bool includesFrame=false)
Attempts to resize the item to a specified target size.
Definition: qgslayoutitem.cpp:429
QgsApplication::numericFormatRegistry
static QgsNumericFormatRegistry * numericFormatRegistry()
Gets the registry of available numeric formats.
Definition: qgsapplication.cpp:2475
QgsLayoutItemScaleBar::minimumBarWidth
double minimumBarWidth() const
Returns the minimum width (in millimeters) for scale bar segments.
Definition: qgslayoutitemscalebar.h:157
QgsSymbolLayerUtils::decodePenJoinStyle
static Qt::PenJoinStyle decodePenJoinStyle(const QString &str)
Definition: qgssymbollayerutils.cpp:200
QgsTextFormat::font
QFont font() const
Returns the font used for rendering text.
Definition: qgstextformat.cpp:160
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:71
QgsTextFormat::setSizeUnit
void setSizeUnit(QgsUnitTypes::RenderUnit unit)
Sets the units for the size of rendered text.
Definition: qgstextformat.cpp:269
QgsLayoutSize
This class provides a method of storing sizes, consisting of a width and height, for use in QGIS layo...
Definition: qgslayoutsize.h:40
QgsUnitTypes::DistanceMiles
@ DistanceMiles
Terrestrial miles.
Definition: qgsunittypes.h:74
QgsLayoutItemScaleBar::maximumBarWidth
double maximumBarWidth() const
Returns the maximum width (in millimeters) for scale bar segments.
Definition: qgslayoutitemscalebar.h:177
QgsLayoutItemScaleBar::alternateFillSymbol
QgsFillSymbol * alternateFillSymbol() const
Returns the secondary fill symbol used to render the scalebar (only used for some scalebar types).
Definition: qgslayoutitemscalebar.cpp:231
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:206
QgsDistanceArea
A general purpose distance and area calculator, capable of performing ellipsoid based calculations.
Definition: qgsdistancearea.h:52
qgsdistancearea.h
QgsNumericFormat::writeXml
void writeXml(QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const
Writes the format to an XML element.
Definition: qgsnumericformat.cpp:58
QgsSymbolLayerUtils::encodePenJoinStyle
static QString encodePenJoinStyle(Qt::PenJoinStyle style)
Definition: qgssymbollayerutils.cpp:185
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:208
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
QgsApplication::getThemeIcon
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
Definition: qgsapplication.cpp:693
QgsUnitTypes::LayoutMillimeters
@ LayoutMillimeters
Millimeters.
Definition: qgsunittypes.h:183
QgsLayoutItemScaleBar::style
QString style() const
Returns the scale bar style name.
Definition: qgslayoutitemscalebar.cpp:818
QgsLayoutItemScaleBar
A layout item subclass for scale bars.
Definition: qgslayoutitemscalebar.h:35
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:56
QgsTextFormat::setSize
void setSize(double size)
Sets the size for rendered text.
Definition: qgstextformat.cpp:291
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:238
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:854
QgsLayoutItemScaleBar::applyDefaultSettings
void applyDefaultSettings()
Applies the default scalebar settings to the scale bar.
Definition: qgslayoutitemscalebar.cpp:661
QgsPropertyCollection::isActive
bool isActive(int key) const override
Returns true if the collection contains an active property with the specified key.
Definition: qgspropertycollection.cpp:268
qgslayoutitemregistry.h
QgsScaleBarSettings::numericFormat
const QgsNumericFormat * numericFormat() const
Returns the numeric format used for numbers in the scalebar.
Definition: qgsscalebarsettings.cpp:325
Q_NOWARN_DEPRECATED_PUSH
#define Q_NOWARN_DEPRECATED_PUSH
Definition: qgis.h:2819
QgsLayoutItemScaleBar::brush2
Q_DECL_DEPRECATED QBrush brush2() const
Returns the secondary brush for the scalebar.
Definition: qgslayoutitemscalebar.cpp:937
QgsLayoutObject::ScalebarFillColor
@ ScalebarFillColor
Scalebar fill color (deprecated, use data defined properties on scalebar fill symbol 1 instead)
Definition: qgslayoutobject.h:204
QgsLayoutItemScaleBar::draw
void draw(QgsLayoutItemRenderContext &context) override
Draws the item's contents using the specified item render context.
Definition: qgslayoutitemscalebar.cpp:77
QgsLayoutItemScaleBar::exportLayerBehavior
ExportLayerBehavior exportLayerBehavior() const override
Returns the behavior of this item during exporting to layered exports (e.g.
Definition: qgslayoutitemscalebar.cpp:1406
QgsScaleBarSettings::alternateFillSymbol
QgsFillSymbol * alternateFillSymbol() const
Returns the secondary fill symbol used to render the scalebar (only used for some scalebar types).
Definition: qgsscalebarsettings.cpp:233
qgsfillsymbol.h
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:330
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:432
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:1159
QgsTextFormat::writeXml
QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context) const
Write settings into a DOM element.
Definition: qgstextformat.cpp:671
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:1397
QgsLayoutItemScaleBar::setTextFormat
void setTextFormat(const QgsTextFormat &format)
Sets the text format used for drawing text in the scalebar.
Definition: qgslayoutitemscalebar.cpp:184
QgsLayoutObject::ScalebarSubdivisionHeight
@ ScalebarSubdivisionHeight
Scalebar subdivision height (since QGIS 3.26)
Definition: qgslayoutobject.h:203
qgsproject.h
QgsLayoutMeasurement
This class provides a method of storing measurements for use in QGIS layouts using a variety of diffe...
Definition: qgslayoutmeasurement.h:33
QgsLayoutItemScaleBar::setNumberOfSegmentsLeft
void setNumberOfSegmentsLeft(int segments)
Sets the number of segments included in the left part of the scalebar.
Definition: qgslayoutitemscalebar.cpp:241
QgsScaleBarRenderer::ScaleBarContext::flags
Flags flags
Scalebar renderer flags.
Definition: qgsscalebarrenderer.h:90
QgsLayoutObject::ScalebarMaximumWidth
@ ScalebarMaximumWidth
Scalebar segment maximum width (since QGIS 3.26)
Definition: qgslayoutobject.h:200
QgsLayoutObject::DataDefinedProperty
DataDefinedProperty
Data defined properties for different item types.
Definition: qgslayoutobject.h:132
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:236
qgslinesymbol.h
qgslayoutitemmap.h
QgsLayoutItemScaleBar::setUnitLabel
void setUnitLabel(const QString &label)
Sets the label for units.
Definition: qgslayoutitemscalebar.h:211
qgsmessagelog.h
QgsApplication::scaleBarRendererRegistry
static QgsScaleBarRendererRegistry * scaleBarRendererRegistry()
Gets the registry of available scalebar renderers.
Definition: qgsapplication.cpp:2495
QgsLayoutItemScaleBar::create
static QgsLayoutItemScaleBar * create(QgsLayout *layout)
Returns a new scale bar item for the specified layout.
Definition: qgslayoutitemscalebar.cpp:66
QgsScaleBarSettings::LabelVerticalPlacement
LabelVerticalPlacement
Label vertical placement.
Definition: qgsscalebarsettings.h:66