24 #include <QButtonGroup> 32 , mLayoutObject( layoutObject )
34 if ( mLayoutObject->layout() )
37 this, [ = ] { updateDataDefinedButtons(); } );
45 void QgsLayoutConfigObject::updateDataDefinedProperty()
56 key = static_cast< QgsLayoutObject::DataDefinedProperty >( ddButton->
propertyKey() );
66 mLayoutObject->dataDefinedProperties().setProperty( key, ddButton->
toProperty() );
67 mLayoutObject->refresh();
71 void QgsLayoutConfigObject::updateDataDefinedButtons()
73 const QList< QgsPropertyOverrideButton * > buttons = findChildren< QgsPropertyOverrideButton * >();
82 button->blockSignals(
true );
86 button->blockSignals(
false );
98 whileBlocking( button )->setToProperty( mLayoutObject->dataDefinedProperties().property( key ) );
107 if ( !mLayoutObject )
119 return printLayout->
atlas();
124 mLayoutObject = object;
129 if ( !mLayoutObject )
132 QgsLayout *layout = mLayoutObject->layout();
147 , mObject( layoutObject )
166 oldConfigObject->deleteLater();
173 mConfigObject->deleteLater();
174 mConfigObject = oldConfigObject;
213 void QgsLayoutItemPropertiesWidget::updateVariables()
218 mBlockVariableUpdates =
true;
220 mVariableEditor->setContext( &context );
221 int editableIndex = context.
indexOfScope( tr(
"Layout Item" ) );
222 if ( editableIndex >= 0 )
223 mVariableEditor->setEditableScopeIndex( editableIndex );
224 mBlockVariableUpdates =
false;
233 mVariableEditor->setMinimumHeight( mVariableEditor->fontMetrics().height() * 15 );
235 mItemRotationSpinBox->setClearValue( 0 );
236 mStrokeUnitsComboBox->linkToWidget( mStrokeWidthSpinBox );
239 mPosUnitsComboBox->linkToWidget( mXPosSpin );
240 mPosUnitsComboBox->linkToWidget( mYPosSpin );
241 mSizeUnitsComboBox->linkToWidget( mWidthSpin );
242 mSizeUnitsComboBox->linkToWidget( mHeightSpin );
247 mPosLockAspectRatio->setWidthSpinBox( mXPosSpin );
248 mPosLockAspectRatio->setHeightSpinBox( mYPosSpin );
249 mSizeLockAspectRatio->setWidthSpinBox( mWidthSpin );
250 mSizeLockAspectRatio->setHeightSpinBox( mHeightSpin );
253 connect( mBackgroundColorButton, &
QgsColorButton::colorChanged,
this, &QgsLayoutItemPropertiesWidget::mBackgroundColorButton_colorChanged );
254 connect( mStrokeWidthSpinBox, static_cast <
void ( QDoubleSpinBox::* )(
double ) > ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutItemPropertiesWidget::mStrokeWidthSpinBox_valueChanged );
256 connect( mFrameGroupBox, &QgsCollapsibleGroupBoxBasic::toggled,
this, &QgsLayoutItemPropertiesWidget::mFrameGroupBox_toggled );
257 connect( mFrameJoinStyleCombo,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutItemPropertiesWidget::mFrameJoinStyleCombo_currentIndexChanged );
258 connect( mBackgroundGroupBox, &QgsCollapsibleGroupBoxBasic::toggled,
this, &QgsLayoutItemPropertiesWidget::mBackgroundGroupBox_toggled );
259 connect( mItemIdLineEdit, &QLineEdit::editingFinished,
this, &QgsLayoutItemPropertiesWidget::mItemIdLineEdit_editingFinished );
260 connect( mPageSpinBox, static_cast <
void ( QSpinBox::* )(
int ) > ( &QSpinBox::valueChanged ),
this, &QgsLayoutItemPropertiesWidget::mPageSpinBox_valueChanged );
261 connect( mXPosSpin, static_cast <
void ( QDoubleSpinBox::* )(
double ) > ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutItemPropertiesWidget::mXPosSpin_valueChanged );
262 connect( mYPosSpin, static_cast <
void ( QDoubleSpinBox::* )(
double ) > ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutItemPropertiesWidget::mYPosSpin_valueChanged );
264 connect( mWidthSpin, static_cast <
void ( QDoubleSpinBox::* )(
double ) > ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutItemPropertiesWidget::mWidthSpin_valueChanged );
265 connect( mHeightSpin, static_cast <
void ( QDoubleSpinBox::* )(
double ) > ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutItemPropertiesWidget::mHeightSpin_valueChanged );
267 connect( mUpperLeftRadioButton, &QRadioButton::toggled,
this, &QgsLayoutItemPropertiesWidget::mUpperLeftCheckBox_stateChanged );
268 connect( mUpperMiddleRadioButton, &QRadioButton::toggled,
this, &QgsLayoutItemPropertiesWidget::mUpperMiddleCheckBox_stateChanged );
269 connect( mUpperRightRadioButton, &QRadioButton::toggled,
this, &QgsLayoutItemPropertiesWidget::mUpperRightCheckBox_stateChanged );
270 connect( mMiddleLeftRadioButton, &QRadioButton::toggled,
this, &QgsLayoutItemPropertiesWidget::mMiddleLeftCheckBox_stateChanged );
271 connect( mMiddleRadioButton, &QRadioButton::toggled,
this, &QgsLayoutItemPropertiesWidget::mMiddleCheckBox_stateChanged );
272 connect( mMiddleRightRadioButton, &QRadioButton::toggled,
this, &QgsLayoutItemPropertiesWidget::mMiddleRightCheckBox_stateChanged );
273 connect( mLowerLeftRadioButton, &QRadioButton::toggled,
this, &QgsLayoutItemPropertiesWidget::mLowerLeftCheckBox_stateChanged );
274 connect( mLowerMiddleRadioButton, &QRadioButton::toggled,
this, &QgsLayoutItemPropertiesWidget::mLowerMiddleCheckBox_stateChanged );
275 connect( mLowerRightRadioButton, &QRadioButton::toggled,
this, &QgsLayoutItemPropertiesWidget::mLowerRightCheckBox_stateChanged );
276 connect( mBlendModeCombo,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutItemPropertiesWidget::mBlendModeCombo_currentIndexChanged );
277 connect( mItemRotationSpinBox, static_cast <
void ( QDoubleSpinBox::* )(
double ) > ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutItemPropertiesWidget::mItemRotationSpinBox_valueChanged );
278 connect( mExcludeFromPrintsCheckBox, &QCheckBox::toggled,
this, &QgsLayoutItemPropertiesWidget::mExcludeFromPrintsCheckBox_toggled );
281 QButtonGroup *buttonGroup =
new QButtonGroup(
this );
282 buttonGroup->addButton( mUpperLeftRadioButton );
283 buttonGroup->addButton( mUpperMiddleRadioButton );
284 buttonGroup->addButton( mUpperRightRadioButton );
285 buttonGroup->addButton( mMiddleLeftRadioButton );
286 buttonGroup->addButton( mMiddleRadioButton );
287 buttonGroup->addButton( mMiddleRightRadioButton );
288 buttonGroup->addButton( mLowerLeftRadioButton );
289 buttonGroup->addButton( mLowerMiddleRadioButton );
290 buttonGroup->addButton( mLowerRightRadioButton );
291 buttonGroup->setExclusive(
true );
302 if ( !mBlockVariableUpdates )
303 QgsLayoutItemPropertiesWidget::variablesChanged();
315 mBackgroundGroupBox->setVisible( showGroup );
320 mFrameGroupBox->setVisible( showGroup );
328 disconnect( mItem, &
QgsLayoutObject::changed,
this, &QgsLayoutItemPropertiesWidget::setValuesForGuiNonPositionElements );
334 connect( mItem, &
QgsLayoutObject::changed,
this, &QgsLayoutItemPropertiesWidget::setValuesForGuiNonPositionElements );
339 setValuesForGuiElements();
344 void QgsLayoutItemPropertiesWidget::mFrameColorButton_colorChanged(
const QColor &newFrameColor )
351 mItem->setFrameStrokeColor( newFrameColor );
352 mItem->layout()->undoStack()->endCommand();
356 void QgsLayoutItemPropertiesWidget::mBackgroundColorButton_colorChanged(
const QColor &newBackgroundColor )
363 mItem->setBackgroundColor( newBackgroundColor );
364 mItem->layout()->undoStack()->endCommand();
365 mItem->invalidateCache();
368 void QgsLayoutItemPropertiesWidget::changeItemPosition()
375 QgsLayoutPoint point( mXPosSpin->value(), mYPosSpin->value(), mPosUnitsComboBox->unit() );
376 mItem->attemptMove( point,
true,
false, mPageSpinBox->value() - 1 );
378 mItem->layout()->undoStack()->endCommand();
386 mItem->layout()->undoStack()->beginCommand( mItem, tr(
"Change Item Reference" ) );
387 mItem->setReferencePoint( point );
388 mItem->layout()->undoStack()->endCommand();
391 void QgsLayoutItemPropertiesWidget::changeItemSize()
398 QgsLayoutSize size( mWidthSpin->value(), mHeightSpin->value(), mSizeUnitsComboBox->unit() );
399 mItem->attemptResize( size );
401 mItem->layout()->undoStack()->endCommand();
404 void QgsLayoutItemPropertiesWidget::variablesChanged()
414 if ( mUpperLeftRadioButton->isChecked() )
418 else if ( mUpperMiddleRadioButton->isChecked() )
422 else if ( mUpperRightRadioButton->isChecked() )
426 else if ( mMiddleLeftRadioButton->isChecked() )
430 else if ( mMiddleRadioButton->isChecked() )
434 else if ( mMiddleRightRadioButton->isChecked() )
438 else if ( mLowerLeftRadioButton->isChecked() )
442 else if ( mLowerMiddleRadioButton->isChecked() )
446 else if ( mLowerRightRadioButton->isChecked() )
453 void QgsLayoutItemPropertiesWidget::mStrokeWidthSpinBox_valueChanged(
double d )
462 mItem->layout()->undoStack()->endCommand();
474 mItem->layout()->undoStack()->endCommand();
477 void QgsLayoutItemPropertiesWidget::mFrameJoinStyleCombo_currentIndexChanged(
int index )
485 mItem->layout()->undoStack()->beginCommand( mItem, tr(
"Change Frame Join Style" ) );
486 mItem->setFrameJoinStyle( mFrameJoinStyleCombo->penJoinStyle() );
487 mItem->layout()->undoStack()->endCommand();
490 void QgsLayoutItemPropertiesWidget::mFrameGroupBox_toggled(
bool state )
497 mItem->layout()->undoStack()->beginCommand( mItem, state ? tr(
"Enable Frame" ) : tr(
"Disable Frame" ) );
498 mItem->setFrameEnabled( state );
500 mItem->layout()->undoStack()->endCommand();
503 void QgsLayoutItemPropertiesWidget::mBackgroundGroupBox_toggled(
bool state )
510 mItem->layout()->undoStack()->beginCommand( mItem, state ? tr(
"Enable Background" ) : tr(
"Disable Background" ) );
511 mItem->setBackgroundEnabled( state );
512 mItem->layout()->undoStack()->endCommand();
513 mItem->invalidateCache();
517 void QgsLayoutItemPropertiesWidget::setValuesForGuiPositionElements()
524 auto block = [ = ](
bool blocked )
526 mXPosSpin->blockSignals( blocked );
527 mYPosSpin->blockSignals( blocked );
528 mPosUnitsComboBox->blockSignals( blocked );
529 mWidthSpin->blockSignals( blocked );
530 mHeightSpin->blockSignals( blocked );
531 mSizeUnitsComboBox->blockSignals( blocked );
532 mUpperLeftRadioButton->blockSignals( blocked );
533 mUpperMiddleRadioButton->blockSignals( blocked );
534 mUpperRightRadioButton->blockSignals( blocked );
535 mMiddleLeftRadioButton->blockSignals( blocked );
536 mMiddleRadioButton->blockSignals( blocked );
537 mMiddleRightRadioButton->blockSignals( blocked );
538 mLowerLeftRadioButton->blockSignals( blocked );
539 mLowerMiddleRadioButton->blockSignals( blocked );
540 mLowerRightRadioButton->blockSignals( blocked );
541 mPageSpinBox->blockSignals( blocked );
547 if ( !mFreezeXPosSpin )
548 mXPosSpin->setValue( point.
x() );
549 if ( !mFreezeYPosSpin )
550 mYPosSpin->setValue( point.
y() );
551 mPosUnitsComboBox->setUnit( point.
units() );
553 switch ( mItem->referencePoint() )
557 mUpperLeftRadioButton->setChecked(
true );
563 mUpperMiddleRadioButton->setChecked(
true );
569 mUpperRightRadioButton->setChecked(
true );
575 mMiddleLeftRadioButton->setChecked(
true );
581 mMiddleRadioButton->setChecked(
true );
587 mMiddleRightRadioButton->setChecked(
true );
593 mLowerLeftRadioButton->setChecked(
true );
599 mLowerMiddleRadioButton->setChecked(
true );
605 mLowerRightRadioButton->setChecked(
true );
611 if ( !mFreezeWidthSpin )
612 mWidthSpin->setValue( size.
width() );
613 if ( !mFreezeHeightSpin )
614 mHeightSpin->setValue( size.
height() );
616 mSizeUnitsComboBox->setUnit( size.
units() );
618 mSizeLockAspectRatio->resetRatio();
619 mPosLockAspectRatio->resetRatio();
621 if ( !mFreezePageSpin )
622 mPageSpinBox->setValue( mItem->page() + 1 );
627 void QgsLayoutItemPropertiesWidget::setValuesForGuiNonPositionElements()
634 auto block = [ = ](
bool blocked )
636 mStrokeWidthSpinBox->blockSignals( blocked );
637 mStrokeUnitsComboBox->blockSignals( blocked );
638 mFrameGroupBox->blockSignals( blocked );
639 mBackgroundGroupBox->blockSignals( blocked );
640 mItemIdLineEdit->blockSignals( blocked );
641 mBlendModeCombo->blockSignals( blocked );
642 mOpacityWidget->blockSignals( blocked );
643 mFrameColorButton->blockSignals( blocked );
644 mFrameJoinStyleCombo->blockSignals( blocked );
645 mBackgroundColorButton->blockSignals( blocked );
646 mItemRotationSpinBox->blockSignals( blocked );
647 mExcludeFromPrintsCheckBox->blockSignals( blocked );
651 mBackgroundColorButton->setColor( mItem->backgroundColor() );
652 mFrameColorButton->setColor( mItem->frameStrokeColor() );
653 mStrokeUnitsComboBox->setUnit( mItem->frameStrokeWidth().units() );
654 mStrokeWidthSpinBox->setValue( mItem->frameStrokeWidth().length() );
655 mFrameJoinStyleCombo->setPenJoinStyle( mItem->frameJoinStyle() );
656 mItemIdLineEdit->setText( mItem->id() );
657 mFrameGroupBox->setChecked( mItem->frameEnabled() );
658 mBackgroundGroupBox->setChecked( mItem->hasBackground() );
659 mBlendModeCombo->setBlendMode( mItem->blendMode() );
660 mOpacityWidget->setOpacity( mItem->itemOpacity() );
661 mItemRotationSpinBox->setValue( mItem->itemRotation() );
662 mExcludeFromPrintsCheckBox->setChecked( mItem->excludeFromExports() );
683 const QList< QgsPropertyOverrideButton * > buttons = findChildren< QgsPropertyOverrideButton * >();
690 void QgsLayoutItemPropertiesWidget::setValuesForGuiElements()
697 mBackgroundColorButton->setColorDialogTitle( tr(
"Select Background Color" ) );
698 mBackgroundColorButton->setAllowOpacity(
true );
699 mBackgroundColorButton->setContext( QStringLiteral(
"composer" ) );
700 mFrameColorButton->setColorDialogTitle( tr(
"Select Frame Color" ) );
701 mFrameColorButton->setAllowOpacity(
true );
702 mFrameColorButton->setContext( QStringLiteral(
"composer" ) );
704 setValuesForGuiPositionElements();
705 setValuesForGuiNonPositionElements();
711 void QgsLayoutItemPropertiesWidget::mBlendModeCombo_currentIndexChanged(
int index )
716 mItem->layout()->undoStack()->beginCommand( mItem, tr(
"Change Blend Mode" ) );
717 mItem->setBlendMode( mBlendModeCombo->blendMode() );
718 mItem->layout()->undoStack()->endCommand();
722 void QgsLayoutItemPropertiesWidget::opacityChanged(
double value )
727 mItem->setItemOpacity( value );
728 mItem->layout()->undoStack()->endCommand();
732 void QgsLayoutItemPropertiesWidget::mItemIdLineEdit_editingFinished()
737 mItem->setId( mItemIdLineEdit->text() );
738 mItemIdLineEdit->setText( mItem->id() );
739 mItem->layout()->undoStack()->endCommand();
743 void QgsLayoutItemPropertiesWidget::mPageSpinBox_valueChanged(
int )
745 mFreezePageSpin =
true;
746 changeItemPosition();
747 mFreezePageSpin =
false;
750 void QgsLayoutItemPropertiesWidget::mXPosSpin_valueChanged(
double )
752 mFreezeXPosSpin =
true;
753 changeItemPosition();
754 mFreezeXPosSpin =
false;
757 void QgsLayoutItemPropertiesWidget::mYPosSpin_valueChanged(
double )
759 mFreezeYPosSpin =
true;
760 changeItemPosition();
761 mFreezeYPosSpin =
false;
766 changeItemPosition();
769 void QgsLayoutItemPropertiesWidget::mWidthSpin_valueChanged(
double )
771 mFreezeWidthSpin =
true;
773 mFreezeWidthSpin =
false;
776 void QgsLayoutItemPropertiesWidget::mHeightSpin_valueChanged(
double )
778 mFreezeHeightSpin =
true;
780 mFreezeHeightSpin =
false;
788 void QgsLayoutItemPropertiesWidget::mUpperLeftCheckBox_stateChanged(
bool state )
797 setValuesForGuiPositionElements();
800 void QgsLayoutItemPropertiesWidget::mUpperMiddleCheckBox_stateChanged(
bool state )
808 setValuesForGuiPositionElements();
811 void QgsLayoutItemPropertiesWidget::mUpperRightCheckBox_stateChanged(
bool state )
819 setValuesForGuiPositionElements();
822 void QgsLayoutItemPropertiesWidget::mMiddleLeftCheckBox_stateChanged(
bool state )
830 setValuesForGuiPositionElements();
833 void QgsLayoutItemPropertiesWidget::mMiddleCheckBox_stateChanged(
bool state )
841 setValuesForGuiPositionElements();
844 void QgsLayoutItemPropertiesWidget::mMiddleRightCheckBox_stateChanged(
bool state )
852 setValuesForGuiPositionElements();
855 void QgsLayoutItemPropertiesWidget::mLowerLeftCheckBox_stateChanged(
bool state )
863 setValuesForGuiPositionElements();
866 void QgsLayoutItemPropertiesWidget::mLowerMiddleCheckBox_stateChanged(
bool state )
874 setValuesForGuiPositionElements();
877 void QgsLayoutItemPropertiesWidget::mLowerRightCheckBox_stateChanged(
bool state )
885 setValuesForGuiPositionElements();
888 void QgsLayoutItemPropertiesWidget::mItemRotationSpinBox_valueChanged(
double val )
893 mItem->setItemRotation( val,
true );
895 mItem->layout()->undoStack()->endCommand();
899 void QgsLayoutItemPropertiesWidget::mExcludeFromPrintsCheckBox_toggled(
bool checked )
903 mItem->layout()->undoStack()->beginCommand( mItem, checked ? tr(
"Exclude from Exports" ) : tr(
"Include in Exports" ) );
904 mItem->setExcludeFromExports( checked );
905 mItem->layout()->undoStack()->endCommand();
static void setLayoutItemVariables(QgsLayoutItem *item, const QVariantMap &variables)
Sets all layout item context variables for an item.
Base class for graphical items within a QgsLayout.
Lower left corner of item.
static QgsApplication * instance()
Returns the singleton instance of the QgsApplication.
void customVariablesChanged()
Emitted whenever a custom global variable changes.
QgsUnitTypes::LayoutUnit units() const
Returns the units for the size.
Exclude item from exports.
double x() const
Returns x coordinate of point.
void toggled(bool)
Emitted when atlas is enabled or disabled.
QgsLayoutConfigObject(QWidget *parent SIP_TRANSFERTHIS, QgsLayoutObject *layoutObject)
Constructor for QgsLayoutConfigObject, linked with the specified layoutObject.
Lower right corner of item.
int indexOfScope(QgsExpressionContextScope *scope) const
Returns the index of the specified scope if it exists within the context.
const QgsLayoutMeasurementConverter & measurementConverter() const
Returns the layout measurement converter to be used in the layout.
double height() const
Returns the height of the size.
QgsLayoutRenderContext & renderContext()
Returns a reference to the layout's render context, which stores information relating to the current ...
static const QgsPropertiesDefinition & propertyDefinitions()
Returns the layout object property definitions.
This class provides a method of storing points, consisting of an x and y coordinate, for use in QGIS layouts.
ReferencePoint
Fixed position reference point.
void sizePositionChanged()
Emitted when the item's size or position changes.
double width() const
Returns the width of the size.
void variablesChanged()
Emitted whenever the expression variables stored in the layout have been changed. ...
This class provides a method of storing measurements for use in QGIS layouts using a variety of diffe...
Upper right corner of item.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Class used to render QgsLayout as an atlas, by iterating over the features from an associated vector ...
void initializeDataDefinedButton(QgsPropertyOverrideButton *button, QgsLayoutObject::DataDefinedProperty key)
Registers a data defined button, setting up its initial value, connections and description.
void setObject(QgsLayoutObject *object) SIP_SKIP
Links a new layout object to this QgsLayoutConfigObject.
void layerChanged(QgsVectorLayer *layer)
Emitted when the context's layer is changed.
void updateDataDefinedButton(QgsPropertyOverrideButton *button)
Updates a data defined button to reflect the item's current properties.
void changed(QgsUnitTypes::LayoutUnit unit)
Emitted when the unit is changed.
Upper left corner of item.
QgsLayoutAtlas * atlas()
Returns the print layout's atlas.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
QgsLayoutAtlas * layoutAtlas() const
Returns the atlas for the layout, if available.
QgsLayoutReportContext & reportContext()
Returns a reference to the layout's report context, which stores information relating to the current ...
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
void customVariablesChanged()
Emitted whenever the expression variables stored in the project have been changed.
QgsVectorLayer * coverageLayer() const
Returns the current layout context coverage layer (if set).
An object for property widgets for layout items.
Background color adjustment.
A base class for objects which belong to a layout.
LayoutUnit
Layout measurement units.
Layout item incremental movement, e.g. as a result of a keypress.
const QgsLayout * layout() const
Returns the layout the object is attached to.
Print layout, a QgsLayout subclass for static or atlas-based layouts.
This class provides a method of storing sizes, consisting of a width and height, for use in QGIS layo...
void changed()
Emitted when the object's properties change.
Represents a vector layer which manages a vector based data sets.
DataDefinedProperty
Data defined properties for different item types.
QgsUnitTypes::LayoutUnit units() const
Returns the units for the point.
QgsProject * project() const
The project associated with the layout.
QgsVectorLayer * layer() const
Returns the vector layer associated with the layout's context.
double y() const
Returns y coordinate of point.