QGIS API Documentation 4.1.0-Master (5bf3c20f3c9)
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(
327 mDistanceLabelPlacementComboBox->findData( static_cast<int>( 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(
509)
510{
511 switch ( horizontalPlacement )
512 {
514 switch ( verticalPlacement )
515 {
517 return DistanceLabelPlacement::CenteredAboveSegmentEdges;
519 return DistanceLabelPlacement::CenteredBelowSegmentEdges;
520 }
522
524 switch ( verticalPlacement )
525 {
527 return DistanceLabelPlacement::CenteredAboveSegmentCenters;
529 return DistanceLabelPlacement::CenteredBelowSegmentCenters;
530 }
532 }
534}
535
536void QgsLayoutScaleBarWidget::mUnitLabelLineEdit_textChanged( const QString &text )
537{
538 if ( !mScalebar )
539 {
540 return;
541 }
542
543 mScalebar->beginCommand( tr( "Set Scalebar Unit Text" ), QgsLayoutItem::UndoScaleBarUnitText );
544 disconnectUpdateSignal();
545 mScalebar->setUnitLabel( text );
546 mScalebar->update();
547 connectUpdateSignal();
548 mScalebar->endCommand();
549}
550
551void QgsLayoutScaleBarWidget::mMapUnitsPerBarUnitSpinBox_valueChanged( double d )
552{
553 if ( !mScalebar )
554 {
555 return;
556 }
557
558 mScalebar->beginCommand( tr( "Set Scalebar Map Units per Segment" ), QgsLayoutItem::UndoScaleBarMapUnitsSegment );
559 disconnectUpdateSignal();
560 mScalebar->setMapUnitsPerScaleBarUnit( d );
561 mScalebar->update();
562 connectUpdateSignal();
563 mScalebar->endCommand();
564}
565
566void QgsLayoutScaleBarWidget::mStyleComboBox_currentIndexChanged( const QString & )
567{
568 if ( !mScalebar )
569 {
570 return;
571 }
572
573 const QString rendererId = mStyleComboBox->currentData().toString();
574 if ( rendererId == mScalebar->style() )
575 return;
576
577 mScalebar->beginCommand( tr( "Set Scalebar Style" ) );
578 disconnectUpdateSignal();
579
580 bool defaultsApplied = false;
581 const std::unique_ptr<QgsScaleBarRenderer> renderer( QgsApplication::scaleBarRendererRegistry()->renderer( rendererId ) );
582 if ( renderer )
583 defaultsApplied = mScalebar->applyDefaultRendererSettings( renderer.get() );
584
585 //disable or enable controls which apply to specific scale bar styles
586 toggleStyleSpecificControls( rendererId );
587
588 mScalebar->setStyle( rendererId );
589 mScalebar->update();
590 connectUpdateSignal();
591 mScalebar->endCommand();
592
593 if ( defaultsApplied )
594 setGuiElements();
595}
596
597void QgsLayoutScaleBarWidget::toggleStyleSpecificControls( const QString &style )
598{
599 std::unique_ptr<QgsScaleBarRenderer> renderer( QgsApplication::scaleBarRendererRegistry()->renderer( style ) );
600
601 //Selectively enable controls which apply to the scale bar style
602 mUnitsComboBox->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagRespectsUnits : true );
603 mUnitsLabel->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagRespectsUnits : true );
604 mMapUnitsPerBarUnitSpinBox->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagRespectsMapUnitsPerScaleBarUnit : true );
605 mMapUnitsPerBarUnitLabel->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagRespectsMapUnitsPerScaleBarUnit : true );
606 mUnitLabelLineEdit->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesUnitLabel : true );
607 mUnitLabelLabel->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesUnitLabel : true );
608 mSubdivisionsLabel->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesSubdivisions : true );
609 mNumberOfSubdivisionsSpinBox->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesSubdivisions : true );
610 mSubdivisionsHeightLabel->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesSubdivisionsHeight : true );
611 mSubdivisionsHeightSpinBox->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesSubdivisionsHeight : true );
612 mGroupBoxSegments->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesSegments : true );
613 if ( !mGroupBoxUnits->isEnabled() )
614 mGroupBoxSegments->setCollapsed( true );
615 mLabelBarSpaceSpinBox->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesLabelBarSpace : true );
616 mLabelBarSpaceLabel->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesLabelBarSpace : true );
617 mDistanceLabelPlacementComboBox->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesLabelVerticalPlacement : true );
618 mLabelVerticalPlacementLabel->setEnabled(
620 );
621 mAlignmentComboBox->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesAlignment : true );
622 mAlignmentLabel->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesAlignment : true );
623 mFillSymbol1Button->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesFillSymbol : true );
624 mFillSymbol1Label->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesFillSymbol : true );
625 mFillSymbol2Button->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesAlternateFillSymbol : true );
626 mFillSymbol2Label->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesAlternateFillSymbol : true );
627 mLineStyleButton->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesLineSymbol : true );
628 mLineStyleLabel->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesLineSymbol : true );
629 mDivisionStyleButton->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesDivisionSymbol : true );
630 mDivisionStyleLabel->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesDivisionSymbol : true );
631 mSubdivisionStyleButton->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesSubdivisionSymbol : true );
632 mSubdivisionStyleLabel->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesSubdivisionSymbol : true );
633}
634
635void QgsLayoutScaleBarWidget::mLabelBarSpaceSpinBox_valueChanged( double d )
636{
637 if ( !mScalebar )
638 {
639 return;
640 }
641
642 mScalebar->beginCommand( tr( "Set Scalebar Label Space" ), QgsLayoutItem::UndoScaleBarLabelBarSize );
643 disconnectUpdateSignal();
644 mScalebar->setLabelBarSpace( d );
645 mScalebar->update();
646 connectUpdateSignal();
647 mScalebar->endCommand();
648}
649
650void QgsLayoutScaleBarWidget::mBoxSizeSpinBox_valueChanged( double d )
651{
652 if ( !mScalebar )
653 {
654 return;
655 }
656
657 mScalebar->beginCommand( tr( "Set Scalebar Box Space" ), QgsLayoutItem::UndoScaleBarBoxContentSpace );
658 disconnectUpdateSignal();
659 mScalebar->setBoxContentSpace( d );
660 mScalebar->update();
661 connectUpdateSignal();
662 mScalebar->endCommand();
663}
664
665void QgsLayoutScaleBarWidget::mDistanceLabelPlacementComboBox_currentIndexChanged( int index )
666{
667 if ( !mScalebar )
668 {
669 return;
670 }
671
672 mScalebar->beginCommand( tr( "Set Scalebar Label Placement" ) );
673 disconnectUpdateSignal();
674
675 const DistanceLabelPlacement placement = static_cast<DistanceLabelPlacement>( mDistanceLabelPlacementComboBox->itemData( index ).toInt() );
676 switch ( placement )
677 {
678 case DistanceLabelPlacement::CenteredAboveSegmentEdges:
679 mScalebar->setLabelVerticalPlacement( Qgis::ScaleBarDistanceLabelVerticalPlacement::AboveSegment );
680 mScalebar->setLabelHorizontalPlacement( Qgis::ScaleBarDistanceLabelHorizontalPlacement::CenteredEdge );
681 break;
682 case DistanceLabelPlacement::CenteredAboveSegmentCenters:
683 mScalebar->setLabelVerticalPlacement( Qgis::ScaleBarDistanceLabelVerticalPlacement::AboveSegment );
684 mScalebar->setLabelHorizontalPlacement( Qgis::ScaleBarDistanceLabelHorizontalPlacement::CenteredSegment );
685 break;
686 case DistanceLabelPlacement::CenteredBelowSegmentEdges:
687 mScalebar->setLabelVerticalPlacement( Qgis::ScaleBarDistanceLabelVerticalPlacement::BelowSegment );
688 mScalebar->setLabelHorizontalPlacement( Qgis::ScaleBarDistanceLabelHorizontalPlacement::CenteredEdge );
689 break;
690 case DistanceLabelPlacement::CenteredBelowSegmentCenters:
691 mScalebar->setLabelVerticalPlacement( Qgis::ScaleBarDistanceLabelVerticalPlacement::BelowSegment );
692 mScalebar->setLabelHorizontalPlacement( Qgis::ScaleBarDistanceLabelHorizontalPlacement::CenteredSegment );
693 break;
694 }
695
696 mScalebar->update();
697 connectUpdateSignal();
698 mScalebar->endCommand();
699}
700
701void QgsLayoutScaleBarWidget::alignmentChanged()
702{
703 if ( !mScalebar )
704 {
705 return;
706 }
707
708 mScalebar->beginCommand( tr( "Set Scalebar Alignment" ) );
709 disconnectUpdateSignal();
710
711 const Qgis::ScaleBarAlignment a = mAlignmentComboBox->currentAlignment() & Qt::AlignLeft ? Qgis::ScaleBarAlignment::Left
712 : mAlignmentComboBox->currentAlignment() & Qt::AlignRight ? Qgis::ScaleBarAlignment::Right
714 mScalebar->setAlignment( a );
715 mScalebar->update();
716 connectUpdateSignal();
717 mScalebar->endCommand();
718}
719
720void QgsLayoutScaleBarWidget::mUnitsComboBox_currentIndexChanged( int index )
721{
722 if ( !mScalebar )
723 {
724 return;
725 }
726
727 const QVariant unitData = mUnitsComboBox->itemData( index );
728 if ( unitData.userType() == QMetaType::Type::UnknownType )
729 {
730 return;
731 }
732
733 disconnectUpdateSignal();
734 mScalebar->beginCommand( tr( "Set Scalebar Units" ) );
735 mScalebar->applyDefaultSize( static_cast<Qgis::DistanceUnit>( unitData.toInt() ) );
736 mScalebar->update();
737
738 mNumberOfSegmentsSpinBox->setValue( mScalebar->numberOfSegments() );
739 mSegmentsLeftSpinBox->setValue( mScalebar->numberOfSegmentsLeft() );
740 mUnitLabelLineEdit->setText( mScalebar->unitLabel() );
741 mSegmentSizeSpinBox->setValue( mScalebar->unitsPerSegment() );
742 mMapUnitsPerBarUnitSpinBox->setValue( mScalebar->mapUnitsPerScaleBarUnit() );
743
744 connectUpdateSignal();
745 mScalebar->endCommand();
746}
747
748void QgsLayoutScaleBarWidget::blockMemberSignals( bool block )
749{
750 mSegmentSizeSpinBox->blockSignals( block );
751 mNumberOfSegmentsSpinBox->blockSignals( block );
752 mSegmentsLeftSpinBox->blockSignals( block );
753 mNumberOfSubdivisionsSpinBox->blockSignals( block );
754 mSubdivisionsHeightSpinBox->blockSignals( block );
755 mStyleComboBox->blockSignals( block );
756 mUnitLabelLineEdit->blockSignals( block );
757 mMapUnitsPerBarUnitSpinBox->blockSignals( block );
758 mHeightSpinBox->blockSignals( block );
759 mLineStyleButton->blockSignals( block );
760 mDivisionStyleButton->blockSignals( block );
761 mSubdivisionStyleButton->blockSignals( block );
762 mLabelBarSpaceSpinBox->blockSignals( block );
763 mBoxSizeSpinBox->blockSignals( block );
764 mDistanceLabelPlacementComboBox->blockSignals( block );
765 mAlignmentComboBox->blockSignals( block );
766 mUnitsComboBox->blockSignals( block );
767 mFillSymbol1Button->blockSignals( block );
768 mFillSymbol2Button->blockSignals( block );
769 mSegmentSizeRadioGroup.blockSignals( block );
770 mMapItemComboBox->blockSignals( block );
771 mFontButton->blockSignals( block );
772 mMinWidthSpinBox->blockSignals( block );
773 mMaxWidthSpinBox->blockSignals( block );
774 mScaleMethodWidget->blockSignals( block );
775}
776
777void QgsLayoutScaleBarWidget::connectUpdateSignal()
778{
779 if ( mScalebar )
780 {
781 connect( mScalebar, &QgsLayoutObject::changed, this, &QgsLayoutScaleBarWidget::setGuiElements );
782 }
783}
784
785void QgsLayoutScaleBarWidget::disconnectUpdateSignal()
786{
787 if ( mScalebar )
788 {
789 disconnect( mScalebar, &QgsLayoutObject::changed, this, &QgsLayoutScaleBarWidget::setGuiElements );
790 }
791}
792
793void QgsLayoutScaleBarWidget::segmentSizeRadioChanged( QAbstractButton *radio )
794{
795 const bool fixedSizeMode = radio == mFixedSizeRadio;
796 mMinWidthWidget->setEnabled( !fixedSizeMode );
797 mMaxWidthWidget->setEnabled( !fixedSizeMode );
798 mSegmentSizeWidget->setEnabled( fixedSizeMode );
799
800 if ( !mScalebar )
801 {
802 return;
803 }
804
805 mScalebar->beginCommand( tr( "Set Scalebar Size Mode" ), QgsLayoutItem::UndoScaleBarSegmentSize );
806 disconnectUpdateSignal();
807 if ( mFixedSizeRadio->isChecked() )
808 {
809 mScalebar->setSegmentSizeMode( Qgis::ScaleBarSegmentSizeMode::Fixed );
810 mScalebar->setUnitsPerSegment( mSegmentSizeSpinBox->value() );
811 }
812 else /*if(mFitWidthRadio->isChecked())*/
813 {
814 mScalebar->setSegmentSizeMode( Qgis::ScaleBarSegmentSizeMode::FitWidth );
815 }
816 mScalebar->update();
817 connectUpdateSignal();
818 mScalebar->endCommand();
819}
820
821void QgsLayoutScaleBarWidget::mapChanged( QgsLayoutItem *item )
822{
823 QgsLayoutItemMap *map = qobject_cast<QgsLayoutItemMap *>( item );
824 if ( !map )
825 {
826 return;
827 }
828
829 //set it to scale bar
830 mScalebar->beginCommand( tr( "Set Scalebar Map" ) );
831 disconnectUpdateSignal();
832 mScalebar->setLinkedMap( map );
833 mScalebar->update();
834 connectUpdateSignal();
835 mScalebar->endCommand();
836
837 mUnitsComboBox->setItemText( mUnitsComboBox->findData( static_cast<int>( Qgis::DistanceUnit::Unknown ) ), linkedMapUnitsString( mScalebar ) );
838}
839
840void QgsLayoutScaleBarWidget::mMinWidthSpinBox_valueChanged( double )
841{
842 if ( !mScalebar )
843 {
844 return;
845 }
846
847 mScalebar->beginCommand( tr( "Set Scalebar Size Mode" ), QgsLayoutItem::UndoScaleBarSegmentSize );
848 disconnectUpdateSignal();
849 mScalebar->setMinimumBarWidth( mMinWidthSpinBox->value() );
850 mScalebar->update();
851 connectUpdateSignal();
852 mScalebar->endCommand();
853}
854
855void QgsLayoutScaleBarWidget::mMaxWidthSpinBox_valueChanged( double )
856{
857 if ( !mScalebar )
858 {
859 return;
860 }
861
862 mScalebar->beginCommand( tr( "Set Scalebar Size Mode" ), QgsLayoutItem::UndoScaleBarSegmentSize );
863 disconnectUpdateSignal();
864 mScalebar->setMaximumBarWidth( mMaxWidthSpinBox->value() );
865 mScalebar->update();
866 connectUpdateSignal();
867 mScalebar->endCommand();
868}
869
870void QgsLayoutScaleBarWidget::populateDataDefinedButtons()
871{
872 updateDataDefinedButton( mSegmentsLeftDDBtn );
873 updateDataDefinedButton( mSegmentsRightDDBtn );
874 updateDataDefinedButton( mSegmentSizeDDBtn );
875 updateDataDefinedButton( mMinWidthDDBtn );
876 updateDataDefinedButton( mMaxWidthDDBtn );
877 updateDataDefinedButton( mHeightDDBtn );
878 updateDataDefinedButton( mSubdivisionHeightDDBtn );
879 updateDataDefinedButton( mRightSegmentSubdivisionsDDBtn );
880}
881
882QString QgsLayoutScaleBarWidget::linkedMapUnitsString( QgsLayoutItemScaleBar *scalebar )
883{
884 QString mapUnit;
885 if ( scalebar )
886 {
887 if ( QgsLayoutItemMap *map = scalebar->linkedMap() )
888 {
889 const Qgis::DistanceUnit mapCrsUnits = map->crs().mapUnits();
890 if ( mapCrsUnits != Qgis::DistanceUnit::Unknown )
891 {
892 mapUnit = QgsUnitTypes::toString( mapCrsUnits );
893 }
894 }
895 }
896 return mapUnit.isEmpty() ? tr( "Map Units" ) : tr( "Map Units (%1)" ).arg( mapUnit );
897}
ScaleBarDistanceLabelHorizontalPlacement
Scale bar distance label horizontal placement.
Definition qgis.h:5507
@ CenteredSegment
Labels are drawn centered relative to segment.
Definition qgis.h:5509
@ CenteredEdge
Labels are drawn centered relative to segment's edge.
Definition qgis.h:5508
ScaleBarDistanceLabelVerticalPlacement
Scale bar distance label vertical placement.
Definition qgis.h:5493
@ AboveSegment
Labels are drawn above the scalebar.
Definition qgis.h:5494
@ BelowSegment
Labels are drawn below the scalebar.
Definition qgis.h:5495
ScaleBarAlignment
Scalebar alignment.
Definition qgis.h:5464
@ Right
Right aligned.
Definition qgis.h:5467
@ Left
Left aligned.
Definition qgis.h:5465
@ Middle
Center aligned.
Definition qgis.h:5466
DistanceUnit
Units of distance.
Definition qgis.h:5170
@ Feet
Imperial feet.
Definition qgis.h:5173
@ Centimeters
Centimeters.
Definition qgis.h:5178
@ Millimeters
Millimeters.
Definition qgis.h:5179
@ Miles
Terrestrial miles.
Definition qgis.h:5176
@ Meters
Meters.
Definition qgis.h:5171
@ Unknown
Unknown distance unit.
Definition qgis.h:5220
@ Yards
Imperial yards.
Definition qgis.h:5175
@ Inches
Inches.
Definition qgis.h:5180
@ NauticalMiles
Nautical miles.
Definition qgis.h:5174
@ Kilometers
Kilometers.
Definition qgis.h:5172
@ FitWidth
Scale bar segment size is calculated to fit a size range.
Definition qgis.h:5481
@ Fixed
Scale bar segment size is fixed to a map unit.
Definition qgis.h:5480
@ Line
Line symbol.
Definition qgis.h:638
@ Fill
Fill symbol.
Definition qgis.h:639
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:7540
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
Definition qgis.h:6880
Single variable definition for use within a QgsExpressionContextScope.