QGIS API Documentation 4.3.0-Master (45633be667c)
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 mUnitLabelPlacementComboBox->addItemWithCheckState( tr( "Before First Distance Label" ), Qt::CheckState::Unchecked, QVariant::fromValue( Qgis::ScaleBarUnitLabelPlacement::BeforeFirstDistanceLabel ) );
139 mUnitLabelPlacementComboBox->addItemWithCheckState( tr( "After Last Distance Label" ), Qt::CheckState::Unchecked, QVariant::fromValue( Qgis::ScaleBarUnitLabelPlacement::AfterLastDistanceLabel ) );
140 mUnitLabelPlacementComboBox->addItemWithCheckState( tr( "Before Every Distance Label" ), Qt::CheckState::Unchecked, QVariant::fromValue( Qgis::ScaleBarUnitLabelPlacement::BeforeEveryDistanceLabel ) );
141 mUnitLabelPlacementComboBox->addItemWithCheckState( tr( "After Every Distance Label" ), Qt::CheckState::Unchecked, QVariant::fromValue( Qgis::ScaleBarUnitLabelPlacement::AfterEveryDistanceLabel ) );
142 mUnitLabelPlacementComboBox->addItemWithCheckState( tr( "Before Bar" ), Qt::CheckState::Unchecked, QVariant::fromValue( Qgis::ScaleBarUnitLabelPlacement::BeforeBar ) );
143 mUnitLabelPlacementComboBox->addItemWithCheckState( tr( "After Bar" ), Qt::CheckState::Unchecked, QVariant::fromValue( Qgis::ScaleBarUnitLabelPlacement::AfterBar ) );
144 mUnitLabelPlacementComboBox->addItemWithCheckState( tr( "Above Bar, Left" ), Qt::CheckState::Unchecked, QVariant::fromValue( Qgis::ScaleBarUnitLabelPlacement::LeftAbove ) );
145 mUnitLabelPlacementComboBox->addItemWithCheckState( tr( "Above Bar, Center" ), Qt::CheckState::Unchecked, QVariant::fromValue( Qgis::ScaleBarUnitLabelPlacement::CenteredAbove ) );
146 mUnitLabelPlacementComboBox->addItemWithCheckState( tr( "Above Bar, Right" ), Qt::CheckState::Unchecked, QVariant::fromValue( Qgis::ScaleBarUnitLabelPlacement::RightAbove ) );
147 mUnitLabelPlacementComboBox->addItemWithCheckState( tr( "Below Bar, Left" ), Qt::CheckState::Unchecked, QVariant::fromValue( Qgis::ScaleBarUnitLabelPlacement::LeftBelow ) );
148 mUnitLabelPlacementComboBox->addItemWithCheckState( tr( "Below Bar, Center" ), Qt::CheckState::Unchecked, QVariant::fromValue( Qgis::ScaleBarUnitLabelPlacement::CenteredBelow ) );
149 mUnitLabelPlacementComboBox->addItemWithCheckState( tr( "Below Bar, Right" ), Qt::CheckState::Unchecked, QVariant::fromValue( Qgis::ScaleBarUnitLabelPlacement::RightBelow ) );
150 mUnitLabelPlacementComboBox->addItemWithCheckState( tr( "On Bar, After First Division" ), Qt::CheckState::Unchecked, QVariant::fromValue( Qgis::ScaleBarUnitLabelPlacement::OnBarAfterFirstDivision ) );
151 connect( mUnitLabelPlacementComboBox, &QgsCheckableComboBox::checkedItemsChanged, this, &QgsLayoutScaleBarWidget::labelUnitPlacementChanged );
152
153 mLineStyleButton->setSymbolType( Qgis::SymbolType::Line );
154 connect( mLineStyleButton, &QgsSymbolButton::changed, this, &QgsLayoutScaleBarWidget::lineSymbolChanged );
155
156 mDivisionStyleButton->setSymbolType( Qgis::SymbolType::Line );
157 connect( mDivisionStyleButton, &QgsSymbolButton::changed, this, &QgsLayoutScaleBarWidget::divisionSymbolChanged );
158
159 mSubdivisionStyleButton->setSymbolType( Qgis::SymbolType::Line );
160 connect( mSubdivisionStyleButton, &QgsSymbolButton::changed, this, &QgsLayoutScaleBarWidget::subdivisionSymbolChanged );
161
162 mFillSymbol1Button->setSymbolType( Qgis::SymbolType::Fill );
163 connect( mFillSymbol1Button, &QgsSymbolButton::changed, this, &QgsLayoutScaleBarWidget::fillSymbol1Changed );
164
165 mFillSymbol2Button->setSymbolType( Qgis::SymbolType::Fill );
166 connect( mFillSymbol2Button, &QgsSymbolButton::changed, this, &QgsLayoutScaleBarWidget::fillSymbol2Changed );
167
168 mFontButton->setDialogTitle( tr( "Scalebar Font" ) );
169 mFontButton->setMode( QgsFontButton::ModeTextRenderer );
170
171 if ( mScalebar )
172 {
173 QgsLayout *scaleBarLayout = mScalebar->layout();
174 if ( scaleBarLayout )
175 {
176 mMapItemComboBox->setCurrentLayout( scaleBarLayout );
177 mMapItemComboBox->setItemType( QgsLayoutItemRegistry::LayoutMap );
178 }
179 }
180
181 connect( mMapItemComboBox, &QgsLayoutItemComboBox::itemChanged, this, &QgsLayoutScaleBarWidget::mapChanged );
182
183 blockMemberSignals( false );
184 setGuiElements(); //set the GUI elements to the state of scaleBar
185
186 mLineStyleButton->registerExpressionContextGenerator( mScalebar );
187 mLineStyleButton->setLayer( coverageLayer() );
188 mDivisionStyleButton->registerExpressionContextGenerator( mScalebar );
189 mDivisionStyleButton->setLayer( coverageLayer() );
190 mSubdivisionStyleButton->registerExpressionContextGenerator( mScalebar );
191 mSubdivisionStyleButton->setLayer( coverageLayer() );
192 mFillSymbol1Button->registerExpressionContextGenerator( mScalebar );
193 mFillSymbol1Button->setLayer( coverageLayer() );
194 mFillSymbol2Button->registerExpressionContextGenerator( mScalebar );
195 mFillSymbol2Button->setLayer( coverageLayer() );
196
197 connect( mFontButton, &QgsFontButton::changed, this, &QgsLayoutScaleBarWidget::textFormatChanged );
198 mFontButton->setLayer( coverageLayer() );
199 if ( mScalebar->layout() )
200 {
201 connect( &mScalebar->layout()->reportContext(), &QgsLayoutReportContext::layerChanged, mFontButton, &QgsFontButton::setLayer );
202 connect( &mScalebar->layout()->reportContext(), &QgsLayoutReportContext::layerChanged, mLineStyleButton, &QgsSymbolButton::setLayer );
203 connect( &mScalebar->layout()->reportContext(), &QgsLayoutReportContext::layerChanged, mDivisionStyleButton, &QgsSymbolButton::setLayer );
204 connect( &mScalebar->layout()->reportContext(), &QgsLayoutReportContext::layerChanged, mSubdivisionStyleButton, &QgsSymbolButton::setLayer );
205 connect( &mScalebar->layout()->reportContext(), &QgsLayoutReportContext::layerChanged, mFillSymbol1Button, &QgsSymbolButton::setLayer );
206 connect( &mScalebar->layout()->reportContext(), &QgsLayoutReportContext::layerChanged, mFillSymbol2Button, &QgsSymbolButton::setLayer );
207 }
208}
209
211{
212 if ( mItemPropertiesWidget )
213 mItemPropertiesWidget->setMasterLayout( masterLayout );
214}
215
217{
218 QgsExpressionContext context = mScalebar->createExpressionContext();
219 QgsExpressionContextScope *scaleScope = new QgsExpressionContextScope( u"scalebar_text"_s );
220 scaleScope->addVariable( QgsExpressionContextScope::StaticVariable( u"scale_value"_s, 0, true, false ) );
221 context.appendScope( scaleScope );
222 context.setHighlightedVariables( QStringList() << u"scale_value"_s );
223 return context;
224}
225
227{
229 return false;
230
231 disconnectUpdateSignal();
232
233 mScalebar = qobject_cast<QgsLayoutItemScaleBar *>( item );
234 mItemPropertiesWidget->setItem( mScalebar );
235
236 if ( mScalebar )
237 {
238 connectUpdateSignal();
239 mFillSymbol1Button->registerExpressionContextGenerator( mScalebar );
240 mFillSymbol2Button->registerExpressionContextGenerator( mScalebar );
241 mLineStyleButton->registerExpressionContextGenerator( mScalebar );
242 mDivisionStyleButton->registerExpressionContextGenerator( mScalebar );
243 mSubdivisionStyleButton->registerExpressionContextGenerator( mScalebar );
244 }
245
246 setGuiElements();
247
248 return true;
249}
250
251void QgsLayoutScaleBarWidget::lineSymbolChanged()
252{
253 if ( !mScalebar )
254 return;
255
256 mScalebar->layout()->undoStack()->beginCommand( mScalebar, tr( "Change Scalebar Line Style" ), QgsLayoutItem::UndoShapeStyle );
257 mScalebar->setLineSymbol( mLineStyleButton->clonedSymbol<QgsLineSymbol>() );
258 mScalebar->update();
259 mScalebar->layout()->undoStack()->endCommand();
260}
261
262void QgsLayoutScaleBarWidget::divisionSymbolChanged()
263{
264 if ( !mScalebar )
265 return;
266
267 mScalebar->layout()->undoStack()->beginCommand( mScalebar, tr( "Change Scalebar Division Style" ), QgsLayoutItem::UndoShapeStyle );
268 mScalebar->setDivisionLineSymbol( mDivisionStyleButton->clonedSymbol<QgsLineSymbol>() );
269 mScalebar->update();
270 mScalebar->layout()->undoStack()->endCommand();
271}
272
273void QgsLayoutScaleBarWidget::subdivisionSymbolChanged()
274{
275 if ( !mScalebar )
276 return;
277
278 mScalebar->layout()->undoStack()->beginCommand( mScalebar, tr( "Change Scalebar Subdivision Style" ), QgsLayoutItem::UndoShapeStyle );
279 mScalebar->setSubdivisionLineSymbol( mSubdivisionStyleButton->clonedSymbol<QgsLineSymbol>() );
280 mScalebar->update();
281 mScalebar->layout()->undoStack()->endCommand();
282}
283
284void QgsLayoutScaleBarWidget::fillSymbol1Changed()
285{
286 if ( !mScalebar )
287 return;
288
289 mScalebar->layout()->undoStack()->beginCommand( mScalebar, tr( "Change Scalebar Fill Style" ), QgsLayoutItem::UndoShapeStyle );
290 mScalebar->setFillSymbol( mFillSymbol1Button->clonedSymbol<QgsFillSymbol>() );
291 mScalebar->update();
292 mScalebar->layout()->undoStack()->endCommand();
293}
294
295void QgsLayoutScaleBarWidget::fillSymbol2Changed()
296{
297 if ( !mScalebar )
298 return;
299
300 mScalebar->layout()->undoStack()->beginCommand( mScalebar, tr( "Change Scalebar Fill Style" ), QgsLayoutItem::UndoShapeStyle );
301 mScalebar->setAlternateFillSymbol( mFillSymbol2Button->clonedSymbol<QgsFillSymbol>() );
302 mScalebar->update();
303 mScalebar->layout()->undoStack()->endCommand();
304}
305
306void QgsLayoutScaleBarWidget::setGuiElements()
307{
308 if ( !mScalebar )
309 {
310 return;
311 }
312
313 blockMemberSignals( true );
314 mNumberOfSegmentsSpinBox->setValue( mScalebar->numberOfSegments() );
315 mSegmentsLeftSpinBox->setValue( mScalebar->numberOfSegmentsLeft() );
316 mSegmentSizeSpinBox->setValue( mScalebar->unitsPerSegment() );
317 mHeightSpinBox->setValue( mScalebar->height() );
318 mNumberOfSubdivisionsSpinBox->setValue( mScalebar->numberOfSubdivisions() );
319 mSubdivisionsHeightSpinBox->setValue( mScalebar->subdivisionsHeight() );
320 mMapUnitsPerBarUnitSpinBox->setValue( mScalebar->mapUnitsPerScaleBarUnit() );
321 mLabelBarSpaceSpinBox->setValue( mScalebar->labelBarSpace() );
322 mBoxSizeSpinBox->setValue( mScalebar->boxContentSpace() );
323 mUnitLabelLineEdit->setText( mScalebar->unitLabel() );
324 mFontButton->setTextFormat( mScalebar->textFormat() );
325
326 whileBlocking( mLineStyleButton )->setSymbol( mScalebar->lineSymbol()->clone() );
327 whileBlocking( mDivisionStyleButton )->setSymbol( mScalebar->divisionLineSymbol()->clone() );
328 whileBlocking( mSubdivisionStyleButton )->setSymbol( mScalebar->subdivisionLineSymbol()->clone() );
329 whileBlocking( mFillSymbol1Button )->setSymbol( mScalebar->fillSymbol()->clone() );
330 whileBlocking( mFillSymbol2Button )->setSymbol( mScalebar->alternateFillSymbol()->clone() );
331
332 //map combo box
333 mMapItemComboBox->setItem( mScalebar->linkedMap() );
334
335 //style...
336 const QString style = mScalebar->style();
337 mStyleComboBox->setCurrentIndex( mStyleComboBox->findData( style ) );
338 toggleStyleSpecificControls( style );
339
340 //label vertical/horizontal placement
341 mDistanceLabelPlacementComboBox->setCurrentIndex(
342 mDistanceLabelPlacementComboBox->findData( static_cast<int>( distanceLabelPlacement( mScalebar->labelHorizontalPlacement(), mScalebar->labelVerticalPlacement() ) ) )
343 );
344
345 mUnitLabelPlacementComboBox->setCheckedItemsFromFlags< Qgis::ScaleBarUnitLabelPlacement >( mScalebar->unitLabelPlacements() );
346
347 //alignment
348
349 Qt::Alignment a = Qt::AlignLeft;
350 switch ( mScalebar->alignment() )
351 {
353 a = Qt::AlignLeft;
354 break;
356 a = Qt::AlignRight;
357 break;
359 a = Qt::AlignHCenter;
360 break;
361 }
362 mAlignmentComboBox->setCurrentAlignment( a );
363
364 //units
365 mUnitsComboBox->setCurrentIndex( mUnitsComboBox->findData( static_cast<int>( mScalebar->units() ) ) );
366
367 switch ( mScalebar->segmentSizeMode() )
368 {
370 {
371 mFixedSizeRadio->setChecked( true );
372 mSegmentSizeWidget->setEnabled( true );
373 mMinWidthWidget->setEnabled( false );
374 mMaxWidthWidget->setEnabled( false );
375 break;
376 }
377
379 {
380 mFitWidthRadio->setChecked( true );
381 mSegmentSizeWidget->setEnabled( false );
382 mMinWidthWidget->setEnabled( true );
383 mMaxWidthWidget->setEnabled( true );
384 break;
385 }
386 }
387 mMinWidthSpinBox->setValue( mScalebar->minimumBarWidth() );
388 mMaxWidthSpinBox->setValue( mScalebar->maximumBarWidth() );
389
390 mScaleMethodWidget->setScaleMethod( mScalebar->method() );
391
392 populateDataDefinedButtons();
393
394 blockMemberSignals( false );
395}
396
397//slots
398
399void QgsLayoutScaleBarWidget::mSegmentSizeSpinBox_valueChanged( double d )
400{
401 if ( !mScalebar )
402 {
403 return;
404 }
405
406 mScalebar->beginCommand( tr( "Set Scalebar Segment Size" ), QgsLayoutItem::UndoScaleBarSegmentSize );
407 disconnectUpdateSignal();
408 mScalebar->setUnitsPerSegment( d );
409 mScalebar->update();
410 connectUpdateSignal();
411 mScalebar->endCommand();
412}
413
414void QgsLayoutScaleBarWidget::mSegmentsLeftSpinBox_valueChanged( int i )
415{
416 if ( !mScalebar )
417 {
418 return;
419 }
420
421 mScalebar->beginCommand( tr( "Set Scalebar Segments" ), QgsLayoutItem::UndoScaleBarSegmentsLeft );
422 disconnectUpdateSignal();
423 mScalebar->setNumberOfSegmentsLeft( i );
424 mScalebar->update();
425 connectUpdateSignal();
426 mScalebar->endCommand();
427}
428
429void QgsLayoutScaleBarWidget::mNumberOfSegmentsSpinBox_valueChanged( int i )
430{
431 if ( !mScalebar )
432 {
433 return;
434 }
435
436 mScalebar->beginCommand( tr( "Set Scalebar Segments" ), QgsLayoutItem::UndoScaleBarSegments );
437 disconnectUpdateSignal();
438 mScalebar->setNumberOfSegments( i );
439 mScalebar->update();
440 connectUpdateSignal();
441 mScalebar->endCommand();
442}
443
444void QgsLayoutScaleBarWidget::mHeightSpinBox_valueChanged( double d )
445{
446 if ( !mScalebar )
447 {
448 return;
449 }
450 mScalebar->beginCommand( tr( "Set Scalebar Height" ), QgsLayoutItem::UndoScaleBarHeight );
451 disconnectUpdateSignal();
452 mScalebar->setHeight( d );
453 mScalebar->update();
454 connectUpdateSignal();
455 mScalebar->endCommand();
456}
457
458void QgsLayoutScaleBarWidget::mNumberOfSubdivisionsSpinBox_valueChanged( int i )
459{
460 if ( !mScalebar )
461 {
462 return;
463 }
464
465 mScalebar->beginCommand( tr( "Set Scalebar Subdivisions" ), QgsLayoutItem::UndoScaleBarSubdivisions );
466 disconnectUpdateSignal();
467 mScalebar->setNumberOfSubdivisions( i );
468 mScalebar->update();
469 connectUpdateSignal();
470 mScalebar->endCommand();
471}
472
473void QgsLayoutScaleBarWidget::mSubdivisionsHeightSpinBox_valueChanged( double d )
474{
475 if ( !mScalebar )
476 {
477 return;
478 }
479 mScalebar->beginCommand( tr( "Set Subdivisions Height" ), QgsLayoutItem::UndoScaleBarSubdivisionsHeight );
480 disconnectUpdateSignal();
481 mScalebar->setSubdivisionsHeight( d );
482 mScalebar->update();
483 connectUpdateSignal();
484 mScalebar->endCommand();
485}
486
487void QgsLayoutScaleBarWidget::textFormatChanged()
488{
489 if ( !mScalebar )
490 {
491 return;
492 }
493
494 mScalebar->beginCommand( tr( "Set Scalebar Font" ) );
495 disconnectUpdateSignal();
496 mScalebar->setTextFormat( mFontButton->textFormat() );
497 connectUpdateSignal();
498 mScalebar->endCommand();
499 mScalebar->update();
500}
501
502void QgsLayoutScaleBarWidget::changeNumberFormat()
503{
504 if ( !mScalebar )
505 {
506 return;
507 }
508
509 QgsNumericFormatSelectorWidget *widget = new QgsNumericFormatSelectorWidget( this );
510 widget->setPanelTitle( tr( "Number Format" ) );
511 widget->setFormat( mScalebar->numericFormat() );
512 connect( widget, &QgsNumericFormatSelectorWidget::changed, this, [this, widget] {
513 mScalebar->beginCommand( tr( "Set Scalebar Number Format" ) );
514 disconnectUpdateSignal();
515 mScalebar->setNumericFormat( widget->format() );
516 connectUpdateSignal();
517 mScalebar->endCommand();
518 mScalebar->update();
519 } );
520 openPanel( widget );
521 return;
522}
523
524QgsLayoutScaleBarWidget::DistanceLabelPlacement QgsLayoutScaleBarWidget::distanceLabelPlacement(
526)
527{
528 switch ( horizontalPlacement )
529 {
531 switch ( verticalPlacement )
532 {
534 return DistanceLabelPlacement::CenteredAboveSegmentEdges;
536 return DistanceLabelPlacement::CenteredBelowSegmentEdges;
537 }
539
541 switch ( verticalPlacement )
542 {
544 return DistanceLabelPlacement::CenteredAboveSegmentCenters;
546 return DistanceLabelPlacement::CenteredBelowSegmentCenters;
547 }
549 }
551}
552
553void QgsLayoutScaleBarWidget::mUnitLabelLineEdit_textChanged( const QString &text )
554{
555 if ( !mScalebar )
556 {
557 return;
558 }
559
560 mScalebar->beginCommand( tr( "Set Scalebar Unit Text" ), QgsLayoutItem::UndoScaleBarUnitText );
561 disconnectUpdateSignal();
562 mScalebar->setUnitLabel( text );
563 mScalebar->update();
564 connectUpdateSignal();
565 mScalebar->endCommand();
566}
567
568void QgsLayoutScaleBarWidget::mMapUnitsPerBarUnitSpinBox_valueChanged( double d )
569{
570 if ( !mScalebar )
571 {
572 return;
573 }
574
575 mScalebar->beginCommand( tr( "Set Scalebar Map Units per Segment" ), QgsLayoutItem::UndoScaleBarMapUnitsSegment );
576 disconnectUpdateSignal();
577 mScalebar->setMapUnitsPerScaleBarUnit( d );
578 mScalebar->update();
579 connectUpdateSignal();
580 mScalebar->endCommand();
581}
582
583void QgsLayoutScaleBarWidget::mStyleComboBox_currentIndexChanged( const QString & )
584{
585 if ( !mScalebar )
586 {
587 return;
588 }
589
590 const QString rendererId = mStyleComboBox->currentData().toString();
591 if ( rendererId == mScalebar->style() )
592 return;
593
594 mScalebar->beginCommand( tr( "Set Scalebar Style" ) );
595 disconnectUpdateSignal();
596
597 bool defaultsApplied = false;
598 const std::unique_ptr<QgsScaleBarRenderer> renderer( QgsApplication::scaleBarRendererRegistry()->renderer( rendererId ) );
599 if ( renderer )
600 defaultsApplied = mScalebar->applyDefaultRendererSettings( renderer.get() );
601
602 //disable or enable controls which apply to specific scale bar styles
603 toggleStyleSpecificControls( rendererId );
604
605 mScalebar->setStyle( rendererId );
606 mScalebar->update();
607 connectUpdateSignal();
608 mScalebar->endCommand();
609
610 if ( defaultsApplied )
611 setGuiElements();
612}
613
614void QgsLayoutScaleBarWidget::toggleStyleSpecificControls( const QString &style )
615{
616 std::unique_ptr<QgsScaleBarRenderer> renderer( QgsApplication::scaleBarRendererRegistry()->renderer( style ) );
617
618 //Selectively enable controls which apply to the scale bar style
619 mUnitsComboBox->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagRespectsUnits : true );
620 mUnitsLabel->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagRespectsUnits : true );
621 mMapUnitsPerBarUnitSpinBox->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagRespectsMapUnitsPerScaleBarUnit : true );
622 mMapUnitsPerBarUnitLabel->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagRespectsMapUnitsPerScaleBarUnit : true );
623 mUnitLabelLineEdit->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesUnitLabel : true );
624 mUnitLabelLabel->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesUnitLabel : true );
625 mSubdivisionsLabel->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesSubdivisions : true );
626 mNumberOfSubdivisionsSpinBox->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesSubdivisions : true );
627 mSubdivisionsHeightLabel->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesSubdivisionsHeight : true );
628 mSubdivisionsHeightSpinBox->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesSubdivisionsHeight : true );
629 mGroupBoxSegments->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesSegments : true );
630 if ( !mGroupBoxUnits->isEnabled() )
631 mGroupBoxSegments->setCollapsed( true );
632 mLabelBarSpaceSpinBox->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesLabelBarSpace : true );
633 mLabelBarSpaceLabel->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesLabelBarSpace : true );
634 mDistanceLabelPlacementComboBox->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesLabelVerticalPlacement : true );
635 mLabelVerticalPlacementLabel->setEnabled(
637 );
638 mAlignmentComboBox->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesAlignment : true );
639 mAlignmentLabel->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesAlignment : true );
640 mFillSymbol1Button->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesFillSymbol : true );
641 mFillSymbol1Label->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesFillSymbol : true );
642 mFillSymbol2Button->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesAlternateFillSymbol : true );
643 mFillSymbol2Label->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesAlternateFillSymbol : true );
644 mLineStyleButton->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesLineSymbol : true );
645 mLineStyleLabel->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesLineSymbol : true );
646 mDivisionStyleButton->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesDivisionSymbol : true );
647 mDivisionStyleLabel->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesDivisionSymbol : true );
648 mSubdivisionStyleButton->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesSubdivisionSymbol : true );
649 mSubdivisionStyleLabel->setEnabled( renderer ? renderer->flags() & QgsScaleBarRenderer::Flag::FlagUsesSubdivisionSymbol : true );
650}
651
652void QgsLayoutScaleBarWidget::mLabelBarSpaceSpinBox_valueChanged( double d )
653{
654 if ( !mScalebar )
655 {
656 return;
657 }
658
659 mScalebar->beginCommand( tr( "Set Scalebar Label Space" ), QgsLayoutItem::UndoScaleBarLabelBarSize );
660 disconnectUpdateSignal();
661 mScalebar->setLabelBarSpace( d );
662 mScalebar->update();
663 connectUpdateSignal();
664 mScalebar->endCommand();
665}
666
667void QgsLayoutScaleBarWidget::mBoxSizeSpinBox_valueChanged( double d )
668{
669 if ( !mScalebar )
670 {
671 return;
672 }
673
674 mScalebar->beginCommand( tr( "Set Scalebar Box Space" ), QgsLayoutItem::UndoScaleBarBoxContentSpace );
675 disconnectUpdateSignal();
676 mScalebar->setBoxContentSpace( d );
677 mScalebar->update();
678 connectUpdateSignal();
679 mScalebar->endCommand();
680}
681
682void QgsLayoutScaleBarWidget::mDistanceLabelPlacementComboBox_currentIndexChanged( int index )
683{
684 if ( !mScalebar )
685 {
686 return;
687 }
688
689 mScalebar->beginCommand( tr( "Set Scalebar Label Placement" ) );
690 disconnectUpdateSignal();
691
692 const DistanceLabelPlacement placement = static_cast<DistanceLabelPlacement>( mDistanceLabelPlacementComboBox->itemData( index ).toInt() );
693 switch ( placement )
694 {
695 case DistanceLabelPlacement::CenteredAboveSegmentEdges:
696 mScalebar->setLabelVerticalPlacement( Qgis::ScaleBarDistanceLabelVerticalPlacement::AboveSegment );
697 mScalebar->setLabelHorizontalPlacement( Qgis::ScaleBarDistanceLabelHorizontalPlacement::CenteredEdge );
698 break;
699 case DistanceLabelPlacement::CenteredAboveSegmentCenters:
700 mScalebar->setLabelVerticalPlacement( Qgis::ScaleBarDistanceLabelVerticalPlacement::AboveSegment );
701 mScalebar->setLabelHorizontalPlacement( Qgis::ScaleBarDistanceLabelHorizontalPlacement::CenteredSegment );
702 break;
703 case DistanceLabelPlacement::CenteredBelowSegmentEdges:
704 mScalebar->setLabelVerticalPlacement( Qgis::ScaleBarDistanceLabelVerticalPlacement::BelowSegment );
705 mScalebar->setLabelHorizontalPlacement( Qgis::ScaleBarDistanceLabelHorizontalPlacement::CenteredEdge );
706 break;
707 case DistanceLabelPlacement::CenteredBelowSegmentCenters:
708 mScalebar->setLabelVerticalPlacement( Qgis::ScaleBarDistanceLabelVerticalPlacement::BelowSegment );
709 mScalebar->setLabelHorizontalPlacement( Qgis::ScaleBarDistanceLabelHorizontalPlacement::CenteredSegment );
710 break;
711 }
712
713 mScalebar->update();
714 connectUpdateSignal();
715 mScalebar->endCommand();
716}
717
718void QgsLayoutScaleBarWidget::alignmentChanged()
719{
720 if ( !mScalebar )
721 {
722 return;
723 }
724
725 mScalebar->beginCommand( tr( "Set Scalebar Alignment" ) );
726 disconnectUpdateSignal();
727
728 const Qgis::ScaleBarAlignment a = mAlignmentComboBox->currentAlignment() & Qt::AlignLeft ? Qgis::ScaleBarAlignment::Left
729 : mAlignmentComboBox->currentAlignment() & Qt::AlignRight ? Qgis::ScaleBarAlignment::Right
731 mScalebar->setAlignment( a );
732 mScalebar->update();
733 connectUpdateSignal();
734 mScalebar->endCommand();
735}
736
737void QgsLayoutScaleBarWidget::mUnitsComboBox_currentIndexChanged( int index )
738{
739 if ( !mScalebar )
740 {
741 return;
742 }
743
744 const QVariant unitData = mUnitsComboBox->itemData( index );
745 if ( unitData.userType() == QMetaType::Type::UnknownType )
746 {
747 return;
748 }
749
750 disconnectUpdateSignal();
751 mScalebar->beginCommand( tr( "Set Scalebar Units" ) );
752 mScalebar->applyDefaultSize( static_cast<Qgis::DistanceUnit>( unitData.toInt() ) );
753 mScalebar->update();
754
755 mNumberOfSegmentsSpinBox->setValue( mScalebar->numberOfSegments() );
756 mSegmentsLeftSpinBox->setValue( mScalebar->numberOfSegmentsLeft() );
757 mUnitLabelLineEdit->setText( mScalebar->unitLabel() );
758 mSegmentSizeSpinBox->setValue( mScalebar->unitsPerSegment() );
759 mMapUnitsPerBarUnitSpinBox->setValue( mScalebar->mapUnitsPerScaleBarUnit() );
760
761 connectUpdateSignal();
762 mScalebar->endCommand();
763}
764
765void QgsLayoutScaleBarWidget::blockMemberSignals( bool block )
766{
767 mSegmentSizeSpinBox->blockSignals( block );
768 mNumberOfSegmentsSpinBox->blockSignals( block );
769 mSegmentsLeftSpinBox->blockSignals( block );
770 mNumberOfSubdivisionsSpinBox->blockSignals( block );
771 mSubdivisionsHeightSpinBox->blockSignals( block );
772 mStyleComboBox->blockSignals( block );
773 mUnitLabelLineEdit->blockSignals( block );
774 mMapUnitsPerBarUnitSpinBox->blockSignals( block );
775 mHeightSpinBox->blockSignals( block );
776 mLineStyleButton->blockSignals( block );
777 mDivisionStyleButton->blockSignals( block );
778 mSubdivisionStyleButton->blockSignals( block );
779 mLabelBarSpaceSpinBox->blockSignals( block );
780 mBoxSizeSpinBox->blockSignals( block );
781 mDistanceLabelPlacementComboBox->blockSignals( block );
782 mAlignmentComboBox->blockSignals( block );
783 mUnitsComboBox->blockSignals( block );
784 mFillSymbol1Button->blockSignals( block );
785 mFillSymbol2Button->blockSignals( block );
786 mSegmentSizeRadioGroup.blockSignals( block );
787 mMapItemComboBox->blockSignals( block );
788 mFontButton->blockSignals( block );
789 mMinWidthSpinBox->blockSignals( block );
790 mMaxWidthSpinBox->blockSignals( block );
791 mScaleMethodWidget->blockSignals( block );
792 mUnitLabelPlacementComboBox->blockSignals( block );
793}
794
795void QgsLayoutScaleBarWidget::connectUpdateSignal()
796{
797 if ( mScalebar )
798 {
799 connect( mScalebar, &QgsLayoutObject::changed, this, &QgsLayoutScaleBarWidget::setGuiElements );
800 }
801}
802
803void QgsLayoutScaleBarWidget::disconnectUpdateSignal()
804{
805 if ( mScalebar )
806 {
807 disconnect( mScalebar, &QgsLayoutObject::changed, this, &QgsLayoutScaleBarWidget::setGuiElements );
808 }
809}
810
811void QgsLayoutScaleBarWidget::segmentSizeRadioChanged( QAbstractButton *radio )
812{
813 const bool fixedSizeMode = radio == mFixedSizeRadio;
814 mMinWidthWidget->setEnabled( !fixedSizeMode );
815 mMaxWidthWidget->setEnabled( !fixedSizeMode );
816 mSegmentSizeWidget->setEnabled( fixedSizeMode );
817
818 if ( !mScalebar )
819 {
820 return;
821 }
822
823 mScalebar->beginCommand( tr( "Set Scalebar Size Mode" ), QgsLayoutItem::UndoScaleBarSegmentSize );
824 disconnectUpdateSignal();
825 if ( mFixedSizeRadio->isChecked() )
826 {
827 mScalebar->setSegmentSizeMode( Qgis::ScaleBarSegmentSizeMode::Fixed );
828 mScalebar->setUnitsPerSegment( mSegmentSizeSpinBox->value() );
829 }
830 else /*if(mFitWidthRadio->isChecked())*/
831 {
832 mScalebar->setSegmentSizeMode( Qgis::ScaleBarSegmentSizeMode::FitWidth );
833 }
834 mScalebar->update();
835 connectUpdateSignal();
836 mScalebar->endCommand();
837}
838
839void QgsLayoutScaleBarWidget::mapChanged( QgsLayoutItem *item )
840{
841 QgsLayoutItemMap *map = qobject_cast<QgsLayoutItemMap *>( item );
842 if ( !map )
843 {
844 return;
845 }
846
847 //set it to scale bar
848 mScalebar->beginCommand( tr( "Set Scalebar Map" ) );
849 disconnectUpdateSignal();
850 mScalebar->setLinkedMap( map );
851 mScalebar->update();
852 connectUpdateSignal();
853 mScalebar->endCommand();
854
855 mUnitsComboBox->setItemText( mUnitsComboBox->findData( static_cast<int>( Qgis::DistanceUnit::Unknown ) ), linkedMapUnitsString( mScalebar ) );
856}
857
858void QgsLayoutScaleBarWidget::mMinWidthSpinBox_valueChanged( double )
859{
860 if ( !mScalebar )
861 {
862 return;
863 }
864
865 mScalebar->beginCommand( tr( "Set Scalebar Size Mode" ), QgsLayoutItem::UndoScaleBarSegmentSize );
866 disconnectUpdateSignal();
867 mScalebar->setMinimumBarWidth( mMinWidthSpinBox->value() );
868 mScalebar->update();
869 connectUpdateSignal();
870 mScalebar->endCommand();
871}
872
873void QgsLayoutScaleBarWidget::mMaxWidthSpinBox_valueChanged( double )
874{
875 if ( !mScalebar )
876 {
877 return;
878 }
879
880 mScalebar->beginCommand( tr( "Set Scalebar Size Mode" ), QgsLayoutItem::UndoScaleBarSegmentSize );
881 disconnectUpdateSignal();
882 mScalebar->setMaximumBarWidth( mMaxWidthSpinBox->value() );
883 mScalebar->update();
884 connectUpdateSignal();
885 mScalebar->endCommand();
886}
887
888void QgsLayoutScaleBarWidget::labelUnitPlacementChanged()
889{
890 if ( !mScalebar )
891 {
892 return;
893 }
894
895 mScalebar->beginCommand( tr( "Set Scalebar Label Unit Placement" ) );
896 disconnectUpdateSignal();
897 mScalebar->setUnitLabelPlacements( mUnitLabelPlacementComboBox->flagsFromCheckedItems<Qgis::ScaleBarUnitLabelPlacement >() );
898 mScalebar->update();
899 connectUpdateSignal();
900 mScalebar->endCommand();
901}
902
903void QgsLayoutScaleBarWidget::populateDataDefinedButtons()
904{
905 updateDataDefinedButton( mSegmentsLeftDDBtn );
906 updateDataDefinedButton( mSegmentsRightDDBtn );
907 updateDataDefinedButton( mSegmentSizeDDBtn );
908 updateDataDefinedButton( mMinWidthDDBtn );
909 updateDataDefinedButton( mMaxWidthDDBtn );
910 updateDataDefinedButton( mHeightDDBtn );
911 updateDataDefinedButton( mSubdivisionHeightDDBtn );
912 updateDataDefinedButton( mRightSegmentSubdivisionsDDBtn );
913}
914
915QString QgsLayoutScaleBarWidget::linkedMapUnitsString( QgsLayoutItemScaleBar *scalebar )
916{
917 QString mapUnit;
918 if ( scalebar )
919 {
920 if ( QgsLayoutItemMap *map = scalebar->linkedMap() )
921 {
922 const Qgis::DistanceUnit mapCrsUnits = map->crs().mapUnits();
923 if ( mapCrsUnits != Qgis::DistanceUnit::Unknown )
924 {
925 mapUnit = QgsUnitTypes::toString( mapCrsUnits );
926 }
927 }
928 }
929 return mapUnit.isEmpty() ? tr( "Map Units" ) : tr( "Map Units (%1)" ).arg( mapUnit );
930}
ScaleBarDistanceLabelHorizontalPlacement
Scale bar distance label horizontal placement.
Definition qgis.h:5905
@ CenteredSegment
Labels are drawn centered relative to segment.
Definition qgis.h:5907
@ CenteredEdge
Labels are drawn centered relative to segment's edge.
Definition qgis.h:5906
ScaleBarDistanceLabelVerticalPlacement
Scale bar distance label vertical placement.
Definition qgis.h:5891
@ AboveSegment
Labels are drawn above the scalebar.
Definition qgis.h:5892
@ BelowSegment
Labels are drawn below the scalebar.
Definition qgis.h:5893
ScaleBarAlignment
Scalebar alignment.
Definition qgis.h:5862
@ Right
Right aligned.
Definition qgis.h:5865
@ Left
Left aligned.
Definition qgis.h:5863
@ Middle
Center aligned.
Definition qgis.h:5864
DistanceUnit
Units of distance.
Definition qgis.h:5548
@ Feet
Imperial feet.
Definition qgis.h:5551
@ Centimeters
Centimeters.
Definition qgis.h:5556
@ Millimeters
Millimeters.
Definition qgis.h:5557
@ Miles
Terrestrial miles.
Definition qgis.h:5554
@ Meters
Meters.
Definition qgis.h:5549
@ Unknown
Unknown distance unit.
Definition qgis.h:5598
@ Yards
Imperial yards.
Definition qgis.h:5553
@ Inches
Inches.
Definition qgis.h:5558
@ NauticalMiles
Nautical miles.
Definition qgis.h:5552
@ Kilometers
Kilometers.
Definition qgis.h:5550
ScaleBarUnitLabelPlacement
Available placement options for a scale bar's unit label.
Definition qgis.h:5919
@ AfterLastDistanceLabel
Placed after the last distance label.
Definition qgis.h:5929
@ CenteredBelow
Horizontally centered on the bar, below the bar.
Definition qgis.h:5926
@ LeftAbove
Text centered over the left edge of the bar, above the bar.
Definition qgis.h:5922
@ AfterBar
Vertically centered on the bar, after the bar ends.
Definition qgis.h:5921
@ BeforeBar
Vertically centered on the bar, before the bar begins.
Definition qgis.h:5920
@ BeforeEveryDistanceLabel
Placed before every distance label (as part of the distance label text).
Definition qgis.h:5931
@ CenteredAbove
Horizontally centered on the bar, above the bar.
Definition qgis.h:5923
@ RightBelow
Text centered over the right edge of the bar, below the bar.
Definition qgis.h:5927
@ OnBarAfterFirstDivision
Placed on top of the bar, after the first bar division.
Definition qgis.h:5930
@ BeforeFirstDistanceLabel
Placed before the first distance label.
Definition qgis.h:5928
@ RightAbove
Text centered over the right edge of the bar, above the bar.
Definition qgis.h:5924
@ AfterEveryDistanceLabel
Placed after every distance label (as part of the distance label text).
Definition qgis.h:5932
@ LeftBelow
Text centered over the left edge of the bar, below the bar.
Definition qgis.h:5925
@ FitWidth
Scale bar segment size is calculated to fit a size range.
Definition qgis.h:5879
@ Fixed
Scale bar segment size is fixed to a map unit.
Definition qgis.h:5878
@ Line
Line symbol.
Definition qgis.h:653
@ Fill
Fill symbol.
Definition qgis.h:654
void changed()
Emitted when the alignment is changed.
static QgsScaleBarRendererRegistry * scaleBarRendererRegistry()
Gets the registry of available scalebar renderers.
void checkedItemsChanged(const QStringList &items)
Emitted whenever the checked items list changed.
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:51
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:8365
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
Definition qgis.h:7587
Single variable definition for use within a QgsExpressionContextScope.