30 #include <QButtonGroup>
38 , mLayoutObject( layoutObject )
40 if ( mLayoutObject->layout() )
43 this, [ = ] { updateDataDefinedButtons(); } );
51 void QgsLayoutConfigObject::updateDataDefinedProperty()
72 if ( propertyAssociatesWithMultiFrame )
78 multiFrame->dataDefinedProperties().setProperty( key, ddButton->
toProperty() );
79 multiFrame->refresh();
84 multiFrame->dataDefinedProperties().setProperty( key, ddButton->
toProperty() );
85 multiFrame->refresh();
88 else if ( mLayoutObject )
90 mLayoutObject->dataDefinedProperties().setProperty( key, ddButton->
toProperty() );
91 mLayoutObject->refresh();
95 void QgsLayoutConfigObject::updateDataDefinedButtons()
97 const QList< QgsPropertyOverrideButton * > buttons = findChildren< QgsPropertyOverrideButton * >();
106 button->blockSignals(
true );
110 button->blockSignals(
false );
125 if ( propertyAssociatesWithMultiFrame )
131 whileBlocking( button )->setToProperty( multiFrame->dataDefinedProperties().property( key ) );
136 whileBlocking( button )->setToProperty( multiFrame->dataDefinedProperties().property( key ) );
139 else if ( mLayoutObject )
141 whileBlocking( button )->setToProperty( mLayoutObject->dataDefinedProperties().property( key ) );
151 if ( !mLayoutObject )
156 QgsPrintLayout *printLayout = qobject_cast< QgsPrintLayout * >( mLayoutObject->layout() );
163 return printLayout->
atlas();
168 mLayoutObject = object;
173 if ( !mLayoutObject )
176 QgsLayout *layout = mLayoutObject->layout();
191 , mObject( layoutObject )
210 oldConfigObject->deleteLater();
217 mConfigObject->deleteLater();
218 mConfigObject = oldConfigObject;
229 const auto symbolButtonWidgets = findChildren<QgsSymbolButton *>();
232 symbolWidget->setMessageBar( iface->
messageBar() );
234 const auto fontButtonWidgets = findChildren<QgsFontButton *>();
237 fontButton->setMessageBar( iface->
messageBar() );
281 mBlockVariableUpdates =
true;
283 mVariableEditor->setContext( &context );
288 const int multiFrameScopeIndex = context.
indexOfScope( tr(
"Multiframe Item" ) );
289 const int itemScopeIndex = context.
indexOfScope( tr(
"Layout Item" ) );
290 if ( multiFrameScopeIndex >= 0 )
291 mVariableEditor->setEditableScopeIndex( multiFrameScopeIndex );
292 else if ( itemScopeIndex >= 0 )
293 mVariableEditor->setEditableScopeIndex( itemScopeIndex );
294 mBlockVariableUpdates =
false;
303 mVariableEditor->setMinimumHeight( mVariableEditor->fontMetrics().height() * 15 );
305 mItemRotationSpinBox->setClearValue( 0 );
306 mStrokeUnitsComboBox->linkToWidget( mStrokeWidthSpinBox );
309 mPosUnitsComboBox->linkToWidget( mXPosSpin );
310 mPosUnitsComboBox->linkToWidget( mYPosSpin );
311 mSizeUnitsComboBox->linkToWidget( mWidthSpin );
312 mSizeUnitsComboBox->linkToWidget( mHeightSpin );
317 mPosLockAspectRatio->setWidthSpinBox( mXPosSpin );
318 mPosLockAspectRatio->setHeightSpinBox( mYPosSpin );
319 mSizeLockAspectRatio->setWidthSpinBox( mWidthSpin );
320 mSizeLockAspectRatio->setHeightSpinBox( mHeightSpin );
322 mItemFrameColorDDBtn->registerLinkedWidget( mFrameColorButton );
323 mItemBackgroundColorDDBtn->registerLinkedWidget( mBackgroundColorButton );
326 connect( mBackgroundColorButton, &
QgsColorButton::colorChanged,
this, &QgsLayoutItemPropertiesWidget::mBackgroundColorButton_colorChanged );
327 connect( mStrokeWidthSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutItemPropertiesWidget::mStrokeWidthSpinBox_valueChanged );
329 connect( mFrameGroupBox, &QgsCollapsibleGroupBoxBasic::toggled,
this, &QgsLayoutItemPropertiesWidget::mFrameGroupBox_toggled );
330 connect( mFrameJoinStyleCombo,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutItemPropertiesWidget::mFrameJoinStyleCombo_currentIndexChanged );
331 connect( mBackgroundGroupBox, &QgsCollapsibleGroupBoxBasic::toggled,
this, &QgsLayoutItemPropertiesWidget::mBackgroundGroupBox_toggled );
332 connect( mItemIdLineEdit, &QLineEdit::editingFinished,
this, &QgsLayoutItemPropertiesWidget::mItemIdLineEdit_editingFinished );
333 connect( mPageSpinBox,
static_cast < void ( QSpinBox::* )(
int )
> ( &QSpinBox::valueChanged ),
this, &QgsLayoutItemPropertiesWidget::mPageSpinBox_valueChanged );
334 connect( mXPosSpin,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutItemPropertiesWidget::mXPosSpin_valueChanged );
335 connect( mYPosSpin,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutItemPropertiesWidget::mYPosSpin_valueChanged );
337 connect( mWidthSpin,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutItemPropertiesWidget::mWidthSpin_valueChanged );
338 connect( mHeightSpin,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutItemPropertiesWidget::mHeightSpin_valueChanged );
340 connect( mUpperLeftRadioButton, &QRadioButton::toggled,
this, &QgsLayoutItemPropertiesWidget::mUpperLeftCheckBox_stateChanged );
341 connect( mUpperMiddleRadioButton, &QRadioButton::toggled,
this, &QgsLayoutItemPropertiesWidget::mUpperMiddleCheckBox_stateChanged );
342 connect( mUpperRightRadioButton, &QRadioButton::toggled,
this, &QgsLayoutItemPropertiesWidget::mUpperRightCheckBox_stateChanged );
343 connect( mMiddleLeftRadioButton, &QRadioButton::toggled,
this, &QgsLayoutItemPropertiesWidget::mMiddleLeftCheckBox_stateChanged );
344 connect( mMiddleRadioButton, &QRadioButton::toggled,
this, &QgsLayoutItemPropertiesWidget::mMiddleCheckBox_stateChanged );
345 connect( mMiddleRightRadioButton, &QRadioButton::toggled,
this, &QgsLayoutItemPropertiesWidget::mMiddleRightCheckBox_stateChanged );
346 connect( mLowerLeftRadioButton, &QRadioButton::toggled,
this, &QgsLayoutItemPropertiesWidget::mLowerLeftCheckBox_stateChanged );
347 connect( mLowerMiddleRadioButton, &QRadioButton::toggled,
this, &QgsLayoutItemPropertiesWidget::mLowerMiddleCheckBox_stateChanged );
348 connect( mLowerRightRadioButton, &QRadioButton::toggled,
this, &QgsLayoutItemPropertiesWidget::mLowerRightCheckBox_stateChanged );
349 connect( mBlendModeCombo,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutItemPropertiesWidget::mBlendModeCombo_currentIndexChanged );
350 connect( mItemRotationSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutItemPropertiesWidget::mItemRotationSpinBox_valueChanged );
351 connect( mExcludeFromPrintsCheckBox, &QCheckBox::toggled,
this, &QgsLayoutItemPropertiesWidget::mExcludeFromPrintsCheckBox_toggled );
354 QButtonGroup *buttonGroup =
new QButtonGroup(
this );
355 buttonGroup->addButton( mUpperLeftRadioButton );
356 buttonGroup->addButton( mUpperMiddleRadioButton );
357 buttonGroup->addButton( mUpperRightRadioButton );
358 buttonGroup->addButton( mMiddleLeftRadioButton );
359 buttonGroup->addButton( mMiddleRadioButton );
360 buttonGroup->addButton( mMiddleRightRadioButton );
361 buttonGroup->addButton( mLowerLeftRadioButton );
362 buttonGroup->addButton( mLowerMiddleRadioButton );
363 buttonGroup->addButton( mLowerRightRadioButton );
364 buttonGroup->setExclusive(
true );
375 if ( !mBlockVariableUpdates )
376 QgsLayoutItemPropertiesWidget::variablesChanged();
393 mBackgroundGroupBox->setVisible( showGroup );
398 mFrameGroupBox->setVisible( showGroup );
406 disconnect( mItem, &
QgsLayoutObject::changed,
this, &QgsLayoutItemPropertiesWidget::setValuesForGuiNonPositionElements );
412 connect( mItem, &
QgsLayoutObject::changed,
this, &QgsLayoutItemPropertiesWidget::setValuesForGuiNonPositionElements );
417 setValuesForGuiElements();
431 void QgsLayoutItemPropertiesWidget::mFrameColorButton_colorChanged(
const QColor &newFrameColor )
438 mItem->setFrameStrokeColor( newFrameColor );
439 mItem->layout()->undoStack()->endCommand();
443 void QgsLayoutItemPropertiesWidget::mBackgroundColorButton_colorChanged(
const QColor &newBackgroundColor )
450 mItem->setBackgroundColor( newBackgroundColor );
451 mItem->layout()->undoStack()->endCommand();
452 mItem->invalidateCache();
455 void QgsLayoutItemPropertiesWidget::changeItemPosition()
462 const QgsLayoutPoint point( mXPosSpin->value(), mYPosSpin->value(), mPosUnitsComboBox->unit() );
463 mItem->attemptMove( point,
true,
false, mPageSpinBox->value() - 1 );
465 mItem->layout()->undoStack()->endCommand();
473 mItem->layout()->undoStack()->beginCommand( mItem, tr(
"Change Item Reference" ) );
474 mItem->setReferencePoint( point );
475 mItem->layout()->undoStack()->endCommand();
478 void QgsLayoutItemPropertiesWidget::changeItemSize()
485 const QgsLayoutSize size( mWidthSpin->value(), mHeightSpin->value(), mSizeUnitsComboBox->unit() );
486 mItem->attemptResize( size );
488 mItem->layout()->undoStack()->endCommand();
491 void QgsLayoutItemPropertiesWidget::variablesChanged()
496 if (
QgsLayoutFrame *frame = qobject_cast< QgsLayoutFrame * >( mItem ) )
511 if ( mUpperLeftRadioButton->isChecked() )
515 else if ( mUpperMiddleRadioButton->isChecked() )
519 else if ( mUpperRightRadioButton->isChecked() )
523 else if ( mMiddleLeftRadioButton->isChecked() )
527 else if ( mMiddleRadioButton->isChecked() )
531 else if ( mMiddleRightRadioButton->isChecked() )
535 else if ( mLowerLeftRadioButton->isChecked() )
539 else if ( mLowerMiddleRadioButton->isChecked() )
543 else if ( mLowerRightRadioButton->isChecked() )
550 void QgsLayoutItemPropertiesWidget::mStrokeWidthSpinBox_valueChanged(
double d )
559 mItem->layout()->undoStack()->endCommand();
571 mItem->layout()->undoStack()->endCommand();
574 void QgsLayoutItemPropertiesWidget::mFrameJoinStyleCombo_currentIndexChanged(
int index )
582 mItem->layout()->undoStack()->beginCommand( mItem, tr(
"Change Frame Join Style" ) );
583 mItem->setFrameJoinStyle( mFrameJoinStyleCombo->penJoinStyle() );
584 mItem->layout()->undoStack()->endCommand();
587 void QgsLayoutItemPropertiesWidget::mFrameGroupBox_toggled(
bool state )
594 mItem->layout()->undoStack()->beginCommand( mItem, state ? tr(
"Enable Frame" ) : tr(
"Disable Frame" ) );
595 mItem->setFrameEnabled( state );
597 mItem->layout()->undoStack()->endCommand();
600 void QgsLayoutItemPropertiesWidget::mBackgroundGroupBox_toggled(
bool state )
607 mItem->layout()->undoStack()->beginCommand( mItem, state ? tr(
"Enable Background" ) : tr(
"Disable Background" ) );
608 mItem->setBackgroundEnabled( state );
609 mItem->layout()->undoStack()->endCommand();
610 mItem->invalidateCache();
614 void QgsLayoutItemPropertiesWidget::setValuesForGuiPositionElements()
621 auto block = [ = ](
bool blocked )
623 mXPosSpin->blockSignals( blocked );
624 mYPosSpin->blockSignals( blocked );
625 mPosUnitsComboBox->blockSignals( blocked );
626 mWidthSpin->blockSignals( blocked );
627 mHeightSpin->blockSignals( blocked );
628 mSizeUnitsComboBox->blockSignals( blocked );
629 mUpperLeftRadioButton->blockSignals( blocked );
630 mUpperMiddleRadioButton->blockSignals( blocked );
631 mUpperRightRadioButton->blockSignals( blocked );
632 mMiddleLeftRadioButton->blockSignals( blocked );
633 mMiddleRadioButton->blockSignals( blocked );
634 mMiddleRightRadioButton->blockSignals( blocked );
635 mLowerLeftRadioButton->blockSignals( blocked );
636 mLowerMiddleRadioButton->blockSignals( blocked );
637 mLowerRightRadioButton->blockSignals( blocked );
638 mPageSpinBox->blockSignals( blocked );
644 if ( !mFreezeXPosSpin )
645 mXPosSpin->setValue( point.
x() );
646 if ( !mFreezeYPosSpin )
647 mYPosSpin->setValue( point.
y() );
648 mPosUnitsComboBox->setUnit( point.
units() );
650 switch ( mItem->referencePoint() )
654 mUpperLeftRadioButton->setChecked(
true );
660 mUpperMiddleRadioButton->setChecked(
true );
666 mUpperRightRadioButton->setChecked(
true );
672 mMiddleLeftRadioButton->setChecked(
true );
678 mMiddleRadioButton->setChecked(
true );
684 mMiddleRightRadioButton->setChecked(
true );
690 mLowerLeftRadioButton->setChecked(
true );
696 mLowerMiddleRadioButton->setChecked(
true );
702 mLowerRightRadioButton->setChecked(
true );
708 if ( !mFreezeWidthSpin )
709 mWidthSpin->setValue( size.
width() );
710 if ( !mFreezeHeightSpin )
711 mHeightSpin->setValue( size.
height() );
713 mSizeUnitsComboBox->setUnit( size.
units() );
715 mSizeLockAspectRatio->resetRatio();
716 mPosLockAspectRatio->resetRatio();
718 if ( !mFreezePageSpin )
719 mPageSpinBox->setValue( mItem->page() + 1 );
724 void QgsLayoutItemPropertiesWidget::setValuesForGuiNonPositionElements()
731 auto block = [ = ](
bool blocked )
733 mStrokeWidthSpinBox->blockSignals( blocked );
734 mStrokeUnitsComboBox->blockSignals( blocked );
735 mFrameGroupBox->blockSignals( blocked );
736 mBackgroundGroupBox->blockSignals( blocked );
737 mItemIdLineEdit->blockSignals( blocked );
738 mBlendModeCombo->blockSignals( blocked );
739 mOpacityWidget->blockSignals( blocked );
740 mFrameColorButton->blockSignals( blocked );
741 mFrameJoinStyleCombo->blockSignals( blocked );
742 mBackgroundColorButton->blockSignals( blocked );
743 mItemRotationSpinBox->blockSignals( blocked );
744 mExcludeFromPrintsCheckBox->blockSignals( blocked );
748 mBackgroundColorButton->setColor( mItem->backgroundColor() );
749 mFrameColorButton->setColor( mItem->frameStrokeColor() );
750 mStrokeUnitsComboBox->setUnit( mItem->frameStrokeWidth().units() );
751 mStrokeWidthSpinBox->setValue( mItem->frameStrokeWidth().length() );
752 mFrameJoinStyleCombo->setPenJoinStyle( mItem->frameJoinStyle() );
753 mItemIdLineEdit->setText( mItem->id() );
754 mFrameGroupBox->setChecked( mItem->frameEnabled() );
755 mBackgroundGroupBox->setChecked( mItem->hasBackground() );
756 mBlendModeCombo->setBlendMode( mItem->blendMode() );
757 mOpacityWidget->setOpacity( mItem->itemOpacity() );
758 mItemRotationSpinBox->setValue( mItem->itemRotation() );
759 mExcludeFromPrintsCheckBox->setChecked( mItem->excludeFromExports() );
780 const QList< QgsPropertyOverrideButton * > buttons = findChildren< QgsPropertyOverrideButton * >();
787 void QgsLayoutItemPropertiesWidget::setValuesForGuiElements()
794 mBackgroundColorButton->setColorDialogTitle( tr(
"Select Background Color" ) );
795 mBackgroundColorButton->setAllowOpacity(
true );
796 mBackgroundColorButton->setContext( QStringLiteral(
"composer" ) );
797 mFrameColorButton->setColorDialogTitle( tr(
"Select Frame Color" ) );
798 mFrameColorButton->setAllowOpacity(
true );
799 mFrameColorButton->setContext( QStringLiteral(
"composer" ) );
801 setValuesForGuiPositionElements();
802 setValuesForGuiNonPositionElements();
808 void QgsLayoutItemPropertiesWidget::mBlendModeCombo_currentIndexChanged(
int index )
813 mItem->layout()->undoStack()->beginCommand( mItem, tr(
"Change Blend Mode" ) );
814 mItem->setBlendMode( mBlendModeCombo->blendMode() );
815 mItem->layout()->undoStack()->endCommand();
819 void QgsLayoutItemPropertiesWidget::opacityChanged(
double value )
824 mItem->setItemOpacity( value );
825 mItem->layout()->undoStack()->endCommand();
829 void QgsLayoutItemPropertiesWidget::mItemIdLineEdit_editingFinished()
834 mItem->setId( mItemIdLineEdit->text() );
835 mItemIdLineEdit->setText( mItem->id() );
836 mItem->layout()->undoStack()->endCommand();
840 void QgsLayoutItemPropertiesWidget::mPageSpinBox_valueChanged(
int )
842 mFreezePageSpin =
true;
843 changeItemPosition();
844 mFreezePageSpin =
false;
847 void QgsLayoutItemPropertiesWidget::mXPosSpin_valueChanged(
double )
849 mFreezeXPosSpin =
true;
850 changeItemPosition();
851 mFreezeXPosSpin =
false;
854 void QgsLayoutItemPropertiesWidget::mYPosSpin_valueChanged(
double )
856 mFreezeYPosSpin =
true;
857 changeItemPosition();
858 mFreezeYPosSpin =
false;
863 changeItemPosition();
866 void QgsLayoutItemPropertiesWidget::mWidthSpin_valueChanged(
double )
868 mFreezeWidthSpin =
true;
870 mFreezeWidthSpin =
false;
873 void QgsLayoutItemPropertiesWidget::mHeightSpin_valueChanged(
double )
875 mFreezeHeightSpin =
true;
877 mFreezeHeightSpin =
false;
885 void QgsLayoutItemPropertiesWidget::mUpperLeftCheckBox_stateChanged(
bool state )
894 setValuesForGuiPositionElements();
897 void QgsLayoutItemPropertiesWidget::mUpperMiddleCheckBox_stateChanged(
bool state )
905 setValuesForGuiPositionElements();
908 void QgsLayoutItemPropertiesWidget::mUpperRightCheckBox_stateChanged(
bool state )
916 setValuesForGuiPositionElements();
919 void QgsLayoutItemPropertiesWidget::mMiddleLeftCheckBox_stateChanged(
bool state )
927 setValuesForGuiPositionElements();
930 void QgsLayoutItemPropertiesWidget::mMiddleCheckBox_stateChanged(
bool state )
938 setValuesForGuiPositionElements();
941 void QgsLayoutItemPropertiesWidget::mMiddleRightCheckBox_stateChanged(
bool state )
949 setValuesForGuiPositionElements();
952 void QgsLayoutItemPropertiesWidget::mLowerLeftCheckBox_stateChanged(
bool state )
960 setValuesForGuiPositionElements();
963 void QgsLayoutItemPropertiesWidget::mLowerMiddleCheckBox_stateChanged(
bool state )
971 setValuesForGuiPositionElements();
974 void QgsLayoutItemPropertiesWidget::mLowerRightCheckBox_stateChanged(
bool state )
982 setValuesForGuiPositionElements();
985 void QgsLayoutItemPropertiesWidget::mItemRotationSpinBox_valueChanged(
double val )
990 mItem->setItemRotation( val,
true );
992 mItem->layout()->undoStack()->endCommand();
996 void QgsLayoutItemPropertiesWidget::mExcludeFromPrintsCheckBox_toggled(
bool checked )
1000 mItem->layout()->undoStack()->beginCommand( mItem, checked ? tr(
"Exclude from Exports" ) : tr(
"Include in Exports" ) );
1001 mItem->setExcludeFromExports( checked );
1002 mItem->layout()->undoStack()->endCommand();