29 #include <QButtonGroup>
37 , mLayoutObject( layoutObject )
39 if ( mLayoutObject->layout() )
42 this, [ = ] { updateDataDefinedButtons(); } );
50 void QgsLayoutConfigObject::updateDataDefinedProperty()
71 mLayoutObject->dataDefinedProperties().setProperty( key, ddButton->
toProperty() );
72 mLayoutObject->refresh();
76 void QgsLayoutConfigObject::updateDataDefinedButtons()
78 const QList< QgsPropertyOverrideButton * > buttons = findChildren< QgsPropertyOverrideButton * >();
87 button->blockSignals(
true );
91 button->blockSignals(
false );
103 whileBlocking( button )->setToProperty( mLayoutObject->dataDefinedProperties().property( key ) );
112 if ( !mLayoutObject )
117 QgsPrintLayout *printLayout = qobject_cast< QgsPrintLayout * >( mLayoutObject->layout() );
124 return printLayout->
atlas();
129 mLayoutObject = object;
134 if ( !mLayoutObject )
137 QgsLayout *layout = mLayoutObject->layout();
152 , mObject( layoutObject )
171 oldConfigObject->deleteLater();
178 mConfigObject->deleteLater();
179 mConfigObject = oldConfigObject;
190 const auto symbolButtonWidgets = findChildren<QgsSymbolButton *>();
193 symbolWidget->setMessageBar( iface->
messageBar() );
195 const auto fontButtonWidgets = findChildren<QgsFontButton *>();
198 fontButton->setMessageBar( iface->
messageBar() );
242 mBlockVariableUpdates =
true;
244 mVariableEditor->setContext( &context );
249 const int multiFrameScopeIndex = context.
indexOfScope( tr(
"Multiframe Item" ) );
250 const int itemScopeIndex = context.
indexOfScope( tr(
"Layout Item" ) );
251 if ( multiFrameScopeIndex >= 0 )
252 mVariableEditor->setEditableScopeIndex( multiFrameScopeIndex );
253 else if ( itemScopeIndex >= 0 )
254 mVariableEditor->setEditableScopeIndex( itemScopeIndex );
255 mBlockVariableUpdates =
false;
264 mVariableEditor->setMinimumHeight( mVariableEditor->fontMetrics().height() * 15 );
266 mItemRotationSpinBox->setClearValue( 0 );
267 mStrokeUnitsComboBox->linkToWidget( mStrokeWidthSpinBox );
270 mPosUnitsComboBox->linkToWidget( mXPosSpin );
271 mPosUnitsComboBox->linkToWidget( mYPosSpin );
272 mSizeUnitsComboBox->linkToWidget( mWidthSpin );
273 mSizeUnitsComboBox->linkToWidget( mHeightSpin );
278 mPosLockAspectRatio->setWidthSpinBox( mXPosSpin );
279 mPosLockAspectRatio->setHeightSpinBox( mYPosSpin );
280 mSizeLockAspectRatio->setWidthSpinBox( mWidthSpin );
281 mSizeLockAspectRatio->setHeightSpinBox( mHeightSpin );
283 mItemFrameColorDDBtn->registerLinkedWidget( mFrameColorButton );
284 mItemBackgroundColorDDBtn->registerLinkedWidget( mBackgroundColorButton );
287 connect( mBackgroundColorButton, &
QgsColorButton::colorChanged,
this, &QgsLayoutItemPropertiesWidget::mBackgroundColorButton_colorChanged );
288 connect( mStrokeWidthSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutItemPropertiesWidget::mStrokeWidthSpinBox_valueChanged );
290 connect( mFrameGroupBox, &QgsCollapsibleGroupBoxBasic::toggled,
this, &QgsLayoutItemPropertiesWidget::mFrameGroupBox_toggled );
291 connect( mFrameJoinStyleCombo,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutItemPropertiesWidget::mFrameJoinStyleCombo_currentIndexChanged );
292 connect( mBackgroundGroupBox, &QgsCollapsibleGroupBoxBasic::toggled,
this, &QgsLayoutItemPropertiesWidget::mBackgroundGroupBox_toggled );
293 connect( mItemIdLineEdit, &QLineEdit::editingFinished,
this, &QgsLayoutItemPropertiesWidget::mItemIdLineEdit_editingFinished );
294 connect( mPageSpinBox,
static_cast < void ( QSpinBox::* )(
int )
> ( &QSpinBox::valueChanged ),
this, &QgsLayoutItemPropertiesWidget::mPageSpinBox_valueChanged );
295 connect( mXPosSpin,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutItemPropertiesWidget::mXPosSpin_valueChanged );
296 connect( mYPosSpin,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutItemPropertiesWidget::mYPosSpin_valueChanged );
298 connect( mWidthSpin,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutItemPropertiesWidget::mWidthSpin_valueChanged );
299 connect( mHeightSpin,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutItemPropertiesWidget::mHeightSpin_valueChanged );
301 connect( mUpperLeftRadioButton, &QRadioButton::toggled,
this, &QgsLayoutItemPropertiesWidget::mUpperLeftCheckBox_stateChanged );
302 connect( mUpperMiddleRadioButton, &QRadioButton::toggled,
this, &QgsLayoutItemPropertiesWidget::mUpperMiddleCheckBox_stateChanged );
303 connect( mUpperRightRadioButton, &QRadioButton::toggled,
this, &QgsLayoutItemPropertiesWidget::mUpperRightCheckBox_stateChanged );
304 connect( mMiddleLeftRadioButton, &QRadioButton::toggled,
this, &QgsLayoutItemPropertiesWidget::mMiddleLeftCheckBox_stateChanged );
305 connect( mMiddleRadioButton, &QRadioButton::toggled,
this, &QgsLayoutItemPropertiesWidget::mMiddleCheckBox_stateChanged );
306 connect( mMiddleRightRadioButton, &QRadioButton::toggled,
this, &QgsLayoutItemPropertiesWidget::mMiddleRightCheckBox_stateChanged );
307 connect( mLowerLeftRadioButton, &QRadioButton::toggled,
this, &QgsLayoutItemPropertiesWidget::mLowerLeftCheckBox_stateChanged );
308 connect( mLowerMiddleRadioButton, &QRadioButton::toggled,
this, &QgsLayoutItemPropertiesWidget::mLowerMiddleCheckBox_stateChanged );
309 connect( mLowerRightRadioButton, &QRadioButton::toggled,
this, &QgsLayoutItemPropertiesWidget::mLowerRightCheckBox_stateChanged );
310 connect( mBlendModeCombo,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutItemPropertiesWidget::mBlendModeCombo_currentIndexChanged );
311 connect( mItemRotationSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutItemPropertiesWidget::mItemRotationSpinBox_valueChanged );
312 connect( mExcludeFromPrintsCheckBox, &QCheckBox::toggled,
this, &QgsLayoutItemPropertiesWidget::mExcludeFromPrintsCheckBox_toggled );
315 QButtonGroup *buttonGroup =
new QButtonGroup(
this );
316 buttonGroup->addButton( mUpperLeftRadioButton );
317 buttonGroup->addButton( mUpperMiddleRadioButton );
318 buttonGroup->addButton( mUpperRightRadioButton );
319 buttonGroup->addButton( mMiddleLeftRadioButton );
320 buttonGroup->addButton( mMiddleRadioButton );
321 buttonGroup->addButton( mMiddleRightRadioButton );
322 buttonGroup->addButton( mLowerLeftRadioButton );
323 buttonGroup->addButton( mLowerMiddleRadioButton );
324 buttonGroup->addButton( mLowerRightRadioButton );
325 buttonGroup->setExclusive(
true );
336 if ( !mBlockVariableUpdates )
337 QgsLayoutItemPropertiesWidget::variablesChanged();
354 mBackgroundGroupBox->setVisible( showGroup );
359 mFrameGroupBox->setVisible( showGroup );
367 disconnect( mItem, &
QgsLayoutObject::changed,
this, &QgsLayoutItemPropertiesWidget::setValuesForGuiNonPositionElements );
373 connect( mItem, &
QgsLayoutObject::changed,
this, &QgsLayoutItemPropertiesWidget::setValuesForGuiNonPositionElements );
378 setValuesForGuiElements();
392 void QgsLayoutItemPropertiesWidget::mFrameColorButton_colorChanged(
const QColor &newFrameColor )
399 mItem->setFrameStrokeColor( newFrameColor );
400 mItem->layout()->undoStack()->endCommand();
404 void QgsLayoutItemPropertiesWidget::mBackgroundColorButton_colorChanged(
const QColor &newBackgroundColor )
411 mItem->setBackgroundColor( newBackgroundColor );
412 mItem->layout()->undoStack()->endCommand();
413 mItem->invalidateCache();
416 void QgsLayoutItemPropertiesWidget::changeItemPosition()
423 QgsLayoutPoint point( mXPosSpin->value(), mYPosSpin->value(), mPosUnitsComboBox->unit() );
424 mItem->attemptMove( point,
true,
false, mPageSpinBox->value() - 1 );
426 mItem->layout()->undoStack()->endCommand();
434 mItem->layout()->undoStack()->beginCommand( mItem, tr(
"Change Item Reference" ) );
435 mItem->setReferencePoint( point );
436 mItem->layout()->undoStack()->endCommand();
439 void QgsLayoutItemPropertiesWidget::changeItemSize()
446 QgsLayoutSize size( mWidthSpin->value(), mHeightSpin->value(), mSizeUnitsComboBox->unit() );
447 mItem->attemptResize( size );
449 mItem->layout()->undoStack()->endCommand();
452 void QgsLayoutItemPropertiesWidget::variablesChanged()
457 if (
QgsLayoutFrame *frame = qobject_cast< QgsLayoutFrame * >( mItem ) )
472 if ( mUpperLeftRadioButton->isChecked() )
476 else if ( mUpperMiddleRadioButton->isChecked() )
480 else if ( mUpperRightRadioButton->isChecked() )
484 else if ( mMiddleLeftRadioButton->isChecked() )
488 else if ( mMiddleRadioButton->isChecked() )
492 else if ( mMiddleRightRadioButton->isChecked() )
496 else if ( mLowerLeftRadioButton->isChecked() )
500 else if ( mLowerMiddleRadioButton->isChecked() )
504 else if ( mLowerRightRadioButton->isChecked() )
511 void QgsLayoutItemPropertiesWidget::mStrokeWidthSpinBox_valueChanged(
double d )
520 mItem->layout()->undoStack()->endCommand();
532 mItem->layout()->undoStack()->endCommand();
535 void QgsLayoutItemPropertiesWidget::mFrameJoinStyleCombo_currentIndexChanged(
int index )
543 mItem->layout()->undoStack()->beginCommand( mItem, tr(
"Change Frame Join Style" ) );
544 mItem->setFrameJoinStyle( mFrameJoinStyleCombo->penJoinStyle() );
545 mItem->layout()->undoStack()->endCommand();
548 void QgsLayoutItemPropertiesWidget::mFrameGroupBox_toggled(
bool state )
555 mItem->layout()->undoStack()->beginCommand( mItem, state ? tr(
"Enable Frame" ) : tr(
"Disable Frame" ) );
556 mItem->setFrameEnabled( state );
558 mItem->layout()->undoStack()->endCommand();
561 void QgsLayoutItemPropertiesWidget::mBackgroundGroupBox_toggled(
bool state )
568 mItem->layout()->undoStack()->beginCommand( mItem, state ? tr(
"Enable Background" ) : tr(
"Disable Background" ) );
569 mItem->setBackgroundEnabled( state );
570 mItem->layout()->undoStack()->endCommand();
571 mItem->invalidateCache();
575 void QgsLayoutItemPropertiesWidget::setValuesForGuiPositionElements()
582 auto block = [ = ](
bool blocked )
584 mXPosSpin->blockSignals( blocked );
585 mYPosSpin->blockSignals( blocked );
586 mPosUnitsComboBox->blockSignals( blocked );
587 mWidthSpin->blockSignals( blocked );
588 mHeightSpin->blockSignals( blocked );
589 mSizeUnitsComboBox->blockSignals( blocked );
590 mUpperLeftRadioButton->blockSignals( blocked );
591 mUpperMiddleRadioButton->blockSignals( blocked );
592 mUpperRightRadioButton->blockSignals( blocked );
593 mMiddleLeftRadioButton->blockSignals( blocked );
594 mMiddleRadioButton->blockSignals( blocked );
595 mMiddleRightRadioButton->blockSignals( blocked );
596 mLowerLeftRadioButton->blockSignals( blocked );
597 mLowerMiddleRadioButton->blockSignals( blocked );
598 mLowerRightRadioButton->blockSignals( blocked );
599 mPageSpinBox->blockSignals( blocked );
605 if ( !mFreezeXPosSpin )
606 mXPosSpin->setValue( point.
x() );
607 if ( !mFreezeYPosSpin )
608 mYPosSpin->setValue( point.
y() );
609 mPosUnitsComboBox->setUnit( point.
units() );
611 switch ( mItem->referencePoint() )
615 mUpperLeftRadioButton->setChecked(
true );
621 mUpperMiddleRadioButton->setChecked(
true );
627 mUpperRightRadioButton->setChecked(
true );
633 mMiddleLeftRadioButton->setChecked(
true );
639 mMiddleRadioButton->setChecked(
true );
645 mMiddleRightRadioButton->setChecked(
true );
651 mLowerLeftRadioButton->setChecked(
true );
657 mLowerMiddleRadioButton->setChecked(
true );
663 mLowerRightRadioButton->setChecked(
true );
669 if ( !mFreezeWidthSpin )
670 mWidthSpin->setValue( size.
width() );
671 if ( !mFreezeHeightSpin )
672 mHeightSpin->setValue( size.
height() );
674 mSizeUnitsComboBox->setUnit( size.
units() );
676 mSizeLockAspectRatio->resetRatio();
677 mPosLockAspectRatio->resetRatio();
679 if ( !mFreezePageSpin )
680 mPageSpinBox->setValue( mItem->page() + 1 );
685 void QgsLayoutItemPropertiesWidget::setValuesForGuiNonPositionElements()
692 auto block = [ = ](
bool blocked )
694 mStrokeWidthSpinBox->blockSignals( blocked );
695 mStrokeUnitsComboBox->blockSignals( blocked );
696 mFrameGroupBox->blockSignals( blocked );
697 mBackgroundGroupBox->blockSignals( blocked );
698 mItemIdLineEdit->blockSignals( blocked );
699 mBlendModeCombo->blockSignals( blocked );
700 mOpacityWidget->blockSignals( blocked );
701 mFrameColorButton->blockSignals( blocked );
702 mFrameJoinStyleCombo->blockSignals( blocked );
703 mBackgroundColorButton->blockSignals( blocked );
704 mItemRotationSpinBox->blockSignals( blocked );
705 mExcludeFromPrintsCheckBox->blockSignals( blocked );
709 mBackgroundColorButton->setColor( mItem->backgroundColor() );
710 mFrameColorButton->setColor( mItem->frameStrokeColor() );
711 mStrokeUnitsComboBox->setUnit( mItem->frameStrokeWidth().units() );
712 mStrokeWidthSpinBox->setValue( mItem->frameStrokeWidth().length() );
713 mFrameJoinStyleCombo->setPenJoinStyle( mItem->frameJoinStyle() );
714 mItemIdLineEdit->setText( mItem->id() );
715 mFrameGroupBox->setChecked( mItem->frameEnabled() );
716 mBackgroundGroupBox->setChecked( mItem->hasBackground() );
717 mBlendModeCombo->setBlendMode( mItem->blendMode() );
718 mOpacityWidget->setOpacity( mItem->itemOpacity() );
719 mItemRotationSpinBox->setValue( mItem->itemRotation() );
720 mExcludeFromPrintsCheckBox->setChecked( mItem->excludeFromExports() );
741 const QList< QgsPropertyOverrideButton * > buttons = findChildren< QgsPropertyOverrideButton * >();
748 void QgsLayoutItemPropertiesWidget::setValuesForGuiElements()
755 mBackgroundColorButton->setColorDialogTitle( tr(
"Select Background Color" ) );
756 mBackgroundColorButton->setAllowOpacity(
true );
757 mBackgroundColorButton->setContext( QStringLiteral(
"composer" ) );
758 mFrameColorButton->setColorDialogTitle( tr(
"Select Frame Color" ) );
759 mFrameColorButton->setAllowOpacity(
true );
760 mFrameColorButton->setContext( QStringLiteral(
"composer" ) );
762 setValuesForGuiPositionElements();
763 setValuesForGuiNonPositionElements();
769 void QgsLayoutItemPropertiesWidget::mBlendModeCombo_currentIndexChanged(
int index )
774 mItem->layout()->undoStack()->beginCommand( mItem, tr(
"Change Blend Mode" ) );
775 mItem->setBlendMode( mBlendModeCombo->blendMode() );
776 mItem->layout()->undoStack()->endCommand();
780 void QgsLayoutItemPropertiesWidget::opacityChanged(
double value )
785 mItem->setItemOpacity( value );
786 mItem->layout()->undoStack()->endCommand();
790 void QgsLayoutItemPropertiesWidget::mItemIdLineEdit_editingFinished()
795 mItem->setId( mItemIdLineEdit->text() );
796 mItemIdLineEdit->setText( mItem->id() );
797 mItem->layout()->undoStack()->endCommand();
801 void QgsLayoutItemPropertiesWidget::mPageSpinBox_valueChanged(
int )
803 mFreezePageSpin =
true;
804 changeItemPosition();
805 mFreezePageSpin =
false;
808 void QgsLayoutItemPropertiesWidget::mXPosSpin_valueChanged(
double )
810 mFreezeXPosSpin =
true;
811 changeItemPosition();
812 mFreezeXPosSpin =
false;
815 void QgsLayoutItemPropertiesWidget::mYPosSpin_valueChanged(
double )
817 mFreezeYPosSpin =
true;
818 changeItemPosition();
819 mFreezeYPosSpin =
false;
824 changeItemPosition();
827 void QgsLayoutItemPropertiesWidget::mWidthSpin_valueChanged(
double )
829 mFreezeWidthSpin =
true;
831 mFreezeWidthSpin =
false;
834 void QgsLayoutItemPropertiesWidget::mHeightSpin_valueChanged(
double )
836 mFreezeHeightSpin =
true;
838 mFreezeHeightSpin =
false;
846 void QgsLayoutItemPropertiesWidget::mUpperLeftCheckBox_stateChanged(
bool state )
855 setValuesForGuiPositionElements();
858 void QgsLayoutItemPropertiesWidget::mUpperMiddleCheckBox_stateChanged(
bool state )
866 setValuesForGuiPositionElements();
869 void QgsLayoutItemPropertiesWidget::mUpperRightCheckBox_stateChanged(
bool state )
877 setValuesForGuiPositionElements();
880 void QgsLayoutItemPropertiesWidget::mMiddleLeftCheckBox_stateChanged(
bool state )
888 setValuesForGuiPositionElements();
891 void QgsLayoutItemPropertiesWidget::mMiddleCheckBox_stateChanged(
bool state )
899 setValuesForGuiPositionElements();
902 void QgsLayoutItemPropertiesWidget::mMiddleRightCheckBox_stateChanged(
bool state )
910 setValuesForGuiPositionElements();
913 void QgsLayoutItemPropertiesWidget::mLowerLeftCheckBox_stateChanged(
bool state )
921 setValuesForGuiPositionElements();
924 void QgsLayoutItemPropertiesWidget::mLowerMiddleCheckBox_stateChanged(
bool state )
932 setValuesForGuiPositionElements();
935 void QgsLayoutItemPropertiesWidget::mLowerRightCheckBox_stateChanged(
bool state )
943 setValuesForGuiPositionElements();
946 void QgsLayoutItemPropertiesWidget::mItemRotationSpinBox_valueChanged(
double val )
951 mItem->setItemRotation( val,
true );
953 mItem->layout()->undoStack()->endCommand();
957 void QgsLayoutItemPropertiesWidget::mExcludeFromPrintsCheckBox_toggled(
bool checked )
961 mItem->layout()->undoStack()->beginCommand( mItem, checked ? tr(
"Exclude from Exports" ) : tr(
"Include in Exports" ) );
962 mItem->setExcludeFromExports( checked );
963 mItem->layout()->undoStack()->endCommand();