27 #include <QColorDialog>
28 #include <QFontDialog>
33 , mScalebar( scaleBar )
37 mNumberOfSubdivisionsSpinBox->setClearValue( 1 );
39 connect( mHeightSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutScaleBarWidget::mHeightSpinBox_valueChanged );
40 connect( mSegmentSizeSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutScaleBarWidget::mSegmentSizeSpinBox_valueChanged );
41 connect( mSegmentsLeftSpinBox,
static_cast < void ( QSpinBox::* )(
int )
> ( &QSpinBox::valueChanged ),
this, &QgsLayoutScaleBarWidget::mSegmentsLeftSpinBox_valueChanged );
42 connect( mNumberOfSegmentsSpinBox,
static_cast < void ( QSpinBox::* )(
int )
> ( &QSpinBox::valueChanged ),
this, &QgsLayoutScaleBarWidget::mNumberOfSegmentsSpinBox_valueChanged );
43 connect( mNumberOfSubdivisionsSpinBox,
static_cast < void ( QSpinBox::* )(
int )
> ( &QSpinBox::valueChanged ),
this, &QgsLayoutScaleBarWidget::mNumberOfSubdivisionsSpinBox_valueChanged );
44 connect( mSubdivisionsHeightSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutScaleBarWidget::mSubdivisionsHeightSpinBox_valueChanged );
45 connect( mUnitLabelLineEdit, &QLineEdit::textChanged,
this, &QgsLayoutScaleBarWidget::mUnitLabelLineEdit_textChanged );
46 connect( mMapUnitsPerBarUnitSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutScaleBarWidget::mMapUnitsPerBarUnitSpinBox_valueChanged );
47 connect( mStyleComboBox, &QComboBox::currentTextChanged,
this, &QgsLayoutScaleBarWidget::mStyleComboBox_currentIndexChanged );
48 connect( mLabelBarSpaceSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutScaleBarWidget::mLabelBarSpaceSpinBox_valueChanged );
49 connect( mBoxSizeSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutScaleBarWidget::mBoxSizeSpinBox_valueChanged );
51 connect( mLabelVerticalPlacementComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutScaleBarWidget::mLabelVerticalPlacementComboBox_currentIndexChanged );
52 connect( mLabelHorizontalPlacementComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutScaleBarWidget::mLabelHorizontalPlacementComboBox_currentIndexChanged );
53 connect( mUnitsComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutScaleBarWidget::mUnitsComboBox_currentIndexChanged );
54 connect( mMinWidthSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutScaleBarWidget::mMinWidthSpinBox_valueChanged );
55 connect( mMaxWidthSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutScaleBarWidget::mMaxWidthSpinBox_valueChanged );
56 connect( mNumberFormatPushButton, &QPushButton::clicked,
this, &QgsLayoutScaleBarWidget::changeNumberFormat );
59 mFontButton->registerExpressionContextGenerator(
this );
61 connectUpdateSignal();
65 mainLayout->addWidget( mItemPropertiesWidget );
67 mSegmentSizeRadioGroup.addButton( mFixedSizeRadio );
68 mSegmentSizeRadioGroup.addButton( mFitWidthRadio );
69 connect( &mSegmentSizeRadioGroup,
static_cast < void ( QButtonGroup::* )( QAbstractButton * )
> ( &QButtonGroup::buttonClicked ),
this, &QgsLayoutScaleBarWidget::segmentSizeRadioChanged );
71 blockMemberSignals(
true );
75 for (
const QString &renderer : renderers )
87 mAlignmentComboBox->setAvailableAlignments( Qt::AlignLeft | Qt::AlignHCenter | Qt::AlignRight );
107 connect( mSubdivisionStyleButton, &
QgsSymbolButton::changed,
this, &QgsLayoutScaleBarWidget::subdivisionSymbolChanged );
115 mFontButton->setDialogTitle( tr(
"Scalebar Font" ) );
120 QgsLayout *scaleBarLayout = mScalebar->layout();
121 if ( scaleBarLayout )
123 mMapItemComboBox->setCurrentLayout( scaleBarLayout );
130 blockMemberSignals(
false );
133 mLineStyleButton->registerExpressionContextGenerator( mScalebar );
135 mDivisionStyleButton->registerExpressionContextGenerator( mScalebar );
137 mSubdivisionStyleButton->registerExpressionContextGenerator( mScalebar );
139 mFillSymbol1Button->registerExpressionContextGenerator( mScalebar );
141 mFillSymbol2Button->registerExpressionContextGenerator( mScalebar );
146 if ( mScalebar->layout() )
159 if ( mItemPropertiesWidget )
178 disconnectUpdateSignal();
180 mScalebar = qobject_cast< QgsLayoutItemScaleBar * >( item );
181 mItemPropertiesWidget->
setItem( mScalebar );
185 connectUpdateSignal();
186 mFillSymbol1Button->registerExpressionContextGenerator( mScalebar );
187 mFillSymbol2Button->registerExpressionContextGenerator( mScalebar );
188 mLineStyleButton->registerExpressionContextGenerator( mScalebar );
189 mDivisionStyleButton->registerExpressionContextGenerator( mScalebar );
190 mSubdivisionStyleButton->registerExpressionContextGenerator( mScalebar );
198 void QgsLayoutScaleBarWidget::lineSymbolChanged()
204 mScalebar->setLineSymbol( mLineStyleButton->clonedSymbol<
QgsLineSymbol>() );
206 mScalebar->layout()->undoStack()->endCommand();
209 void QgsLayoutScaleBarWidget::divisionSymbolChanged()
215 mScalebar->setDivisionLineSymbol( mDivisionStyleButton->clonedSymbol<
QgsLineSymbol>() );
217 mScalebar->layout()->undoStack()->endCommand();
220 void QgsLayoutScaleBarWidget::subdivisionSymbolChanged()
226 mScalebar->setSubdivisionLineSymbol( mSubdivisionStyleButton->clonedSymbol<
QgsLineSymbol>() );
228 mScalebar->layout()->undoStack()->endCommand();
231 void QgsLayoutScaleBarWidget::fillSymbol1Changed()
237 mScalebar->setFillSymbol( mFillSymbol1Button->clonedSymbol<
QgsFillSymbol>() );
239 mScalebar->layout()->undoStack()->endCommand();
242 void QgsLayoutScaleBarWidget::fillSymbol2Changed()
248 mScalebar->setAlternateFillSymbol( mFillSymbol2Button->clonedSymbol<
QgsFillSymbol>() );
250 mScalebar->layout()->undoStack()->endCommand();
253 void QgsLayoutScaleBarWidget::setGuiElements()
260 blockMemberSignals(
true );
261 mNumberOfSegmentsSpinBox->setValue( mScalebar->numberOfSegments() );
262 mSegmentsLeftSpinBox->setValue( mScalebar->numberOfSegmentsLeft() );
263 mSegmentSizeSpinBox->setValue( mScalebar->unitsPerSegment() );
264 mHeightSpinBox->setValue( mScalebar->height() );
265 mNumberOfSubdivisionsSpinBox->setValue( mScalebar->numberOfSubdivisions() );
266 mSubdivisionsHeightSpinBox->setValue( mScalebar->subdivisionsHeight() );
267 mMapUnitsPerBarUnitSpinBox->setValue( mScalebar->mapUnitsPerScaleBarUnit() );
268 mLabelBarSpaceSpinBox->setValue( mScalebar->labelBarSpace() );
269 mBoxSizeSpinBox->setValue( mScalebar->boxContentSpace() );
270 mUnitLabelLineEdit->setText( mScalebar->unitLabel() );
271 mFontButton->setTextFormat( mScalebar->textFormat() );
273 whileBlocking( mLineStyleButton )->setSymbol( mScalebar->lineSymbol()->clone() );
274 whileBlocking( mDivisionStyleButton )->setSymbol( mScalebar->divisionLineSymbol()->clone() );
275 whileBlocking( mSubdivisionStyleButton )->setSymbol( mScalebar->subdivisionLineSymbol()->clone() );
276 whileBlocking( mFillSymbol1Button )->setSymbol( mScalebar->fillSymbol()->clone() );
277 whileBlocking( mFillSymbol2Button )->setSymbol( mScalebar->alternateFillSymbol()->clone() );
280 mMapItemComboBox->setItem( mScalebar->linkedMap() );
283 const QString style = mScalebar->style();
284 mStyleComboBox->setCurrentIndex( mStyleComboBox->findData( style ) );
285 toggleStyleSpecificControls( style );
288 mLabelVerticalPlacementComboBox->setCurrentIndex( mLabelVerticalPlacementComboBox->findData(
static_cast< int >( mScalebar->labelVerticalPlacement() ) ) );
289 mLabelHorizontalPlacementComboBox->setCurrentIndex( mLabelHorizontalPlacementComboBox->findData(
static_cast< int >( mScalebar->labelHorizontalPlacement() ) ) );
293 Qt::Alignment a = Qt::AlignLeft;
294 switch ( mScalebar->alignment() )
303 a = Qt::AlignHCenter;
306 mAlignmentComboBox->setCurrentAlignment( a );
309 mUnitsComboBox->setCurrentIndex( mUnitsComboBox->findData(
static_cast< int >( mScalebar->units() ) ) );
313 mFixedSizeRadio->setChecked(
true );
314 mSegmentSizeSpinBox->setEnabled(
true );
315 mMinWidthSpinBox->setEnabled(
false );
316 mMaxWidthSpinBox->setEnabled(
false );
320 mFitWidthRadio->setChecked(
true );
321 mSegmentSizeSpinBox->setEnabled(
false );
322 mMinWidthSpinBox->setEnabled(
true );
323 mMaxWidthSpinBox->setEnabled(
true );
325 mMinWidthSpinBox->setValue( mScalebar->minimumBarWidth() );
326 mMaxWidthSpinBox->setValue( mScalebar->maximumBarWidth() );
327 blockMemberSignals(
false );
332 void QgsLayoutScaleBarWidget::mSegmentSizeSpinBox_valueChanged(
double d )
340 disconnectUpdateSignal();
341 mScalebar->setUnitsPerSegment( d );
343 connectUpdateSignal();
344 mScalebar->endCommand();
347 void QgsLayoutScaleBarWidget::mSegmentsLeftSpinBox_valueChanged(
int i )
355 disconnectUpdateSignal();
356 mScalebar->setNumberOfSegmentsLeft( i );
358 connectUpdateSignal();
359 mScalebar->endCommand();
362 void QgsLayoutScaleBarWidget::mNumberOfSegmentsSpinBox_valueChanged(
int i )
370 disconnectUpdateSignal();
371 mScalebar->setNumberOfSegments( i );
373 connectUpdateSignal();
374 mScalebar->endCommand();
377 void QgsLayoutScaleBarWidget::mHeightSpinBox_valueChanged(
double d )
384 disconnectUpdateSignal();
385 mScalebar->setHeight( d );
387 connectUpdateSignal();
388 mScalebar->endCommand();
391 void QgsLayoutScaleBarWidget::mNumberOfSubdivisionsSpinBox_valueChanged(
int i )
399 disconnectUpdateSignal();
400 mScalebar->setNumberOfSubdivisions( i );
402 connectUpdateSignal();
403 mScalebar->endCommand();
406 void QgsLayoutScaleBarWidget::mSubdivisionsHeightSpinBox_valueChanged(
double d )
413 disconnectUpdateSignal();
414 mScalebar->setSubdivisionsHeight( d );
416 connectUpdateSignal();
417 mScalebar->endCommand();
420 void QgsLayoutScaleBarWidget::textFormatChanged()
427 mScalebar->beginCommand( tr(
"Set Scalebar Font" ) );
428 disconnectUpdateSignal();
429 mScalebar->setTextFormat( mFontButton->textFormat() );
430 connectUpdateSignal();
431 mScalebar->endCommand();
435 void QgsLayoutScaleBarWidget::changeNumberFormat()
444 widget->
setFormat( mScalebar->numericFormat() );
447 mScalebar->beginCommand( tr(
"Set Scalebar Number Format" ) );
448 disconnectUpdateSignal();
449 mScalebar->setNumericFormat( widget->
format() );
450 connectUpdateSignal();
451 mScalebar->endCommand();
458 void QgsLayoutScaleBarWidget::mUnitLabelLineEdit_textChanged(
const QString &text )
466 disconnectUpdateSignal();
467 mScalebar->setUnitLabel( text );
469 connectUpdateSignal();
470 mScalebar->endCommand();
473 void QgsLayoutScaleBarWidget::mMapUnitsPerBarUnitSpinBox_valueChanged(
double d )
481 disconnectUpdateSignal();
482 mScalebar->setMapUnitsPerScaleBarUnit( d );
484 connectUpdateSignal();
485 mScalebar->endCommand();
488 void QgsLayoutScaleBarWidget::mStyleComboBox_currentIndexChanged(
const QString & )
495 const QString rendererId = mStyleComboBox->currentData().toString();
496 if ( rendererId == mScalebar->style() )
499 mScalebar->beginCommand( tr(
"Set Scalebar Style" ) );
500 disconnectUpdateSignal();
502 bool defaultsApplied =
false;
505 defaultsApplied = mScalebar->applyDefaultRendererSettings( renderer.get() );
508 toggleStyleSpecificControls( rendererId );
510 mScalebar->setStyle( rendererId );
512 connectUpdateSignal();
513 mScalebar->endCommand();
515 if ( defaultsApplied )
519 void QgsLayoutScaleBarWidget::toggleStyleSpecificControls(
const QString &style )
535 if ( !mGroupBoxUnits->isEnabled() )
536 mGroupBoxSegments->setCollapsed(
true );
557 void QgsLayoutScaleBarWidget::mLabelBarSpaceSpinBox_valueChanged(
double d )
565 disconnectUpdateSignal();
566 mScalebar->setLabelBarSpace( d );
568 connectUpdateSignal();
569 mScalebar->endCommand();
572 void QgsLayoutScaleBarWidget::mBoxSizeSpinBox_valueChanged(
double d )
580 disconnectUpdateSignal();
581 mScalebar->setBoxContentSpace( d );
583 connectUpdateSignal();
584 mScalebar->endCommand();
587 void QgsLayoutScaleBarWidget::mLabelVerticalPlacementComboBox_currentIndexChanged(
int index )
594 mScalebar->beginCommand( tr(
"Set Scalebar Label Vertical Placement" ) );
595 disconnectUpdateSignal();
598 connectUpdateSignal();
599 mScalebar->endCommand();
602 void QgsLayoutScaleBarWidget::mLabelHorizontalPlacementComboBox_currentIndexChanged(
int index )
609 mScalebar->beginCommand( tr(
"Set Scalebar Label Horizontal Placement" ) );
610 disconnectUpdateSignal();
613 connectUpdateSignal();
614 mScalebar->endCommand();
617 void QgsLayoutScaleBarWidget::alignmentChanged()
624 mScalebar->beginCommand( tr(
"Set Scalebar Alignment" ) );
625 disconnectUpdateSignal();
629 mScalebar->setAlignment( a );
631 connectUpdateSignal();
632 mScalebar->endCommand();
635 void QgsLayoutScaleBarWidget::mUnitsComboBox_currentIndexChanged(
int index )
642 QVariant unitData = mUnitsComboBox->itemData( index );
643 if ( unitData.type() == QVariant::Invalid )
648 disconnectUpdateSignal();
649 mScalebar->beginCommand( tr(
"Set Scalebar Units" ) );
653 mUnitLabelLineEdit->setText( mScalebar->unitLabel() );
654 mSegmentSizeSpinBox->setValue( mScalebar->unitsPerSegment() );
655 mMapUnitsPerBarUnitSpinBox->setValue( mScalebar->mapUnitsPerScaleBarUnit() );
657 connectUpdateSignal();
658 mScalebar->endCommand();
661 void QgsLayoutScaleBarWidget::blockMemberSignals(
bool block )
663 mSegmentSizeSpinBox->blockSignals( block );
664 mNumberOfSegmentsSpinBox->blockSignals( block );
665 mSegmentsLeftSpinBox->blockSignals( block );
666 mNumberOfSubdivisionsSpinBox->blockSignals( block );
667 mSubdivisionsHeightSpinBox->blockSignals( block );
668 mStyleComboBox->blockSignals( block );
669 mUnitLabelLineEdit->blockSignals( block );
670 mMapUnitsPerBarUnitSpinBox->blockSignals( block );
671 mHeightSpinBox->blockSignals( block );
672 mLineStyleButton->blockSignals( block );
673 mDivisionStyleButton->blockSignals( block );
674 mSubdivisionStyleButton->blockSignals( block );
675 mLabelBarSpaceSpinBox->blockSignals( block );
676 mBoxSizeSpinBox->blockSignals( block );
677 mLabelVerticalPlacementComboBox->blockSignals( block );
678 mLabelHorizontalPlacementComboBox->blockSignals( block );
679 mAlignmentComboBox->blockSignals( block );
680 mUnitsComboBox->blockSignals( block );
681 mFillSymbol1Button->blockSignals( block );
682 mFillSymbol2Button->blockSignals( block );
683 mSegmentSizeRadioGroup.blockSignals( block );
684 mMapItemComboBox->blockSignals( block );
685 mFontButton->blockSignals( block );
686 mMinWidthSpinBox->blockSignals( block );
687 mMaxWidthSpinBox->blockSignals( block );
690 void QgsLayoutScaleBarWidget::connectUpdateSignal()
698 void QgsLayoutScaleBarWidget::disconnectUpdateSignal()
706 void QgsLayoutScaleBarWidget::segmentSizeRadioChanged( QAbstractButton *radio )
708 bool fixedSizeMode = radio == mFixedSizeRadio;
709 mMinWidthSpinBox->setEnabled( !fixedSizeMode );
710 mMaxWidthSpinBox->setEnabled( !fixedSizeMode );
711 mSegmentSizeSpinBox->setEnabled( fixedSizeMode );
719 disconnectUpdateSignal();
720 if ( mFixedSizeRadio->isChecked() )
723 mScalebar->setUnitsPerSegment( mSegmentSizeSpinBox->value() );
730 connectUpdateSignal();
731 mScalebar->endCommand();
734 void QgsLayoutScaleBarWidget::mapChanged(
QgsLayoutItem *item )
743 mScalebar->beginCommand( tr(
"Set Scalebar Map" ) );
744 disconnectUpdateSignal();
745 mScalebar->setLinkedMap( map );
747 connectUpdateSignal();
748 mScalebar->endCommand();
751 void QgsLayoutScaleBarWidget::mMinWidthSpinBox_valueChanged(
double )
759 disconnectUpdateSignal();
760 mScalebar->setMinimumBarWidth( mMinWidthSpinBox->value() );
762 connectUpdateSignal();
763 mScalebar->endCommand();
766 void QgsLayoutScaleBarWidget::mMaxWidthSpinBox_valueChanged(
double )
774 disconnectUpdateSignal();
775 mScalebar->setMaximumBarWidth( mMaxWidthSpinBox->value() );
777 connectUpdateSignal();
778 mScalebar->endCommand();