QGIS API Documentation 3.99.0-Master (d270888f95f)
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 <QString>
33#include <QWidget>
34
35#include "moc_qgslayoutscalebarwidget.cpp"
36
37using namespace Qt::StringLiterals;
38
40 : QgsLayoutItemBaseWidget( nullptr, scaleBar )
41 , mScalebar( scaleBar )
42{
43 setupUi( this );
44
45 mNumberOfSubdivisionsSpinBox->setClearValue( 1 );
46
47 connect( mHeightSpinBox, static_cast<void ( QDoubleSpinBox::* )( double )>( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutScaleBarWidget::mHeightSpinBox_valueChanged );
48 connect( mSegmentSizeSpinBox, static_cast<void ( QDoubleSpinBox::* )( double )>( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutScaleBarWidget::mSegmentSizeSpinBox_valueChanged );
49 connect( mSegmentsLeftSpinBox, static_cast<void ( QSpinBox::* )( int )>( &QSpinBox::valueChanged ), this, &QgsLayoutScaleBarWidget::mSegmentsLeftSpinBox_valueChanged );
50 connect( mNumberOfSegmentsSpinBox, static_cast<void ( QSpinBox::* )( int )>( &QSpinBox::valueChanged ), this, &QgsLayoutScaleBarWidget::mNumberOfSegmentsSpinBox_valueChanged );
51 connect( mNumberOfSubdivisionsSpinBox, static_cast<void ( QSpinBox::* )( int )>( &QSpinBox::valueChanged ), this, &QgsLayoutScaleBarWidget::mNumberOfSubdivisionsSpinBox_valueChanged );
52 connect( mSubdivisionsHeightSpinBox, static_cast<void ( QDoubleSpinBox::* )( double )>( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutScaleBarWidget::mSubdivisionsHeightSpinBox_valueChanged );
53 connect( mUnitLabelLineEdit, &QLineEdit::textChanged, this, &QgsLayoutScaleBarWidget::mUnitLabelLineEdit_textChanged );
54 connect( mMapUnitsPerBarUnitSpinBox, static_cast<void ( QDoubleSpinBox::* )( double )>( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutScaleBarWidget::mMapUnitsPerBarUnitSpinBox_valueChanged );
55 connect( mStyleComboBox, &QComboBox::currentTextChanged, this, &QgsLayoutScaleBarWidget::mStyleComboBox_currentIndexChanged );
56 connect( mLabelBarSpaceSpinBox, static_cast<void ( QDoubleSpinBox::* )( double )>( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutScaleBarWidget::mLabelBarSpaceSpinBox_valueChanged );
57 connect( mBoxSizeSpinBox, static_cast<void ( QDoubleSpinBox::* )( double )>( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutScaleBarWidget::mBoxSizeSpinBox_valueChanged );
58 connect( mAlignmentComboBox, &QgsAlignmentComboBox::changed, this, &QgsLayoutScaleBarWidget::alignmentChanged );
59 connect( mDistanceLabelPlacementComboBox, qOverload<int>( &QComboBox::currentIndexChanged ), this, &QgsLayoutScaleBarWidget::mDistanceLabelPlacementComboBox_currentIndexChanged );
60 connect( mUnitsComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsLayoutScaleBarWidget::mUnitsComboBox_currentIndexChanged );
61 connect( mMinWidthSpinBox, static_cast<void ( QDoubleSpinBox::* )( double )>( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutScaleBarWidget::mMinWidthSpinBox_valueChanged );
62 connect( mMaxWidthSpinBox, static_cast<void ( QDoubleSpinBox::* )( double )>( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutScaleBarWidget::mMaxWidthSpinBox_valueChanged );
63 connect( mNumberFormatPushButton, &QPushButton::clicked, this, &QgsLayoutScaleBarWidget::changeNumberFormat );
64 connect( mScaleMethodWidget, &QgsScaleMethodWidget::methodChanged, this, [this] {
65 if ( !mScalebar )
66 {
67 return;
68 }
69
70 disconnectUpdateSignal();
71 mScalebar->beginCommand( tr( "Set Scalebar Method" ) );
72 mScalebar->setMethod( mScaleMethodWidget->scaleMethod() );
73 mScalebar->update();
74 connectUpdateSignal();
75 mScalebar->endCommand();
76 } );
77
86
87 mSegmentsLeftDDBtn->registerEnabledWidget( mSegmentsLeftSpinBox, false );
88 mSegmentsRightDDBtn->registerEnabledWidget( mNumberOfSegmentsSpinBox, false );
89 mSegmentSizeDDBtn->registerEnabledWidget( mSegmentSizeSpinBox, false );
90 mMinWidthDDBtn->registerEnabledWidget( mMinWidthSpinBox, false );
91 mMaxWidthDDBtn->registerEnabledWidget( mMaxWidthSpinBox, false );
92
93 setPanelTitle( tr( "Scalebar Properties" ) );
94
95 mFontButton->registerExpressionContextGenerator( this );
96
97 connectUpdateSignal();
98
99 //add widget for general composer item properties
100 mItemPropertiesWidget = new QgsLayoutItemPropertiesWidget( this, scaleBar );
101 mainLayout->addWidget( mItemPropertiesWidget );
102
103 mSegmentSizeRadioGroup.addButton( mFixedSizeRadio );
104 mSegmentSizeRadioGroup.addButton( mFitWidthRadio );
105 connect( &mSegmentSizeRadioGroup, static_cast<void ( QButtonGroup::* )( QAbstractButton * )>( &QButtonGroup::buttonClicked ), this, &QgsLayoutScaleBarWidget::segmentSizeRadioChanged );
106
107 blockMemberSignals( true );
108
109 //style combo box
110 const QStringList renderers = QgsApplication::scaleBarRendererRegistry()->sortedRendererList();
111 for ( const QString &renderer : renderers )
112 {
113 mStyleComboBox->addItem( QgsApplication::scaleBarRendererRegistry()->visibleName( renderer ), renderer );
114 }
115
116 //label vertical/horizontal placement combo box
117 mDistanceLabelPlacementComboBox->addItem( tr( "Above Segment Edges" ), static_cast<int>( DistanceLabelPlacement::CenteredAboveSegmentEdges ) );
118 mDistanceLabelPlacementComboBox->addItem( tr( "Above Segment Centers" ), static_cast<int>( DistanceLabelPlacement::CenteredAboveSegmentCenters ) );
119 mDistanceLabelPlacementComboBox->addItem( tr( "Below Segment Edges" ), static_cast<int>( DistanceLabelPlacement::CenteredBelowSegmentEdges ) );
120 mDistanceLabelPlacementComboBox->addItem( tr( "Below Segment Centers" ), static_cast<int>( DistanceLabelPlacement::CenteredBelowSegmentCenters ) );
121
122 //alignment combo box
123 mAlignmentComboBox->setAvailableAlignments( Qt::AlignLeft | Qt::AlignHCenter | Qt::AlignRight );
124
125 //units combo box
126
127 mUnitsComboBox->addItem( linkedMapUnitsString( scaleBar ), static_cast<int>( Qgis::DistanceUnit::Unknown ) );
128 mUnitsComboBox->addItem( tr( "Meters" ), static_cast<int>( Qgis::DistanceUnit::Meters ) );
129 mUnitsComboBox->addItem( tr( "Kilometers" ), static_cast<int>( Qgis::DistanceUnit::Kilometers ) );
130 mUnitsComboBox->addItem( tr( "Feet" ), static_cast<int>( Qgis::DistanceUnit::Feet ) );
131 mUnitsComboBox->addItem( tr( "Yards" ), static_cast<int>( Qgis::DistanceUnit::Yards ) );
132 mUnitsComboBox->addItem( tr( "Miles" ), static_cast<int>( Qgis::DistanceUnit::Miles ) );
133 mUnitsComboBox->addItem( tr( "Nautical Miles" ), static_cast<int>( Qgis::DistanceUnit::NauticalMiles ) );
134 mUnitsComboBox->addItem( tr( "Centimeters" ), static_cast<int>( Qgis::DistanceUnit::Centimeters ) );
135 mUnitsComboBox->addItem( tr( "Millimeters" ), static_cast<int>( Qgis::DistanceUnit::Millimeters ) );
136 mUnitsComboBox->addItem( tr( "Inches" ), static_cast<int>( Qgis::DistanceUnit::Inches ) );
137
138 mLineStyleButton->setSymbolType( Qgis::SymbolType::Line );
139 connect( mLineStyleButton, &QgsSymbolButton::changed, this, &QgsLayoutScaleBarWidget::lineSymbolChanged );
140
141 mDivisionStyleButton->setSymbolType( Qgis::SymbolType::Line );
142 connect( mDivisionStyleButton, &QgsSymbolButton::changed, this, &QgsLayoutScaleBarWidget::divisionSymbolChanged );
143
144 mSubdivisionStyleButton->setSymbolType( Qgis::SymbolType::Line );
145 connect( mSubdivisionStyleButton, &QgsSymbolButton::changed, this, &QgsLayoutScaleBarWidget::subdivisionSymbolChanged );
146
147 mFillSymbol1Button->setSymbolType( Qgis::SymbolType::Fill );
148 connect( mFillSymbol1Button, &QgsSymbolButton::changed, this, &QgsLayoutScaleBarWidget::fillSymbol1Changed );
149
150 mFillSymbol2Button->setSymbolType( Qgis::SymbolType::Fill );
151 connect( mFillSymbol2Button, &QgsSymbolButton::changed, this, &QgsLayoutScaleBarWidget::fillSymbol2Changed );
152
153 mFontButton->setDialogTitle( tr( "Scalebar Font" ) );
154 mFontButton->setMode( QgsFontButton::ModeTextRenderer );
155
156 if ( mScalebar )
157 {
158 QgsLayout *scaleBarLayout = mScalebar->layout();
159 if ( scaleBarLayout )
160 {
161 mMapItemComboBox->setCurrentLayout( scaleBarLayout );
162 mMapItemComboBox->setItemType( QgsLayoutItemRegistry::LayoutMap );
163 }
164 }
165
166 connect( mMapItemComboBox, &QgsLayoutItemComboBox::itemChanged, this, &QgsLayoutScaleBarWidget::mapChanged );
167
168 blockMemberSignals( false );
169 setGuiElements(); //set the GUI elements to the state of scaleBar
170
171 mLineStyleButton->registerExpressionContextGenerator( mScalebar );
172 mLineStyleButton->setLayer( coverageLayer() );
173 mDivisionStyleButton->registerExpressionContextGenerator( mScalebar );
174 mDivisionStyleButton->setLayer( coverageLayer() );
175 mSubdivisionStyleButton->registerExpressionContextGenerator( mScalebar );
176 mSubdivisionStyleButton->setLayer( coverageLayer() );
177 mFillSymbol1Button->registerExpressionContextGenerator( mScalebar );
178 mFillSymbol1Button->setLayer( coverageLayer() );
179 mFillSymbol2Button->registerExpressionContextGenerator( mScalebar );
180 mFillSymbol2Button->setLayer( coverageLayer() );
181
182 connect( mFontButton, &QgsFontButton::changed, this, &QgsLayoutScaleBarWidget::textFormatChanged );
183 mFontButton->setLayer( coverageLayer() );
184 if ( mScalebar->layout() )
185 {
186 connect( &mScalebar->layout()->reportContext(), &QgsLayoutReportContext::layerChanged, mFontButton, &QgsFontButton::setLayer );
187 connect( &mScalebar->layout()->reportContext(), &QgsLayoutReportContext::layerChanged, mLineStyleButton, &QgsSymbolButton::setLayer );
188 connect( &mScalebar->layout()->reportContext(), &QgsLayoutReportContext::layerChanged, mDivisionStyleButton, &QgsSymbolButton::setLayer );
189 connect( &mScalebar->layout()->reportContext(), &QgsLayoutReportContext::layerChanged, mSubdivisionStyleButton, &QgsSymbolButton::setLayer );
190 connect( &mScalebar->layout()->reportContext(), &QgsLayoutReportContext::layerChanged, mFillSymbol1Button, &QgsSymbolButton::setLayer );
191 connect( &mScalebar->layout()->reportContext(), &QgsLayoutReportContext::layerChanged, mFillSymbol2Button, &QgsSymbolButton::setLayer );
192 }
193}
194
196{
197 if ( mItemPropertiesWidget )
198 mItemPropertiesWidget->setMasterLayout( masterLayout );
199}
200
202{
203 QgsExpressionContext context = mScalebar->createExpressionContext();
204 QgsExpressionContextScope *scaleScope = new QgsExpressionContextScope( u"scalebar_text"_s );
205 scaleScope->addVariable( QgsExpressionContextScope::StaticVariable( u"scale_value"_s, 0, true, false ) );
206 context.appendScope( scaleScope );
207 context.setHighlightedVariables( QStringList() << u"scale_value"_s );
208 return context;
209}
210
212{
214 return false;
215
216 disconnectUpdateSignal();
217
218 mScalebar = qobject_cast<QgsLayoutItemScaleBar *>( item );
219 mItemPropertiesWidget->setItem( mScalebar );
220
221 if ( mScalebar )
222 {
223 connectUpdateSignal();
224 mFillSymbol1Button->registerExpressionContextGenerator( mScalebar );
225 mFillSymbol2Button->registerExpressionContextGenerator( mScalebar );
226 mLineStyleButton->registerExpressionContextGenerator( mScalebar );
227 mDivisionStyleButton->registerExpressionContextGenerator( mScalebar );
228 mSubdivisionStyleButton->registerExpressionContextGenerator( mScalebar );
229 }
230
231 setGuiElements();
232
233 return true;
234}
235
236void QgsLayoutScaleBarWidget::lineSymbolChanged()
237{
238 if ( !mScalebar )
239 return;
240
241 mScalebar->layout()->undoStack()->beginCommand( mScalebar, tr( "Change Scalebar Line Style" ), QgsLayoutItem::UndoShapeStyle );
242 mScalebar->setLineSymbol( mLineStyleButton->clonedSymbol<QgsLineSymbol>() );
243 mScalebar->update();
244 mScalebar->layout()->undoStack()->endCommand();
245}
246
247void QgsLayoutScaleBarWidget::divisionSymbolChanged()
248{
249 if ( !mScalebar )
250 return;
251
252 mScalebar->layout()->undoStack()->beginCommand( mScalebar, tr( "Change Scalebar Division Style" ), QgsLayoutItem::UndoShapeStyle );
253 mScalebar->setDivisionLineSymbol( mDivisionStyleButton->clonedSymbol<QgsLineSymbol>() );
254 mScalebar->update();
255 mScalebar->layout()->undoStack()->endCommand();
256}
257
258void QgsLayoutScaleBarWidget::subdivisionSymbolChanged()
259{
260 if ( !mScalebar )
261 return;
262
263 mScalebar->layout()->undoStack()->beginCommand( mScalebar, tr( "Change Scalebar Subdivision Style" ), QgsLayoutItem::UndoShapeStyle );
264 mScalebar->setSubdivisionLineSymbol( mSubdivisionStyleButton->clonedSymbol<QgsLineSymbol>() );
265 mScalebar->update();
266 mScalebar->layout()->undoStack()->endCommand();
267}
268
269void QgsLayoutScaleBarWidget::fillSymbol1Changed()
270{
271 if ( !mScalebar )
272 return;
273
274 mScalebar->layout()->undoStack()->beginCommand( mScalebar, tr( "Change Scalebar Fill Style" ), QgsLayoutItem::UndoShapeStyle );
275 mScalebar->setFillSymbol( mFillSymbol1Button->clonedSymbol<QgsFillSymbol>() );
276 mScalebar->update();
277 mScalebar->layout()->undoStack()->endCommand();
278}
279
280void QgsLayoutScaleBarWidget::fillSymbol2Changed()
281{
282 if ( !mScalebar )
283 return;
284
285 mScalebar->layout()->undoStack()->beginCommand( mScalebar, tr( "Change Scalebar Fill Style" ), QgsLayoutItem::UndoShapeStyle );
286 mScalebar->setAlternateFillSymbol( mFillSymbol2Button->clonedSymbol<QgsFillSymbol>() );
287 mScalebar->update();
288 mScalebar->layout()->undoStack()->endCommand();
289}
290
291void QgsLayoutScaleBarWidget::setGuiElements()
292{
293 if ( !mScalebar )
294 {
295 return;
296 }
297
298 blockMemberSignals( true );
299 mNumberOfSegmentsSpinBox->setValue( mScalebar->numberOfSegments() );
300 mSegmentsLeftSpinBox->setValue( mScalebar->numberOfSegmentsLeft() );
301 mSegmentSizeSpinBox->setValue( mScalebar->unitsPerSegment() );
302 mHeightSpinBox->setValue( mScalebar->height() );
303 mNumberOfSubdivisionsSpinBox->setValue( mScalebar->numberOfSubdivisions() );
304 mSubdivisionsHeightSpinBox->setValue( mScalebar->subdivisionsHeight() );
305 mMapUnitsPerBarUnitSpinBox->setValue( mScalebar->mapUnitsPerScaleBarUnit() );
306 mLabelBarSpaceSpinBox->setValue( mScalebar->labelBarSpace() );
307 mBoxSizeSpinBox->setValue( mScalebar->boxContentSpace() );
308 mUnitLabelLineEdit->setText( mScalebar->unitLabel() );
309 mFontButton->setTextFormat( mScalebar->textFormat() );
310
311 whileBlocking( mLineStyleButton )->setSymbol( mScalebar->lineSymbol()->clone() );
312 whileBlocking( mDivisionStyleButton )->setSymbol( mScalebar->divisionLineSymbol()->clone() );
313 whileBlocking( mSubdivisionStyleButton )->setSymbol( mScalebar->subdivisionLineSymbol()->clone() );
314 whileBlocking( mFillSymbol1Button )->setSymbol( mScalebar->fillSymbol()->clone() );
315 whileBlocking( mFillSymbol2Button )->setSymbol( mScalebar->alternateFillSymbol()->clone() );
316
317 //map combo box
318 mMapItemComboBox->setItem( mScalebar->linkedMap() );
319
320 //style...
321 const QString style = mScalebar->style();
322 mStyleComboBox->setCurrentIndex( mStyleComboBox->findData( style ) );
323 toggleStyleSpecificControls( style );
324
325 //label vertical/horizontal placement
326 mDistanceLabelPlacementComboBox->setCurrentIndex( mDistanceLabelPlacementComboBox->findData( static_cast<int>(
327 distanceLabelPlacement( mScalebar->labelHorizontalPlacement(), mScalebar->labelVerticalPlacement() )
328 ) ) );
329
330 //alignment
331
332 Qt::Alignment a = Qt::AlignLeft;
333 switch ( mScalebar->alignment() )
334 {
336 a = Qt::AlignLeft;
337 break;
339 a = Qt::AlignRight;
340 break;
342 a = Qt::AlignHCenter;
343 break;
344 }
345 mAlignmentComboBox->setCurrentAlignment( a );
346
347 //units
348 mUnitsComboBox->setCurrentIndex( mUnitsComboBox->findData( static_cast<int>( mScalebar->units() ) ) );
349
350 switch ( mScalebar->segmentSizeMode() )
351 {
353 {
354 mFixedSizeRadio->setChecked( true );
355 mSegmentSizeWidget->setEnabled( true );
356 mMinWidthWidget->setEnabled( false );
357 mMaxWidthWidget->setEnabled( false );
358 break;
359 }
360
362 {
363 mFitWidthRadio->setChecked( true );
364 mSegmentSizeWidget->setEnabled( false );
365 mMinWidthWidget->setEnabled( true );
366 mMaxWidthWidget->setEnabled( true );
367 break;
368 }
369 }
370 mMinWidthSpinBox->setValue( mScalebar->minimumBarWidth() );
371 mMaxWidthSpinBox->setValue( mScalebar->maximumBarWidth() );
372
373 mScaleMethodWidget->setScaleMethod( mScalebar->method() );
374
375 populateDataDefinedButtons();
376
377 blockMemberSignals( false );
378}
379
380//slots
381
382void QgsLayoutScaleBarWidget::mSegmentSizeSpinBox_valueChanged( double d )
383{
384 if ( !mScalebar )
385 {
386 return;
387 }
388
389 mScalebar->beginCommand( tr( "Set Scalebar Segment Size" ), QgsLayoutItem::UndoScaleBarSegmentSize );
390 disconnectUpdateSignal();
391 mScalebar->setUnitsPerSegment( d );
392 mScalebar->update();
393 connectUpdateSignal();
394 mScalebar->endCommand();
395}
396
397void QgsLayoutScaleBarWidget::mSegmentsLeftSpinBox_valueChanged( int i )
398{
399 if ( !mScalebar )
400 {
401 return;
402 }
403
404 mScalebar->beginCommand( tr( "Set Scalebar Segments" ), QgsLayoutItem::UndoScaleBarSegmentsLeft );
405 disconnectUpdateSignal();
406 mScalebar->setNumberOfSegmentsLeft( i );
407 mScalebar->update();
408 connectUpdateSignal();
409 mScalebar->endCommand();
410}
411
412void QgsLayoutScaleBarWidget::mNumberOfSegmentsSpinBox_valueChanged( int i )
413{
414 if ( !mScalebar )
415 {
416 return;
417 }
418
419 mScalebar->beginCommand( tr( "Set Scalebar Segments" ), QgsLayoutItem::UndoScaleBarSegments );
420 disconnectUpdateSignal();
421 mScalebar->setNumberOfSegments( i );
422 mScalebar->update();
423 connectUpdateSignal();
424 mScalebar->endCommand();
425}
426
427void QgsLayoutScaleBarWidget::mHeightSpinBox_valueChanged( double d )
428{
429 if ( !mScalebar )
430 {
431 return;
432 }
433 mScalebar->beginCommand( tr( "Set Scalebar Height" ), QgsLayoutItem::UndoScaleBarHeight );
434 disconnectUpdateSignal();
435 mScalebar->setHeight( d );
436 mScalebar->update();
437 connectUpdateSignal();
438 mScalebar->endCommand();
439}
440
441void QgsLayoutScaleBarWidget::mNumberOfSubdivisionsSpinBox_valueChanged( int i )
442{
443 if ( !mScalebar )
444 {
445 return;
446 }
447
448 mScalebar->beginCommand( tr( "Set Scalebar Subdivisions" ), QgsLayoutItem::UndoScaleBarSubdivisions );
449 disconnectUpdateSignal();
450 mScalebar->setNumberOfSubdivisions( i );
451 mScalebar->update();
452 connectUpdateSignal();
453 mScalebar->endCommand();
454}
455
456void QgsLayoutScaleBarWidget::mSubdivisionsHeightSpinBox_valueChanged( double d )
457{
458 if ( !mScalebar )
459 {
460 return;
461 }
462 mScalebar->beginCommand( tr( "Set Subdivisions Height" ), QgsLayoutItem::UndoScaleBarSubdivisionsHeight );
463 disconnectUpdateSignal();
464 mScalebar->setSubdivisionsHeight( d );
465 mScalebar->update();
466 connectUpdateSignal();
467 mScalebar->endCommand();
468}
469
470void QgsLayoutScaleBarWidget::textFormatChanged()
471{
472 if ( !mScalebar )
473 {
474 return;
475 }
476
477 mScalebar->beginCommand( tr( "Set Scalebar Font" ) );
478 disconnectUpdateSignal();
479 mScalebar->setTextFormat( mFontButton->textFormat() );
480 connectUpdateSignal();
481 mScalebar->endCommand();
482 mScalebar->update();
483}
484
485void QgsLayoutScaleBarWidget::changeNumberFormat()
486{
487 if ( !mScalebar )
488 {
489 return;
490 }
491
492 QgsNumericFormatSelectorWidget *widget = new QgsNumericFormatSelectorWidget( this );
493 widget->setPanelTitle( tr( "Number Format" ) );
494 widget->setFormat( mScalebar->numericFormat() );
495 connect( widget, &QgsNumericFormatSelectorWidget::changed, this, [this, widget] {
496 mScalebar->beginCommand( tr( "Set Scalebar Number Format" ) );
497 disconnectUpdateSignal();
498 mScalebar->setNumericFormat( widget->format() );
499 connectUpdateSignal();
500 mScalebar->endCommand();
501 mScalebar->update();
502 } );
503 openPanel( widget );
504 return;
505}
506
507QgsLayoutScaleBarWidget::DistanceLabelPlacement QgsLayoutScaleBarWidget::distanceLabelPlacement( Qgis::ScaleBarDistanceLabelHorizontalPlacement horizontalPlacement, Qgis::ScaleBarDistanceLabelVerticalPlacement verticalPlacement )
508{
509 switch ( horizontalPlacement )
510 {
512 switch ( verticalPlacement )
513 {
515 return DistanceLabelPlacement::CenteredAboveSegmentEdges;
517 return DistanceLabelPlacement::CenteredBelowSegmentEdges;
518 }
520
522 switch ( verticalPlacement )
523 {
525 return DistanceLabelPlacement::CenteredAboveSegmentCenters;
527 return DistanceLabelPlacement::CenteredBelowSegmentCenters;
528 }
530 }
532}
533
534void QgsLayoutScaleBarWidget::mUnitLabelLineEdit_textChanged( const QString &text )
535{
536 if ( !mScalebar )
537 {
538 return;
539 }
540
541 mScalebar->beginCommand( tr( "Set Scalebar Unit Text" ), QgsLayoutItem::UndoScaleBarUnitText );
542 disconnectUpdateSignal();
543 mScalebar->setUnitLabel( text );
544 mScalebar->update();
545 connectUpdateSignal();
546 mScalebar->endCommand();
547}
548
549void QgsLayoutScaleBarWidget::mMapUnitsPerBarUnitSpinBox_valueChanged( double d )
550{
551 if ( !mScalebar )
552 {
553 return;
554 }
555
556 mScalebar->beginCommand( tr( "Set Scalebar Map Units per Segment" ), QgsLayoutItem::UndoScaleBarMapUnitsSegment );
557 disconnectUpdateSignal();
558 mScalebar->setMapUnitsPerScaleBarUnit( d );
559 mScalebar->update();
560 connectUpdateSignal();
561 mScalebar->endCommand();
562}
563
564void QgsLayoutScaleBarWidget::mStyleComboBox_currentIndexChanged( const QString & )
565{
566 if ( !mScalebar )
567 {
568 return;
569 }
570
571 const QString rendererId = mStyleComboBox->currentData().toString();
572 if ( rendererId == mScalebar->style() )
573 return;
574
575 mScalebar->beginCommand( tr( "Set Scalebar Style" ) );
576 disconnectUpdateSignal();
577
578 bool defaultsApplied = false;
579 const std::unique_ptr<QgsScaleBarRenderer> renderer( QgsApplication::scaleBarRendererRegistry()->renderer( rendererId ) );
580 if ( renderer )
581 defaultsApplied = mScalebar->applyDefaultRendererSettings( renderer.get() );
582
583 //disable or enable controls which apply to specific scale bar styles
584 toggleStyleSpecificControls( rendererId );
585
586 mScalebar->setStyle( rendererId );
587 mScalebar->update();
588 connectUpdateSignal();
589 mScalebar->endCommand();
590
591 if ( defaultsApplied )
592 setGuiElements();
593}
594
595void QgsLayoutScaleBarWidget::toggleStyleSpecificControls( const QString &style )
596{
597 std::unique_ptr<QgsScaleBarRenderer> renderer( QgsApplication::scaleBarRendererRegistry()->renderer( style ) );
598
599 //Selectively enable controls which apply to the scale bar style
600 mUnitsComboBox->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagRespectsUnits : true );
601 mUnitsLabel->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagRespectsUnits : true );
602 mMapUnitsPerBarUnitSpinBox->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagRespectsMapUnitsPerScaleBarUnit : true );
603 mMapUnitsPerBarUnitLabel->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagRespectsMapUnitsPerScaleBarUnit : true );
604 mUnitLabelLineEdit->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesUnitLabel : true );
605 mUnitLabelLabel->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesUnitLabel : true );
606 mSubdivisionsLabel->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesSubdivisions : true );
607 mNumberOfSubdivisionsSpinBox->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesSubdivisions : true );
608 mSubdivisionsHeightLabel->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesSubdivisionsHeight : true );
609 mSubdivisionsHeightSpinBox->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesSubdivisionsHeight : true );
610 mGroupBoxSegments->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesSegments : true );
611 if ( !mGroupBoxUnits->isEnabled() )
612 mGroupBoxSegments->setCollapsed( true );
613 mLabelBarSpaceSpinBox->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesLabelBarSpace : true );
614 mLabelBarSpaceLabel->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesLabelBarSpace : true );
615 mDistanceLabelPlacementComboBox->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesLabelVerticalPlacement : true );
616 mLabelVerticalPlacementLabel->setEnabled( renderer ? ( renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesLabelHorizontalPlacement || 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
710 mScalebar->setAlignment( a );
711 mScalebar->update();
712 connectUpdateSignal();
713 mScalebar->endCommand();
714}
715
716void QgsLayoutScaleBarWidget::mUnitsComboBox_currentIndexChanged( int index )
717{
718 if ( !mScalebar )
719 {
720 return;
721 }
722
723 const QVariant unitData = mUnitsComboBox->itemData( index );
724 if ( unitData.userType() == QMetaType::Type::UnknownType )
725 {
726 return;
727 }
728
729 disconnectUpdateSignal();
730 mScalebar->beginCommand( tr( "Set Scalebar Units" ) );
731 mScalebar->applyDefaultSize( static_cast<Qgis::DistanceUnit>( unitData.toInt() ) );
732 mScalebar->update();
733
734 mNumberOfSegmentsSpinBox->setValue( mScalebar->numberOfSegments() );
735 mSegmentsLeftSpinBox->setValue( mScalebar->numberOfSegmentsLeft() );
736 mUnitLabelLineEdit->setText( mScalebar->unitLabel() );
737 mSegmentSizeSpinBox->setValue( mScalebar->unitsPerSegment() );
738 mMapUnitsPerBarUnitSpinBox->setValue( mScalebar->mapUnitsPerScaleBarUnit() );
739
740 connectUpdateSignal();
741 mScalebar->endCommand();
742}
743
744void QgsLayoutScaleBarWidget::blockMemberSignals( bool block )
745{
746 mSegmentSizeSpinBox->blockSignals( block );
747 mNumberOfSegmentsSpinBox->blockSignals( block );
748 mSegmentsLeftSpinBox->blockSignals( block );
749 mNumberOfSubdivisionsSpinBox->blockSignals( block );
750 mSubdivisionsHeightSpinBox->blockSignals( block );
751 mStyleComboBox->blockSignals( block );
752 mUnitLabelLineEdit->blockSignals( block );
753 mMapUnitsPerBarUnitSpinBox->blockSignals( block );
754 mHeightSpinBox->blockSignals( block );
755 mLineStyleButton->blockSignals( block );
756 mDivisionStyleButton->blockSignals( block );
757 mSubdivisionStyleButton->blockSignals( block );
758 mLabelBarSpaceSpinBox->blockSignals( block );
759 mBoxSizeSpinBox->blockSignals( block );
760 mDistanceLabelPlacementComboBox->blockSignals( block );
761 mAlignmentComboBox->blockSignals( block );
762 mUnitsComboBox->blockSignals( block );
763 mFillSymbol1Button->blockSignals( block );
764 mFillSymbol2Button->blockSignals( block );
765 mSegmentSizeRadioGroup.blockSignals( block );
766 mMapItemComboBox->blockSignals( block );
767 mFontButton->blockSignals( block );
768 mMinWidthSpinBox->blockSignals( block );
769 mMaxWidthSpinBox->blockSignals( block );
770 mScaleMethodWidget->blockSignals( block );
771}
772
773void QgsLayoutScaleBarWidget::connectUpdateSignal()
774{
775 if ( mScalebar )
776 {
777 connect( mScalebar, &QgsLayoutObject::changed, this, &QgsLayoutScaleBarWidget::setGuiElements );
778 }
779}
780
781void QgsLayoutScaleBarWidget::disconnectUpdateSignal()
782{
783 if ( mScalebar )
784 {
785 disconnect( mScalebar, &QgsLayoutObject::changed, this, &QgsLayoutScaleBarWidget::setGuiElements );
786 }
787}
788
789void QgsLayoutScaleBarWidget::segmentSizeRadioChanged( QAbstractButton *radio )
790{
791 const bool fixedSizeMode = radio == mFixedSizeRadio;
792 mMinWidthWidget->setEnabled( !fixedSizeMode );
793 mMaxWidthWidget->setEnabled( !fixedSizeMode );
794 mSegmentSizeWidget->setEnabled( fixedSizeMode );
795
796 if ( !mScalebar )
797 {
798 return;
799 }
800
801 mScalebar->beginCommand( tr( "Set Scalebar Size Mode" ), QgsLayoutItem::UndoScaleBarSegmentSize );
802 disconnectUpdateSignal();
803 if ( mFixedSizeRadio->isChecked() )
804 {
805 mScalebar->setSegmentSizeMode( Qgis::ScaleBarSegmentSizeMode::Fixed );
806 mScalebar->setUnitsPerSegment( mSegmentSizeSpinBox->value() );
807 }
808 else /*if(mFitWidthRadio->isChecked())*/
809 {
810 mScalebar->setSegmentSizeMode( Qgis::ScaleBarSegmentSizeMode::FitWidth );
811 }
812 mScalebar->update();
813 connectUpdateSignal();
814 mScalebar->endCommand();
815}
816
817void QgsLayoutScaleBarWidget::mapChanged( QgsLayoutItem *item )
818{
819 QgsLayoutItemMap *map = qobject_cast<QgsLayoutItemMap *>( item );
820 if ( !map )
821 {
822 return;
823 }
824
825 //set it to scale bar
826 mScalebar->beginCommand( tr( "Set Scalebar Map" ) );
827 disconnectUpdateSignal();
828 mScalebar->setLinkedMap( map );
829 mScalebar->update();
830 connectUpdateSignal();
831 mScalebar->endCommand();
832
833 mUnitsComboBox->setItemText( mUnitsComboBox->findData( static_cast<int>( Qgis::DistanceUnit::Unknown ) ), linkedMapUnitsString( mScalebar ) );
834}
835
836void QgsLayoutScaleBarWidget::mMinWidthSpinBox_valueChanged( double )
837{
838 if ( !mScalebar )
839 {
840 return;
841 }
842
843 mScalebar->beginCommand( tr( "Set Scalebar Size Mode" ), QgsLayoutItem::UndoScaleBarSegmentSize );
844 disconnectUpdateSignal();
845 mScalebar->setMinimumBarWidth( mMinWidthSpinBox->value() );
846 mScalebar->update();
847 connectUpdateSignal();
848 mScalebar->endCommand();
849}
850
851void QgsLayoutScaleBarWidget::mMaxWidthSpinBox_valueChanged( double )
852{
853 if ( !mScalebar )
854 {
855 return;
856 }
857
858 mScalebar->beginCommand( tr( "Set Scalebar Size Mode" ), QgsLayoutItem::UndoScaleBarSegmentSize );
859 disconnectUpdateSignal();
860 mScalebar->setMaximumBarWidth( mMaxWidthSpinBox->value() );
861 mScalebar->update();
862 connectUpdateSignal();
863 mScalebar->endCommand();
864}
865
866void QgsLayoutScaleBarWidget::populateDataDefinedButtons()
867{
868 updateDataDefinedButton( mSegmentsLeftDDBtn );
869 updateDataDefinedButton( mSegmentsRightDDBtn );
870 updateDataDefinedButton( mSegmentSizeDDBtn );
871 updateDataDefinedButton( mMinWidthDDBtn );
872 updateDataDefinedButton( mMaxWidthDDBtn );
873 updateDataDefinedButton( mHeightDDBtn );
874 updateDataDefinedButton( mSubdivisionHeightDDBtn );
875 updateDataDefinedButton( mRightSegmentSubdivisionsDDBtn );
876}
877
878QString QgsLayoutScaleBarWidget::linkedMapUnitsString( QgsLayoutItemScaleBar *scalebar )
879{
880 QString mapUnit;
881 if ( scalebar )
882 {
883 if ( QgsLayoutItemMap *map = scalebar->linkedMap() )
884 {
885 const Qgis::DistanceUnit mapCrsUnits = map->crs().mapUnits();
886 if ( mapCrsUnits != Qgis::DistanceUnit::Unknown )
887 {
888 mapUnit = QgsUnitTypes::toString( mapCrsUnits );
889 }
890 }
891 }
892 return mapUnit.isEmpty() ? tr( "Map Units" ) : tr( "Map Units (%1)" ).arg( mapUnit );
893}
ScaleBarDistanceLabelHorizontalPlacement
Scale bar distance label horizontal placement.
Definition qgis.h:5417
@ CenteredSegment
Labels are drawn centered relative to segment.
Definition qgis.h:5419
@ CenteredEdge
Labels are drawn centered relative to segment's edge.
Definition qgis.h:5418
ScaleBarDistanceLabelVerticalPlacement
Scale bar distance label vertical placement.
Definition qgis.h:5403
@ AboveSegment
Labels are drawn above the scalebar.
Definition qgis.h:5404
@ BelowSegment
Labels are drawn below the scalebar.
Definition qgis.h:5405
ScaleBarAlignment
Scalebar alignment.
Definition qgis.h:5374
@ Right
Right aligned.
Definition qgis.h:5377
@ Left
Left aligned.
Definition qgis.h:5375
@ Middle
Center aligned.
Definition qgis.h:5376
DistanceUnit
Units of distance.
Definition qgis.h:5085
@ Feet
Imperial feet.
Definition qgis.h:5088
@ Centimeters
Centimeters.
Definition qgis.h:5093
@ Millimeters
Millimeters.
Definition qgis.h:5094
@ Miles
Terrestrial miles.
Definition qgis.h:5091
@ Meters
Meters.
Definition qgis.h:5086
@ Unknown
Unknown distance unit.
Definition qgis.h:5135
@ Yards
Imperial yards.
Definition qgis.h:5090
@ Inches
Inches.
Definition qgis.h:5095
@ NauticalMiles
Nautical miles.
Definition qgis.h:5089
@ Kilometers
Kilometers.
Definition qgis.h:5087
@ FitWidth
Scale bar segment size is calculated to fit a size range.
Definition qgis.h:5391
@ Fixed
Scale bar segment size is fixed to a map unit.
Definition qgis.h:5390
@ Line
Line symbol.
Definition qgis.h:631
@ Fill
Fill symbol.
Definition qgis.h:632
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:7489
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
Definition qgis.h:6804
Single variable definition for use within a QgsExpressionContextScope.