29 #include <QColorDialog>
30 #include <QFontDialog>
35 , mScalebar( scaleBar )
39 mNumberOfSubdivisionsSpinBox->setClearValue( 1 );
41 connect( mHeightSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutScaleBarWidget::mHeightSpinBox_valueChanged );
42 connect( mSegmentSizeSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutScaleBarWidget::mSegmentSizeSpinBox_valueChanged );
43 connect( mSegmentsLeftSpinBox,
static_cast < void ( QSpinBox::* )(
int )
> ( &QSpinBox::valueChanged ),
this, &QgsLayoutScaleBarWidget::mSegmentsLeftSpinBox_valueChanged );
44 connect( mNumberOfSegmentsSpinBox,
static_cast < void ( QSpinBox::* )(
int )
> ( &QSpinBox::valueChanged ),
this, &QgsLayoutScaleBarWidget::mNumberOfSegmentsSpinBox_valueChanged );
45 connect( mNumberOfSubdivisionsSpinBox,
static_cast < void ( QSpinBox::* )(
int )
> ( &QSpinBox::valueChanged ),
this, &QgsLayoutScaleBarWidget::mNumberOfSubdivisionsSpinBox_valueChanged );
46 connect( mSubdivisionsHeightSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutScaleBarWidget::mSubdivisionsHeightSpinBox_valueChanged );
47 connect( mUnitLabelLineEdit, &QLineEdit::textChanged,
this, &QgsLayoutScaleBarWidget::mUnitLabelLineEdit_textChanged );
48 connect( mMapUnitsPerBarUnitSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutScaleBarWidget::mMapUnitsPerBarUnitSpinBox_valueChanged );
49 connect( mStyleComboBox, &QComboBox::currentTextChanged,
this, &QgsLayoutScaleBarWidget::mStyleComboBox_currentIndexChanged );
50 connect( mLabelBarSpaceSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutScaleBarWidget::mLabelBarSpaceSpinBox_valueChanged );
51 connect( mBoxSizeSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutScaleBarWidget::mBoxSizeSpinBox_valueChanged );
53 connect( mLabelVerticalPlacementComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutScaleBarWidget::mLabelVerticalPlacementComboBox_currentIndexChanged );
54 connect( mLabelHorizontalPlacementComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutScaleBarWidget::mLabelHorizontalPlacementComboBox_currentIndexChanged );
55 connect( mUnitsComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutScaleBarWidget::mUnitsComboBox_currentIndexChanged );
56 connect( mMinWidthSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutScaleBarWidget::mMinWidthSpinBox_valueChanged );
57 connect( mMaxWidthSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutScaleBarWidget::mMaxWidthSpinBox_valueChanged );
58 connect( mNumberFormatPushButton, &QPushButton::clicked,
this, &QgsLayoutScaleBarWidget::changeNumberFormat );
69 mSegmentsLeftDDBtn->registerEnabledWidget( mSegmentsLeftSpinBox,
false );
70 mSegmentsRightDDBtn->registerEnabledWidget( mNumberOfSegmentsSpinBox,
false );
71 mSegmentSizeDDBtn->registerEnabledWidget( mSegmentSizeSpinBox,
false );
72 mMinWidthDDBtn->registerEnabledWidget( mMinWidthSpinBox,
false );
73 mMaxWidthDDBtn->registerEnabledWidget( mMaxWidthSpinBox,
false );
77 mFontButton->registerExpressionContextGenerator(
this );
79 connectUpdateSignal();
83 mainLayout->addWidget( mItemPropertiesWidget );
85 mSegmentSizeRadioGroup.addButton( mFixedSizeRadio );
86 mSegmentSizeRadioGroup.addButton( mFitWidthRadio );
87 connect( &mSegmentSizeRadioGroup,
static_cast < void ( QButtonGroup::* )( QAbstractButton * )
> ( &QButtonGroup::buttonClicked ),
this, &QgsLayoutScaleBarWidget::segmentSizeRadioChanged );
89 blockMemberSignals(
true );
93 for (
const QString &renderer : renderers )
105 mAlignmentComboBox->setAvailableAlignments( Qt::AlignLeft | Qt::AlignHCenter | Qt::AlignRight );
125 connect( mSubdivisionStyleButton, &
QgsSymbolButton::changed,
this, &QgsLayoutScaleBarWidget::subdivisionSymbolChanged );
133 mFontButton->setDialogTitle( tr(
"Scalebar Font" ) );
138 QgsLayout *scaleBarLayout = mScalebar->layout();
139 if ( scaleBarLayout )
141 mMapItemComboBox->setCurrentLayout( scaleBarLayout );
148 blockMemberSignals(
false );
151 mLineStyleButton->registerExpressionContextGenerator( mScalebar );
153 mDivisionStyleButton->registerExpressionContextGenerator( mScalebar );
155 mSubdivisionStyleButton->registerExpressionContextGenerator( mScalebar );
157 mFillSymbol1Button->registerExpressionContextGenerator( mScalebar );
159 mFillSymbol2Button->registerExpressionContextGenerator( mScalebar );
164 if ( mScalebar->layout() )
177 if ( mItemPropertiesWidget )
196 disconnectUpdateSignal();
198 mScalebar = qobject_cast< QgsLayoutItemScaleBar * >( item );
199 mItemPropertiesWidget->
setItem( mScalebar );
203 connectUpdateSignal();
204 mFillSymbol1Button->registerExpressionContextGenerator( mScalebar );
205 mFillSymbol2Button->registerExpressionContextGenerator( mScalebar );
206 mLineStyleButton->registerExpressionContextGenerator( mScalebar );
207 mDivisionStyleButton->registerExpressionContextGenerator( mScalebar );
208 mSubdivisionStyleButton->registerExpressionContextGenerator( mScalebar );
216 void QgsLayoutScaleBarWidget::lineSymbolChanged()
222 mScalebar->setLineSymbol( mLineStyleButton->clonedSymbol<
QgsLineSymbol>() );
224 mScalebar->layout()->undoStack()->endCommand();
227 void QgsLayoutScaleBarWidget::divisionSymbolChanged()
233 mScalebar->setDivisionLineSymbol( mDivisionStyleButton->clonedSymbol<
QgsLineSymbol>() );
235 mScalebar->layout()->undoStack()->endCommand();
238 void QgsLayoutScaleBarWidget::subdivisionSymbolChanged()
244 mScalebar->setSubdivisionLineSymbol( mSubdivisionStyleButton->clonedSymbol<
QgsLineSymbol>() );
246 mScalebar->layout()->undoStack()->endCommand();
249 void QgsLayoutScaleBarWidget::fillSymbol1Changed()
255 mScalebar->setFillSymbol( mFillSymbol1Button->clonedSymbol<
QgsFillSymbol>() );
257 mScalebar->layout()->undoStack()->endCommand();
260 void QgsLayoutScaleBarWidget::fillSymbol2Changed()
266 mScalebar->setAlternateFillSymbol( mFillSymbol2Button->clonedSymbol<
QgsFillSymbol>() );
268 mScalebar->layout()->undoStack()->endCommand();
271 void QgsLayoutScaleBarWidget::setGuiElements()
278 blockMemberSignals(
true );
279 mNumberOfSegmentsSpinBox->setValue( mScalebar->numberOfSegments() );
280 mSegmentsLeftSpinBox->setValue( mScalebar->numberOfSegmentsLeft() );
281 mSegmentSizeSpinBox->setValue( mScalebar->unitsPerSegment() );
282 mHeightSpinBox->setValue( mScalebar->height() );
283 mNumberOfSubdivisionsSpinBox->setValue( mScalebar->numberOfSubdivisions() );
284 mSubdivisionsHeightSpinBox->setValue( mScalebar->subdivisionsHeight() );
285 mMapUnitsPerBarUnitSpinBox->setValue( mScalebar->mapUnitsPerScaleBarUnit() );
286 mLabelBarSpaceSpinBox->setValue( mScalebar->labelBarSpace() );
287 mBoxSizeSpinBox->setValue( mScalebar->boxContentSpace() );
288 mUnitLabelLineEdit->setText( mScalebar->unitLabel() );
289 mFontButton->setTextFormat( mScalebar->textFormat() );
291 whileBlocking( mLineStyleButton )->setSymbol( mScalebar->lineSymbol()->clone() );
292 whileBlocking( mDivisionStyleButton )->setSymbol( mScalebar->divisionLineSymbol()->clone() );
293 whileBlocking( mSubdivisionStyleButton )->setSymbol( mScalebar->subdivisionLineSymbol()->clone() );
294 whileBlocking( mFillSymbol1Button )->setSymbol( mScalebar->fillSymbol()->clone() );
295 whileBlocking( mFillSymbol2Button )->setSymbol( mScalebar->alternateFillSymbol()->clone() );
298 mMapItemComboBox->setItem( mScalebar->linkedMap() );
301 const QString style = mScalebar->style();
302 mStyleComboBox->setCurrentIndex( mStyleComboBox->findData( style ) );
303 toggleStyleSpecificControls( style );
306 mLabelVerticalPlacementComboBox->setCurrentIndex( mLabelVerticalPlacementComboBox->findData(
static_cast< int >( mScalebar->labelVerticalPlacement() ) ) );
307 mLabelHorizontalPlacementComboBox->setCurrentIndex( mLabelHorizontalPlacementComboBox->findData(
static_cast< int >( mScalebar->labelHorizontalPlacement() ) ) );
311 Qt::Alignment a = Qt::AlignLeft;
312 switch ( mScalebar->alignment() )
321 a = Qt::AlignHCenter;
324 mAlignmentComboBox->setCurrentAlignment( a );
327 mUnitsComboBox->setCurrentIndex( mUnitsComboBox->findData(
static_cast< int >( mScalebar->units() ) ) );
331 mFixedSizeRadio->setChecked(
true );
332 mSegmentSizeSpinBox->setEnabled(
true );
333 mMinWidthSpinBox->setEnabled(
false );
334 mMaxWidthSpinBox->setEnabled(
false );
338 mFitWidthRadio->setChecked(
true );
339 mSegmentSizeSpinBox->setEnabled(
false );
340 mMinWidthSpinBox->setEnabled(
true );
341 mMaxWidthSpinBox->setEnabled(
true );
343 mMinWidthSpinBox->setValue( mScalebar->minimumBarWidth() );
344 mMaxWidthSpinBox->setValue( mScalebar->maximumBarWidth() );
346 populateDataDefinedButtons();
348 blockMemberSignals(
false );
353 void QgsLayoutScaleBarWidget::mSegmentSizeSpinBox_valueChanged(
double d )
361 disconnectUpdateSignal();
362 mScalebar->setUnitsPerSegment( d );
364 connectUpdateSignal();
365 mScalebar->endCommand();
368 void QgsLayoutScaleBarWidget::mSegmentsLeftSpinBox_valueChanged(
int i )
376 disconnectUpdateSignal();
377 mScalebar->setNumberOfSegmentsLeft( i );
379 connectUpdateSignal();
380 mScalebar->endCommand();
383 void QgsLayoutScaleBarWidget::mNumberOfSegmentsSpinBox_valueChanged(
int i )
391 disconnectUpdateSignal();
392 mScalebar->setNumberOfSegments( i );
394 connectUpdateSignal();
395 mScalebar->endCommand();
398 void QgsLayoutScaleBarWidget::mHeightSpinBox_valueChanged(
double d )
405 disconnectUpdateSignal();
406 mScalebar->setHeight( d );
408 connectUpdateSignal();
409 mScalebar->endCommand();
412 void QgsLayoutScaleBarWidget::mNumberOfSubdivisionsSpinBox_valueChanged(
int i )
420 disconnectUpdateSignal();
421 mScalebar->setNumberOfSubdivisions( i );
423 connectUpdateSignal();
424 mScalebar->endCommand();
427 void QgsLayoutScaleBarWidget::mSubdivisionsHeightSpinBox_valueChanged(
double d )
434 disconnectUpdateSignal();
435 mScalebar->setSubdivisionsHeight( d );
437 connectUpdateSignal();
438 mScalebar->endCommand();
441 void QgsLayoutScaleBarWidget::textFormatChanged()
448 mScalebar->beginCommand( tr(
"Set Scalebar Font" ) );
449 disconnectUpdateSignal();
450 mScalebar->setTextFormat( mFontButton->textFormat() );
451 connectUpdateSignal();
452 mScalebar->endCommand();
456 void QgsLayoutScaleBarWidget::changeNumberFormat()
465 widget->
setFormat( mScalebar->numericFormat() );
468 mScalebar->beginCommand( tr(
"Set Scalebar Number Format" ) );
469 disconnectUpdateSignal();
470 mScalebar->setNumericFormat( widget->
format() );
471 connectUpdateSignal();
472 mScalebar->endCommand();
479 void QgsLayoutScaleBarWidget::mUnitLabelLineEdit_textChanged(
const QString &text )
487 disconnectUpdateSignal();
488 mScalebar->setUnitLabel( text );
490 connectUpdateSignal();
491 mScalebar->endCommand();
494 void QgsLayoutScaleBarWidget::mMapUnitsPerBarUnitSpinBox_valueChanged(
double d )
502 disconnectUpdateSignal();
503 mScalebar->setMapUnitsPerScaleBarUnit( d );
505 connectUpdateSignal();
506 mScalebar->endCommand();
509 void QgsLayoutScaleBarWidget::mStyleComboBox_currentIndexChanged(
const QString & )
516 const QString rendererId = mStyleComboBox->currentData().toString();
517 if ( rendererId == mScalebar->style() )
520 mScalebar->beginCommand( tr(
"Set Scalebar Style" ) );
521 disconnectUpdateSignal();
523 bool defaultsApplied =
false;
526 defaultsApplied = mScalebar->applyDefaultRendererSettings( renderer.get() );
529 toggleStyleSpecificControls( rendererId );
531 mScalebar->setStyle( rendererId );
533 connectUpdateSignal();
534 mScalebar->endCommand();
536 if ( defaultsApplied )
540 void QgsLayoutScaleBarWidget::toggleStyleSpecificControls(
const QString &style )
556 if ( !mGroupBoxUnits->isEnabled() )
557 mGroupBoxSegments->setCollapsed(
true );
578 void QgsLayoutScaleBarWidget::mLabelBarSpaceSpinBox_valueChanged(
double d )
586 disconnectUpdateSignal();
587 mScalebar->setLabelBarSpace( d );
589 connectUpdateSignal();
590 mScalebar->endCommand();
593 void QgsLayoutScaleBarWidget::mBoxSizeSpinBox_valueChanged(
double d )
601 disconnectUpdateSignal();
602 mScalebar->setBoxContentSpace( d );
604 connectUpdateSignal();
605 mScalebar->endCommand();
608 void QgsLayoutScaleBarWidget::mLabelVerticalPlacementComboBox_currentIndexChanged(
int index )
615 mScalebar->beginCommand( tr(
"Set Scalebar Label Vertical Placement" ) );
616 disconnectUpdateSignal();
619 connectUpdateSignal();
620 mScalebar->endCommand();
623 void QgsLayoutScaleBarWidget::mLabelHorizontalPlacementComboBox_currentIndexChanged(
int index )
630 mScalebar->beginCommand( tr(
"Set Scalebar Label Horizontal Placement" ) );
631 disconnectUpdateSignal();
634 connectUpdateSignal();
635 mScalebar->endCommand();
638 void QgsLayoutScaleBarWidget::alignmentChanged()
645 mScalebar->beginCommand( tr(
"Set Scalebar Alignment" ) );
646 disconnectUpdateSignal();
650 mScalebar->setAlignment( a );
652 connectUpdateSignal();
653 mScalebar->endCommand();
656 void QgsLayoutScaleBarWidget::mUnitsComboBox_currentIndexChanged(
int index )
663 const QVariant unitData = mUnitsComboBox->itemData( index );
664 if ( unitData.type() == QVariant::Invalid )
669 disconnectUpdateSignal();
670 mScalebar->beginCommand( tr(
"Set Scalebar Units" ) );
674 mNumberOfSegmentsSpinBox->setValue( mScalebar->numberOfSegments() );
675 mSegmentsLeftSpinBox->setValue( mScalebar->numberOfSegmentsLeft() );
676 mUnitLabelLineEdit->setText( mScalebar->unitLabel() );
677 mSegmentSizeSpinBox->setValue( mScalebar->unitsPerSegment() );
678 mMapUnitsPerBarUnitSpinBox->setValue( mScalebar->mapUnitsPerScaleBarUnit() );
680 connectUpdateSignal();
681 mScalebar->endCommand();
684 void QgsLayoutScaleBarWidget::blockMemberSignals(
bool block )
686 mSegmentSizeSpinBox->blockSignals( block );
687 mNumberOfSegmentsSpinBox->blockSignals( block );
688 mSegmentsLeftSpinBox->blockSignals( block );
689 mNumberOfSubdivisionsSpinBox->blockSignals( block );
690 mSubdivisionsHeightSpinBox->blockSignals( block );
691 mStyleComboBox->blockSignals( block );
692 mUnitLabelLineEdit->blockSignals( block );
693 mMapUnitsPerBarUnitSpinBox->blockSignals( block );
694 mHeightSpinBox->blockSignals( block );
695 mLineStyleButton->blockSignals( block );
696 mDivisionStyleButton->blockSignals( block );
697 mSubdivisionStyleButton->blockSignals( block );
698 mLabelBarSpaceSpinBox->blockSignals( block );
699 mBoxSizeSpinBox->blockSignals( block );
700 mLabelVerticalPlacementComboBox->blockSignals( block );
701 mLabelHorizontalPlacementComboBox->blockSignals( block );
702 mAlignmentComboBox->blockSignals( block );
703 mUnitsComboBox->blockSignals( block );
704 mFillSymbol1Button->blockSignals( block );
705 mFillSymbol2Button->blockSignals( block );
706 mSegmentSizeRadioGroup.blockSignals( block );
707 mMapItemComboBox->blockSignals( block );
708 mFontButton->blockSignals( block );
709 mMinWidthSpinBox->blockSignals( block );
710 mMaxWidthSpinBox->blockSignals( block );
713 void QgsLayoutScaleBarWidget::connectUpdateSignal()
721 void QgsLayoutScaleBarWidget::disconnectUpdateSignal()
729 void QgsLayoutScaleBarWidget::segmentSizeRadioChanged( QAbstractButton *radio )
731 const bool fixedSizeMode = radio == mFixedSizeRadio;
732 mMinWidthSpinBox->setEnabled( !fixedSizeMode );
733 mMaxWidthSpinBox->setEnabled( !fixedSizeMode );
734 mSegmentSizeSpinBox->setEnabled( fixedSizeMode );
742 disconnectUpdateSignal();
743 if ( mFixedSizeRadio->isChecked() )
746 mScalebar->setUnitsPerSegment( mSegmentSizeSpinBox->value() );
753 connectUpdateSignal();
754 mScalebar->endCommand();
757 void QgsLayoutScaleBarWidget::mapChanged(
QgsLayoutItem *item )
766 mScalebar->beginCommand( tr(
"Set Scalebar Map" ) );
767 disconnectUpdateSignal();
768 mScalebar->setLinkedMap( map );
770 connectUpdateSignal();
771 mScalebar->endCommand();
774 void QgsLayoutScaleBarWidget::mMinWidthSpinBox_valueChanged(
double )
782 disconnectUpdateSignal();
783 mScalebar->setMinimumBarWidth( mMinWidthSpinBox->value() );
785 connectUpdateSignal();
786 mScalebar->endCommand();
789 void QgsLayoutScaleBarWidget::mMaxWidthSpinBox_valueChanged(
double )
797 disconnectUpdateSignal();
798 mScalebar->setMaximumBarWidth( mMaxWidthSpinBox->value() );
800 connectUpdateSignal();
801 mScalebar->endCommand();
804 void QgsLayoutScaleBarWidget::populateDataDefinedButtons()