QGIS API Documentation 3.40.0-Bratislava (b56115d8743)
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 "qgslayoutitemmap.h"
21#include "qgslayout.h"
23#include "qgslayoutundostack.h"
24#include "qgsfillsymbol.h"
25#include "qgslinesymbol.h"
27#include "qgsvectorlayer.h"
28
29#include <QColorDialog>
30#include <QFontDialog>
31#include <QWidget>
32
34 : QgsLayoutItemBaseWidget( nullptr, scaleBar )
35 , mScalebar( scaleBar )
36{
37 setupUi( this );
38
39 mNumberOfSubdivisionsSpinBox->setClearValue( 1 );
40
41 connect( mHeightSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutScaleBarWidget::mHeightSpinBox_valueChanged );
42 connect( mSegmentSizeSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutScaleBarWidget::mSegmentSizeSpinBox_valueChanged );
43 connect( mSegmentsLeftSpinBox, static_cast < void ( QSpinBox::* )( int ) > ( &QSpinBox::valueChanged ), this, &QgsLayoutScaleBarWidget::mSegmentsLeftSpinBox_valueChanged );
44 connect( mNumberOfSegmentsSpinBox, static_cast < void ( QSpinBox::* )( int ) > ( &QSpinBox::valueChanged ), this, &QgsLayoutScaleBarWidget::mNumberOfSegmentsSpinBox_valueChanged );
45 connect( mNumberOfSubdivisionsSpinBox, static_cast < void ( QSpinBox::* )( int ) > ( &QSpinBox::valueChanged ), this, &QgsLayoutScaleBarWidget::mNumberOfSubdivisionsSpinBox_valueChanged );
46 connect( mSubdivisionsHeightSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutScaleBarWidget::mSubdivisionsHeightSpinBox_valueChanged );
47 connect( mUnitLabelLineEdit, &QLineEdit::textChanged, this, &QgsLayoutScaleBarWidget::mUnitLabelLineEdit_textChanged );
48 connect( mMapUnitsPerBarUnitSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutScaleBarWidget::mMapUnitsPerBarUnitSpinBox_valueChanged );
49 connect( mStyleComboBox, &QComboBox::currentTextChanged, this, &QgsLayoutScaleBarWidget::mStyleComboBox_currentIndexChanged );
50 connect( mLabelBarSpaceSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutScaleBarWidget::mLabelBarSpaceSpinBox_valueChanged );
51 connect( mBoxSizeSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutScaleBarWidget::mBoxSizeSpinBox_valueChanged );
52 connect( mAlignmentComboBox, &QgsAlignmentComboBox::changed, this, &QgsLayoutScaleBarWidget::alignmentChanged );
53 connect( mDistanceLabelPlacementComboBox, qOverload<int>( &QComboBox::currentIndexChanged ), this, &QgsLayoutScaleBarWidget::mDistanceLabelPlacementComboBox_currentIndexChanged );
54 connect( mUnitsComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsLayoutScaleBarWidget::mUnitsComboBox_currentIndexChanged );
55 connect( mMinWidthSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutScaleBarWidget::mMinWidthSpinBox_valueChanged );
56 connect( mMaxWidthSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutScaleBarWidget::mMaxWidthSpinBox_valueChanged );
57 connect( mNumberFormatPushButton, &QPushButton::clicked, this, &QgsLayoutScaleBarWidget::changeNumberFormat );
58 connect( mMethodCombo, qOverload<int>( &QComboBox::currentIndexChanged ), this, [ = ]
59 {
60 if ( !mScalebar )
61 {
62 return;
63 }
64
65 disconnectUpdateSignal();
66 mScalebar->beginCommand( tr( "Set Scalebar Method" ) );
67 mScalebar->setMethod( mMethodCombo->currentData().value< Qgis::ScaleCalculationMethod >() );
68 mScalebar->update();
69 connectUpdateSignal();
70 mScalebar->endCommand();
71 } );
72
81
82 mSegmentsLeftDDBtn->registerEnabledWidget( mSegmentsLeftSpinBox, false );
83 mSegmentsRightDDBtn->registerEnabledWidget( mNumberOfSegmentsSpinBox, false );
84 mSegmentSizeDDBtn->registerEnabledWidget( mSegmentSizeSpinBox, false );
85 mMinWidthDDBtn->registerEnabledWidget( mMinWidthSpinBox, false );
86 mMaxWidthDDBtn->registerEnabledWidget( mMaxWidthSpinBox, false );
87
88 setPanelTitle( tr( "Scalebar Properties" ) );
89
90 mFontButton->registerExpressionContextGenerator( this );
91
92 connectUpdateSignal();
93
94 //add widget for general composer item properties
95 mItemPropertiesWidget = new QgsLayoutItemPropertiesWidget( this, scaleBar );
96 mainLayout->addWidget( mItemPropertiesWidget );
97
98 mSegmentSizeRadioGroup.addButton( mFixedSizeRadio );
99 mSegmentSizeRadioGroup.addButton( mFitWidthRadio );
100 connect( &mSegmentSizeRadioGroup, static_cast < void ( QButtonGroup::* )( QAbstractButton * ) > ( &QButtonGroup::buttonClicked ), this, &QgsLayoutScaleBarWidget::segmentSizeRadioChanged );
101
102 blockMemberSignals( true );
103
104 //style combo box
105 const QStringList renderers = QgsApplication::scaleBarRendererRegistry()->sortedRendererList();
106 for ( const QString &renderer : renderers )
107 {
108 mStyleComboBox->addItem( QgsApplication::scaleBarRendererRegistry()->visibleName( renderer ), renderer );
109 }
110
111 //label vertical/horizontal placement combo box
112 mDistanceLabelPlacementComboBox->addItem( tr( "Above Segment Edges" ), static_cast< int >( DistanceLabelPlacement::CenteredAboveSegmentEdges ) );
113 mDistanceLabelPlacementComboBox->addItem( tr( "Above Segment Centers" ), static_cast< int >( DistanceLabelPlacement::CenteredAboveSegmentCenters ) );
114 mDistanceLabelPlacementComboBox->addItem( tr( "Below Segment Edges" ), static_cast< int >( DistanceLabelPlacement::CenteredBelowSegmentEdges ) );
115 mDistanceLabelPlacementComboBox->addItem( tr( "Below Segment Centers" ), static_cast< int >( DistanceLabelPlacement::CenteredBelowSegmentCenters ) );
116
117 //alignment combo box
118 mAlignmentComboBox->setAvailableAlignments( Qt::AlignLeft | Qt::AlignHCenter | Qt::AlignRight );
119
120 //units combo box
121 mUnitsComboBox->addItem( tr( "Map units" ), static_cast< int >( Qgis::DistanceUnit::Unknown ) );
122 mUnitsComboBox->addItem( tr( "Meters" ), static_cast< int >( Qgis::DistanceUnit::Meters ) );
123 mUnitsComboBox->addItem( tr( "Kilometers" ), static_cast< int >( Qgis::DistanceUnit::Kilometers ) );
124 mUnitsComboBox->addItem( tr( "Feet" ), static_cast< int >( Qgis::DistanceUnit::Feet ) );
125 mUnitsComboBox->addItem( tr( "Yards" ), static_cast< int >( Qgis::DistanceUnit::Yards ) );
126 mUnitsComboBox->addItem( tr( "Miles" ), static_cast< int >( Qgis::DistanceUnit::Miles ) );
127 mUnitsComboBox->addItem( tr( "Nautical Miles" ), static_cast< int >( Qgis::DistanceUnit::NauticalMiles ) );
128 mUnitsComboBox->addItem( tr( "Centimeters" ), static_cast< int >( Qgis::DistanceUnit::Centimeters ) );
129 mUnitsComboBox->addItem( tr( "Millimeters" ), static_cast< int >( Qgis::DistanceUnit::Millimeters ) );
130 mUnitsComboBox->addItem( tr( "Inches" ), static_cast< int >( Qgis::DistanceUnit::Inches ) );
131
132 mMethodCombo->addItem( tr( "Average Top, Middle and Bottom Scales" ), QVariant::fromValue( Qgis::ScaleCalculationMethod::HorizontalAverage ) );
133 mMethodCombo->addItem( tr( "Calculate along Top of Map" ), QVariant::fromValue( Qgis::ScaleCalculationMethod::HorizontalTop ) );
134 mMethodCombo->addItem( tr( "Calculate along Middle of Map" ), QVariant::fromValue( Qgis::ScaleCalculationMethod::HorizontalMiddle ) );
135 mMethodCombo->addItem( tr( "Calculate along Bottom of Map" ), QVariant::fromValue( Qgis::ScaleCalculationMethod::HorizontalBottom ) );
136
137 mLineStyleButton->setSymbolType( Qgis::SymbolType::Line );
138 connect( mLineStyleButton, &QgsSymbolButton::changed, this, &QgsLayoutScaleBarWidget::lineSymbolChanged );
139
140 mDivisionStyleButton->setSymbolType( Qgis::SymbolType::Line );
141 connect( mDivisionStyleButton, &QgsSymbolButton::changed, this, &QgsLayoutScaleBarWidget::divisionSymbolChanged );
142
143 mSubdivisionStyleButton->setSymbolType( Qgis::SymbolType::Line );
144 connect( mSubdivisionStyleButton, &QgsSymbolButton::changed, this, &QgsLayoutScaleBarWidget::subdivisionSymbolChanged );
145
146 mFillSymbol1Button->setSymbolType( Qgis::SymbolType::Fill );
147 connect( mFillSymbol1Button, &QgsSymbolButton::changed, this, &QgsLayoutScaleBarWidget::fillSymbol1Changed );
148
149 mFillSymbol2Button->setSymbolType( Qgis::SymbolType::Fill );
150 connect( mFillSymbol2Button, &QgsSymbolButton::changed, this, &QgsLayoutScaleBarWidget::fillSymbol2Changed );
151
152 mFontButton->setDialogTitle( tr( "Scalebar Font" ) );
153 mFontButton->setMode( QgsFontButton::ModeTextRenderer );
154
155 if ( mScalebar )
156 {
157 QgsLayout *scaleBarLayout = mScalebar->layout();
158 if ( scaleBarLayout )
159 {
160 mMapItemComboBox->setCurrentLayout( scaleBarLayout );
161 mMapItemComboBox->setItemType( QgsLayoutItemRegistry::LayoutMap );
162 }
163 }
164
165 connect( mMapItemComboBox, &QgsLayoutItemComboBox::itemChanged, this, &QgsLayoutScaleBarWidget::mapChanged );
166
167 blockMemberSignals( false );
168 setGuiElements(); //set the GUI elements to the state of scaleBar
169
170 mLineStyleButton->registerExpressionContextGenerator( mScalebar );
171 mLineStyleButton->setLayer( coverageLayer() );
172 mDivisionStyleButton->registerExpressionContextGenerator( mScalebar );
173 mDivisionStyleButton->setLayer( coverageLayer() );
174 mSubdivisionStyleButton->registerExpressionContextGenerator( mScalebar );
175 mSubdivisionStyleButton->setLayer( coverageLayer() );
176 mFillSymbol1Button->registerExpressionContextGenerator( mScalebar );
177 mFillSymbol1Button->setLayer( coverageLayer() );
178 mFillSymbol2Button->registerExpressionContextGenerator( mScalebar );
179 mFillSymbol2Button->setLayer( coverageLayer() );
180
181 connect( mFontButton, &QgsFontButton::changed, this, &QgsLayoutScaleBarWidget::textFormatChanged );
182 mFontButton->setLayer( coverageLayer() );
183 if ( mScalebar->layout() )
184 {
185 connect( &mScalebar->layout()->reportContext(), &QgsLayoutReportContext::layerChanged, mFontButton, &QgsFontButton::setLayer );
186 connect( &mScalebar->layout()->reportContext(), &QgsLayoutReportContext::layerChanged, mLineStyleButton, &QgsSymbolButton::setLayer );
187 connect( &mScalebar->layout()->reportContext(), &QgsLayoutReportContext::layerChanged, mDivisionStyleButton, &QgsSymbolButton::setLayer );
188 connect( &mScalebar->layout()->reportContext(), &QgsLayoutReportContext::layerChanged, mSubdivisionStyleButton, &QgsSymbolButton::setLayer );
189 connect( &mScalebar->layout()->reportContext(), &QgsLayoutReportContext::layerChanged, mFillSymbol1Button, &QgsSymbolButton::setLayer );
190 connect( &mScalebar->layout()->reportContext(), &QgsLayoutReportContext::layerChanged, mFillSymbol2Button, &QgsSymbolButton::setLayer );
191 }
192}
193
195{
196 if ( mItemPropertiesWidget )
197 mItemPropertiesWidget->setMasterLayout( masterLayout );
198}
199
201{
202 QgsExpressionContext context = mScalebar->createExpressionContext();
203 QgsExpressionContextScope *scaleScope = new QgsExpressionContextScope( QStringLiteral( "scalebar_text" ) );
204 scaleScope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "scale_value" ), 0, true, false ) );
205 context.appendScope( scaleScope );
206 context.setHighlightedVariables( QStringList() << QStringLiteral( "scale_value" ) );
207 return context;
208}
209
211{
213 return false;
214
215 disconnectUpdateSignal();
216
217 mScalebar = qobject_cast< QgsLayoutItemScaleBar * >( item );
218 mItemPropertiesWidget->setItem( mScalebar );
219
220 if ( mScalebar )
221 {
222 connectUpdateSignal();
223 mFillSymbol1Button->registerExpressionContextGenerator( mScalebar );
224 mFillSymbol2Button->registerExpressionContextGenerator( mScalebar );
225 mLineStyleButton->registerExpressionContextGenerator( mScalebar );
226 mDivisionStyleButton->registerExpressionContextGenerator( mScalebar );
227 mSubdivisionStyleButton->registerExpressionContextGenerator( mScalebar );
228 }
229
230 setGuiElements();
231
232 return true;
233}
234
235void QgsLayoutScaleBarWidget::lineSymbolChanged()
236{
237 if ( !mScalebar )
238 return;
239
240 mScalebar->layout()->undoStack()->beginCommand( mScalebar, tr( "Change Scalebar Line Style" ), QgsLayoutItem::UndoShapeStyle );
241 mScalebar->setLineSymbol( mLineStyleButton->clonedSymbol<QgsLineSymbol>() );
242 mScalebar->update();
243 mScalebar->layout()->undoStack()->endCommand();
244}
245
246void QgsLayoutScaleBarWidget::divisionSymbolChanged()
247{
248 if ( !mScalebar )
249 return;
250
251 mScalebar->layout()->undoStack()->beginCommand( mScalebar, tr( "Change Scalebar Division Style" ), QgsLayoutItem::UndoShapeStyle );
252 mScalebar->setDivisionLineSymbol( mDivisionStyleButton->clonedSymbol<QgsLineSymbol>() );
253 mScalebar->update();
254 mScalebar->layout()->undoStack()->endCommand();
255}
256
257void QgsLayoutScaleBarWidget::subdivisionSymbolChanged()
258{
259 if ( !mScalebar )
260 return;
261
262 mScalebar->layout()->undoStack()->beginCommand( mScalebar, tr( "Change Scalebar Subdivision Style" ), QgsLayoutItem::UndoShapeStyle );
263 mScalebar->setSubdivisionLineSymbol( mSubdivisionStyleButton->clonedSymbol<QgsLineSymbol>() );
264 mScalebar->update();
265 mScalebar->layout()->undoStack()->endCommand();
266}
267
268void QgsLayoutScaleBarWidget::fillSymbol1Changed()
269{
270 if ( !mScalebar )
271 return;
272
273 mScalebar->layout()->undoStack()->beginCommand( mScalebar, tr( "Change Scalebar Fill Style" ), QgsLayoutItem::UndoShapeStyle );
274 mScalebar->setFillSymbol( mFillSymbol1Button->clonedSymbol<QgsFillSymbol>() );
275 mScalebar->update();
276 mScalebar->layout()->undoStack()->endCommand();
277}
278
279void QgsLayoutScaleBarWidget::fillSymbol2Changed()
280{
281 if ( !mScalebar )
282 return;
283
284 mScalebar->layout()->undoStack()->beginCommand( mScalebar, tr( "Change Scalebar Fill Style" ), QgsLayoutItem::UndoShapeStyle );
285 mScalebar->setAlternateFillSymbol( mFillSymbol2Button->clonedSymbol<QgsFillSymbol>() );
286 mScalebar->update();
287 mScalebar->layout()->undoStack()->endCommand();
288}
289
290void QgsLayoutScaleBarWidget::setGuiElements()
291{
292 if ( !mScalebar )
293 {
294 return;
295 }
296
297 blockMemberSignals( true );
298 mNumberOfSegmentsSpinBox->setValue( mScalebar->numberOfSegments() );
299 mSegmentsLeftSpinBox->setValue( mScalebar->numberOfSegmentsLeft() );
300 mSegmentSizeSpinBox->setValue( mScalebar->unitsPerSegment() );
301 mHeightSpinBox->setValue( mScalebar->height() );
302 mNumberOfSubdivisionsSpinBox->setValue( mScalebar->numberOfSubdivisions() );
303 mSubdivisionsHeightSpinBox->setValue( mScalebar->subdivisionsHeight() );
304 mMapUnitsPerBarUnitSpinBox->setValue( mScalebar->mapUnitsPerScaleBarUnit() );
305 mLabelBarSpaceSpinBox->setValue( mScalebar->labelBarSpace() );
306 mBoxSizeSpinBox->setValue( mScalebar->boxContentSpace() );
307 mUnitLabelLineEdit->setText( mScalebar->unitLabel() );
308 mFontButton->setTextFormat( mScalebar->textFormat() );
309
310 whileBlocking( mLineStyleButton )->setSymbol( mScalebar->lineSymbol()->clone() );
311 whileBlocking( mDivisionStyleButton )->setSymbol( mScalebar->divisionLineSymbol()->clone() );
312 whileBlocking( mSubdivisionStyleButton )->setSymbol( mScalebar->subdivisionLineSymbol()->clone() );
313 whileBlocking( mFillSymbol1Button )->setSymbol( mScalebar->fillSymbol()->clone() );
314 whileBlocking( mFillSymbol2Button )->setSymbol( mScalebar->alternateFillSymbol()->clone() );
315
316 //map combo box
317 mMapItemComboBox->setItem( mScalebar->linkedMap() );
318
319 //style...
320 const QString style = mScalebar->style();
321 mStyleComboBox->setCurrentIndex( mStyleComboBox->findData( style ) );
322 toggleStyleSpecificControls( style );
323
324 //label vertical/horizontal placement
325 mDistanceLabelPlacementComboBox->setCurrentIndex( mDistanceLabelPlacementComboBox->findData( static_cast< int >(
326 distanceLabelPlacement( mScalebar->labelHorizontalPlacement(), mScalebar->labelVerticalPlacement() ) ) ) );
327
328 //alignment
329
330 Qt::Alignment a = Qt::AlignLeft;
331 switch ( mScalebar->alignment() )
332 {
334 a = Qt::AlignLeft;
335 break;
337 a = Qt::AlignRight;
338 break;
340 a = Qt::AlignHCenter;
341 break;
342 }
343 mAlignmentComboBox->setCurrentAlignment( a );
344
345 //units
346 mUnitsComboBox->setCurrentIndex( mUnitsComboBox->findData( static_cast< int >( mScalebar->units() ) ) );
347
348 switch ( mScalebar->segmentSizeMode() )
349 {
351 {
352 mFixedSizeRadio->setChecked( true );
353 mSegmentSizeWidget->setEnabled( true );
354 mMinWidthWidget->setEnabled( false );
355 mMaxWidthWidget->setEnabled( false );
356 break;
357 }
358
360 {
361 mFitWidthRadio->setChecked( true );
362 mSegmentSizeWidget->setEnabled( false );
363 mMinWidthWidget->setEnabled( true );
364 mMaxWidthWidget->setEnabled( true );
365 break;
366 }
367 }
368 mMinWidthSpinBox->setValue( mScalebar->minimumBarWidth() );
369 mMaxWidthSpinBox->setValue( mScalebar->maximumBarWidth() );
370
371 mMethodCombo->setCurrentIndex( mMethodCombo->findData( QVariant::fromValue( mScalebar->method() ) ) );
372
373 populateDataDefinedButtons();
374
375 blockMemberSignals( false );
376}
377
378//slots
379
380void QgsLayoutScaleBarWidget::mSegmentSizeSpinBox_valueChanged( double d )
381{
382 if ( !mScalebar )
383 {
384 return;
385 }
386
387 mScalebar->beginCommand( tr( "Set Scalebar Segment Size" ), QgsLayoutItem::UndoScaleBarSegmentSize );
388 disconnectUpdateSignal();
389 mScalebar->setUnitsPerSegment( d );
390 mScalebar->update();
391 connectUpdateSignal();
392 mScalebar->endCommand();
393}
394
395void QgsLayoutScaleBarWidget::mSegmentsLeftSpinBox_valueChanged( int i )
396{
397 if ( !mScalebar )
398 {
399 return;
400 }
401
402 mScalebar->beginCommand( tr( "Set Scalebar Segments" ), QgsLayoutItem::UndoScaleBarSegmentsLeft );
403 disconnectUpdateSignal();
404 mScalebar->setNumberOfSegmentsLeft( i );
405 mScalebar->update();
406 connectUpdateSignal();
407 mScalebar->endCommand();
408}
409
410void QgsLayoutScaleBarWidget::mNumberOfSegmentsSpinBox_valueChanged( int i )
411{
412 if ( !mScalebar )
413 {
414 return;
415 }
416
417 mScalebar->beginCommand( tr( "Set Scalebar Segments" ), QgsLayoutItem::UndoScaleBarSegments );
418 disconnectUpdateSignal();
419 mScalebar->setNumberOfSegments( i );
420 mScalebar->update();
421 connectUpdateSignal();
422 mScalebar->endCommand();
423}
424
425void QgsLayoutScaleBarWidget::mHeightSpinBox_valueChanged( double d )
426{
427 if ( !mScalebar )
428 {
429 return;
430 }
431 mScalebar->beginCommand( tr( "Set Scalebar Height" ), QgsLayoutItem::UndoScaleBarHeight );
432 disconnectUpdateSignal();
433 mScalebar->setHeight( d );
434 mScalebar->update();
435 connectUpdateSignal();
436 mScalebar->endCommand();
437}
438
439void QgsLayoutScaleBarWidget::mNumberOfSubdivisionsSpinBox_valueChanged( int i )
440{
441 if ( !mScalebar )
442 {
443 return;
444 }
445
446 mScalebar->beginCommand( tr( "Set Scalebar Subdivisions" ), QgsLayoutItem::UndoScaleBarSubdivisions );
447 disconnectUpdateSignal();
448 mScalebar->setNumberOfSubdivisions( i );
449 mScalebar->update();
450 connectUpdateSignal();
451 mScalebar->endCommand();
452}
453
454void QgsLayoutScaleBarWidget::mSubdivisionsHeightSpinBox_valueChanged( double d )
455{
456 if ( !mScalebar )
457 {
458 return;
459 }
460 mScalebar->beginCommand( tr( "Set Subdivisions Height" ), QgsLayoutItem::UndoScaleBarSubdivisionsHeight );
461 disconnectUpdateSignal();
462 mScalebar->setSubdivisionsHeight( d );
463 mScalebar->update();
464 connectUpdateSignal();
465 mScalebar->endCommand();
466}
467
468void QgsLayoutScaleBarWidget::textFormatChanged()
469{
470 if ( !mScalebar )
471 {
472 return;
473 }
474
475 mScalebar->beginCommand( tr( "Set Scalebar Font" ) );
476 disconnectUpdateSignal();
477 mScalebar->setTextFormat( mFontButton->textFormat() );
478 connectUpdateSignal();
479 mScalebar->endCommand();
480 mScalebar->update();
481}
482
483void QgsLayoutScaleBarWidget::changeNumberFormat()
484{
485 if ( !mScalebar )
486 {
487 return;
488 }
489
491 widget->setPanelTitle( tr( "Number Format" ) );
492 widget->setFormat( mScalebar->numericFormat() );
493 connect( widget, &QgsNumericFormatSelectorWidget::changed, this, [ = ]
494 {
495 mScalebar->beginCommand( tr( "Set Scalebar Number Format" ) );
496 disconnectUpdateSignal();
497 mScalebar->setNumericFormat( widget->format() );
498 connectUpdateSignal();
499 mScalebar->endCommand();
500 mScalebar->update();
501 } );
502 openPanel( widget );
503 return;
504}
505
506QgsLayoutScaleBarWidget::DistanceLabelPlacement QgsLayoutScaleBarWidget::distanceLabelPlacement( Qgis::ScaleBarDistanceLabelHorizontalPlacement horizontalPlacement, Qgis::ScaleBarDistanceLabelVerticalPlacement verticalPlacement )
507{
508 switch ( horizontalPlacement )
509 {
511 switch ( verticalPlacement )
512 {
514 return DistanceLabelPlacement::CenteredAboveSegmentEdges;
516 return DistanceLabelPlacement::CenteredBelowSegmentEdges;
517 }
519
521 switch ( verticalPlacement )
522 {
524 return DistanceLabelPlacement::CenteredAboveSegmentCenters;
526 return DistanceLabelPlacement::CenteredBelowSegmentCenters;
527 }
529 }
531}
532
533void QgsLayoutScaleBarWidget::mUnitLabelLineEdit_textChanged( const QString &text )
534{
535 if ( !mScalebar )
536 {
537 return;
538 }
539
540 mScalebar->beginCommand( tr( "Set Scalebar Unit Text" ), QgsLayoutItem::UndoScaleBarUnitText );
541 disconnectUpdateSignal();
542 mScalebar->setUnitLabel( text );
543 mScalebar->update();
544 connectUpdateSignal();
545 mScalebar->endCommand();
546}
547
548void QgsLayoutScaleBarWidget::mMapUnitsPerBarUnitSpinBox_valueChanged( double d )
549{
550 if ( !mScalebar )
551 {
552 return;
553 }
554
555 mScalebar->beginCommand( tr( "Set Scalebar Map Units per Segment" ), QgsLayoutItem::UndoScaleBarMapUnitsSegment );
556 disconnectUpdateSignal();
557 mScalebar->setMapUnitsPerScaleBarUnit( d );
558 mScalebar->update();
559 connectUpdateSignal();
560 mScalebar->endCommand();
561}
562
563void QgsLayoutScaleBarWidget::mStyleComboBox_currentIndexChanged( const QString & )
564{
565 if ( !mScalebar )
566 {
567 return;
568 }
569
570 const QString rendererId = mStyleComboBox->currentData().toString();
571 if ( rendererId == mScalebar->style() )
572 return;
573
574 mScalebar->beginCommand( tr( "Set Scalebar Style" ) );
575 disconnectUpdateSignal();
576
577 bool defaultsApplied = false;
578 const std::unique_ptr< QgsScaleBarRenderer > renderer( QgsApplication::scaleBarRendererRegistry()->renderer( rendererId ) );
579 if ( renderer )
580 defaultsApplied = mScalebar->applyDefaultRendererSettings( renderer.get() );
581
582 //disable or enable controls which apply to specific scale bar styles
583 toggleStyleSpecificControls( rendererId );
584
585 mScalebar->setStyle( rendererId );
586 mScalebar->update();
587 connectUpdateSignal();
588 mScalebar->endCommand();
589
590 if ( defaultsApplied )
591 setGuiElements();
592}
593
594void QgsLayoutScaleBarWidget::toggleStyleSpecificControls( const QString &style )
595{
596 std::unique_ptr< QgsScaleBarRenderer > renderer( QgsApplication::scaleBarRendererRegistry()->renderer( style ) );
597
598 //Selectively enable controls which apply to the scale bar style
599 mUnitsComboBox->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagRespectsUnits : true );
600 mUnitsLabel->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagRespectsUnits : true );
601 mMapUnitsPerBarUnitSpinBox->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagRespectsMapUnitsPerScaleBarUnit : true );
602 mMapUnitsPerBarUnitLabel->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagRespectsMapUnitsPerScaleBarUnit : true );
603 mUnitLabelLineEdit->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesUnitLabel : true );
604 mUnitLabelLabel->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesUnitLabel : true );
605 mSubdivisionsLabel->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesSubdivisions : true );
606 mNumberOfSubdivisionsSpinBox->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesSubdivisions : true );
607 mSubdivisionsHeightLabel->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesSubdivisionsHeight : true );
608 mSubdivisionsHeightSpinBox->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesSubdivisionsHeight : true );
609 mGroupBoxSegments->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesSegments : true );
610 if ( !mGroupBoxUnits->isEnabled() )
611 mGroupBoxSegments->setCollapsed( true );
612 mLabelBarSpaceSpinBox->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesLabelBarSpace : true );
613 mLabelBarSpaceLabel->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesLabelBarSpace : true );
614 mDistanceLabelPlacementComboBox->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesLabelVerticalPlacement : true );
615 mLabelVerticalPlacementLabel->setEnabled( renderer ? ( renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesLabelHorizontalPlacement
616 || renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesLabelVerticalPlacement ) : true );
617 mAlignmentComboBox->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesAlignment : true );
618 mAlignmentLabel->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesAlignment : true );
619 mFillSymbol1Button->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesFillSymbol : true );
620 mFillSymbol1Label->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesFillSymbol : true );
621 mFillSymbol2Button->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesAlternateFillSymbol : true );
622 mFillSymbol2Label->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesAlternateFillSymbol : true );
623 mLineStyleButton->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesLineSymbol : true );
624 mLineStyleLabel->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesLineSymbol : true );
625 mDivisionStyleButton->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesDivisionSymbol : true );
626 mDivisionStyleLabel->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesDivisionSymbol : true );
627 mSubdivisionStyleButton->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesSubdivisionSymbol : true );
628 mSubdivisionStyleLabel->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesSubdivisionSymbol : true );
629}
630
631void QgsLayoutScaleBarWidget::mLabelBarSpaceSpinBox_valueChanged( double d )
632{
633 if ( !mScalebar )
634 {
635 return;
636 }
637
638 mScalebar->beginCommand( tr( "Set Scalebar Label Space" ), QgsLayoutItem::UndoScaleBarLabelBarSize );
639 disconnectUpdateSignal();
640 mScalebar->setLabelBarSpace( d );
641 mScalebar->update();
642 connectUpdateSignal();
643 mScalebar->endCommand();
644}
645
646void QgsLayoutScaleBarWidget::mBoxSizeSpinBox_valueChanged( double d )
647{
648 if ( !mScalebar )
649 {
650 return;
651 }
652
653 mScalebar->beginCommand( tr( "Set Scalebar Box Space" ), QgsLayoutItem::UndoScaleBarBoxContentSpace );
654 disconnectUpdateSignal();
655 mScalebar->setBoxContentSpace( d );
656 mScalebar->update();
657 connectUpdateSignal();
658 mScalebar->endCommand();
659}
660
661void QgsLayoutScaleBarWidget::mDistanceLabelPlacementComboBox_currentIndexChanged( int index )
662{
663 if ( !mScalebar )
664 {
665 return;
666 }
667
668 mScalebar->beginCommand( tr( "Set Scalebar Label Placement" ) );
669 disconnectUpdateSignal();
670
671 const DistanceLabelPlacement placement = static_cast<DistanceLabelPlacement>( mDistanceLabelPlacementComboBox->itemData( index ).toInt() );
672 switch ( placement )
673 {
674 case DistanceLabelPlacement::CenteredAboveSegmentEdges:
675 mScalebar->setLabelVerticalPlacement( Qgis::ScaleBarDistanceLabelVerticalPlacement::AboveSegment );
676 mScalebar->setLabelHorizontalPlacement( Qgis::ScaleBarDistanceLabelHorizontalPlacement::CenteredEdge );
677 break;
678 case DistanceLabelPlacement::CenteredAboveSegmentCenters:
679 mScalebar->setLabelVerticalPlacement( Qgis::ScaleBarDistanceLabelVerticalPlacement::AboveSegment );
680 mScalebar->setLabelHorizontalPlacement( Qgis::ScaleBarDistanceLabelHorizontalPlacement::CenteredSegment );
681 break;
682 case DistanceLabelPlacement::CenteredBelowSegmentEdges:
683 mScalebar->setLabelVerticalPlacement( Qgis::ScaleBarDistanceLabelVerticalPlacement::BelowSegment );
684 mScalebar->setLabelHorizontalPlacement( Qgis::ScaleBarDistanceLabelHorizontalPlacement::CenteredEdge );
685 break;
686 case DistanceLabelPlacement::CenteredBelowSegmentCenters:
687 mScalebar->setLabelVerticalPlacement( Qgis::ScaleBarDistanceLabelVerticalPlacement::BelowSegment );
688 mScalebar->setLabelHorizontalPlacement( Qgis::ScaleBarDistanceLabelHorizontalPlacement::CenteredSegment );
689 break;
690 }
691
692 mScalebar->update();
693 connectUpdateSignal();
694 mScalebar->endCommand();
695}
696
697void QgsLayoutScaleBarWidget::alignmentChanged()
698{
699 if ( !mScalebar )
700 {
701 return;
702 }
703
704 mScalebar->beginCommand( tr( "Set Scalebar Alignment" ) );
705 disconnectUpdateSignal();
706
707 const Qgis::ScaleBarAlignment a = mAlignmentComboBox->currentAlignment() & Qt::AlignLeft ? Qgis::ScaleBarAlignment::Left
708 : mAlignmentComboBox->currentAlignment() & Qt::AlignRight ? Qgis::ScaleBarAlignment::Right : Qgis::ScaleBarAlignment::Middle;
709 mScalebar->setAlignment( a );
710 mScalebar->update();
711 connectUpdateSignal();
712 mScalebar->endCommand();
713}
714
715void QgsLayoutScaleBarWidget::mUnitsComboBox_currentIndexChanged( int index )
716{
717 if ( !mScalebar )
718 {
719 return;
720 }
721
722 const QVariant unitData = mUnitsComboBox->itemData( index );
723 if ( unitData.userType() == QMetaType::Type::UnknownType )
724 {
725 return;
726 }
727
728 disconnectUpdateSignal();
729 mScalebar->beginCommand( tr( "Set Scalebar Units" ) );
730 mScalebar->applyDefaultSize( static_cast< Qgis::DistanceUnit >( unitData.toInt() ) );
731 mScalebar->update();
732
733 mNumberOfSegmentsSpinBox->setValue( mScalebar->numberOfSegments() );
734 mSegmentsLeftSpinBox->setValue( mScalebar->numberOfSegmentsLeft() );
735 mUnitLabelLineEdit->setText( mScalebar->unitLabel() );
736 mSegmentSizeSpinBox->setValue( mScalebar->unitsPerSegment() );
737 mMapUnitsPerBarUnitSpinBox->setValue( mScalebar->mapUnitsPerScaleBarUnit() );
738
739 connectUpdateSignal();
740 mScalebar->endCommand();
741}
742
743void QgsLayoutScaleBarWidget::blockMemberSignals( bool block )
744{
745 mSegmentSizeSpinBox->blockSignals( block );
746 mNumberOfSegmentsSpinBox->blockSignals( block );
747 mSegmentsLeftSpinBox->blockSignals( block );
748 mNumberOfSubdivisionsSpinBox->blockSignals( block );
749 mSubdivisionsHeightSpinBox->blockSignals( block );
750 mStyleComboBox->blockSignals( block );
751 mUnitLabelLineEdit->blockSignals( block );
752 mMapUnitsPerBarUnitSpinBox->blockSignals( block );
753 mHeightSpinBox->blockSignals( block );
754 mLineStyleButton->blockSignals( block );
755 mDivisionStyleButton->blockSignals( block );
756 mSubdivisionStyleButton->blockSignals( block );
757 mLabelBarSpaceSpinBox->blockSignals( block );
758 mBoxSizeSpinBox->blockSignals( block );
759 mDistanceLabelPlacementComboBox->blockSignals( block );
760 mAlignmentComboBox->blockSignals( block );
761 mUnitsComboBox->blockSignals( block );
762 mFillSymbol1Button->blockSignals( block );
763 mFillSymbol2Button->blockSignals( block );
764 mSegmentSizeRadioGroup.blockSignals( block );
765 mMapItemComboBox->blockSignals( block );
766 mFontButton->blockSignals( block );
767 mMinWidthSpinBox->blockSignals( block );
768 mMaxWidthSpinBox->blockSignals( block );
769 mMethodCombo->blockSignals( block );
770}
771
772void QgsLayoutScaleBarWidget::connectUpdateSignal()
773{
774 if ( mScalebar )
775 {
776 connect( mScalebar, &QgsLayoutObject::changed, this, &QgsLayoutScaleBarWidget::setGuiElements );
777 }
778}
779
780void QgsLayoutScaleBarWidget::disconnectUpdateSignal()
781{
782 if ( mScalebar )
783 {
784 disconnect( mScalebar, &QgsLayoutObject::changed, this, &QgsLayoutScaleBarWidget::setGuiElements );
785 }
786}
787
788void QgsLayoutScaleBarWidget::segmentSizeRadioChanged( QAbstractButton *radio )
789{
790 const bool fixedSizeMode = radio == mFixedSizeRadio;
791 mMinWidthWidget->setEnabled( !fixedSizeMode );
792 mMaxWidthWidget->setEnabled( !fixedSizeMode );
793 mSegmentSizeWidget->setEnabled( fixedSizeMode );
794
795 if ( !mScalebar )
796 {
797 return;
798 }
799
800 mScalebar->beginCommand( tr( "Set Scalebar Size Mode" ), QgsLayoutItem::UndoScaleBarSegmentSize );
801 disconnectUpdateSignal();
802 if ( mFixedSizeRadio->isChecked() )
803 {
804 mScalebar->setSegmentSizeMode( Qgis::ScaleBarSegmentSizeMode::Fixed );
805 mScalebar->setUnitsPerSegment( mSegmentSizeSpinBox->value() );
806 }
807 else /*if(mFitWidthRadio->isChecked())*/
808 {
809 mScalebar->setSegmentSizeMode( Qgis::ScaleBarSegmentSizeMode::FitWidth );
810 }
811 mScalebar->update();
812 connectUpdateSignal();
813 mScalebar->endCommand();
814}
815
816void QgsLayoutScaleBarWidget::mapChanged( QgsLayoutItem *item )
817{
818 QgsLayoutItemMap *map = qobject_cast< QgsLayoutItemMap * >( item );
819 if ( !map )
820 {
821 return;
822 }
823
824 //set it to scale bar
825 mScalebar->beginCommand( tr( "Set Scalebar Map" ) );
826 disconnectUpdateSignal();
827 mScalebar->setLinkedMap( map );
828 mScalebar->update();
829 connectUpdateSignal();
830 mScalebar->endCommand();
831}
832
833void QgsLayoutScaleBarWidget::mMinWidthSpinBox_valueChanged( double )
834{
835 if ( !mScalebar )
836 {
837 return;
838 }
839
840 mScalebar->beginCommand( tr( "Set Scalebar Size Mode" ), QgsLayoutItem::UndoScaleBarSegmentSize );
841 disconnectUpdateSignal();
842 mScalebar->setMinimumBarWidth( mMinWidthSpinBox->value() );
843 mScalebar->update();
844 connectUpdateSignal();
845 mScalebar->endCommand();
846}
847
848void QgsLayoutScaleBarWidget::mMaxWidthSpinBox_valueChanged( double )
849{
850 if ( !mScalebar )
851 {
852 return;
853 }
854
855 mScalebar->beginCommand( tr( "Set Scalebar Size Mode" ), QgsLayoutItem::UndoScaleBarSegmentSize );
856 disconnectUpdateSignal();
857 mScalebar->setMaximumBarWidth( mMaxWidthSpinBox->value() );
858 mScalebar->update();
859 connectUpdateSignal();
860 mScalebar->endCommand();
861}
862
863void QgsLayoutScaleBarWidget::populateDataDefinedButtons()
864{
865 updateDataDefinedButton( mSegmentsLeftDDBtn );
866 updateDataDefinedButton( mSegmentsRightDDBtn );
867 updateDataDefinedButton( mSegmentSizeDDBtn );
868 updateDataDefinedButton( mMinWidthDDBtn );
869 updateDataDefinedButton( mMaxWidthDDBtn );
870 updateDataDefinedButton( mHeightDDBtn );
871 updateDataDefinedButton( mSubdivisionHeightDDBtn );
872 updateDataDefinedButton( mRightSegmentSubdivisionsDDBtn );
873}
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.