QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
Loading...
Searching...
No Matches
qgslayoutscalebarwidget.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgslayoutscalebarwidget.cpp
3 -----------------------------
4 begin : 11 June 2008
5 copyright : (C) 2008 by Marco Hugentobler
6 email : marco dot hugentobler at karto dot baug dot ethz dot ch
7 ***************************************************************************/
8/***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
16
18#include "moc_qgslayoutscalebarwidget.cpp"
19#include "qgslayoutitemmap.h"
22#include "qgslayout.h"
24#include "qgslayoutundostack.h"
25#include "qgsfillsymbol.h"
26#include "qgslinesymbol.h"
28#include "qgsvectorlayer.h"
29
30#include <QColorDialog>
31#include <QFontDialog>
32#include <QWidget>
33
35 : QgsLayoutItemBaseWidget( nullptr, scaleBar )
36 , mScalebar( scaleBar )
37{
38 setupUi( this );
39
40 mNumberOfSubdivisionsSpinBox->setClearValue( 1 );
41
42 connect( mHeightSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutScaleBarWidget::mHeightSpinBox_valueChanged );
43 connect( mSegmentSizeSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutScaleBarWidget::mSegmentSizeSpinBox_valueChanged );
44 connect( mSegmentsLeftSpinBox, static_cast < void ( QSpinBox::* )( int ) > ( &QSpinBox::valueChanged ), this, &QgsLayoutScaleBarWidget::mSegmentsLeftSpinBox_valueChanged );
45 connect( mNumberOfSegmentsSpinBox, static_cast < void ( QSpinBox::* )( int ) > ( &QSpinBox::valueChanged ), this, &QgsLayoutScaleBarWidget::mNumberOfSegmentsSpinBox_valueChanged );
46 connect( mNumberOfSubdivisionsSpinBox, static_cast < void ( QSpinBox::* )( int ) > ( &QSpinBox::valueChanged ), this, &QgsLayoutScaleBarWidget::mNumberOfSubdivisionsSpinBox_valueChanged );
47 connect( mSubdivisionsHeightSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutScaleBarWidget::mSubdivisionsHeightSpinBox_valueChanged );
48 connect( mUnitLabelLineEdit, &QLineEdit::textChanged, this, &QgsLayoutScaleBarWidget::mUnitLabelLineEdit_textChanged );
49 connect( mMapUnitsPerBarUnitSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutScaleBarWidget::mMapUnitsPerBarUnitSpinBox_valueChanged );
50 connect( mStyleComboBox, &QComboBox::currentTextChanged, this, &QgsLayoutScaleBarWidget::mStyleComboBox_currentIndexChanged );
51 connect( mLabelBarSpaceSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutScaleBarWidget::mLabelBarSpaceSpinBox_valueChanged );
52 connect( mBoxSizeSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutScaleBarWidget::mBoxSizeSpinBox_valueChanged );
53 connect( mAlignmentComboBox, &QgsAlignmentComboBox::changed, this, &QgsLayoutScaleBarWidget::alignmentChanged );
54 connect( mDistanceLabelPlacementComboBox, qOverload<int>( &QComboBox::currentIndexChanged ), this, &QgsLayoutScaleBarWidget::mDistanceLabelPlacementComboBox_currentIndexChanged );
55 connect( mUnitsComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsLayoutScaleBarWidget::mUnitsComboBox_currentIndexChanged );
56 connect( mMinWidthSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutScaleBarWidget::mMinWidthSpinBox_valueChanged );
57 connect( mMaxWidthSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutScaleBarWidget::mMaxWidthSpinBox_valueChanged );
58 connect( mNumberFormatPushButton, &QPushButton::clicked, this, &QgsLayoutScaleBarWidget::changeNumberFormat );
59 connect( mMethodCombo, qOverload<int>( &QComboBox::currentIndexChanged ), this, [ = ]
60 {
61 if ( !mScalebar )
62 {
63 return;
64 }
65
66 disconnectUpdateSignal();
67 mScalebar->beginCommand( tr( "Set Scalebar Method" ) );
68 mScalebar->setMethod( mMethodCombo->currentData().value< Qgis::ScaleCalculationMethod >() );
69 mScalebar->update();
70 connectUpdateSignal();
71 mScalebar->endCommand();
72 } );
73
82
83 mSegmentsLeftDDBtn->registerEnabledWidget( mSegmentsLeftSpinBox, false );
84 mSegmentsRightDDBtn->registerEnabledWidget( mNumberOfSegmentsSpinBox, false );
85 mSegmentSizeDDBtn->registerEnabledWidget( mSegmentSizeSpinBox, false );
86 mMinWidthDDBtn->registerEnabledWidget( mMinWidthSpinBox, false );
87 mMaxWidthDDBtn->registerEnabledWidget( mMaxWidthSpinBox, false );
88
89 setPanelTitle( tr( "Scalebar Properties" ) );
90
91 mFontButton->registerExpressionContextGenerator( this );
92
93 connectUpdateSignal();
94
95 //add widget for general composer item properties
96 mItemPropertiesWidget = new QgsLayoutItemPropertiesWidget( this, scaleBar );
97 mainLayout->addWidget( mItemPropertiesWidget );
98
99 mSegmentSizeRadioGroup.addButton( mFixedSizeRadio );
100 mSegmentSizeRadioGroup.addButton( mFitWidthRadio );
101 connect( &mSegmentSizeRadioGroup, static_cast < void ( QButtonGroup::* )( QAbstractButton * ) > ( &QButtonGroup::buttonClicked ), this, &QgsLayoutScaleBarWidget::segmentSizeRadioChanged );
102
103 blockMemberSignals( true );
104
105 //style combo box
106 const QStringList renderers = QgsApplication::scaleBarRendererRegistry()->sortedRendererList();
107 for ( const QString &renderer : renderers )
108 {
109 mStyleComboBox->addItem( QgsApplication::scaleBarRendererRegistry()->visibleName( renderer ), renderer );
110 }
111
112 //label vertical/horizontal placement combo box
113 mDistanceLabelPlacementComboBox->addItem( tr( "Above Segment Edges" ), static_cast< int >( DistanceLabelPlacement::CenteredAboveSegmentEdges ) );
114 mDistanceLabelPlacementComboBox->addItem( tr( "Above Segment Centers" ), static_cast< int >( DistanceLabelPlacement::CenteredAboveSegmentCenters ) );
115 mDistanceLabelPlacementComboBox->addItem( tr( "Below Segment Edges" ), static_cast< int >( DistanceLabelPlacement::CenteredBelowSegmentEdges ) );
116 mDistanceLabelPlacementComboBox->addItem( tr( "Below Segment Centers" ), static_cast< int >( DistanceLabelPlacement::CenteredBelowSegmentCenters ) );
117
118 //alignment combo box
119 mAlignmentComboBox->setAvailableAlignments( Qt::AlignLeft | Qt::AlignHCenter | Qt::AlignRight );
120
121 //units combo box
122 mUnitsComboBox->addItem( tr( "Map units" ), static_cast< int >( Qgis::DistanceUnit::Unknown ) );
123 mUnitsComboBox->addItem( tr( "Meters" ), static_cast< int >( Qgis::DistanceUnit::Meters ) );
124 mUnitsComboBox->addItem( tr( "Kilometers" ), static_cast< int >( Qgis::DistanceUnit::Kilometers ) );
125 mUnitsComboBox->addItem( tr( "Feet" ), static_cast< int >( Qgis::DistanceUnit::Feet ) );
126 mUnitsComboBox->addItem( tr( "Yards" ), static_cast< int >( Qgis::DistanceUnit::Yards ) );
127 mUnitsComboBox->addItem( tr( "Miles" ), static_cast< int >( Qgis::DistanceUnit::Miles ) );
128 mUnitsComboBox->addItem( tr( "Nautical Miles" ), static_cast< int >( Qgis::DistanceUnit::NauticalMiles ) );
129 mUnitsComboBox->addItem( tr( "Centimeters" ), static_cast< int >( Qgis::DistanceUnit::Centimeters ) );
130 mUnitsComboBox->addItem( tr( "Millimeters" ), static_cast< int >( Qgis::DistanceUnit::Millimeters ) );
131 mUnitsComboBox->addItem( tr( "Inches" ), static_cast< int >( Qgis::DistanceUnit::Inches ) );
132
133 mMethodCombo->addItem( tr( "Average Top, Middle and Bottom Scales" ), QVariant::fromValue( Qgis::ScaleCalculationMethod::HorizontalAverage ) );
134 mMethodCombo->addItem( tr( "Calculate along Top of Map" ), QVariant::fromValue( Qgis::ScaleCalculationMethod::HorizontalTop ) );
135 mMethodCombo->addItem( tr( "Calculate along Middle of Map" ), QVariant::fromValue( Qgis::ScaleCalculationMethod::HorizontalMiddle ) );
136 mMethodCombo->addItem( tr( "Calculate along Bottom of Map" ), QVariant::fromValue( Qgis::ScaleCalculationMethod::HorizontalBottom ) );
137
138 mLineStyleButton->setSymbolType( Qgis::SymbolType::Line );
139 connect( mLineStyleButton, &QgsSymbolButton::changed, this, &QgsLayoutScaleBarWidget::lineSymbolChanged );
140
141 mDivisionStyleButton->setSymbolType( Qgis::SymbolType::Line );
142 connect( mDivisionStyleButton, &QgsSymbolButton::changed, this, &QgsLayoutScaleBarWidget::divisionSymbolChanged );
143
144 mSubdivisionStyleButton->setSymbolType( Qgis::SymbolType::Line );
145 connect( mSubdivisionStyleButton, &QgsSymbolButton::changed, this, &QgsLayoutScaleBarWidget::subdivisionSymbolChanged );
146
147 mFillSymbol1Button->setSymbolType( Qgis::SymbolType::Fill );
148 connect( mFillSymbol1Button, &QgsSymbolButton::changed, this, &QgsLayoutScaleBarWidget::fillSymbol1Changed );
149
150 mFillSymbol2Button->setSymbolType( Qgis::SymbolType::Fill );
151 connect( mFillSymbol2Button, &QgsSymbolButton::changed, this, &QgsLayoutScaleBarWidget::fillSymbol2Changed );
152
153 mFontButton->setDialogTitle( tr( "Scalebar Font" ) );
154 mFontButton->setMode( QgsFontButton::ModeTextRenderer );
155
156 if ( mScalebar )
157 {
158 QgsLayout *scaleBarLayout = mScalebar->layout();
159 if ( scaleBarLayout )
160 {
161 mMapItemComboBox->setCurrentLayout( scaleBarLayout );
162 mMapItemComboBox->setItemType( QgsLayoutItemRegistry::LayoutMap );
163 }
164 }
165
166 connect( mMapItemComboBox, &QgsLayoutItemComboBox::itemChanged, this, &QgsLayoutScaleBarWidget::mapChanged );
167
168 blockMemberSignals( false );
169 setGuiElements(); //set the GUI elements to the state of scaleBar
170
171 mLineStyleButton->registerExpressionContextGenerator( mScalebar );
172 mLineStyleButton->setLayer( coverageLayer() );
173 mDivisionStyleButton->registerExpressionContextGenerator( mScalebar );
174 mDivisionStyleButton->setLayer( coverageLayer() );
175 mSubdivisionStyleButton->registerExpressionContextGenerator( mScalebar );
176 mSubdivisionStyleButton->setLayer( coverageLayer() );
177 mFillSymbol1Button->registerExpressionContextGenerator( mScalebar );
178 mFillSymbol1Button->setLayer( coverageLayer() );
179 mFillSymbol2Button->registerExpressionContextGenerator( mScalebar );
180 mFillSymbol2Button->setLayer( coverageLayer() );
181
182 connect( mFontButton, &QgsFontButton::changed, this, &QgsLayoutScaleBarWidget::textFormatChanged );
183 mFontButton->setLayer( coverageLayer() );
184 if ( mScalebar->layout() )
185 {
186 connect( &mScalebar->layout()->reportContext(), &QgsLayoutReportContext::layerChanged, mFontButton, &QgsFontButton::setLayer );
187 connect( &mScalebar->layout()->reportContext(), &QgsLayoutReportContext::layerChanged, mLineStyleButton, &QgsSymbolButton::setLayer );
188 connect( &mScalebar->layout()->reportContext(), &QgsLayoutReportContext::layerChanged, mDivisionStyleButton, &QgsSymbolButton::setLayer );
189 connect( &mScalebar->layout()->reportContext(), &QgsLayoutReportContext::layerChanged, mSubdivisionStyleButton, &QgsSymbolButton::setLayer );
190 connect( &mScalebar->layout()->reportContext(), &QgsLayoutReportContext::layerChanged, mFillSymbol1Button, &QgsSymbolButton::setLayer );
191 connect( &mScalebar->layout()->reportContext(), &QgsLayoutReportContext::layerChanged, mFillSymbol2Button, &QgsSymbolButton::setLayer );
192 }
193}
194
196{
197 if ( mItemPropertiesWidget )
198 mItemPropertiesWidget->setMasterLayout( masterLayout );
199}
200
202{
203 QgsExpressionContext context = mScalebar->createExpressionContext();
204 QgsExpressionContextScope *scaleScope = new QgsExpressionContextScope( QStringLiteral( "scalebar_text" ) );
205 scaleScope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "scale_value" ), 0, true, false ) );
206 context.appendScope( scaleScope );
207 context.setHighlightedVariables( QStringList() << QStringLiteral( "scale_value" ) );
208 return context;
209}
210
212{
214 return false;
215
216 disconnectUpdateSignal();
217
218 mScalebar = qobject_cast< QgsLayoutItemScaleBar * >( item );
219 mItemPropertiesWidget->setItem( mScalebar );
220
221 if ( mScalebar )
222 {
223 connectUpdateSignal();
224 mFillSymbol1Button->registerExpressionContextGenerator( mScalebar );
225 mFillSymbol2Button->registerExpressionContextGenerator( mScalebar );
226 mLineStyleButton->registerExpressionContextGenerator( mScalebar );
227 mDivisionStyleButton->registerExpressionContextGenerator( mScalebar );
228 mSubdivisionStyleButton->registerExpressionContextGenerator( mScalebar );
229 }
230
231 setGuiElements();
232
233 return true;
234}
235
236void QgsLayoutScaleBarWidget::lineSymbolChanged()
237{
238 if ( !mScalebar )
239 return;
240
241 mScalebar->layout()->undoStack()->beginCommand( mScalebar, tr( "Change Scalebar Line Style" ), QgsLayoutItem::UndoShapeStyle );
242 mScalebar->setLineSymbol( mLineStyleButton->clonedSymbol<QgsLineSymbol>() );
243 mScalebar->update();
244 mScalebar->layout()->undoStack()->endCommand();
245}
246
247void QgsLayoutScaleBarWidget::divisionSymbolChanged()
248{
249 if ( !mScalebar )
250 return;
251
252 mScalebar->layout()->undoStack()->beginCommand( mScalebar, tr( "Change Scalebar Division Style" ), QgsLayoutItem::UndoShapeStyle );
253 mScalebar->setDivisionLineSymbol( mDivisionStyleButton->clonedSymbol<QgsLineSymbol>() );
254 mScalebar->update();
255 mScalebar->layout()->undoStack()->endCommand();
256}
257
258void QgsLayoutScaleBarWidget::subdivisionSymbolChanged()
259{
260 if ( !mScalebar )
261 return;
262
263 mScalebar->layout()->undoStack()->beginCommand( mScalebar, tr( "Change Scalebar Subdivision Style" ), QgsLayoutItem::UndoShapeStyle );
264 mScalebar->setSubdivisionLineSymbol( mSubdivisionStyleButton->clonedSymbol<QgsLineSymbol>() );
265 mScalebar->update();
266 mScalebar->layout()->undoStack()->endCommand();
267}
268
269void QgsLayoutScaleBarWidget::fillSymbol1Changed()
270{
271 if ( !mScalebar )
272 return;
273
274 mScalebar->layout()->undoStack()->beginCommand( mScalebar, tr( "Change Scalebar Fill Style" ), QgsLayoutItem::UndoShapeStyle );
275 mScalebar->setFillSymbol( mFillSymbol1Button->clonedSymbol<QgsFillSymbol>() );
276 mScalebar->update();
277 mScalebar->layout()->undoStack()->endCommand();
278}
279
280void QgsLayoutScaleBarWidget::fillSymbol2Changed()
281{
282 if ( !mScalebar )
283 return;
284
285 mScalebar->layout()->undoStack()->beginCommand( mScalebar, tr( "Change Scalebar Fill Style" ), QgsLayoutItem::UndoShapeStyle );
286 mScalebar->setAlternateFillSymbol( mFillSymbol2Button->clonedSymbol<QgsFillSymbol>() );
287 mScalebar->update();
288 mScalebar->layout()->undoStack()->endCommand();
289}
290
291void QgsLayoutScaleBarWidget::setGuiElements()
292{
293 if ( !mScalebar )
294 {
295 return;
296 }
297
298 blockMemberSignals( true );
299 mNumberOfSegmentsSpinBox->setValue( mScalebar->numberOfSegments() );
300 mSegmentsLeftSpinBox->setValue( mScalebar->numberOfSegmentsLeft() );
301 mSegmentSizeSpinBox->setValue( mScalebar->unitsPerSegment() );
302 mHeightSpinBox->setValue( mScalebar->height() );
303 mNumberOfSubdivisionsSpinBox->setValue( mScalebar->numberOfSubdivisions() );
304 mSubdivisionsHeightSpinBox->setValue( mScalebar->subdivisionsHeight() );
305 mMapUnitsPerBarUnitSpinBox->setValue( mScalebar->mapUnitsPerScaleBarUnit() );
306 mLabelBarSpaceSpinBox->setValue( mScalebar->labelBarSpace() );
307 mBoxSizeSpinBox->setValue( mScalebar->boxContentSpace() );
308 mUnitLabelLineEdit->setText( mScalebar->unitLabel() );
309 mFontButton->setTextFormat( mScalebar->textFormat() );
310
311 whileBlocking( mLineStyleButton )->setSymbol( mScalebar->lineSymbol()->clone() );
312 whileBlocking( mDivisionStyleButton )->setSymbol( mScalebar->divisionLineSymbol()->clone() );
313 whileBlocking( mSubdivisionStyleButton )->setSymbol( mScalebar->subdivisionLineSymbol()->clone() );
314 whileBlocking( mFillSymbol1Button )->setSymbol( mScalebar->fillSymbol()->clone() );
315 whileBlocking( mFillSymbol2Button )->setSymbol( mScalebar->alternateFillSymbol()->clone() );
316
317 //map combo box
318 mMapItemComboBox->setItem( mScalebar->linkedMap() );
319
320 //style...
321 const QString style = mScalebar->style();
322 mStyleComboBox->setCurrentIndex( mStyleComboBox->findData( style ) );
323 toggleStyleSpecificControls( style );
324
325 //label vertical/horizontal placement
326 mDistanceLabelPlacementComboBox->setCurrentIndex( mDistanceLabelPlacementComboBox->findData( static_cast< int >(
327 distanceLabelPlacement( mScalebar->labelHorizontalPlacement(), mScalebar->labelVerticalPlacement() ) ) ) );
328
329 //alignment
330
331 Qt::Alignment a = Qt::AlignLeft;
332 switch ( mScalebar->alignment() )
333 {
335 a = Qt::AlignLeft;
336 break;
338 a = Qt::AlignRight;
339 break;
341 a = Qt::AlignHCenter;
342 break;
343 }
344 mAlignmentComboBox->setCurrentAlignment( a );
345
346 //units
347 mUnitsComboBox->setCurrentIndex( mUnitsComboBox->findData( static_cast< int >( mScalebar->units() ) ) );
348
349 switch ( mScalebar->segmentSizeMode() )
350 {
352 {
353 mFixedSizeRadio->setChecked( true );
354 mSegmentSizeWidget->setEnabled( true );
355 mMinWidthWidget->setEnabled( false );
356 mMaxWidthWidget->setEnabled( false );
357 break;
358 }
359
361 {
362 mFitWidthRadio->setChecked( true );
363 mSegmentSizeWidget->setEnabled( false );
364 mMinWidthWidget->setEnabled( true );
365 mMaxWidthWidget->setEnabled( true );
366 break;
367 }
368 }
369 mMinWidthSpinBox->setValue( mScalebar->minimumBarWidth() );
370 mMaxWidthSpinBox->setValue( mScalebar->maximumBarWidth() );
371
372 mMethodCombo->setCurrentIndex( mMethodCombo->findData( QVariant::fromValue( mScalebar->method() ) ) );
373
374 populateDataDefinedButtons();
375
376 blockMemberSignals( false );
377}
378
379//slots
380
381void QgsLayoutScaleBarWidget::mSegmentSizeSpinBox_valueChanged( double d )
382{
383 if ( !mScalebar )
384 {
385 return;
386 }
387
388 mScalebar->beginCommand( tr( "Set Scalebar Segment Size" ), QgsLayoutItem::UndoScaleBarSegmentSize );
389 disconnectUpdateSignal();
390 mScalebar->setUnitsPerSegment( d );
391 mScalebar->update();
392 connectUpdateSignal();
393 mScalebar->endCommand();
394}
395
396void QgsLayoutScaleBarWidget::mSegmentsLeftSpinBox_valueChanged( int i )
397{
398 if ( !mScalebar )
399 {
400 return;
401 }
402
403 mScalebar->beginCommand( tr( "Set Scalebar Segments" ), QgsLayoutItem::UndoScaleBarSegmentsLeft );
404 disconnectUpdateSignal();
405 mScalebar->setNumberOfSegmentsLeft( i );
406 mScalebar->update();
407 connectUpdateSignal();
408 mScalebar->endCommand();
409}
410
411void QgsLayoutScaleBarWidget::mNumberOfSegmentsSpinBox_valueChanged( int i )
412{
413 if ( !mScalebar )
414 {
415 return;
416 }
417
418 mScalebar->beginCommand( tr( "Set Scalebar Segments" ), QgsLayoutItem::UndoScaleBarSegments );
419 disconnectUpdateSignal();
420 mScalebar->setNumberOfSegments( i );
421 mScalebar->update();
422 connectUpdateSignal();
423 mScalebar->endCommand();
424}
425
426void QgsLayoutScaleBarWidget::mHeightSpinBox_valueChanged( double d )
427{
428 if ( !mScalebar )
429 {
430 return;
431 }
432 mScalebar->beginCommand( tr( "Set Scalebar Height" ), QgsLayoutItem::UndoScaleBarHeight );
433 disconnectUpdateSignal();
434 mScalebar->setHeight( d );
435 mScalebar->update();
436 connectUpdateSignal();
437 mScalebar->endCommand();
438}
439
440void QgsLayoutScaleBarWidget::mNumberOfSubdivisionsSpinBox_valueChanged( int i )
441{
442 if ( !mScalebar )
443 {
444 return;
445 }
446
447 mScalebar->beginCommand( tr( "Set Scalebar Subdivisions" ), QgsLayoutItem::UndoScaleBarSubdivisions );
448 disconnectUpdateSignal();
449 mScalebar->setNumberOfSubdivisions( i );
450 mScalebar->update();
451 connectUpdateSignal();
452 mScalebar->endCommand();
453}
454
455void QgsLayoutScaleBarWidget::mSubdivisionsHeightSpinBox_valueChanged( double d )
456{
457 if ( !mScalebar )
458 {
459 return;
460 }
461 mScalebar->beginCommand( tr( "Set Subdivisions Height" ), QgsLayoutItem::UndoScaleBarSubdivisionsHeight );
462 disconnectUpdateSignal();
463 mScalebar->setSubdivisionsHeight( d );
464 mScalebar->update();
465 connectUpdateSignal();
466 mScalebar->endCommand();
467}
468
469void QgsLayoutScaleBarWidget::textFormatChanged()
470{
471 if ( !mScalebar )
472 {
473 return;
474 }
475
476 mScalebar->beginCommand( tr( "Set Scalebar Font" ) );
477 disconnectUpdateSignal();
478 mScalebar->setTextFormat( mFontButton->textFormat() );
479 connectUpdateSignal();
480 mScalebar->endCommand();
481 mScalebar->update();
482}
483
484void QgsLayoutScaleBarWidget::changeNumberFormat()
485{
486 if ( !mScalebar )
487 {
488 return;
489 }
490
492 widget->setPanelTitle( tr( "Number Format" ) );
493 widget->setFormat( mScalebar->numericFormat() );
494 connect( widget, &QgsNumericFormatSelectorWidget::changed, this, [ = ]
495 {
496 mScalebar->beginCommand( tr( "Set Scalebar Number Format" ) );
497 disconnectUpdateSignal();
498 mScalebar->setNumericFormat( widget->format() );
499 connectUpdateSignal();
500 mScalebar->endCommand();
501 mScalebar->update();
502 } );
503 openPanel( widget );
504 return;
505}
506
507QgsLayoutScaleBarWidget::DistanceLabelPlacement QgsLayoutScaleBarWidget::distanceLabelPlacement( Qgis::ScaleBarDistanceLabelHorizontalPlacement horizontalPlacement, Qgis::ScaleBarDistanceLabelVerticalPlacement verticalPlacement )
508{
509 switch ( horizontalPlacement )
510 {
512 switch ( verticalPlacement )
513 {
515 return DistanceLabelPlacement::CenteredAboveSegmentEdges;
517 return DistanceLabelPlacement::CenteredBelowSegmentEdges;
518 }
520
522 switch ( verticalPlacement )
523 {
525 return DistanceLabelPlacement::CenteredAboveSegmentCenters;
527 return DistanceLabelPlacement::CenteredBelowSegmentCenters;
528 }
530 }
532}
533
534void QgsLayoutScaleBarWidget::mUnitLabelLineEdit_textChanged( const QString &text )
535{
536 if ( !mScalebar )
537 {
538 return;
539 }
540
541 mScalebar->beginCommand( tr( "Set Scalebar Unit Text" ), QgsLayoutItem::UndoScaleBarUnitText );
542 disconnectUpdateSignal();
543 mScalebar->setUnitLabel( text );
544 mScalebar->update();
545 connectUpdateSignal();
546 mScalebar->endCommand();
547}
548
549void QgsLayoutScaleBarWidget::mMapUnitsPerBarUnitSpinBox_valueChanged( double d )
550{
551 if ( !mScalebar )
552 {
553 return;
554 }
555
556 mScalebar->beginCommand( tr( "Set Scalebar Map Units per Segment" ), QgsLayoutItem::UndoScaleBarMapUnitsSegment );
557 disconnectUpdateSignal();
558 mScalebar->setMapUnitsPerScaleBarUnit( d );
559 mScalebar->update();
560 connectUpdateSignal();
561 mScalebar->endCommand();
562}
563
564void QgsLayoutScaleBarWidget::mStyleComboBox_currentIndexChanged( const QString & )
565{
566 if ( !mScalebar )
567 {
568 return;
569 }
570
571 const QString rendererId = mStyleComboBox->currentData().toString();
572 if ( rendererId == mScalebar->style() )
573 return;
574
575 mScalebar->beginCommand( tr( "Set Scalebar Style" ) );
576 disconnectUpdateSignal();
577
578 bool defaultsApplied = false;
579 const std::unique_ptr< QgsScaleBarRenderer > renderer( QgsApplication::scaleBarRendererRegistry()->renderer( rendererId ) );
580 if ( renderer )
581 defaultsApplied = mScalebar->applyDefaultRendererSettings( renderer.get() );
582
583 //disable or enable controls which apply to specific scale bar styles
584 toggleStyleSpecificControls( rendererId );
585
586 mScalebar->setStyle( rendererId );
587 mScalebar->update();
588 connectUpdateSignal();
589 mScalebar->endCommand();
590
591 if ( defaultsApplied )
592 setGuiElements();
593}
594
595void QgsLayoutScaleBarWidget::toggleStyleSpecificControls( const QString &style )
596{
597 std::unique_ptr< QgsScaleBarRenderer > renderer( QgsApplication::scaleBarRendererRegistry()->renderer( style ) );
598
599 //Selectively enable controls which apply to the scale bar style
600 mUnitsComboBox->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagRespectsUnits : true );
601 mUnitsLabel->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagRespectsUnits : true );
602 mMapUnitsPerBarUnitSpinBox->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagRespectsMapUnitsPerScaleBarUnit : true );
603 mMapUnitsPerBarUnitLabel->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagRespectsMapUnitsPerScaleBarUnit : true );
604 mUnitLabelLineEdit->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesUnitLabel : true );
605 mUnitLabelLabel->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesUnitLabel : true );
606 mSubdivisionsLabel->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesSubdivisions : true );
607 mNumberOfSubdivisionsSpinBox->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesSubdivisions : true );
608 mSubdivisionsHeightLabel->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesSubdivisionsHeight : true );
609 mSubdivisionsHeightSpinBox->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesSubdivisionsHeight : true );
610 mGroupBoxSegments->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesSegments : true );
611 if ( !mGroupBoxUnits->isEnabled() )
612 mGroupBoxSegments->setCollapsed( true );
613 mLabelBarSpaceSpinBox->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesLabelBarSpace : true );
614 mLabelBarSpaceLabel->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesLabelBarSpace : true );
615 mDistanceLabelPlacementComboBox->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesLabelVerticalPlacement : true );
616 mLabelVerticalPlacementLabel->setEnabled( renderer ? ( renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesLabelHorizontalPlacement
617 || renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesLabelVerticalPlacement ) : true );
618 mAlignmentComboBox->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesAlignment : true );
619 mAlignmentLabel->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesAlignment : true );
620 mFillSymbol1Button->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesFillSymbol : true );
621 mFillSymbol1Label->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesFillSymbol : true );
622 mFillSymbol2Button->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesAlternateFillSymbol : true );
623 mFillSymbol2Label->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesAlternateFillSymbol : true );
624 mLineStyleButton->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesLineSymbol : true );
625 mLineStyleLabel->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesLineSymbol : true );
626 mDivisionStyleButton->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesDivisionSymbol : true );
627 mDivisionStyleLabel->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesDivisionSymbol : true );
628 mSubdivisionStyleButton->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesSubdivisionSymbol : true );
629 mSubdivisionStyleLabel->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesSubdivisionSymbol : true );
630}
631
632void QgsLayoutScaleBarWidget::mLabelBarSpaceSpinBox_valueChanged( double d )
633{
634 if ( !mScalebar )
635 {
636 return;
637 }
638
639 mScalebar->beginCommand( tr( "Set Scalebar Label Space" ), QgsLayoutItem::UndoScaleBarLabelBarSize );
640 disconnectUpdateSignal();
641 mScalebar->setLabelBarSpace( d );
642 mScalebar->update();
643 connectUpdateSignal();
644 mScalebar->endCommand();
645}
646
647void QgsLayoutScaleBarWidget::mBoxSizeSpinBox_valueChanged( double d )
648{
649 if ( !mScalebar )
650 {
651 return;
652 }
653
654 mScalebar->beginCommand( tr( "Set Scalebar Box Space" ), QgsLayoutItem::UndoScaleBarBoxContentSpace );
655 disconnectUpdateSignal();
656 mScalebar->setBoxContentSpace( d );
657 mScalebar->update();
658 connectUpdateSignal();
659 mScalebar->endCommand();
660}
661
662void QgsLayoutScaleBarWidget::mDistanceLabelPlacementComboBox_currentIndexChanged( int index )
663{
664 if ( !mScalebar )
665 {
666 return;
667 }
668
669 mScalebar->beginCommand( tr( "Set Scalebar Label Placement" ) );
670 disconnectUpdateSignal();
671
672 const DistanceLabelPlacement placement = static_cast<DistanceLabelPlacement>( mDistanceLabelPlacementComboBox->itemData( index ).toInt() );
673 switch ( placement )
674 {
675 case DistanceLabelPlacement::CenteredAboveSegmentEdges:
676 mScalebar->setLabelVerticalPlacement( Qgis::ScaleBarDistanceLabelVerticalPlacement::AboveSegment );
677 mScalebar->setLabelHorizontalPlacement( Qgis::ScaleBarDistanceLabelHorizontalPlacement::CenteredEdge );
678 break;
679 case DistanceLabelPlacement::CenteredAboveSegmentCenters:
680 mScalebar->setLabelVerticalPlacement( Qgis::ScaleBarDistanceLabelVerticalPlacement::AboveSegment );
681 mScalebar->setLabelHorizontalPlacement( Qgis::ScaleBarDistanceLabelHorizontalPlacement::CenteredSegment );
682 break;
683 case DistanceLabelPlacement::CenteredBelowSegmentEdges:
684 mScalebar->setLabelVerticalPlacement( Qgis::ScaleBarDistanceLabelVerticalPlacement::BelowSegment );
685 mScalebar->setLabelHorizontalPlacement( Qgis::ScaleBarDistanceLabelHorizontalPlacement::CenteredEdge );
686 break;
687 case DistanceLabelPlacement::CenteredBelowSegmentCenters:
688 mScalebar->setLabelVerticalPlacement( Qgis::ScaleBarDistanceLabelVerticalPlacement::BelowSegment );
689 mScalebar->setLabelHorizontalPlacement( Qgis::ScaleBarDistanceLabelHorizontalPlacement::CenteredSegment );
690 break;
691 }
692
693 mScalebar->update();
694 connectUpdateSignal();
695 mScalebar->endCommand();
696}
697
698void QgsLayoutScaleBarWidget::alignmentChanged()
699{
700 if ( !mScalebar )
701 {
702 return;
703 }
704
705 mScalebar->beginCommand( tr( "Set Scalebar Alignment" ) );
706 disconnectUpdateSignal();
707
708 const Qgis::ScaleBarAlignment a = mAlignmentComboBox->currentAlignment() & Qt::AlignLeft ? Qgis::ScaleBarAlignment::Left
709 : mAlignmentComboBox->currentAlignment() & Qt::AlignRight ? Qgis::ScaleBarAlignment::Right : Qgis::ScaleBarAlignment::Middle;
710 mScalebar->setAlignment( a );
711 mScalebar->update();
712 connectUpdateSignal();
713 mScalebar->endCommand();
714}
715
716void QgsLayoutScaleBarWidget::mUnitsComboBox_currentIndexChanged( int index )
717{
718 if ( !mScalebar )
719 {
720 return;
721 }
722
723 const QVariant unitData = mUnitsComboBox->itemData( index );
724 if ( unitData.userType() == QMetaType::Type::UnknownType )
725 {
726 return;
727 }
728
729 disconnectUpdateSignal();
730 mScalebar->beginCommand( tr( "Set Scalebar Units" ) );
731 mScalebar->applyDefaultSize( static_cast< Qgis::DistanceUnit >( unitData.toInt() ) );
732 mScalebar->update();
733
734 mNumberOfSegmentsSpinBox->setValue( mScalebar->numberOfSegments() );
735 mSegmentsLeftSpinBox->setValue( mScalebar->numberOfSegmentsLeft() );
736 mUnitLabelLineEdit->setText( mScalebar->unitLabel() );
737 mSegmentSizeSpinBox->setValue( mScalebar->unitsPerSegment() );
738 mMapUnitsPerBarUnitSpinBox->setValue( mScalebar->mapUnitsPerScaleBarUnit() );
739
740 connectUpdateSignal();
741 mScalebar->endCommand();
742}
743
744void QgsLayoutScaleBarWidget::blockMemberSignals( bool block )
745{
746 mSegmentSizeSpinBox->blockSignals( block );
747 mNumberOfSegmentsSpinBox->blockSignals( block );
748 mSegmentsLeftSpinBox->blockSignals( block );
749 mNumberOfSubdivisionsSpinBox->blockSignals( block );
750 mSubdivisionsHeightSpinBox->blockSignals( block );
751 mStyleComboBox->blockSignals( block );
752 mUnitLabelLineEdit->blockSignals( block );
753 mMapUnitsPerBarUnitSpinBox->blockSignals( block );
754 mHeightSpinBox->blockSignals( block );
755 mLineStyleButton->blockSignals( block );
756 mDivisionStyleButton->blockSignals( block );
757 mSubdivisionStyleButton->blockSignals( block );
758 mLabelBarSpaceSpinBox->blockSignals( block );
759 mBoxSizeSpinBox->blockSignals( block );
760 mDistanceLabelPlacementComboBox->blockSignals( block );
761 mAlignmentComboBox->blockSignals( block );
762 mUnitsComboBox->blockSignals( block );
763 mFillSymbol1Button->blockSignals( block );
764 mFillSymbol2Button->blockSignals( block );
765 mSegmentSizeRadioGroup.blockSignals( block );
766 mMapItemComboBox->blockSignals( block );
767 mFontButton->blockSignals( block );
768 mMinWidthSpinBox->blockSignals( block );
769 mMaxWidthSpinBox->blockSignals( block );
770 mMethodCombo->blockSignals( block );
771}
772
773void QgsLayoutScaleBarWidget::connectUpdateSignal()
774{
775 if ( mScalebar )
776 {
777 connect( mScalebar, &QgsLayoutObject::changed, this, &QgsLayoutScaleBarWidget::setGuiElements );
778 }
779}
780
781void QgsLayoutScaleBarWidget::disconnectUpdateSignal()
782{
783 if ( mScalebar )
784 {
785 disconnect( mScalebar, &QgsLayoutObject::changed, this, &QgsLayoutScaleBarWidget::setGuiElements );
786 }
787}
788
789void QgsLayoutScaleBarWidget::segmentSizeRadioChanged( QAbstractButton *radio )
790{
791 const bool fixedSizeMode = radio == mFixedSizeRadio;
792 mMinWidthWidget->setEnabled( !fixedSizeMode );
793 mMaxWidthWidget->setEnabled( !fixedSizeMode );
794 mSegmentSizeWidget->setEnabled( fixedSizeMode );
795
796 if ( !mScalebar )
797 {
798 return;
799 }
800
801 mScalebar->beginCommand( tr( "Set Scalebar Size Mode" ), QgsLayoutItem::UndoScaleBarSegmentSize );
802 disconnectUpdateSignal();
803 if ( mFixedSizeRadio->isChecked() )
804 {
805 mScalebar->setSegmentSizeMode( Qgis::ScaleBarSegmentSizeMode::Fixed );
806 mScalebar->setUnitsPerSegment( mSegmentSizeSpinBox->value() );
807 }
808 else /*if(mFitWidthRadio->isChecked())*/
809 {
810 mScalebar->setSegmentSizeMode( Qgis::ScaleBarSegmentSizeMode::FitWidth );
811 }
812 mScalebar->update();
813 connectUpdateSignal();
814 mScalebar->endCommand();
815}
816
817void QgsLayoutScaleBarWidget::mapChanged( QgsLayoutItem *item )
818{
819 QgsLayoutItemMap *map = qobject_cast< QgsLayoutItemMap * >( item );
820 if ( !map )
821 {
822 return;
823 }
824
825 //set it to scale bar
826 mScalebar->beginCommand( tr( "Set Scalebar Map" ) );
827 disconnectUpdateSignal();
828 mScalebar->setLinkedMap( map );
829 mScalebar->update();
830 connectUpdateSignal();
831 mScalebar->endCommand();
832}
833
834void QgsLayoutScaleBarWidget::mMinWidthSpinBox_valueChanged( double )
835{
836 if ( !mScalebar )
837 {
838 return;
839 }
840
841 mScalebar->beginCommand( tr( "Set Scalebar Size Mode" ), QgsLayoutItem::UndoScaleBarSegmentSize );
842 disconnectUpdateSignal();
843 mScalebar->setMinimumBarWidth( mMinWidthSpinBox->value() );
844 mScalebar->update();
845 connectUpdateSignal();
846 mScalebar->endCommand();
847}
848
849void QgsLayoutScaleBarWidget::mMaxWidthSpinBox_valueChanged( double )
850{
851 if ( !mScalebar )
852 {
853 return;
854 }
855
856 mScalebar->beginCommand( tr( "Set Scalebar Size Mode" ), QgsLayoutItem::UndoScaleBarSegmentSize );
857 disconnectUpdateSignal();
858 mScalebar->setMaximumBarWidth( mMaxWidthSpinBox->value() );
859 mScalebar->update();
860 connectUpdateSignal();
861 mScalebar->endCommand();
862}
863
864void QgsLayoutScaleBarWidget::populateDataDefinedButtons()
865{
866 updateDataDefinedButton( mSegmentsLeftDDBtn );
867 updateDataDefinedButton( mSegmentsRightDDBtn );
868 updateDataDefinedButton( mSegmentSizeDDBtn );
869 updateDataDefinedButton( mMinWidthDDBtn );
870 updateDataDefinedButton( mMaxWidthDDBtn );
871 updateDataDefinedButton( mHeightDDBtn );
872 updateDataDefinedButton( mSubdivisionHeightDDBtn );
873 updateDataDefinedButton( mRightSegmentSubdivisionsDDBtn );
874}
ScaleBarDistanceLabelHorizontalPlacement
Scale bar distance label horizontal placement.
Definition qgis.h:4965
@ CenteredSegment
Labels are drawn centered relative to segment.
@ CenteredEdge
Labels are drawn centered relative to segment's edge.
ScaleBarDistanceLabelVerticalPlacement
Scale bar distance label vertical placement.
Definition qgis.h:4951
@ AboveSegment
Labels are drawn above the scalebar.
@ BelowSegment
Labels are drawn below the scalebar.
ScaleBarAlignment
Scalebar alignment.
Definition qgis.h:4922
@ Right
Right aligned.
@ Middle
Center aligned.
DistanceUnit
Units of distance.
Definition qgis.h:4669
@ Feet
Imperial feet.
@ Centimeters
Centimeters.
@ Millimeters
Millimeters.
@ Miles
Terrestrial miles.
@ Unknown
Unknown distance unit.
@ Yards
Imperial yards.
@ NauticalMiles
Nautical miles.
@ Kilometers
Kilometers.
ScaleCalculationMethod
Scale calculation logic.
Definition qgis.h:4906
@ HorizontalTop
Calculate horizontally, across top of map.
@ HorizontalMiddle
Calculate horizontally, across midle of map.
@ HorizontalAverage
Calculate horizontally, using the average of the top, middle and bottom scales.
@ HorizontalBottom
Calculate horizontally, across bottom of map.
@ FitWidth
Scale bar segment size is calculated to fit a size range.
@ Fixed
Scale bar segment size is fixed to a map unit.
@ Line
Line symbol.
@ Fill
Fill symbol.
void changed()
Emitted when the alignment is changed.
static QgsScaleBarRendererRegistry * scaleBarRendererRegistry()
Gets the registry of available scalebar renderers.
Single scope for storing variables and functions for use within a QgsExpressionContext.
void addVariable(const QgsExpressionContextScope::StaticVariable &variable)
Adds a variable into the context scope.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
void setHighlightedVariables(const QStringList &variableNames)
Sets the list of variable names within the context intended to be highlighted to the user.
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
@ ModeTextRenderer
Configure font settings for use with QgsTextRenderer.
void setLayer(QgsVectorLayer *layer)
Sets a layer to associate with the widget.
void changed()
Emitted when the widget's text format settings are changed.
A base class for property widgets for layout items.
void updateDataDefinedButton(QgsPropertyOverrideButton *button)
Updates a previously registered data defined button to reflect the item's current properties.
QgsVectorLayer * coverageLayer() const
Returns the current layout context coverage layer (if set).
void registerDataDefinedButton(QgsPropertyOverrideButton *button, QgsLayoutObject::DataDefinedProperty property)
Registers a data defined button, setting up its initial value, connections and description.
void itemChanged(QgsLayoutItem *item)
Emitted whenever the currently selected item changes.
Layout graphical items for displaying a map.
A widget for controlling the common properties of layout items (e.g.
void setMasterLayout(QgsMasterLayoutInterface *masterLayout)
Sets the master layout associated with the item.
void setItem(QgsLayoutItem *item)
Sets the layout item.
A layout item subclass for scale bars.
Base class for graphical items within a QgsLayout.
@ UndoScaleBarSubdivisionsHeight
Scalebar subdivisions height.
@ UndoScaleBarLabelBarSize
Scalebar label bar size.
@ UndoScaleBarMapUnitsSegment
Scalebar map units per segment.
@ UndoScaleBarBoxContentSpace
Scalebar box context space.
@ UndoScaleBarSegmentSize
Scalebar segment size.
@ UndoScaleBarHeight
Scalebar height.
@ UndoScaleBarSegments
Scalebar number of segments.
@ UndoScaleBarSubdivisions
Scalebar number of subdivisions.
@ UndoShapeStyle
Shape symbol style.
@ UndoScaleBarSegmentsLeft
Scalebar segments left.
@ UndoScaleBarUnitText
Scalebar unit text.
int type() const override
Returns a unique graphics item type identifier.
void changed()
Emitted when the object's properties change.
@ ScalebarMinimumWidth
Scalebar segment minimum width.
@ ScalebarRightSegments
Number of segments on the right of 0.
@ ScalebarRightSegmentSubdivisions
Number of subdivisions per segment on right of 0.
@ ScalebarMaximumWidth
Scalebar segment maximum width.
@ ScalebarSubdivisionHeight
Scalebar subdivision height.
@ ScalebarLeftSegments
Number of segments on the left of 0.
@ ScalebarSegmentWidth
Scalebar width in map units of a single segment.
void layerChanged(QgsVectorLayer *layer)
Emitted when the context's layer is changed.
bool setNewItem(QgsLayoutItem *item) override
Attempts to update the widget to show the properties for the specified item.
QgsLayoutScaleBarWidget(QgsLayoutItemScaleBar *scaleBar)
constructor
QgsExpressionContext createExpressionContext() const override
This method needs to be reimplemented in all classes which implement this interface and return an exp...
void setMasterLayout(QgsMasterLayoutInterface *masterLayout) override
Sets the master layout associated with the item.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition qgslayout.h:49
A line symbol type, for rendering LineString and MultiLineString geometries.
Interface for master layout type objects, such as print layouts and reports.
A widget which allows choice of numeric formats and the properties of them.
QgsNumericFormat * format() const
Returns a new format object representing the settings currently configured in the widget.
void changed()
Emitted whenever the format configured55 in the widget is changed.
void setFormat(const QgsNumericFormat *format)
Sets the format to show in the widget.
void openPanel(QgsPanelWidget *panel)
Open a panel or dialog depending on dock mode setting If dock mode is true this method will emit the ...
void setPanelTitle(const QString &panelTitle)
Set the title of the panel when shown in the interface.
QStringList sortedRendererList() const
Returns a list of the renderer ids currently contained in the registry, sorted in an order respecting...
QString visibleName(const QString &id) const
Returns the translated, user-visible name for the renderer with matching id.
@ FlagUsesLabelVerticalPlacement
Renderer uses the QgsScaleBarSettings::labelVerticalPlacement() setting.
@ FlagUsesLabelHorizontalPlacement
Renderer uses the QgsScaleBarSettings::labelHorizontalPlacement() setting.
@ FlagUsesLineSymbol
Renderer utilizes the scalebar line symbol (see QgsScaleBarSettings::lineSymbol() )
@ FlagUsesUnitLabel
Renderer uses the QgsScaleBarSettings::unitLabel() setting.
@ FlagUsesSubdivisionsHeight
Renderer uses the scalebar subdivisions height (see QgsScaleBarSettings::subdivisionsHeight() )
@ FlagUsesSubdivisionSymbol
Renderer utilizes the scalebar subdivision symbol (see QgsScaleBarSettings::subdivisionLineSymbol() )
@ FlagUsesSegments
Renderer uses the scalebar segments.
@ FlagUsesLabelBarSpace
Renderer uses the QgsScaleBarSettings::labelBarSpace() setting.
@ FlagUsesAlignment
Renderer uses the QgsScaleBarSettings::alignment() setting.
@ FlagUsesFillSymbol
Renderer utilizes the scalebar fill symbol (see QgsScaleBarSettings::fillSymbol() )
@ FlagRespectsMapUnitsPerScaleBarUnit
Renderer respects the QgsScaleBarSettings::mapUnitsPerScaleBarUnit() setting.
@ FlagRespectsUnits
Renderer respects the QgsScaleBarSettings::units() setting.
@ FlagUsesAlternateFillSymbol
Renderer utilizes the alternate scalebar fill symbol (see QgsScaleBarSettings::alternateFillSymbol() ...
@ FlagUsesSubdivisions
Renderer uses the scalebar subdivisions (see QgsScaleBarSettings::numberOfSubdivisions() )
@ FlagUsesDivisionSymbol
Renderer utilizes the scalebar division symbol (see QgsScaleBarSettings::divisionLineSymbol() )
void setLayer(QgsVectorLayer *layer)
Sets a layer to associate with the widget.
void changed()
Emitted when the symbol's settings are changed.
#define BUILTIN_UNREACHABLE
Definition qgis.h:6571
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
Definition qgis.h:5821
Single variable definition for use within a QgsExpressionContextScope.