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