QGIS API Documentation 3.41.0-Master (af5edcb665c)
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 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
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 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 || renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesLabelVerticalPlacement ) : true );
616 mAlignmentComboBox->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesAlignment : true );
617 mAlignmentLabel->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesAlignment : true );
618 mFillSymbol1Button->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesFillSymbol : true );
619 mFillSymbol1Label->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesFillSymbol : true );
620 mFillSymbol2Button->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesAlternateFillSymbol : true );
621 mFillSymbol2Label->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesAlternateFillSymbol : true );
622 mLineStyleButton->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesLineSymbol : true );
623 mLineStyleLabel->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesLineSymbol : true );
624 mDivisionStyleButton->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesDivisionSymbol : true );
625 mDivisionStyleLabel->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesDivisionSymbol : true );
626 mSubdivisionStyleButton->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesSubdivisionSymbol : true );
627 mSubdivisionStyleLabel->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesSubdivisionSymbol : true );
628}
629
630void QgsLayoutScaleBarWidget::mLabelBarSpaceSpinBox_valueChanged( double d )
631{
632 if ( !mScalebar )
633 {
634 return;
635 }
636
637 mScalebar->beginCommand( tr( "Set Scalebar Label Space" ), QgsLayoutItem::UndoScaleBarLabelBarSize );
638 disconnectUpdateSignal();
639 mScalebar->setLabelBarSpace( d );
640 mScalebar->update();
641 connectUpdateSignal();
642 mScalebar->endCommand();
643}
644
645void QgsLayoutScaleBarWidget::mBoxSizeSpinBox_valueChanged( double d )
646{
647 if ( !mScalebar )
648 {
649 return;
650 }
651
652 mScalebar->beginCommand( tr( "Set Scalebar Box Space" ), QgsLayoutItem::UndoScaleBarBoxContentSpace );
653 disconnectUpdateSignal();
654 mScalebar->setBoxContentSpace( d );
655 mScalebar->update();
656 connectUpdateSignal();
657 mScalebar->endCommand();
658}
659
660void QgsLayoutScaleBarWidget::mDistanceLabelPlacementComboBox_currentIndexChanged( int index )
661{
662 if ( !mScalebar )
663 {
664 return;
665 }
666
667 mScalebar->beginCommand( tr( "Set Scalebar Label Placement" ) );
668 disconnectUpdateSignal();
669
670 const DistanceLabelPlacement placement = static_cast<DistanceLabelPlacement>( mDistanceLabelPlacementComboBox->itemData( index ).toInt() );
671 switch ( placement )
672 {
673 case DistanceLabelPlacement::CenteredAboveSegmentEdges:
674 mScalebar->setLabelVerticalPlacement( Qgis::ScaleBarDistanceLabelVerticalPlacement::AboveSegment );
675 mScalebar->setLabelHorizontalPlacement( Qgis::ScaleBarDistanceLabelHorizontalPlacement::CenteredEdge );
676 break;
677 case DistanceLabelPlacement::CenteredAboveSegmentCenters:
678 mScalebar->setLabelVerticalPlacement( Qgis::ScaleBarDistanceLabelVerticalPlacement::AboveSegment );
679 mScalebar->setLabelHorizontalPlacement( Qgis::ScaleBarDistanceLabelHorizontalPlacement::CenteredSegment );
680 break;
681 case DistanceLabelPlacement::CenteredBelowSegmentEdges:
682 mScalebar->setLabelVerticalPlacement( Qgis::ScaleBarDistanceLabelVerticalPlacement::BelowSegment );
683 mScalebar->setLabelHorizontalPlacement( Qgis::ScaleBarDistanceLabelHorizontalPlacement::CenteredEdge );
684 break;
685 case DistanceLabelPlacement::CenteredBelowSegmentCenters:
686 mScalebar->setLabelVerticalPlacement( Qgis::ScaleBarDistanceLabelVerticalPlacement::BelowSegment );
687 mScalebar->setLabelHorizontalPlacement( Qgis::ScaleBarDistanceLabelHorizontalPlacement::CenteredSegment );
688 break;
689 }
690
691 mScalebar->update();
692 connectUpdateSignal();
693 mScalebar->endCommand();
694}
695
696void QgsLayoutScaleBarWidget::alignmentChanged()
697{
698 if ( !mScalebar )
699 {
700 return;
701 }
702
703 mScalebar->beginCommand( tr( "Set Scalebar Alignment" ) );
704 disconnectUpdateSignal();
705
706 const Qgis::ScaleBarAlignment a = mAlignmentComboBox->currentAlignment() & Qt::AlignLeft ? Qgis::ScaleBarAlignment::Left
707 : mAlignmentComboBox->currentAlignment() & Qt::AlignRight ? Qgis::ScaleBarAlignment::Right
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:5036
@ 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:5022
@ AboveSegment
Labels are drawn above the scalebar.
@ BelowSegment
Labels are drawn below the scalebar.
ScaleBarAlignment
Scalebar alignment.
Definition qgis.h:4993
@ Right
Right aligned.
@ Middle
Center aligned.
DistanceUnit
Units of distance.
Definition qgis.h:4740
@ 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:4977
@ 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:6720
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
Definition qgis.h:5970
Single variable definition for use within a QgsExpressionContextScope.