25 #include <QButtonGroup> 33 , mLayoutObject( layoutObject )
35 if ( mLayoutObject->layout() )
38 this, [ = ] { updateDataDefinedButtons(); } );
46 void QgsLayoutConfigObject::updateDataDefinedProperty()
57 key = static_cast< QgsLayoutObject::DataDefinedProperty >( ddButton->
propertyKey() );
67 mLayoutObject->dataDefinedProperties().setProperty( key, ddButton->
toProperty() );
68 mLayoutObject->refresh();
72 void QgsLayoutConfigObject::updateDataDefinedButtons()
74 const QList< QgsPropertyOverrideButton * > buttons = findChildren< QgsPropertyOverrideButton * >();
83 button->blockSignals(
true );
87 button->blockSignals(
false );
99 whileBlocking( button )->setToProperty( mLayoutObject->dataDefinedProperties().property( key ) );
108 if ( !mLayoutObject )
120 return printLayout->
atlas();
125 mLayoutObject = object;
130 if ( !mLayoutObject )
133 QgsLayout *layout = mLayoutObject->layout();
148 , mObject( layoutObject )
167 oldConfigObject->deleteLater();
174 mConfigObject->deleteLater();
175 mConfigObject = oldConfigObject;
219 void QgsLayoutItemPropertiesWidget::updateVariables()
225 mVariableEditor->setContext( &context );
226 int editableIndex = context.
indexOfScope( tr(
"Layout Item" ) );
227 if ( editableIndex >= 0 )
228 mVariableEditor->setEditableScopeIndex( editableIndex );
237 mVariableEditor->setMinimumHeight( mVariableEditor->fontMetrics().height() * 15 );
239 mItemRotationSpinBox->setClearValue( 0 );
240 mStrokeUnitsComboBox->linkToWidget( mStrokeWidthSpinBox );
243 mPosUnitsComboBox->linkToWidget( mXPosSpin );
244 mPosUnitsComboBox->linkToWidget( mYPosSpin );
245 mSizeUnitsComboBox->linkToWidget( mWidthSpin );
246 mSizeUnitsComboBox->linkToWidget( mHeightSpin );
251 mPosLockAspectRatio->setWidthSpinBox( mXPosSpin );
252 mPosLockAspectRatio->setHeightSpinBox( mYPosSpin );
253 mSizeLockAspectRatio->setWidthSpinBox( mWidthSpin );
254 mSizeLockAspectRatio->setHeightSpinBox( mHeightSpin );
256 mItemFrameColorDDBtn->registerLinkedWidget( mFrameColorButton );
257 mItemBackgroundColorDDBtn->registerLinkedWidget( mBackgroundColorButton );
260 connect( mBackgroundColorButton, &
QgsColorButton::colorChanged,
this, &QgsLayoutItemPropertiesWidget::mBackgroundColorButton_colorChanged );
261 connect( mStrokeWidthSpinBox, static_cast <
void ( QDoubleSpinBox::* )(
double ) > ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutItemPropertiesWidget::mStrokeWidthSpinBox_valueChanged );
263 connect( mFrameGroupBox, &QgsCollapsibleGroupBoxBasic::toggled,
this, &QgsLayoutItemPropertiesWidget::mFrameGroupBox_toggled );
264 connect( mFrameJoinStyleCombo,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutItemPropertiesWidget::mFrameJoinStyleCombo_currentIndexChanged );
265 connect( mBackgroundGroupBox, &QgsCollapsibleGroupBoxBasic::toggled,
this, &QgsLayoutItemPropertiesWidget::mBackgroundGroupBox_toggled );
266 connect( mItemIdLineEdit, &QLineEdit::editingFinished,
this, &QgsLayoutItemPropertiesWidget::mItemIdLineEdit_editingFinished );
267 connect( mPageSpinBox, static_cast <
void ( QSpinBox::* )(
int ) > ( &QSpinBox::valueChanged ),
this, &QgsLayoutItemPropertiesWidget::mPageSpinBox_valueChanged );
268 connect( mXPosSpin, static_cast <
void ( QDoubleSpinBox::* )(
double ) > ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutItemPropertiesWidget::mXPosSpin_valueChanged );
269 connect( mYPosSpin, static_cast <
void ( QDoubleSpinBox::* )(
double ) > ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutItemPropertiesWidget::mYPosSpin_valueChanged );
271 connect( mWidthSpin, static_cast <
void ( QDoubleSpinBox::* )(
double ) > ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutItemPropertiesWidget::mWidthSpin_valueChanged );
272 connect( mHeightSpin, static_cast <
void ( QDoubleSpinBox::* )(
double ) > ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutItemPropertiesWidget::mHeightSpin_valueChanged );
274 connect( mUpperLeftRadioButton, &QRadioButton::toggled,
this, &QgsLayoutItemPropertiesWidget::mUpperLeftCheckBox_stateChanged );
275 connect( mUpperMiddleRadioButton, &QRadioButton::toggled,
this, &QgsLayoutItemPropertiesWidget::mUpperMiddleCheckBox_stateChanged );
276 connect( mUpperRightRadioButton, &QRadioButton::toggled,
this, &QgsLayoutItemPropertiesWidget::mUpperRightCheckBox_stateChanged );
277 connect( mMiddleLeftRadioButton, &QRadioButton::toggled,
this, &QgsLayoutItemPropertiesWidget::mMiddleLeftCheckBox_stateChanged );
278 connect( mMiddleRadioButton, &QRadioButton::toggled,
this, &QgsLayoutItemPropertiesWidget::mMiddleCheckBox_stateChanged );
279 connect( mMiddleRightRadioButton, &QRadioButton::toggled,
this, &QgsLayoutItemPropertiesWidget::mMiddleRightCheckBox_stateChanged );
280 connect( mLowerLeftRadioButton, &QRadioButton::toggled,
this, &QgsLayoutItemPropertiesWidget::mLowerLeftCheckBox_stateChanged );
281 connect( mLowerMiddleRadioButton, &QRadioButton::toggled,
this, &QgsLayoutItemPropertiesWidget::mLowerMiddleCheckBox_stateChanged );
282 connect( mLowerRightRadioButton, &QRadioButton::toggled,
this, &QgsLayoutItemPropertiesWidget::mLowerRightCheckBox_stateChanged );
283 connect( mBlendModeCombo,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutItemPropertiesWidget::mBlendModeCombo_currentIndexChanged );
284 connect( mItemRotationSpinBox, static_cast <
void ( QDoubleSpinBox::* )(
double ) > ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutItemPropertiesWidget::mItemRotationSpinBox_valueChanged );
285 connect( mExcludeFromPrintsCheckBox, &QCheckBox::toggled,
this, &QgsLayoutItemPropertiesWidget::mExcludeFromPrintsCheckBox_toggled );
288 QButtonGroup *buttonGroup =
new QButtonGroup(
this );
289 buttonGroup->addButton( mUpperLeftRadioButton );
290 buttonGroup->addButton( mUpperMiddleRadioButton );
291 buttonGroup->addButton( mUpperRightRadioButton );
292 buttonGroup->addButton( mMiddleLeftRadioButton );
293 buttonGroup->addButton( mMiddleRadioButton );
294 buttonGroup->addButton( mMiddleRightRadioButton );
295 buttonGroup->addButton( mLowerLeftRadioButton );
296 buttonGroup->addButton( mLowerMiddleRadioButton );
297 buttonGroup->addButton( mLowerRightRadioButton );
298 buttonGroup->setExclusive(
true );
318 mBackgroundGroupBox->setVisible( showGroup );
323 mFrameGroupBox->setVisible( showGroup );
331 disconnect( mItem, &
QgsLayoutObject::changed,
this, &QgsLayoutItemPropertiesWidget::setValuesForGuiNonPositionElements );
337 connect( mItem, &
QgsLayoutObject::changed,
this, &QgsLayoutItemPropertiesWidget::setValuesForGuiNonPositionElements );
342 setValuesForGuiElements();
347 void QgsLayoutItemPropertiesWidget::mFrameColorButton_colorChanged(
const QColor &newFrameColor )
354 mItem->setFrameStrokeColor( newFrameColor );
355 mItem->layout()->undoStack()->endCommand();
359 void QgsLayoutItemPropertiesWidget::mBackgroundColorButton_colorChanged(
const QColor &newBackgroundColor )
366 mItem->setBackgroundColor( newBackgroundColor );
367 mItem->layout()->undoStack()->endCommand();
368 mItem->invalidateCache();
371 void QgsLayoutItemPropertiesWidget::changeItemPosition()
378 QgsLayoutPoint point( mXPosSpin->value(), mYPosSpin->value(), mPosUnitsComboBox->unit() );
379 mItem->attemptMove( point,
true,
false, mPageSpinBox->value() - 1 );
381 mItem->layout()->undoStack()->endCommand();
389 mItem->layout()->undoStack()->beginCommand( mItem, tr(
"Change Item Reference" ) );
390 mItem->setReferencePoint( point );
391 mItem->layout()->undoStack()->endCommand();
394 void QgsLayoutItemPropertiesWidget::changeItemSize()
401 QgsLayoutSize size( mWidthSpin->value(), mHeightSpin->value(), mSizeUnitsComboBox->unit() );
402 mItem->attemptResize( size );
404 mItem->layout()->undoStack()->endCommand();
407 void QgsLayoutItemPropertiesWidget::variablesChanged()
417 if ( mUpperLeftRadioButton->isChecked() )
421 else if ( mUpperMiddleRadioButton->isChecked() )
425 else if ( mUpperRightRadioButton->isChecked() )
429 else if ( mMiddleLeftRadioButton->isChecked() )
433 else if ( mMiddleRadioButton->isChecked() )
437 else if ( mMiddleRightRadioButton->isChecked() )
441 else if ( mLowerLeftRadioButton->isChecked() )
445 else if ( mLowerMiddleRadioButton->isChecked() )
449 else if ( mLowerRightRadioButton->isChecked() )
456 void QgsLayoutItemPropertiesWidget::mStrokeWidthSpinBox_valueChanged(
double d )
465 mItem->layout()->undoStack()->endCommand();
477 mItem->layout()->undoStack()->endCommand();
480 void QgsLayoutItemPropertiesWidget::mFrameJoinStyleCombo_currentIndexChanged(
int index )
488 mItem->layout()->undoStack()->beginCommand( mItem, tr(
"Change Frame Join Style" ) );
489 mItem->setFrameJoinStyle( mFrameJoinStyleCombo->penJoinStyle() );
490 mItem->layout()->undoStack()->endCommand();
493 void QgsLayoutItemPropertiesWidget::mFrameGroupBox_toggled(
bool state )
500 mItem->layout()->undoStack()->beginCommand( mItem, state ? tr(
"Enable Frame" ) : tr(
"Disable Frame" ) );
501 mItem->setFrameEnabled( state );
503 mItem->layout()->undoStack()->endCommand();
506 void QgsLayoutItemPropertiesWidget::mBackgroundGroupBox_toggled(
bool state )
513 mItem->layout()->undoStack()->beginCommand( mItem, state ? tr(
"Enable Background" ) : tr(
"Disable Background" ) );
514 mItem->setBackgroundEnabled( state );
515 mItem->layout()->undoStack()->endCommand();
516 mItem->invalidateCache();
520 void QgsLayoutItemPropertiesWidget::setValuesForGuiPositionElements()
527 auto block = [ = ](
bool blocked )
529 mXPosSpin->blockSignals( blocked );
530 mYPosSpin->blockSignals( blocked );
531 mPosUnitsComboBox->blockSignals( blocked );
532 mWidthSpin->blockSignals( blocked );
533 mHeightSpin->blockSignals( blocked );
534 mSizeUnitsComboBox->blockSignals( blocked );
535 mUpperLeftRadioButton->blockSignals( blocked );
536 mUpperMiddleRadioButton->blockSignals( blocked );
537 mUpperRightRadioButton->blockSignals( blocked );
538 mMiddleLeftRadioButton->blockSignals( blocked );
539 mMiddleRadioButton->blockSignals( blocked );
540 mMiddleRightRadioButton->blockSignals( blocked );
541 mLowerLeftRadioButton->blockSignals( blocked );
542 mLowerMiddleRadioButton->blockSignals( blocked );
543 mLowerRightRadioButton->blockSignals( blocked );
544 mPageSpinBox->blockSignals( blocked );
550 if ( !mFreezeXPosSpin )
551 mXPosSpin->setValue( point.
x() );
552 if ( !mFreezeYPosSpin )
553 mYPosSpin->setValue( point.
y() );
554 mPosUnitsComboBox->setUnit( point.
units() );
556 switch ( mItem->referencePoint() )
560 mUpperLeftRadioButton->setChecked(
true );
566 mUpperMiddleRadioButton->setChecked(
true );
572 mUpperRightRadioButton->setChecked(
true );
578 mMiddleLeftRadioButton->setChecked(
true );
584 mMiddleRadioButton->setChecked(
true );
590 mMiddleRightRadioButton->setChecked(
true );
596 mLowerLeftRadioButton->setChecked(
true );
602 mLowerMiddleRadioButton->setChecked(
true );
608 mLowerRightRadioButton->setChecked(
true );
614 if ( !mFreezeWidthSpin )
615 mWidthSpin->setValue( size.
width() );
616 if ( !mFreezeHeightSpin )
617 mHeightSpin->setValue( size.
height() );
619 mSizeUnitsComboBox->setUnit( size.
units() );
621 mSizeLockAspectRatio->resetRatio();
622 mPosLockAspectRatio->resetRatio();
624 if ( !mFreezePageSpin )
625 mPageSpinBox->setValue( mItem->page() + 1 );
630 void QgsLayoutItemPropertiesWidget::setValuesForGuiNonPositionElements()
637 auto block = [ = ](
bool blocked )
639 mStrokeWidthSpinBox->blockSignals( blocked );
640 mStrokeUnitsComboBox->blockSignals( blocked );
641 mFrameGroupBox->blockSignals( blocked );
642 mBackgroundGroupBox->blockSignals( blocked );
643 mItemIdLineEdit->blockSignals( blocked );
644 mBlendModeCombo->blockSignals( blocked );
645 mOpacityWidget->blockSignals( blocked );
646 mFrameColorButton->blockSignals( blocked );
647 mFrameJoinStyleCombo->blockSignals( blocked );
648 mBackgroundColorButton->blockSignals( blocked );
649 mItemRotationSpinBox->blockSignals( blocked );
650 mExcludeFromPrintsCheckBox->blockSignals( blocked );
654 mBackgroundColorButton->setColor( mItem->backgroundColor() );
655 mFrameColorButton->setColor( mItem->frameStrokeColor() );
656 mStrokeUnitsComboBox->setUnit( mItem->frameStrokeWidth().units() );
657 mStrokeWidthSpinBox->setValue( mItem->frameStrokeWidth().length() );
658 mFrameJoinStyleCombo->setPenJoinStyle( mItem->frameJoinStyle() );
659 mItemIdLineEdit->setText( mItem->id() );
660 mFrameGroupBox->setChecked( mItem->frameEnabled() );
661 mBackgroundGroupBox->setChecked( mItem->hasBackground() );
662 mBlendModeCombo->setBlendMode( mItem->blendMode() );
663 mOpacityWidget->setOpacity( mItem->itemOpacity() );
664 mItemRotationSpinBox->setValue( mItem->itemRotation() );
665 mExcludeFromPrintsCheckBox->setChecked( mItem->excludeFromExports() );
686 const QList< QgsPropertyOverrideButton * > buttons = findChildren< QgsPropertyOverrideButton * >();
693 void QgsLayoutItemPropertiesWidget::setValuesForGuiElements()
700 mBackgroundColorButton->setColorDialogTitle( tr(
"Select Background Color" ) );
701 mBackgroundColorButton->setAllowOpacity(
true );
702 mBackgroundColorButton->setContext( QStringLiteral(
"composer" ) );
703 mFrameColorButton->setColorDialogTitle( tr(
"Select Frame Color" ) );
704 mFrameColorButton->setAllowOpacity(
true );
705 mFrameColorButton->setContext( QStringLiteral(
"composer" ) );
707 setValuesForGuiPositionElements();
708 setValuesForGuiNonPositionElements();
712 void QgsLayoutItemPropertiesWidget::mBlendModeCombo_currentIndexChanged(
int index )
717 mItem->layout()->undoStack()->beginCommand( mItem, tr(
"Change Blend Mode" ) );
718 mItem->setBlendMode( mBlendModeCombo->blendMode() );
719 mItem->layout()->undoStack()->endCommand();
723 void QgsLayoutItemPropertiesWidget::opacityChanged(
double value )
728 mItem->setItemOpacity( value );
729 mItem->layout()->undoStack()->endCommand();
733 void QgsLayoutItemPropertiesWidget::mItemIdLineEdit_editingFinished()
738 mItem->setId( mItemIdLineEdit->text() );
739 mItemIdLineEdit->setText( mItem->id() );
740 mItem->layout()->undoStack()->endCommand();
744 void QgsLayoutItemPropertiesWidget::mPageSpinBox_valueChanged(
int )
746 mFreezePageSpin =
true;
747 changeItemPosition();
748 mFreezePageSpin =
false;
751 void QgsLayoutItemPropertiesWidget::mXPosSpin_valueChanged(
double )
753 mFreezeXPosSpin =
true;
754 changeItemPosition();
755 mFreezeXPosSpin =
false;
758 void QgsLayoutItemPropertiesWidget::mYPosSpin_valueChanged(
double )
760 mFreezeYPosSpin =
true;
761 changeItemPosition();
762 mFreezeYPosSpin =
false;
767 changeItemPosition();
770 void QgsLayoutItemPropertiesWidget::mWidthSpin_valueChanged(
double )
772 mFreezeWidthSpin =
true;
774 mFreezeWidthSpin =
false;
777 void QgsLayoutItemPropertiesWidget::mHeightSpin_valueChanged(
double )
779 mFreezeHeightSpin =
true;
781 mFreezeHeightSpin =
false;
789 void QgsLayoutItemPropertiesWidget::mUpperLeftCheckBox_stateChanged(
bool state )
798 setValuesForGuiPositionElements();
801 void QgsLayoutItemPropertiesWidget::mUpperMiddleCheckBox_stateChanged(
bool state )
809 setValuesForGuiPositionElements();
812 void QgsLayoutItemPropertiesWidget::mUpperRightCheckBox_stateChanged(
bool state )
820 setValuesForGuiPositionElements();
823 void QgsLayoutItemPropertiesWidget::mMiddleLeftCheckBox_stateChanged(
bool state )
831 setValuesForGuiPositionElements();
834 void QgsLayoutItemPropertiesWidget::mMiddleCheckBox_stateChanged(
bool state )
842 setValuesForGuiPositionElements();
845 void QgsLayoutItemPropertiesWidget::mMiddleRightCheckBox_stateChanged(
bool state )
853 setValuesForGuiPositionElements();
856 void QgsLayoutItemPropertiesWidget::mLowerLeftCheckBox_stateChanged(
bool state )
864 setValuesForGuiPositionElements();
867 void QgsLayoutItemPropertiesWidget::mLowerMiddleCheckBox_stateChanged(
bool state )
875 setValuesForGuiPositionElements();
878 void QgsLayoutItemPropertiesWidget::mLowerRightCheckBox_stateChanged(
bool state )
886 setValuesForGuiPositionElements();
889 void QgsLayoutItemPropertiesWidget::mItemRotationSpinBox_valueChanged(
double val )
894 mItem->setItemRotation( val,
true );
896 mItem->layout()->undoStack()->endCommand();
900 void QgsLayoutItemPropertiesWidget::mExcludeFromPrintsCheckBox_toggled(
bool checked )
904 mItem->layout()->undoStack()->beginCommand( mItem, checked ? tr(
"Exclude from Exports" ) : tr(
"Include in Exports" ) );
905 mItem->setExcludeFromExports( checked );
906 mItem->layout()->undoStack()->endCommand();
static void setLayoutItemVariables(QgsLayoutItem *item, const QVariantMap &variables)
Sets all layout item context variables for an item.
QgsVectorLayer * coverageLayer() const
Returns the current layout context coverage layer (if set).
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.
Exclude item from exports.
A common interface for layout designer dialogs and widgets.
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.
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.
QgsUnitTypes::LayoutUnit units() const
Returns the units for the point.
QgsVectorLayer * layer() const
Returns the vector layer associated with the layout's context.
QgsLayoutAtlas * layoutAtlas() const
Returns the atlas for the layout, if available.
const QgsLayout * layout() const
Returns the layout the object is attached to.
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...
double y() const
Returns y coordinate of point.
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.
double x() const
Returns x coordinate of point.
QgsUnitTypes::LayoutUnit units() const
Returns the units for the size.
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.
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.
const QgsLayoutMeasurementConverter & measurementConverter() const
Returns the layout measurement converter to be used in the layout.
An object for property widgets for layout items.
Background color adjustment.
QgsProject * project() const
The project associated with the layout.
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.
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.
double height() const
Returns the height of the size.
int indexOfScope(QgsExpressionContextScope *scope) const
Returns the index of the specified scope if it exists within the context.
DataDefinedProperty
Data defined properties for different item types.
double width() const
Returns the width of the size.